Skip to content

Commit

Permalink
test: pass
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed May 15, 2023
1 parent 600f0e4 commit 915e9ec
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 211 deletions.
62 changes: 30 additions & 32 deletions cypress/e2e/header.cy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { getCurrentSession } from '@graasp/sdk';

import { HOME_PATH } from '../../src/config/paths';
import {
HEADER_MEMBER_MENU_BUTTON_ID,
HEADER_MEMBER_MENU_SEE_PROFILE_BUTTON_ID,
HEADER_MEMBER_MENU_SIGN_IN_BUTTON_ID,
HEADER_MEMBER_MENU_SIGN_OUT_BUTTON_ID,
buildMemberMenuItemId,
HEADER_MEMBER_MENU_SEE_PROFILE_BUTTON_ID, // HEADER_MEMBER_MENU_SIGN_IN_BUTTON_ID,
HEADER_MEMBER_MENU_SIGN_OUT_BUTTON_ID, // buildMemberMenuItemId,
} from '../../src/config/selectors';
import { MOCK_SESSIONS } from '../fixtures/members';
// import { MOCK_SESSIONS } from '../fixtures/members';
import { MEMBER_PROFILE_PATH, SIGN_IN_PATH } from '../support/constants';

// catch hook warning from react
Expand All @@ -33,15 +29,16 @@ describe('Header', () => {
cy.url().should('equal', MEMBER_PROFILE_PATH);
});

it('Sign in', () => {
cy.setUpApi();
cy.visit(HOME_PATH);
// todo: not available currently because cookie is httpOnly
// it('Sign in', () => {
// cy.setUpApi();
// cy.visit(HOME_PATH);

cy.wait('@getCurrentMember');
cy.get(`#${HEADER_MEMBER_MENU_BUTTON_ID}`).click();
cy.get(`#${HEADER_MEMBER_MENU_SIGN_IN_BUTTON_ID}`).click();
cy.url().should('contain', SIGN_IN_PATH);
});
// cy.wait('@getCurrentMember');
// cy.get(`#${HEADER_MEMBER_MENU_BUTTON_ID}`).click();
// cy.get(`#${HEADER_MEMBER_MENU_SIGN_IN_BUTTON_ID}`).click();
// cy.url().should('contain', SIGN_IN_PATH);
// });

it('Sign out', () => {
cy.setUpApi();
Expand All @@ -53,25 +50,26 @@ describe('Header', () => {
cy.url().should('equal', SIGN_IN_PATH);
});

it('Switch users', () => {
cy.setUpApi({ storedSessions: MOCK_SESSIONS });
cy.visit(HOME_PATH);
// todo: not available since cookie is httpOnly
// it('Switch users', () => {
// cy.setUpApi({ storedSessions: MOCK_SESSIONS });
// cy.visit(HOME_PATH);

cy.wait('@getCurrentMember');
cy.get(`#${HEADER_MEMBER_MENU_BUTTON_ID}`).click();
// cy.wait('@getCurrentMember');
// cy.get(`#${HEADER_MEMBER_MENU_BUTTON_ID}`).click();

MOCK_SESSIONS.forEach(({ id }) => {
cy.get(`#${buildMemberMenuItemId(id)}`).should('be.visible');
});
// MOCK_SESSIONS.forEach(({ id }) => {
// cy.get(`#${buildMemberMenuItemId(id)}`).should('be.visible');
// });

// switch to first user
cy.get(`#${buildMemberMenuItemId(MOCK_SESSIONS[0].id)}`)
.click()
.then(() => {
// session cookie should be different
const currentCookie = getCurrentSession();
expect(currentCookie).to.equal(MOCK_SESSIONS[0].token);
});
});
// // switch to first user
// cy.get(`#${buildMemberMenuItemId(MOCK_SESSIONS[0].id)}`)
// .click()
// .then(() => {
// // session cookie should be different
// const currentCookie = getCurrentSession();
// expect(currentCookie).to.equal(MOCK_SESSIONS[0].token);
// });
// });
});
});
4 changes: 2 additions & 2 deletions cypress/e2e/pinned.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ describe('Pinned Items', () => {
});

