Skip to content

Commit

Permalink
feat: add item caption
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Jun 17, 2021
1 parent 08da676 commit a6e8a72
Show file tree
Hide file tree
Showing 22 changed files with 178 additions and 139 deletions.
1 change: 0 additions & 1 deletion cypress/fixtures/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { buildDocumentExtra } from '../../src/utils/itemExtra';
import { CURRENT_USER } from './members';
import { DEFAULT_FOLDER_ITEM } from './items';

// eslint-disable-next-line import/prefer-default-export
export const GRAASP_DOCUMENT_ITEM = {
id: 'ecafbd2a-5688-12eb-ae91-0242ac130002',
type: ITEM_TYPES.DOCUMENT,
Expand Down
3 changes: 2 additions & 1 deletion cypress/fixtures/files.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ITEM_TYPES, MIME_TYPES } from '../../src/enums';
import { buildFileExtra, buildS3FileExtra } from '../../src/utils/itemExtra';
import { CURRENT_USER } from './members';

export const ICON_FILEPATH = 'files/icon.png';
export const TEXT_FILEPATH = 'files/sometext.txt';
Expand All @@ -10,7 +11,7 @@ export const IMAGE_ITEM_DEFAULT = {
description: 'a default image description',
type: ITEM_TYPES.FILE,
path: 'bd5519a2_5ba9_4305_b221_185facbe6a99',
creator: 'b792fc1b-d533-41de-9706-b98f60a29cdb',
creator: CURRENT_USER.id,
createdAt: '2021-03-16T16:00:50.968Z',
updatedAt: '2021-03-16T16:00:52.655Z',
extra: buildFileExtra({
Expand Down
3 changes: 0 additions & 3 deletions cypress/fixtures/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { CURRENT_USER, MEMBERS } from './members';
import { DEFAULT_TAGS, ITEM_LOGIN_TAG } from './itemTags';

export const DEFAULT_FOLDER_ITEM = {
description: '',
extra: {},
creator: CURRENT_USER.id,
type: ITEM_TYPES.FOLDER,
Expand All @@ -14,15 +13,13 @@ export const DEFAULT_FOLDER_ITEM = {
export const CREATED_ITEM = {
name: 'created item',
type: ITEM_TYPES.FOLDER,
description: 'I am a newly created element',
extra: {
image: 'someimageurl',
},
};

export const EDITED_FIELDS = {
name: 'new name',
description: 'new description',
};

export const SAMPLE_ITEMS = {
Expand Down
28 changes: 19 additions & 9 deletions cypress/integration/item/edit/editApp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { EDITED_FIELDS } from '../../../fixtures/items';
import { GRAASP_LINK_ITEM } from '../../../fixtures/links';
import { EDIT_ITEM_PAUSE } from '../../../support/constants';
import { editItem } from './utils';
import { editCaptionFromViewPage, editItem } from './utils';

const url = 'http://localhost:3334';
const newFields = {
Expand All @@ -20,6 +20,20 @@ const newFields = {
};

describe('Edit App', () => {
describe('View Page', () => {
it('edit caption', () => {
cy.setUpApi({ items: [GRAASP_APP_ITEM] });
cy.visit(buildItemPath(GRAASP_APP_ITEM.id));
const caption = 'new caption';
editCaptionFromViewPage({ caption });
cy.wait(`@editItem`).then(({ request: { url: endpointUrl, body } }) => {
expect(endpointUrl).to.contain(GRAASP_APP_ITEM.id);
// caption content might be wrapped with html tags
expect(body?.description).to.contain(caption);
});
});
});

describe('List', () => {
it('edit app on Home', () => {
const itemToEdit = GRAASP_APP_ITEM;
Expand All @@ -42,13 +56,12 @@ describe('Edit App', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description },
body: { id, name },
},
}) => {
// check item is edited and updated
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(newFields.name);
expect(description).to.equal(newFields.description);
cy.wait(EDIT_ITEM_PAUSE);
cy.wait('@getOwnItems');
},
Expand Down Expand Up @@ -78,14 +91,13 @@ describe('Edit App', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description },
body: { id, name },
},
}) => {
// check item is edited and updated
cy.wait(EDIT_ITEM_PAUSE);
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(newFields.name);
expect(description).to.equal(newFields.description);
cy.get('@getItem').its('response.url').should('contain', parent.id);
},
);
Expand All @@ -112,15 +124,14 @@ describe('Edit App', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description },
body: { id, name },
},
}) => {
// check item is edited and updated
cy.wait(EDIT_ITEM_PAUSE);
cy.get('@getOwnItems');
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(newFields.name);
expect(description).to.equal(newFields.description);
},
);
});
Expand All @@ -146,14 +157,13 @@ describe('Edit App', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description },
body: { id, name },
},
}) => {
// check item is edited and updated
cy.wait(EDIT_ITEM_PAUSE);
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(newFields.name);
expect(description).to.equal(newFields.description);
cy.get('@getItem').its('response.url').should('contain', parent.id);
},
);
Expand Down
20 changes: 8 additions & 12 deletions cypress/integration/item/edit/editDocument.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const newFields = {

describe('Edit Document', () => {
describe('List', () => {
it('edit document on Home', () => {
it('edit on Home', () => {
cy.setUpApi({ items: [GRAASP_DOCUMENT_ITEM, GRAASP_LINK_ITEM] });
cy.visit(HOME_PATH);

Expand All @@ -46,21 +46,20 @@ describe('Edit Document', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description, extra },
body: { id, name, extra },
},
}) => {
// check item is edited and updated
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(newFields.name);
expect(description).to.equal(newFields.description);
expect(getDocumentExtra(extra)?.content).to.contain(content);
cy.wait(EDIT_ITEM_PAUSE);
cy.wait('@getOwnItems');
},
);
});

it('edit folder in item', () => {
it('edit in item', () => {
cy.setUpApi({ items: GRAASP_DOCUMENT_ITEMS_FIXTURE });
const parent = GRAASP_DOCUMENT_PARENT_FOLDER;
// go to children item
Expand All @@ -84,14 +83,13 @@ describe('Edit Document', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description, extra },
body: { id, name, extra },
},
}) => {
// check item is edited and updated
cy.wait(EDIT_ITEM_PAUSE);
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(newFields.name);
expect(description).to.equal(newFields.description);
expect(getDocumentExtra(extra)?.content).to.contain(content);
cy.get('@getItem').its('response.url').should('contain', parent.id);
},
Expand All @@ -100,7 +98,7 @@ describe('Edit Document', () => {
});

describe('Grid', () => {
it('edit folder on Home', () => {
it('edit on Home', () => {
cy.setUpApi({ items: GRAASP_DOCUMENT_ITEMS_FIXTURE });
cy.visit(HOME_PATH);
cy.switchMode(ITEM_LAYOUT_MODES.GRID);
Expand All @@ -119,7 +117,7 @@ describe('Edit Document', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description, extra },
body: { id, name, extra },
},
}) => {
// check item is edited and updated
Expand All @@ -128,12 +126,11 @@ describe('Edit Document', () => {
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(newFields.name);
expect(getDocumentExtra(extra)?.content).to.contain(content);
expect(description).to.equal(newFields.description);
},
);
});

it('edit folder in item', () => {
it('edit in item', () => {
cy.setUpApi({ items: GRAASP_DOCUMENT_ITEMS_FIXTURE });
// go to children item
const parent = GRAASP_DOCUMENT_PARENT_FOLDER;
Expand All @@ -154,15 +151,14 @@ describe('Edit Document', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description, extra },
body: { id, name, extra },
},
}) => {
// check item is edited and updated
cy.wait(EDIT_ITEM_PAUSE);
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(newFields.name);
expect(getDocumentExtra(extra)?.content).to.contain(content);
expect(description).to.equal(newFields.description);
cy.get('@getItem').its('response.url').should('contain', parent.id);
},
);
Expand Down
23 changes: 17 additions & 6 deletions cypress/integration/item/edit/editFile.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import { DEFAULT_ITEM_LAYOUT_MODE } from '../../../../src/config/constants';
import { ITEM_LAYOUT_MODES } from '../../../../src/enums';
import { HOME_PATH } from '../../../../src/config/paths';
import { buildItemPath, HOME_PATH } from '../../../../src/config/paths';
import { IMAGE_ITEM_DEFAULT, VIDEO_ITEM_S3 } from '../../../fixtures/files';
import { EDITED_FIELDS } from '../../../fixtures/items';
import { EDIT_ITEM_PAUSE } from '../../../support/constants';
import { editItem } from './utils';
import { editCaptionFromViewPage, editItem } from './utils';

describe('Edit File', () => {
beforeEach(() => {
cy.setUpApi({ items: [IMAGE_ITEM_DEFAULT, VIDEO_ITEM_S3] });
});

describe('View Page', () => {
it('edit caption', () => {
cy.visit(buildItemPath(IMAGE_ITEM_DEFAULT.id));
const caption = 'new caption';
editCaptionFromViewPage({ caption });
cy.wait(`@editItem`).then(({ request: { url, body } }) => {
expect(url).to.contain(IMAGE_ITEM_DEFAULT.id);
// caption content might be wrapped with html tags
expect(body?.description).to.contain(caption);
});
});
});

describe('List', () => {
it('edit file on Home', () => {
cy.visit(HOME_PATH);
Expand All @@ -33,13 +46,12 @@ describe('Edit File', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description },
body: { id, name },
},
}) => {
// check item is edited and updated
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(EDITED_FIELDS.name);
expect(description).to.equal(EDITED_FIELDS.description);
cy.wait(EDIT_ITEM_PAUSE);
cy.wait('@getOwnItems');
},
Expand All @@ -66,13 +78,12 @@ describe('Edit File', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description },
body: { id, name },
},
}) => {
// check item is edited and updated
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(EDITED_FIELDS.name);
expect(description).to.equal(EDITED_FIELDS.description);
cy.wait(EDIT_ITEM_PAUSE);
cy.wait('@getOwnItems');
},
Expand Down
12 changes: 4 additions & 8 deletions cypress/integration/item/edit/editFolder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ describe('Edit Folder', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description },
body: { id, name },
},
}) => {
// check item is edited and updated
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(EDITED_FIELDS.name);
expect(description).to.equal(EDITED_FIELDS.description);
cy.wait(EDIT_ITEM_PAUSE);
cy.wait('@getOwnItems');
},
Expand Down Expand Up @@ -65,14 +64,13 @@ describe('Edit Folder', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description },
body: { id, name },
},
}) => {
// check item is edited and updated
cy.wait(EDIT_ITEM_PAUSE);
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(EDITED_FIELDS.name);
expect(description).to.equal(EDITED_FIELDS.description);
cy.get('@getItem')
.its('response.url')
.should('contain', SAMPLE_ITEMS.items[0].id);
Expand Down Expand Up @@ -101,15 +99,14 @@ describe('Edit Folder', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description },
body: { id, name },
},
}) => {
// check item is edited and updated
cy.wait(EDIT_ITEM_PAUSE);
cy.get('@getOwnItems');
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(EDITED_FIELDS.name);
expect(description).to.equal(EDITED_FIELDS.description);
},
);
});
Expand All @@ -134,14 +131,13 @@ describe('Edit Folder', () => {
cy.wait('@editItem').then(
({
response: {
body: { id, name, description },
body: { id, name },
},
}) => {
// check item is edited and updated
cy.wait(EDIT_ITEM_PAUSE);
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(EDITED_FIELDS.name);
expect(description).to.equal(EDITED_FIELDS.description);
cy.get('@getItem')
.its('response.url')
.should('contain', SAMPLE_ITEMS.items[0].id);
Expand Down
17 changes: 15 additions & 2 deletions cypress/integration/item/edit/editLink.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import { DEFAULT_ITEM_LAYOUT_MODE } from '../../../../src/config/constants';
import { ITEM_LAYOUT_MODES } from '../../../../src/enums';
import { HOME_PATH } from '../../../../src/config/paths';
import { buildItemPath, HOME_PATH } from '../../../../src/config/paths';
import { EDITED_FIELDS } from '../../../fixtures/items';
import { GRAASP_LINK_ITEM, YOUTUBE_LINK_ITEM } from '../../../fixtures/links';
import { EDIT_ITEM_PAUSE } from '../../../support/constants';
import { editItem } from './utils';
import { editCaptionFromViewPage, editItem } from './utils';

describe('Edit Link', () => {
beforeEach(() => {
cy.setUpApi({ items: [GRAASP_LINK_ITEM, YOUTUBE_LINK_ITEM] });
});

describe('View Page', () => {
it('edit caption', () => {
cy.visit(buildItemPath(GRAASP_LINK_ITEM.id));
const caption = 'new caption';
editCaptionFromViewPage({ caption });
cy.wait(`@editItem`).then(({ request: { url, body } }) => {
expect(url).to.contain(GRAASP_LINK_ITEM.id);
// caption content might be wrapped with html tags
expect(body?.description).to.contain(caption);
});
});
});

describe('List', () => {
it('edit link on Home', () => {
cy.visit(HOME_PATH);
Expand Down
Loading

0 comments on commit a6e8a72

Please sign in to comment.