Skip to content

Commit

Permalink
feat: add recycle bin
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Sep 23, 2021
1 parent 0ffdde6 commit 3d17344
Show file tree
Hide file tree
Showing 14 changed files with 424 additions and 100 deletions.
51 changes: 51 additions & 0 deletions cypress/fixtures/recycleBin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { PERMISSION_LEVELS } from '../../src/enums';
import { DEFAULT_FOLDER_ITEM } from './items';
import { CURRENT_USER } from './members';

const recycleBinId = 'ecafbd2a-5688-11eb-ae93-1342ac130002';

const MEMBER_WITH_RECYCLE_BIN = {
...CURRENT_USER,
extra: {
...CURRENT_USER.extra,
recycleBin: {
itemId: recycleBinId,
},
},
};

// eslint-disable-next-line import/prefer-default-export
export const DATABASE_WITH_RECYCLE_BIN = {
items: [],
recycledItems: [
{
...DEFAULT_FOLDER_ITEM,
id: 'ecafbd2a-5688-11eb-ae93-0242ac130002',
name: 'recycled_item_name1',
path: `${recycleBinId}.ecafbd2a_5688_11eb_ae93_0242ac130002`,
extra: {},
memberships: [
{
itemPath: 'fdf09f5a_5688_11eb_ae93_0242ac130002',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBER_WITH_RECYCLE_BIN.id,
},
],
},
{
...DEFAULT_FOLDER_ITEM,
id: 'fdf09f5a-5688-11eb-ae93-0242ac130002',
name: 'recycled_item_name2',
path: `${recycleBinId}.fdf09f5a_5688_11eb_ae93_0242ac130002`,
extra: {},
memberships: [
{
itemPath: 'fdf09f5a-5688-11eb-ae93-0242ac130002',
permission: PERMISSION_LEVELS.ADMIN,
memberId: MEMBER_WITH_RECYCLE_BIN.id,
},
],
},
],
currentMember: MEMBER_WITH_RECYCLE_BIN,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ import { ITEM_LAYOUT_MODES } from '../../../../src/enums';
import { buildItemPath, HOME_PATH } from '../../../../src/config/paths';
import {
buildItemCard,
CONFIRM_DELETE_BUTTON_ID,
CONFIRM_RECYCLE_BUTTON_ID,
ITEM_DELETE_BUTTON_CLASS,
} from '../../../../src/config/selectors';
import { SAMPLE_ITEMS } from '../../../fixtures/items';

const deleteItem = (id) => {
const recycleItem = (id) => {
cy.get(`#${buildItemCard(id)} .${ITEM_DELETE_BUTTON_CLASS}`).click();
cy.get(`#${CONFIRM_DELETE_BUTTON_ID}`).click();
cy.get(`#${CONFIRM_RECYCLE_BUTTON_ID}`).click();
};

describe('Delete Item in Grid', () => {
it('delete item on Home', () => {
describe('Recycle Item in Grid', () => {
it('recycle item on Home', () => {
cy.setUpApi(SAMPLE_ITEMS);
cy.visit(HOME_PATH);
cy.switchMode(ITEM_LAYOUT_MODES.GRID);

const { id } = SAMPLE_ITEMS.items[0];

// delete
deleteItem(id);
cy.wait(['@deleteItem', '@getOwnItems']);
// recycle
recycleItem(id);
cy.wait(['@recycleItem', '@getOwnItems']);
});

it('delete item inside parent', () => {
it('recycle item inside parent', () => {
cy.setUpApi(SAMPLE_ITEMS);
const { id } = SAMPLE_ITEMS.items[0];
const { id: idToDelete } = SAMPLE_ITEMS.items[2];
Expand All @@ -34,28 +34,28 @@ describe('Delete Item in Grid', () => {
cy.visit(buildItemPath(id));
cy.switchMode(ITEM_LAYOUT_MODES.GRID);

// delete
deleteItem(idToDelete);
cy.wait('@deleteItem').then(() => {
// recycle
recycleItem(idToDelete);
cy.wait('@recycleItem').then(() => {
// check update
cy.wait('@getItem').its('response.url').should('contain', id);
});
});

describe('Error handling', () => {
it('error while deleting item does not delete in interface', () => {
cy.setUpApi({ ...SAMPLE_ITEMS, deleteItemError: true });
it('error while deleting item does not recycle in interface', () => {
cy.setUpApi({ ...SAMPLE_ITEMS, recycleItemError: true });
const { id } = SAMPLE_ITEMS.items[0];
const { id: idToDelete } = SAMPLE_ITEMS.items[2];

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

// delete
deleteItem(idToDelete);
// recycle
recycleItem(idToDelete);

cy.wait('@deleteItem').then(() => {
cy.wait('@recycleItem').then(() => {
// check item is still displayed
cy.get(`#${buildItemCard(idToDelete)}`).should('exist');
});
Expand Down
46 changes: 13 additions & 33 deletions cypress/integration/item/delete/listDeleteItem.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DEFAULT_ITEM_LAYOUT_MODE } from '../../../../src/config/constants';
import { ITEM_LAYOUT_MODES } from '../../../../src/enums';
import { buildItemPath, HOME_PATH } from '../../../../src/config/paths';
import { RECYCLE_BIN_PATH } from '../../../../src/config/paths';
import {
buildItemsTableRowId,
CONFIRM_DELETE_BUTTON_ID,
ITEM_DELETE_BUTTON_CLASS,
} from '../../../../src/config/selectors';
import { SAMPLE_ITEMS } from '../../../fixtures/items';
import { DATABASE_WITH_RECYCLE_BIN } from '../../../fixtures/recycleBin';
import { TABLE_ITEM_RENDER_TIME } from '../../../support/constants';

const deleteItem = (id) => {
Expand All @@ -16,62 +16,42 @@ const deleteItem = (id) => {
};

describe('Delete Item in List', () => {
it('delete item on Home', () => {
cy.setUpApi(SAMPLE_ITEMS);
cy.visit(HOME_PATH);
it('delete item', () => {
cy.setUpApi(DATABASE_WITH_RECYCLE_BIN);
cy.visit(RECYCLE_BIN_PATH);

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

const { id } = SAMPLE_ITEMS.items[0];
const { id } = DATABASE_WITH_RECYCLE_BIN.recycledItems[0];

// delete
deleteItem(id);
cy.wait('@deleteItem').then(({ request: { url } }) => {
expect(url).to.contain(id);
});
cy.wait('@getOwnItems');
});

it('delete item inside parent', () => {
cy.setUpApi(SAMPLE_ITEMS);
const { id } = SAMPLE_ITEMS.items[0];
const { id: idToDelete } = SAMPLE_ITEMS.items[2];

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

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

// delete
deleteItem(idToDelete);
cy.wait('@deleteItem').then(({ request: { url } }) => {
expect(url).to.contain(idToDelete);
});
cy.wait('@getRecycledItems');
});

describe('Error handling', () => {
it('error while deleting item does not delete in interface', () => {
cy.setUpApi({ ...SAMPLE_ITEMS, deleteItemError: true });
const { id } = SAMPLE_ITEMS.items[0];
const { id: idToDelete } = SAMPLE_ITEMS.items[2];
it.only('error while deleting item does not delete in interface', () => {
cy.setUpApi({ ...DATABASE_WITH_RECYCLE_BIN, deleteItemError: true });
const { id } = DATABASE_WITH_RECYCLE_BIN.recycledItems[0];

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

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

// delete
deleteItem(idToDelete);
deleteItem(id);

cy.wait('@deleteItem').then(() => {
// check item is still displayed
cy.get(`#${buildItemsTableRowId(idToDelete)}`).should('exist');
cy.get(`#${buildItemsTableRowId(id)}`).should('exist');
});
});
});
Expand Down
61 changes: 26 additions & 35 deletions cypress/integration/item/delete/listDeleteItems.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DEFAULT_ITEM_LAYOUT_MODE } from '../../../../src/config/constants';
import { ITEM_LAYOUT_MODES } from '../../../../src/enums';
import { buildItemPath, HOME_PATH } from '../../../../src/config/paths';
import { RECYCLE_BIN_PATH } from '../../../../src/config/paths';
import {
buildItemsTableRowId,
CONFIRM_DELETE_BUTTON_ID,
ITEMS_TABLE_DELETE_SELECTED_ITEMS_ID,
ITEMS_TABLE_ROW_CHECKBOX_CLASS,
} from '../../../../src/config/selectors';
import { SAMPLE_ITEMS } from '../../../fixtures/items';
import { DATABASE_WITH_RECYCLE_BIN } from '../../../fixtures/recycleBin';
import { TABLE_ITEM_RENDER_TIME } from '../../../support/constants';

const deleteItems = (itemIds) => {
Expand All @@ -24,56 +24,47 @@ const deleteItems = (itemIds) => {
};

describe('Delete Items in List', () => {
it('delete 2 items in Home', () => {
cy.setUpApi(SAMPLE_ITEMS);
cy.visit(HOME_PATH);
const itemIds = [
DATABASE_WITH_RECYCLE_BIN.recycledItems[0].id,
DATABASE_WITH_RECYCLE_BIN.recycledItems[1].id,
];
it('delete items', () => {
cy.setUpApi(DATABASE_WITH_RECYCLE_BIN);
cy.visit(RECYCLE_BIN_PATH);

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

// delete
deleteItems([SAMPLE_ITEMS.items[0].id, SAMPLE_ITEMS.items[1].id]);
cy.wait(['@deleteItems', '@getOwnItems']);
});

it('delete 2 items in item', () => {
cy.setUpApi(SAMPLE_ITEMS);
cy.visit(buildItemPath(SAMPLE_ITEMS.items[0].id));

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

// delete
deleteItems([SAMPLE_ITEMS.items[2].id, SAMPLE_ITEMS.items[3].id]);
cy.wait('@deleteItems').then(() => {
// check item is deleted, others are still displayed
cy.wait('@getItem')
.its('response.url')
.should('contain', SAMPLE_ITEMS.items[0].id);
deleteItems(itemIds);
cy.wait('@deleteItems').then(({ request: { url } }) => {
for (const id of itemIds) {
expect(url).to.contain(id);
}
});
cy.wait('@getRecycledItems');
});

describe('Error handling', () => {
it('does not delete items on error', () => {
cy.setUpApi({ ...SAMPLE_ITEMS, deleteItemsError: true });
cy.visit(HOME_PATH);
it('error while deleting items does not delete in interface', () => {
cy.setUpApi({ ...DATABASE_WITH_RECYCLE_BIN, deleteItemError: true });

// go to children item
cy.visit(RECYCLE_BIN_PATH);

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

// delete
deleteItems([SAMPLE_ITEMS.items[0].id, SAMPLE_ITEMS.items[1].id]);
deleteItems(itemIds);

cy.wait('@deleteItems').then(() => {
// check item is deleted, others are still displayed
cy.get(`#${buildItemsTableRowId(SAMPLE_ITEMS.items[0].id)}`).should(
'exist',
);
cy.get(`#${buildItemsTableRowId(SAMPLE_ITEMS.items[1].id)}`).should(
'exist',
);
// check items are still displayed
for (const id of itemIds) {
cy.get(`#${buildItemsTableRowId(id)}`).should('exist');
}
});
});
});
Expand Down
78 changes: 78 additions & 0 deletions cypress/integration/item/delete/listRecycleItem.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { 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,
CONFIRM_RECYCLE_BUTTON_ID,
ITEM_DELETE_BUTTON_CLASS,
} from '../../../../src/config/selectors';
import { SAMPLE_ITEMS } from '../../../fixtures/items';
import { TABLE_ITEM_RENDER_TIME } from '../../../support/constants';

const recycleItem = (id) => {
cy.wait(TABLE_ITEM_RENDER_TIME);
cy.get(`#${buildItemsTableRowId(id)} .${ITEM_DELETE_BUTTON_CLASS}`).click();
cy.get(`#${CONFIRM_RECYCLE_BUTTON_ID}`).click();
};

describe('Recycle Item in List', () => {
it('recycle item 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 { id } = SAMPLE_ITEMS.items[0];

// delete
recycleItem(id);
cy.wait('@recycleItem').then(({ request: { url } }) => {
expect(url).to.contain(id);
});
cy.wait('@getOwnItems');
});

it('recycle item inside parent', () => {
cy.setUpApi(SAMPLE_ITEMS);
const { id } = SAMPLE_ITEMS.items[0];
const { id: idToDelete } = SAMPLE_ITEMS.items[2];

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

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

// delete
recycleItem(idToDelete);
cy.wait('@recycleItem').then(({ request: { url } }) => {
expect(url).to.contain(idToDelete);
});
});

describe('Error handling', () => {
it('error while recycling item does not recycle in interface', () => {
cy.setUpApi({ ...SAMPLE_ITEMS, recycleItemError: true });
const { id } = SAMPLE_ITEMS.items[0];
const { id: idToDelete } = SAMPLE_ITEMS.items[2];

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

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

// delete
recycleItem(idToDelete);

cy.wait('@recycleItem').then(() => {
// check item is still displayed
cy.get(`#${buildItemsTableRowId(idToDelete)}`).should('exist');
});
});
});
});
Loading

0 comments on commit 3d17344

Please sign in to comment.