it('If no items are pinned toggle pinned should not exist', () => {
const parent = FOLDER_WITH_SUBFOLDER_ITEM.items[0];
const parent = FOLDER_WITH_SUBFOLDER_ITEM.items[2];
cy.visit(buildMainPath({ rootId: parent.id }));

cy.wait('@getChildren');
cy.wait(['@getChildren', '@getItemTags']);
cy.get(`#${ITEM_PINNED_BUTTON_ID}`).should('not.exist');
cy.get(`#${ITEM_PINNED_ID}`).should('not.exist');
});
Expand Down
12 changes: 6 additions & 6 deletions cypress/fixtures/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export const GRAASP_APP_ITEM: AppItemType = {
name: 'graasp app',
description: 'a description for graasp app',
path: 'baefbd2a_5688_11eb_ae93_0242ac130002',
creator: CURRENT_USER.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
creator: CURRENT_USER,
createdAt: new Date(),
updatedAt: new Date(),
extra: {
app: { url: 'https://graasp.eu' },
},
Expand Down Expand Up @@ -71,9 +71,9 @@ export const APP_USING_CONTEXT_ITEM: MockItem = {
url: `${API_HOST}/${buildAppItemLinkForTest('app.html')}`,
},
},
creator: CURRENT_USER.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
creator: CURRENT_USER,
createdAt: new Date(),
updatedAt: new Date(),
};

export const GRAASP_APP_ITEMS_FIXTURE = [
Expand Down
17 changes: 17 additions & 0 deletions cypress/fixtures/chat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ChatMessage } from '@graasp/sdk';

import { v4 } from 'uuid';

import { ITEM_WITH_CHAT_BOX } from './items';

