Skip to content

Commit

Permalink
[ASAP-430]- team coproduction from cms (#4280)
Browse files Browse the repository at this point in the history
* add query

* update data provider

* update frontend

* add tests

* 30d default range

* fix

* fix tests

* add tests

* add error test for team collaboration

* minor change

* modify test

* test for codecov

* sort collaboration byTeam list by team name
  • Loading branch information
AkosuaA authored May 21, 2024
1 parent b40ec43 commit f36082e
Show file tree
Hide file tree
Showing 27 changed files with 1,993 additions and 383 deletions.
28 changes: 26 additions & 2 deletions apps/crn-frontend/src/analytics/__tests__/Routes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import { RecoilRoot } from 'recoil';
import { Auth0Provider, WhenReady } from '../../auth/test-utils';
import { getAnalyticsLeadership } from '../leadership/api';
import { getTeamProductivity, getUserProductivity } from '../productivity/api';
import { getUserCollaboration } from '../collaboration/api';
import {
getTeamCollaboration,
getUserCollaboration,
} from '../collaboration/api';
import Analytics from '../Routes';

jest.mock('../leadership/api');
Expand All @@ -39,6 +42,10 @@ const mockGetUserProductivity = getUserProductivity as jest.MockedFunction<
const mockGetUserCollaboration = getUserCollaboration as jest.MockedFunction<
typeof getUserCollaboration
>;
const mockGetTeamCollaboration = getTeamCollaboration as jest.MockedFunction<
typeof getTeamCollaboration
>;

const renderPage = async (path: string) => {
const { container } = render(
<RecoilRoot>
Expand Down Expand Up @@ -183,7 +190,7 @@ describe('Collaboration', () => {
).toBeVisible();
});

it('renders error message when the response is not a 2XX', async () => {
it('renders error message when the user response is not a 2XX', async () => {
mockGetUserCollaboration.mockRejectedValueOnce(
new Error('Failed to fetch'),
);
Expand All @@ -199,4 +206,21 @@ describe('Collaboration', () => {

expect(screen.getByText(/Something went wrong/i)).toBeVisible();
});

it('renders error message when the team response is not a 2XX', async () => {
mockGetTeamCollaboration.mockRejectedValueOnce(
new Error('Failed to fetch'),
);
await renderPage(
analytics({})
.collaboration({})
.collaborationPath({ metric: 'team', type: 'within-team' }).$,
);

await waitFor(() => {
expect(mockGetTeamCollaboration).toHaveBeenCalled();
});

expect(screen.getByText(/Something went wrong/i)).toBeVisible();
});
});
229 changes: 6 additions & 223 deletions apps/crn-frontend/src/analytics/collaboration/TeamCollaboration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@asap-hub/react-components';
import { usePagination, usePaginationParams } from '../../hooks';
import { CollaborationProps } from './UserCollaboration';
import { useAnalyticsTeamCollaboration } from './state';

const getDataForType = (
data: TeamCollaborationResponse[],
Expand Down Expand Up @@ -33,229 +34,11 @@ const getDataForType = (
const TeamCollaboration: React.FC<CollaborationProps> = ({ type }) => {
const { currentPage, pageSize } = usePaginationParams();

const teamItems: TeamCollaborationResponse[] = [
{
id: '1',
name: 'Team A',
isInactive: true,
outputsCoProducedWithin: {
Article: 1,
Bioinformatics: 1,
Dataset: 0,
'Lab Resource': 1,
Protocol: 0,
},
outputsCoProducedAcross: {
byDocumentType: {
Article: 1,
Bioinformatics: 2,
Dataset: 1,
'Lab Resource': 0,
Protocol: 2,
},
byTeam: [
{
id: '2',
name: 'Team B',
isInactive: false,
Article: 1,
Bioinformatics: 2,
Dataset: 1,
'Lab Resource': 0,
Protocol: 2,
},
],
},
},
{
id: '2',
name: 'Team B',
isInactive: false,
outputsCoProducedWithin: {
Article: 1,
Bioinformatics: 2,
Dataset: 3,
'Lab Resource': 4,
Protocol: 5,
},
outputsCoProducedAcross: {
byDocumentType: {
Article: 1,
Bioinformatics: 2,
Dataset: 2,
'Lab Resource': 1,
Protocol: 2,
},
byTeam: [
{
id: '1',
name: 'Team A',
isInactive: true,
Article: 1,
Bioinformatics: 2,
Dataset: 1,
'Lab Resource': 0,
Protocol: 2,
},
{
id: '5',
name: 'Team E',
isInactive: false,
Article: 0,
Bioinformatics: 0,
Dataset: 1,
'Lab Resource': 1,
Protocol: 0,
},
{
id: '6',
name: 'Team F',
isInactive: false,
Article: 0,
Bioinformatics: 0,
Dataset: 1,
'Lab Resource': 0,
Protocol: 0,
},
],
},
},
{
id: '3',
name: 'Team C',
isInactive: false,
outputsCoProducedWithin: {
Article: 1,
Bioinformatics: 0,
Dataset: 3,
'Lab Resource': 0,
Protocol: 0,
},
outputsCoProducedAcross: {
byDocumentType: {
Article: 0,
Bioinformatics: 0,
Dataset: 0,
'Lab Resource': 0,
Protocol: 0,
},
byTeam: [],
},
},
{
id: '4',
name: 'Team D',
isInactive: false,
outputsCoProducedWithin: {
Article: 0,
Bioinformatics: 0,
Dataset: 0,
'Lab Resource': 0,
Protocol: 0,
},
outputsCoProducedAcross: {
byDocumentType: {
Article: 0,
Bioinformatics: 0,
Dataset: 0,
'Lab Resource': 0,
Protocol: 0,
},
byTeam: [],
},
},
{
id: '5',
name: 'Team E',
isInactive: false,
outputsCoProducedWithin: {
Article: 0,
Bioinformatics: 0,
Dataset: 0,
'Lab Resource': 0,
Protocol: 0,
},
outputsCoProducedAcross: {
byDocumentType: {
Article: 0,
Bioinformatics: 0,
Dataset: 1,
'Lab Resource': 1,
Protocol: 0,
},
byTeam: [
{
id: '2',
name: 'Team B',
isInactive: false,
Article: 0,
Bioinformatics: 0,
Dataset: 1,
'Lab Resource': 1,
Protocol: 0,
},
{
id: '6',
name: 'Team F',
isInactive: false,
Article: 0,
Bioinformatics: 0,
Dataset: 1,
'Lab Resource': 0,
Protocol: 0,
},
],
},
},
{
id: '6',
name: 'Team F',
isInactive: false,
outputsCoProducedWithin: {
Article: 0,
Bioinformatics: 0,
Dataset: 0,
'Lab Resource': 0,
Protocol: 0,
},
outputsCoProducedAcross: {
byDocumentType: {
Article: 0,
Bioinformatics: 0,
Dataset: 1,
'Lab Resource': 0,
Protocol: 0,
},
byTeam: [
{
id: '2',
name: 'Team B',
isInactive: false,
Article: 0,
Bioinformatics: 0,
Dataset: 1,
'Lab Resource': 0,
Protocol: 0,
},
{
id: '5',
name: 'Team E',
isInactive: false,
Article: 0,
Bioinformatics: 0,
Dataset: 1,
'Lab Resource': 0,
Protocol: 0,
},
],
},
},
];

const { items: data, total } = {
total: 6,
items: teamItems,
};
const { items: data, total } = useAnalyticsTeamCollaboration({
currentPage,
pageSize,
timeRange: '30d',
});

const { numberOfPages, renderPageHref } = usePagination(total, pageSize);

Expand Down
Loading

0 comments on commit f36082e

Please sign in to comment.