Skip to content

Commit

Permalink
test: add tests for moving multiple items
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-Torrent committed Aug 17, 2021
1 parent 20ed99a commit 1ee402b
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cypress/integration/item/copy/listCopyMultiple.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const copyItem = ({ itemIds, toItemPath }) => {
cy.fillTreeModal(toItemPath);
};

describe('Copy items in List', () => {
describe('Copy items in List', () => {
it('Copy items on Home', () => {
cy.setUpApi(SAMPLE_ITEMS);
cy.visit(HOME_PATH);
Expand Down Expand Up @@ -131,7 +131,7 @@ const copyItem = ({ itemIds, toItemPath }) => {
cy.get(`#${buildItemsTableRowId(id)}`).should('exist');
});
body.forEach(item => {
cy.get(`#${buildItemsTableRowId(item.id)}`).should('exist');
cy.get(`#${buildItemsTableRowId(item.id)}`).should('not.exist');
});
});
});
Expand Down
130 changes: 130 additions & 0 deletions cypress/integration/item/move/listMoveMultiple.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import {
ROOT_ID,
DEFAULT_ITEM_LAYOUT_MODE,
} 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_MOVE_SELECTED_ITEMS_ID
} from '../../../../src/config/selectors';
import { SAMPLE_ITEMS } from '../../../fixtures/items';
import { TABLE_ITEM_RENDER_TIME } from '../../../support/constants';

const moveItem = ({ 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_MOVE_SELECTED_ITEMS_ID}`).click();
cy.fillTreeModal(toItemPath);
};

describe('Move Item in List', () => {
it('Move 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);
}

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

cy.wait('@moveItems').then(({ request: { url, body } }) => {
expect(body.parentId).to.equal(toItem);
itemIds.forEach(movedItem => expect(url).to.contain(movedItem));

itemIds.forEach(id => {
cy.get(`#${buildItemsTableRowId(id)}`).should('not.exist');
});
});
});

it('Move 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);
}

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

cy.wait('@moveItems').then(({ request: { body, url } }) => {
expect(body.parentId).to.equal(toItem);
itemIds.forEach(movedItem => expect(url).to.contain(movedItem));
itemIds.forEach(id => {
cy.get(`#${buildItemsTableRowId(id)}`).should('not.exist');
});
});
});

it('Move 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);
}

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

cy.wait('@moveItems').then(({ request: { body, url } }) => {
expect(body.parentId).to.equal(undefined);
itemIds.forEach(movedItem => expect(url).to.contain(movedItem));

itemIds.forEach(id => {
cy.get(`#${buildItemsTableRowId(id)}`).should('not.exist');
});
});
});

describe('Error handling', () => {
it('error while moving items does not create in interface', () => {
cy.setUpApi({ ...SAMPLE_ITEMS, moveItemsError: 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);
}

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

cy.wait('@moveItems').then(() => {
// check item is still there
itemIds.forEach(id => {
cy.get(`#${buildItemsTableRowId(id)}`).should('exist');
});
});
});
});
});

2 changes: 1 addition & 1 deletion cypress/support/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export const mockMoveItems = (items, 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 updated = ids.map(id => getItemById(items, id));
// actually update cached items
Expand Down

0 comments on commit 1ee402b

Please sign in to comment.