// eslint-disable-next-line import/prefer-default-export
export const ITEM_CHAT_MESSAGES: ChatMessage[] = [
{
id: v4(),
item: ITEM_WITH_CHAT_BOX,
creator: ITEM_WITH_CHAT_BOX.creator,
createdAt: new Date(),
updatedAt: new Date(),
body: 'a message',
},
];
36 changes: 18 additions & 18 deletions cypress/fixtures/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export const GRAASP_DOCUMENT_ITEM: DocumentItemType = {
name: 'graasp text',
description: 'a description for graasp text',
path: 'ecafbd2a_5688_12eb_ae93_0242ac130002',
creator: CURRENT_USER.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
creator: CURRENT_USER,
createdAt: new Date(),
updatedAt: new Date(),
extra: buildDocumentExtra({
content: '<h1>Some Title</h1>',
}),
Expand All @@ -29,9 +29,9 @@ export const GRAASP_DOCUMENT_ITEM_VISIBLE: DocumentItemType = {
name: 'Visible document',
description: 'a description for graasp text',
path: 'ecafbd2a_5688_11eb_ae93_0242ac130008.fdf09f5a_5688_11eb_ae93_0242ac130009',
creator: CURRENT_USER.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
creator: CURRENT_USER,
createdAt: new Date(),
updatedAt: new Date(),
extra: buildDocumentExtra({
content: '<h1>Visible document</h1>',
}),
Expand All @@ -49,9 +49,9 @@ export const GRAASP_DOCUMENT_ITEM_HIDDEN: DocumentItemType & {
name: 'Hidden document',
description: 'a description for graasp text',
path: 'ecafbd2a_5688_11eb_ae93_0242ac130008.fdf09f5a_5688_11eb_ae93_0242ac130010',
creator: CURRENT_USER.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
creator: CURRENT_USER,
createdAt: new Date(),
updatedAt: new Date(),
extra: buildDocumentExtra({
content: '<h1>Hidden document</h1>',
}),
Expand All @@ -74,9 +74,9 @@ export const GRAASP_DOCUMENT_ITEM_PUBLIC_VISIBLE: DocumentItemType & {
name: 'Public visible document',
description: 'a description for graasp text',
path: 'ecafbd2a_5688_11eb_ae93_0242ac130008.fdf09f5a_5688_11eb_ae93_0242ac130009',
creator: CURRENT_USER.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
creator: CURRENT_USER,
createdAt: new Date(),
updatedAt: new Date(),
extra: buildDocumentExtra({
content: '<h1>Public visible document</h1>',
}),
Expand All @@ -99,9 +99,9 @@ export const GRAASP_DOCUMENT_ITEM_PUBLIC_HIDDEN: DocumentItemType & {
name: 'Public hidden document',
description: 'a description for graasp text',
path: 'ecafbd2a_5688_11eb_ae93_0242ac130008.fdf09f5a_5688_11eb_ae93_0242ac130010',
creator: CURRENT_USER.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
creator: CURRENT_USER,
createdAt: new Date(),
updatedAt: new Date(),
extra: buildDocumentExtra({
content: '<h1>Public hidden document</h1>',
}),
Expand All @@ -125,9 +125,9 @@ export const GRAASP_DOCUMENT_ITEM_WITH_CHAT_BOX: DocumentItemType = {
name: 'graasp text',
description: 'a description for graasp text',
path: 'ecafbf2a_5688_12eb_ae93_0242ac130002',
creator: CURRENT_USER.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
creator: CURRENT_USER,
createdAt: new Date(),
updatedAt: new Date(),
extra: buildDocumentExtra({
content: '<h1>Some Title</h1>',
}),
Expand Down
36 changes: 18 additions & 18 deletions cypress/fixtures/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export const IMAGE_ITEM_DEFAULT: LocalFileItemType & { filepath: string } = {
description: 'a default image description',
type: ItemType.LOCAL_FILE,
path: 'bd5519a2_5ba9_4305_b221_185facbe6a99',
creator: CURRENT_USER.id,
createdAt: '2021-03-16T16:00:50.968Z',
updatedAt: '2021-03-16T16:00:52.655Z',
creator: CURRENT_USER,
createdAt: new Date(Date.parse('2021-03-16T16:00:50.968Z')),
updatedAt: new Date(Date.parse('2021-03-16T16:00:52.655Z')),
extra: buildFileExtra({
name: 'icon.png',
path: '9a95/e2e1/2a7b-1615910428274',
Expand All @@ -42,9 +42,9 @@ export const VIDEO_ITEM_DEFAULT: LocalFileItemType & { filepath: string } = {
description: 'a default video description',
type: ItemType.LOCAL_FILE,
path: 'qd5519a2_5ba9_4305_b221_185facbe6a99',
creator: CURRENT_USER.id,
createdAt: '2021-03-16T16:00:50.968Z',
updatedAt: '2021-03-16T16:00:52.655Z',
creator: CURRENT_USER,
createdAt: new Date(Date.parse('2021-03-16T16:00:50.968Z')),
updatedAt: new Date(Date.parse('2021-03-16T16:00:52.655Z')),
extra: buildFileExtra({
name: 'video.mp4',
path: '9a95/e2e1/2a7b-1615910428274',
Expand All @@ -65,9 +65,9 @@ export const PDF_ITEM_DEFAULT: LocalFileItemType & { filepath: string } = {
description: 'a default pdf description',
type: ItemType.LOCAL_FILE,
path: 'cd5519a2_5ba9_4305_b221_185facbe6a99',
creator: CURRENT_USER.id,
createdAt: '2021-03-16T16:00:50.968Z',
updatedAt: '2021-03-16T16:00:52.655Z',
creator: CURRENT_USER,
createdAt: new Date(Date.parse('2021-03-16T16:00:50.968Z')),
updatedAt: new Date(Date.parse('2021-03-16T16:00:52.655Z')),
extra: buildFileExtra({
name: 'doc.pdf',
path: '9a95/e2e1/2a7b-1615910428274',
Expand All @@ -88,9 +88,9 @@ export const IMAGE_ITEM_S3: S3FileItemType = {
description: 'a default image description',
type: ItemType.S3_FILE,
path: 'ad5519a2_5ba9_4305_b221_185facbe6a99',
creator: CURRENT_USER.id,
createdAt: '2021-03-16T16:00:50.968Z',
updatedAt: '2021-03-16T16:00:52.655Z',
creator: CURRENT_USER,
createdAt: new Date(Date.parse('2021-03-16T16:00:50.968Z')),
updatedAt: new Date(Date.parse('2021-03-16T16:00:52.655Z')),
extra: buildS3FileExtra({
name: 'mock-image',
path: MOCK_IMAGE_URL, // for testing
Expand All @@ -109,9 +109,9 @@ export const VIDEO_ITEM_S3: S3FileItemType = {
description: 'a default video description',
type: ItemType.S3_FILE,
path: 'qd5519a2_5ba9_4305_b221_185facbe6a93',
creator: CURRENT_USER.id,
createdAt: '2021-03-16T16:00:50.968Z',
updatedAt: '2021-03-16T16:00:52.655Z',
creator: CURRENT_USER,
createdAt: new Date(Date.parse('2021-03-16T16:00:50.968Z')),
updatedAt: new Date(Date.parse('2021-03-16T16:00:52.655Z')),
extra: buildS3FileExtra({
name: 'mock-video',
path: MOCK_VIDEO_URL, // for testing
Expand All @@ -130,9 +130,9 @@ export const PDF_ITEM_S3: S3FileItemType = {
description: 'a default pdf description',
type: ItemType.S3_FILE,
path: 'bd5519a2_5ba9_4305_b221_185facbe6a99',
creator: CURRENT_USER.id,
createdAt: '2021-03-16T16:00:50.968Z',
updatedAt: '2021-03-16T16:00:52.655Z',
creator: CURRENT_USER,
createdAt: new Date(Date.parse('2021-03-16T16:00:50.968Z')),
updatedAt: new Date(Date.parse('2021-03-16T16:00:52.655Z')),
extra: buildS3FileExtra({
name: 'mock-pdf',
path: MOCK_PDF_URL, // for testing
Expand Down
12 changes: 7 additions & 5 deletions cypress/fixtures/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const PUBLIC_TAG_ID = Cypress.env('PUBLIC_TAG_ID');
export type MockItem = DiscriminatedItem & {
// for testing
filepath?: string;
// path to a fixture file in cypress
filefixture?: string;
memberships?: { memberId: string }[];
tags?: { tagId: string }[];
};
Expand All @@ -27,17 +29,17 @@ export const DEFAULT_FOLDER_ITEM: MockItem = {
childrenOrder: [],
},
},
creator: CURRENT_USER.id,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
creator: CURRENT_USER,
createdAt: new Date(),
updatedAt: new Date(),
type: ItemType.FOLDER,
settings: {
isPinned: false,
showChatbox: false,
},
};

export const ITEM_WITH_CHAT_BOX = {
export const ITEM_WITH_CHAT_BOX: MockItem = {
...DEFAULT_FOLDER_ITEM,
id: 'ecafbd2a-5688-11eb-ae93-0242ac130002',
name: 'parent folder',
Expand All @@ -48,7 +50,7 @@ export const ITEM_WITH_CHAT_BOX = {
},
};

export const ITEM_WITHOUT_CHAT_BOX = {
export const ITEM_WITHOUT_CHAT_BOX: MockItem = {
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130003',
name: 'child folder',
Expand Down
12 changes: 6 additions & 6 deletions cypress/fixtures/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export const GRAASP_LINK_ITEM: EmbeddedLinkItemType = {
name: 'graasp link',
description: 'a description for graasp link',
path: 'ecafbd2a_5688_11eb_ae93_0242ac130002',
creator: CURRENT_USER.id,
createdAt: new Date().toDateString(),
updatedAt: new Date().toDateString(),
creator: CURRENT_USER,
createdAt: new Date(),
updatedAt: new Date(),
extra: buildEmbeddedLinkExtra({
url: 'https://graasp.eu',
thumbnails: ['https://graasp.eu/img/epfl/logo-tile.png'],
Expand Down Expand Up @@ -44,9 +44,9 @@ export const YOUTUBE_LINK_ITEM: EmbeddedLinkItemType = {
type: ItemType.LINK,
name: 'graasp youtube link',
description: 'a description for graasp youtube link',
creator: CURRENT_USER.id,
createdAt: new Date().toDateString(),
updatedAt: new Date().toDateString(),
creator: CURRENT_USER,
createdAt: new Date(),
updatedAt: new Date(),
path: 'gcafbd2a_5688_11eb_ae93_0242ac130002',
extra: buildEmbeddedLinkExtra({
url: 'https://www.youtube.com/watch?v=FmiEgBMTPLo',
Expand Down
Loading

0 comments on commit 915e9ec

Please sign in to comment.