Skip to content

Commit

Permalink
test: fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-Torrent committed Jan 12, 2022
1 parent 73fdd7a commit 9633e96
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions cypress/fixtures/apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export const GRAASP_APP_ITEM = {
isPinned: false,
showChatbox: false,
},
tags: [],
};
1 change: 1 addition & 0 deletions cypress/fixtures/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export const GRAASP_DOCUMENT_ITEM = {
isPinned: false,
showChatbox: false,
},
tags: [],
};
1 change: 1 addition & 0 deletions cypress/fixtures/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@ export const PDF_ITEM_S3 = {
isPinned: false,
showChatbox: false,
},
tags: [],
};
1 change: 1 addition & 0 deletions cypress/fixtures/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const DEFAULT_FOLDER_ITEM = {
isPinned: false,
showChatbox: false,
},
tags: [],
};

export const ITEM_WITH_CHAT_BOX = {
Expand Down
2 changes: 2 additions & 0 deletions cypress/fixtures/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const GRAASP_LINK_ITEM = {
isPinned: false,
showChatbox: false,
},
tags: [],
};

export const YOUTUBE_LINK_ITEM = {
Expand All @@ -39,4 +40,5 @@ export const YOUTUBE_LINK_ITEM = {
isPinned: false,
showChatbox: false,
},
tags: [],
};
4 changes: 4 additions & 0 deletions cypress/integration/ws.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
mockGetChildren,
mockGetCurrentMember,
mockGetItem,
mockGetItemTags,
mockGetItemsTags,
} from '../support/server';

function beforeWs(visitRoute, wsClientStub) {
Expand All @@ -36,6 +38,8 @@ describe('Websocket interactions', () => {
mockGetCurrentMember(CURRENT_USER);
mockGetItem({ items, currentMember: CURRENT_USER }, false);
mockGetChildren(items);
mockGetItemTags(items);
mockGetItemsTags(items);
});

it('Displays create child update', () => {
Expand Down
6 changes: 6 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
mockGetChildren,
mockGetCurrentMember,
mockGetItem,
mockGetItemTags,
mockGetItemsTags,
mockGetMemberBy,
} from './server';

Expand All @@ -37,6 +39,10 @@ Cypress.Commands.add(
getItemError || getCurrentMemberError,
);

mockGetItemTags(items);

mockGetItemsTags(items);

mockGetChildren(cachedItems);

mockGetMemberBy(cachedMembers, getMemberError);
Expand Down
39 changes: 38 additions & 1 deletion cypress/support/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { API_ROUTES } from '@graasp/query-client';
import { getItemById, isChild } from '../../src/utils/item';
import { MEMBERS } from '../fixtures/members';
import { ID_FORMAT, parseStringToRegExp, EMAIL_FORMAT } from './utils';
import { DEFAULT_GET } from '../../src/api/utils';
import { DEFAULT_GET } from '../../src/api/utils';

const {
buildGetChildrenRoute,
buildGetItemRoute,
buildGetMemberBy,
buildGetItemTagsRoute,
GET_CURRENT_MEMBER_ROUTE,
buildDownloadFilesRoute,
} = API_ROUTES;
Expand Down Expand Up @@ -125,4 +126,40 @@ export const mockDefaultDownloadFile = (items, shouldThrowError) => {
).as('downloadFile');
};

export const mockGetItemTags = (items) => {
cy.intercept(
{
method: DEFAULT_GET.method,
url: new RegExp(`${API_HOST}/${buildGetItemTagsRoute(ID_FORMAT)}$`),
},
({ reply, url }) => {
const itemId = url.slice(API_HOST.length).split('/')[2];
const result = items.find(({ id }) => id === itemId).tags || [];
reply(result);
},
).as('getItemTags');
};

export const mockGetItemsTags = (items) => {
cy.intercept(
{
method: DEFAULT_GET.method,
url: new RegExp(`${API_HOST}/items/tags\\?id\\=`),
},
({ reply, url }) => {
const ids = url
.slice(API_HOST.length)
.split('=')
.splice(1)
.map((x) => x.replace('&id', ''));

const result = items.filter(({ id }) => ids.includes(id)).map(item => item.tags || []);
reply({
statusCode: StatusCodes.OK,
body: result,
});
},
).as('getItemsTags');
};

// bug: mockGetS3FileContent intercept static/js/bundle.js which fails tests
4 changes: 2 additions & 2 deletions src/components/common/Tree/CustomTreeItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const CustomTreeItem = ({
),
});
const { data: childrenTags, isLoading: isChildrenTagsLoading } = useItemsTags(
children?.map((child) => child.id),
children?.map((child) => child.id).toJS(),
{ enabled: Boolean(children) },
);

Expand All @@ -53,7 +53,7 @@ const CustomTreeItem = ({
}

const filteredChildren = children?.filter((_child, idx) =>
isHidden(childrenTags.get(idx).toJS()),
isHidden(childrenTags.get(idx)),
);

if (!filteredChildren?.size) {
Expand Down

0 comments on commit 9633e96

Please sign in to comment.