Skip to content

Commit

Permalink
refactor: Group data entries
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed Oct 17, 2023
1 parent 9e1db61 commit 7d0d2ed
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/group/components/GroupView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
import { render, screen } from 'tests/utils';
import { render, screen, within } from 'tests/utils';
import React from 'react';
import { useParams } from 'react-router-dom';
import * as terrasoApi from 'terraso-client-shared/terrasoApi/api';
Expand Down Expand Up @@ -98,6 +98,29 @@ test('GroupView: Display data', async () => {
},
})),
};
const accountMembership = {
id: 'user-id',
userRole: 'MEMBER',
membershipStatus: 'APPROVED',
};
const sharedResources = {
edges: Array(6)
.fill(0)
.map((item, index) => ({
node: {
source: {
id: `de-${index}`,
createdAt: '2022-05-20T16:25:21.536679+00:00',
name: `Data Entry ${index}`,
createdBy: { id: 'user-id', firstName: 'First', lastName: 'Last' },
description: `Description ${index}`,
size: 3456,
entryType: 'FILE',
visualizations: { edges: [] },
},
},
})),
};
terrasoApi.requestGraphQL.mockReturnValue(
Promise.resolve({
groups: {
Expand All @@ -109,6 +132,8 @@ test('GroupView: Display data', async () => {
website: 'https://www.group.org',
email: '[email protected]',
memberships,
accountMembership,
sharedResources,
},
},
],
Expand All @@ -135,6 +160,17 @@ test('GroupView: Display data', async () => {
).toBeInTheDocument();
expect(screen.getByText(/\+2/i)).toBeInTheDocument();
expect(
screen.getByRole('button', { name: 'Join Group' })
screen.getByRole('button', { name: 'Leave: Group name' })
).toBeInTheDocument();

// Shared Data
const sharedDataRegion = within(
screen.getByRole('region', { name: 'Shared files and Links' })
);
expect(
sharedDataRegion.getByRole('heading', { name: 'Shared files and Links' })
).toBeInTheDocument();
const entriesList = within(sharedDataRegion.getByRole('list'));
const items = entriesList.getAllByRole('listitem');
expect(items.length).toBe(6);
});
3 changes: 3 additions & 0 deletions src/group/groupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
import * as terrasoApi from 'terraso-client-shared/terrasoApi/api';
import { graphql } from 'terrasoApi/shared/graphqlSchema';

import { extractDataEntries } from 'sharedData/sharedDataUtils';

import type { Group } from './groupSlice';

export const fetchGroupToUpdate = (slug: string) => {
Expand Down Expand Up @@ -66,6 +68,7 @@ export const fetchGroupToView = async (slug: string) => {
..._.omit(['memberships', 'membershipsCount'], group),
membersInfo: extractMembersInfo(group),
accountMembership: extractAccountMembership(group),
dataEntries: extractDataEntries(group),
}));
};

Expand Down
2 changes: 2 additions & 0 deletions src/group/groupSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { Message } from 'terraso-client-shared/notifications/notificationsS
import { createAsyncThunk } from 'terraso-client-shared/store/utils';

import * as groupService from 'group/groupService';
import { setList } from 'sharedData/sharedDataSlice';

export type Group = {
slug: string;
Expand All @@ -45,6 +46,7 @@ export const fetchGroupView = createAsyncThunk(
async (slug: string, user, { dispatch }) => {
const group = await groupService.fetchGroupToView(slug);
dispatch(setMemberships(getMemberships([group])));
dispatch(setList(group.dataEntries));
return group;
}
);
Expand Down

0 comments on commit 7d0d2ed

Please sign in to comment.