Skip to content

Commit

Permalink
test: add test when viewing links
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Mar 23, 2021
1 parent 63c81d3 commit 3661d42
Show file tree
Hide file tree
Showing 44 changed files with 1,112 additions and 693 deletions.
3 changes: 3 additions & 0 deletions cypress/fixtures/files.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ITEM_TYPES, MIME_TYPES } from '../../src/config/constants';

export const ICON_FILEPATH = 'files/icon.png';
export const TEXT_FILEPATH = 'files/sometext.txt';

export const IMAGE_ITEM_DEFAULT = {
id: 'bd5519a2-5ba9-4305-b221-185facbe6a99',
name: 'icon.png',
Expand Down
2 changes: 1 addition & 1 deletion cypress/fixtures/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const MEMBERS = {
BOB: { id: 'bob-id', name: 'bob', email: '[email protected]' },
};

export const SIMPLE_ITEMS = [
export const SAMPLE_ITEMS = [
{
...DEFAULT_ITEM,
id: 'ecafbd2a-5688-11eb-ae93-0242ac130002',
Expand Down
46 changes: 46 additions & 0 deletions cypress/fixtures/links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ITEM_TYPES } from '../../src/config/constants';

export const GRAASP_LINK_ITEM = {
id: 'ecafbd2a-5688-11eb-ae91-0242ac130002',
type: ITEM_TYPES.LINK,
name: 'graasp link',
description: 'a description for graasp link',
path: 'ecafbd2a_5688_11eb_ae93_0242ac130002',
extra: {
embeddedLinkItem: {
url: 'https://graasp.eu',
thumbnails: ['https://graasp.eu/img/epfl/logo-tile.png'],
icons: [
'https://graasp.eu/cdn/img/epfl/favicons/favicon-32x32.png?v=yyxJ380oWY',
],
},
},
};

export const YOUTUBE_LINK_ITEM = {
id: 'gcafbd2a-5688-11eb-ae93-0242ac130002',
type: ITEM_TYPES.LINK,
name: 'graasp youtube link',
description: 'a description for graasp youtube link',
path: 'gcafbd2a_5688_11eb_ae93_0242ac130002',
extra: {
embeddedLinkItem: {
url: 'https://www.youtube.com/watch?v=FmiEgBMTPLo',
html:
'<div style="left: 0; width: 100%; height: 0; position: relative; padding-bottom: 56.25%;"><iframe src="https://www.youtube.com/embed/FmiEgBMTPLo" style="border: 0; top: 0; left: 0; width: 100%; height: 100%; position: absolute;" allowfullscreen scrolling="no" allow="encrypted-media"></iframe></div>',
thumbnails: ['https://i.ytimg.com/vi/FmiEgBMTPLo/maxresdefault.jpg'],
icons: ['https://www.youtube.com/s/desktop/f0ff6c1d/img/favicon_96.png'],
},
},
};

export const INVALID_LINK_ITEM = {
type: ITEM_TYPES.LINK,
name: 'graasp youtube link',
description: 'a description for graasp youtube link',
extra: {
embeddedLinkItem: {
url: 'wrong link',
},
},
};
30 changes: 15 additions & 15 deletions cypress/integration/item/copy/gridCopyItem.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ITEM_MENU_BUTTON_CLASS,
ITEM_MENU_COPY_BUTTON_CLASS,
} from '../../../../src/config/selectors';
import { SIMPLE_ITEMS } from '../../../fixtures/items';
import { SAMPLE_ITEMS } from '../../../fixtures/items';

const copyItem = (id, toItemId) => {
const menuSelector = `#${buildItemCard(id)} .${ITEM_MENU_BUTTON_CLASS}`;
Expand All @@ -17,13 +17,13 @@ const copyItem = (id, toItemId) => {

describe('Copy Item in Grid', () => {
it('copy item on Home', () => {
cy.setUpApi({ items: SIMPLE_ITEMS });
cy.setUpApi({ items: SAMPLE_ITEMS });
cy.visit(HOME_PATH);
cy.switchMode(MODES.GRID);

// copy
const { id: copyItemId } = SIMPLE_ITEMS[0];
const { id: toItem } = SIMPLE_ITEMS[1];
const { id: copyItemId } = SAMPLE_ITEMS[0];
const { id: toItem } = SAMPLE_ITEMS[1];
copyItem(copyItemId, toItem);

cy.wait('@copyItem').then(({ response: { body } }) => {
Expand All @@ -36,16 +36,16 @@ describe('Copy Item in Grid', () => {
});

it('copy item in item', () => {
cy.setUpApi({ items: SIMPLE_ITEMS });
const { id } = SIMPLE_ITEMS[0];
cy.setUpApi({ items: SAMPLE_ITEMS });
const { id } = SAMPLE_ITEMS[0];

// go to children item
cy.visit(buildItemPath(id));
cy.switchMode(MODES.GRID);

// move
const { id: copyItemId } = SIMPLE_ITEMS[2];
const { id: toItem } = SIMPLE_ITEMS[3];
const { id: copyItemId } = SAMPLE_ITEMS[2];
const { id: toItem } = SAMPLE_ITEMS[3];
copyItem(copyItemId, toItem);

cy.wait('@copyItem').then(({ response: { body } }) => {
Expand All @@ -58,15 +58,15 @@ describe('Copy Item in Grid', () => {
});

it('copy item to Home', () => {
cy.setUpApi({ items: SIMPLE_ITEMS });
const { id } = SIMPLE_ITEMS[0];
cy.setUpApi({ items: SAMPLE_ITEMS });
const { id } = SAMPLE_ITEMS[0];

// go to children item
cy.visit(buildItemPath(id));
cy.switchMode(MODES.GRID);

// move
const { id: copyItemId } = SIMPLE_ITEMS[2];
const { id: copyItemId } = SAMPLE_ITEMS[2];
const toItem = ROOT_ID;
copyItem(copyItemId, toItem);

Expand All @@ -81,16 +81,16 @@ describe('Copy Item in Grid', () => {

describe('Errors handling', () => {
it('error while moving item does not create in interface', () => {
cy.setUpApi({ items: SIMPLE_ITEMS, copyItemError: true });
const { id } = SIMPLE_ITEMS[0];
cy.setUpApi({ items: SAMPLE_ITEMS, copyItemError: true });
const { id } = SAMPLE_ITEMS[0];

// go to children item
cy.visit(buildItemPath(id));
cy.switchMode(MODES.GRID);

// move
const { id: copyItemId } = SIMPLE_ITEMS[2];
const { id: toItem } = SIMPLE_ITEMS[0];
const { id: copyItemId } = SAMPLE_ITEMS[2];
const { id: toItem } = SAMPLE_ITEMS[0];
copyItem(copyItemId, toItem);

cy.wait('@copyItem').then(({ response: { body } }) => {
Expand Down
30 changes: 15 additions & 15 deletions cypress/integration/item/copy/listCopyItem.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ITEM_MENU_BUTTON_CLASS,
ITEM_MENU_COPY_BUTTON_CLASS,
} from '../../../../src/config/selectors';
import { SIMPLE_ITEMS } from '../../../fixtures/items';
import { SAMPLE_ITEMS } from '../../../fixtures/items';

const copyItem = (id, toItemId) => {
const menuSelector = `#${buildItemsTableRowId(
Expand All @@ -19,15 +19,15 @@ const copyItem = (id, toItemId) => {

describe('Copy Item in List', () => {
it('copy item on Home', () => {
cy.setUpApi({ items: SIMPLE_ITEMS });
cy.setUpApi({ items: SAMPLE_ITEMS });
cy.visit(HOME_PATH);
if (DEFAULT_MODE !== MODES.LIST) {
cy.switchMode(MODES.LIST);
}

// copy
const { id: copyItemId } = SIMPLE_ITEMS[0];
const { id: toItem } = SIMPLE_ITEMS[1];
const { id: copyItemId } = SAMPLE_ITEMS[0];
const { id: toItem } = SAMPLE_ITEMS[1];
copyItem(copyItemId, toItem);

cy.wait('@copyItem').then(({ response: { body } }) => {
Expand All @@ -40,8 +40,8 @@ describe('Copy Item in List', () => {
});

it('copy item in item', () => {
cy.setUpApi({ items: SIMPLE_ITEMS });
const { id } = SIMPLE_ITEMS[0];
cy.setUpApi({ items: SAMPLE_ITEMS });
const { id } = SAMPLE_ITEMS[0];

// go to children item
cy.visit(buildItemPath(id));
Expand All @@ -50,8 +50,8 @@ describe('Copy Item in List', () => {
}

// copy
const { id: copyItemId } = SIMPLE_ITEMS[2];
const { id: toItem } = SIMPLE_ITEMS[3];
const { id: copyItemId } = SAMPLE_ITEMS[2];
const { id: toItem } = SAMPLE_ITEMS[3];
copyItem(copyItemId, toItem);

cy.wait('@copyItem').then(({ response: { body } }) => {
Expand All @@ -64,8 +64,8 @@ describe('Copy Item in List', () => {
});

it('copy item to Home', () => {
cy.setUpApi({ items: SIMPLE_ITEMS });
const { id } = SIMPLE_ITEMS[0];
cy.setUpApi({ items: SAMPLE_ITEMS });
const { id } = SAMPLE_ITEMS[0];

// go to children item
cy.visit(buildItemPath(id));
Expand All @@ -74,7 +74,7 @@ describe('Copy Item in List', () => {
}

// copy
const { id: copyItemId } = SIMPLE_ITEMS[2];
const { id: copyItemId } = SAMPLE_ITEMS[2];
const toItem = ROOT_ID;
copyItem(copyItemId, toItem);

Expand All @@ -89,8 +89,8 @@ describe('Copy Item in List', () => {

describe('Errors handling', () => {
it('error while moving item does not create in interface', () => {
cy.setUpApi({ items: SIMPLE_ITEMS, copyItemError: true });
const { id } = SIMPLE_ITEMS[0];
cy.setUpApi({ items: SAMPLE_ITEMS, copyItemError: true });
const { id } = SAMPLE_ITEMS[0];

// go to children item
cy.visit(buildItemPath(id));
Expand All @@ -99,8 +99,8 @@ describe('Copy Item in List', () => {
}

// copy
const { id: copyItemId } = SIMPLE_ITEMS[2];
const { id: toItem } = SIMPLE_ITEMS[0];
const { id: copyItemId } = SAMPLE_ITEMS[2];
const { id: toItem } = SAMPLE_ITEMS[0];
copyItem(copyItemId, toItem);

cy.wait('@copyItem').then(({ response: { body } }) => {
Expand Down
47 changes: 47 additions & 0 deletions cypress/integration/item/create/createFile.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { MODES, DEFAULT_MODE } from '../../../../src/config/constants';
import { buildItemPath, HOME_PATH } from '../../../../src/config/paths';
import { IMAGE_ITEM_DEFAULT, IMAGE_ITEM_S3 } from '../../../fixtures/files';
import { SAMPLE_ITEMS } from '../../../fixtures/items';
import { CREATE_ITEM_PAUSE } from '../../../support/constants';
import { createItem } from './utils';

describe('Create File', () => {
it('create file on Home', () => {
cy.setUpApi();
cy.visit(HOME_PATH);

if (DEFAULT_MODE !== MODES.LIST) {
cy.switchMode(MODES.LIST);
}

// create
createItem(IMAGE_ITEM_DEFAULT, MODES.LIST);

cy.wait('@uploadItem').then(() => {
// check item is created and displayed
cy.wait(CREATE_ITEM_PAUSE);
// should update view
cy.wait('@getOwnItems');
});
});

it('create file in item', () => {
cy.setUpApi({ items: SAMPLE_ITEMS });
const { id } = SAMPLE_ITEMS[0];

// go to children item
cy.visit(buildItemPath(id));

if (DEFAULT_MODE !== MODES.LIST) {
cy.switchMode(MODES.LIST);
}

// create
createItem(IMAGE_ITEM_S3, MODES.LIST);

cy.wait('@uploadItem').then(() => {
// should update view
cy.wait('@getItem');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ import { MODES, DEFAULT_MODE } from '../../../../src/config/constants';
import { buildItemPath, HOME_PATH } from '../../../../src/config/paths';
import {
buildItemsTableRowId,
CREATE_ITEM_BUTTON_ID,
ITEM_FORM_CONFIRM_BUTTON_ID,
} from '../../../../src/config/selectors';
import { CREATED_ITEM, SIMPLE_ITEMS } from '../../../fixtures/items';
import { SAMPLE_ITEMS } from '../../../fixtures/items';
import { GRAASP_LINK_ITEM, INVALID_LINK_ITEM } from '../../../fixtures/links';
import { CREATE_ITEM_PAUSE } from '../../../support/constants';
import { createItem } from './utils';

const createItem = (payload) => {
cy.get(`#${CREATE_ITEM_BUTTON_ID}`).click();

cy.fillItemModal(payload);
};

describe('Create Item in List', () => {
it('create item on Home', () => {
describe('Create Link', () => {
it('create link on Home', () => {
cy.setUpApi();
cy.visit(HOME_PATH);

Expand All @@ -23,7 +19,7 @@ describe('Create Item in List', () => {
}

// create
createItem(CREATED_ITEM);
createItem(GRAASP_LINK_ITEM, { mode: MODES.LIST });

cy.wait('@postItem').then(({ response: { body } }) => {
// check item is created and displayed
Expand All @@ -32,9 +28,9 @@ describe('Create Item in List', () => {
});
});

it('create item in item', () => {
cy.setUpApi({ items: SIMPLE_ITEMS });
const { id } = SIMPLE_ITEMS[0];
it('create space in item', () => {
cy.setUpApi({ items: SAMPLE_ITEMS });
const { id } = SAMPLE_ITEMS[0];

// go to children item
cy.visit(buildItemPath(id));
Expand All @@ -44,7 +40,7 @@ describe('Create Item in List', () => {
}

// create
createItem(CREATED_ITEM);
createItem(GRAASP_LINK_ITEM, { mode: MODES.LIST });

cy.wait('@postItem').then(({ response: { body } }) => {
// check item is created and displayed
Expand All @@ -53,9 +49,9 @@ describe('Create Item in List', () => {
});

describe('Errors handling', () => {
it('error while creating item does not create in interface', () => {
cy.setUpApi({ items: SIMPLE_ITEMS, postItemError: true });
const { id } = SIMPLE_ITEMS[0];
it('cannot add an invalid link', () => {
cy.setUpApi({ items: SAMPLE_ITEMS });
const { id } = SAMPLE_ITEMS[0];

// go to children item
cy.visit(buildItemPath(id));
Expand All @@ -65,12 +61,13 @@ describe('Create Item in List', () => {
}

// create
createItem(CREATED_ITEM);
createItem(INVALID_LINK_ITEM, { mode: MODES.LIST, confirm: false });

cy.wait('@postItem').then(({ response: { body } }) => {
// check item is created and displayed
cy.get(`#${buildItemsTableRowId(body.id)}`).should('not.exist');
});
cy.get(`#${ITEM_FORM_CONFIRM_BUTTON_ID}`).should(
'have.prop',
'disabled',
true,
);
});
});
});
Loading

0 comments on commit 3661d42

Please sign in to comment.