Skip to content

Commit

Permalink
test: add tests for copy multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-Torrent committed Aug 17, 2021
1 parent dc8c279 commit 20ed99a
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 2 deletions.
34 changes: 34 additions & 0 deletions cypress/fixtures/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,40 @@ export const SAMPLE_ITEMS = {
},
],
},
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130005',
name: 'own_item_name5',
path:
'ecafbd2a_5688_11eb_ae93_0242ac130002.fdf09f5a_5688_11eb_ae93_0242ac130005',
extra: {
image: 'someimageurl',
},
memberships: [
{
itemPath: 'fdf09f5a-5688-11eb-ae93-0242ac130005',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
],
},
{
...DEFAULT_FOLDER_ITEM,
id: 'ecafbd2a-5688-11eb-ae93-0242ac130006',
name: 'own_item_name6',
path: 'ecafbd2a_5688_11eb_ae93_0242ac130006',
extra: {
image: 'someimageurl',
},
memberships: [
{
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130006',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBERS.ANNA.id,
},
],
},

],
memberships: [],
};
Expand Down
139 changes: 139 additions & 0 deletions cypress/integration/item/copy/listCopyMultiple.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import {
DEFAULT_ITEM_LAYOUT_MODE,
ROOT_ID,
} from '../../../../src/config/constants';
import { ITEM_LAYOUT_MODES } from '../../../../src/enums';

import { buildItemPath, HOME_PATH } from '../../../../src/config/paths';
import {
buildItemsTableRowId,
ITEMS_TABLE_ROW_CHECKBOX_CLASS,
ITEMS_TABLE_COPY_SELECTED_ITEMS_ID,
} from '../../../../src/config/selectors';
import { SAMPLE_ITEMS } from '../../../fixtures/items';
import { TABLE_ITEM_RENDER_TIME } from '../../../support/constants';


const copyItem = ({ itemIds, toItemPath }) => {
// check selected ids
itemIds.forEach((id) => {
cy.wait(TABLE_ITEM_RENDER_TIME);
cy.get(
`#${buildItemsTableRowId(id)} .${ITEMS_TABLE_ROW_CHECKBOX_CLASS}`,
).click();
});

cy.wait(TABLE_ITEM_RENDER_TIME);
cy.get(`#${ITEMS_TABLE_COPY_SELECTED_ITEMS_ID}`).click();
cy.fillTreeModal(toItemPath);
};

describe('Copy items in List', () => {
it('Copy items on Home', () => {
cy.setUpApi(SAMPLE_ITEMS);
cy.visit(HOME_PATH);

if (DEFAULT_ITEM_LAYOUT_MODE !== ITEM_LAYOUT_MODES.LIST) {
cy.switchMode(ITEM_LAYOUT_MODES.LIST);
}

const itemIds = [SAMPLE_ITEMS.items[0].id, SAMPLE_ITEMS.items[5].id];
const { id: toItem, path: toItemPath } = SAMPLE_ITEMS.items[1];
copyItem({ itemIds, toItemPath });

cy.wait('@copyItems').then(({ response: { body } }) => {
itemIds.forEach(id =>{
cy.get(`#${buildItemsTableRowId(id)}`).should('exist');
});

// check in new parent
cy.goToItemInList(toItem);
body.forEach(item => {
cy.get(`#${buildItemsTableRowId(item.id)}`).should('exist');
});
});
});

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

// go to children item
cy.visit(buildItemPath(start));
if (DEFAULT_ITEM_LAYOUT_MODE !== ITEM_LAYOUT_MODES.LIST) {
cy.switchMode(ITEM_LAYOUT_MODES.LIST);
}

// copy
const itemIds = [SAMPLE_ITEMS.items[2].id, SAMPLE_ITEMS.items[4].id];
const { id: toItem, path: toItemPath } = SAMPLE_ITEMS.items[3];
copyItem({ itemIds, toItemPath });

cy.wait('@copyItems').then(({ response: { body } }) => {
itemIds.forEach(id => {
cy.get(`#${buildItemsTableRowId(id)}`).should('exist');
});

// check in new parent
cy.goToItemInList(toItem);
body.forEach(item => {
cy.get(`#${buildItemsTableRowId(item.id)}`).should('exist');
});
});
});

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

// go to children item
cy.visit(buildItemPath(start));
if (DEFAULT_ITEM_LAYOUT_MODE !== ITEM_LAYOUT_MODES.LIST) {
cy.switchMode(ITEM_LAYOUT_MODES.LIST);
}

// copy
const itemIds = [SAMPLE_ITEMS.items[2].id, SAMPLE_ITEMS.items[4].id];
copyItem({itemIds, toItemPath: ROOT_ID });

cy.wait('@copyItems').then(({ response: { body } }) => {
itemIds.forEach(id => {
cy.get(`#${buildItemsTableRowId(id)}`).should('exist');
});

// check in new parent
cy.goToHome();
body.forEach(item => {
cy.get(`#${buildItemsTableRowId(item.id)}`).should('exist');
});
});
});

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

// go to children item
cy.visit(buildItemPath(start));
if (DEFAULT_ITEM_LAYOUT_MODE !== ITEM_LAYOUT_MODES.LIST) {
cy.switchMode(ITEM_LAYOUT_MODES.LIST);
}

// copy
const itemIds = [SAMPLE_ITEMS.items[2].id, SAMPLE_ITEMS.items[4].id];
const { path: toItemPath } = SAMPLE_ITEMS.items[0];
copyItem({ itemIds, toItemPath });

cy.wait('@copyItems').then(({ response: { body } }) => {
// check item is still existing in parent
itemIds.forEach(id => {
cy.get(`#${buildItemsTableRowId(id)}`).should('exist');
});
body.forEach(item => {
cy.get(`#${buildItemsTableRowId(item.id)}`).should('exist');
});
});
});
});
});
3 changes: 1 addition & 2 deletions cypress/support/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,7 @@ export const mockCopyItems = (items, shouldThrowError) => {
if (shouldThrowError) {
return reply({ statusCode: StatusCodes.BAD_REQUEST, body: null });
}
const ids = url.slice(API_HOST.length).split('=').splice(1);

const ids = url.slice(API_HOST.length).split('=').splice(1).map(x => x.replace('&id', ''));
const original = ids.map(id => getItemById(items, id));
const copies = [];
for(const item of original){
Expand Down

0 comments on commit 20ed99a

Please sign in to comment.