Skip to content

Commit

Permalink
feat: add multi op for home, recycle bin, folder screens (#1354)
Browse files Browse the repository at this point in the history
* feat: add multi op for home and recycle bin

* refactor: remove useless code

* refactor: add tests

* feat: allow drag move many items

* revert: set back thumbnail

* refactor: apply PR requested changes

* refactor: apply PR requested changes

* refactor: fix translations
  • Loading branch information
pyphilia authored Jul 24, 2024
1 parent fb98ad2 commit 3440849
Show file tree
Hide file tree
Showing 40 changed files with 1,233 additions and 460 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/item/bookmarks/bookmarks.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Bookmarked Item', () => {
});

it('Show empty table', () => {
i18n.changeLanguage(CURRENT_USER.extra.lang as string);
i18n.changeLanguage(CURRENT_USER.extra.lang);
const text = i18n.t(BUILDER.BOOKMARKS_NO_ITEM, { ns: BUILDER_NAMESPACE });
cy.get(`#${BOOKMARKED_ITEMS_ID}`).should('contain', text);
});
Expand All @@ -59,7 +59,7 @@ describe('Bookmarked Item', () => {
items: [...ITEMS, NON_BOOKMARKED_ITEM],
bookmarkedItems: BOOKMARKED_ITEMS,
});
i18n.changeLanguage(CURRENT_USER.extra.lang as string);
i18n.changeLanguage(CURRENT_USER.extra.lang);
cy.visit(BOOKMARKED_ITEMS_PATH);
});

Expand Down
98 changes: 98 additions & 0 deletions cypress/e2e/item/copy/copy.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@ import {

import { HOME_PATH, buildItemPath } from '../../../../src/config/paths';
import {
COPY_MANY_ITEMS_BUTTON_SELECTOR,
ITEM_MENU_COPY_BUTTON_CLASS,
MY_GRAASP_ITEM_PATH,
buildItemCard,
buildItemsGridMoreButtonSelector,
} from '../../../../src/config/selectors';

const copyItems = ({
toItemPath,
rootId,
}: {
toItemPath: string;
rootId?: string;
}) => {
cy.get(COPY_MANY_ITEMS_BUTTON_SELECTOR).click();
cy.handleTreeMenu(toItemPath, rootId);
};

const copyItem = ({
id,
toItemPath,
Expand Down Expand Up @@ -82,4 +94,90 @@ describe('Copy Item', () => {
expect(url).to.contain(id);
});
});

it('copy many items on Home', () => {
const folders = [
PackedFolderItemFactory(),
PackedFolderItemFactory(),
PackedFolderItemFactory(),
];
cy.setUpApi({
items: folders,
});

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

folders.forEach((item) => {
cy.selectItem(item.id);
});

// copy on home
copyItems({ toItemPath: '' });

cy.wait('@copyItems').then(({ request: { url } }) => {
folders.forEach((item) => {
expect(url).to.contain(item.id);
});
});
});

it('copy many items from Home to folder', () => {
const folders = [
PackedFolderItemFactory(),
PackedFolderItemFactory(),
PackedFolderItemFactory(),
];
const toItem = PackedFolderItemFactory();
cy.setUpApi({
items: [...folders, toItem],
});

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

folders.forEach((item) => {
cy.selectItem(item.id);
});

// copy on home
copyItems({ toItemPath: toItem.path });

cy.wait('@copyItems').then(({ request: { url, body } }) => {
expect(body.parentId).to.eq(toItem.id);
folders.forEach((item) => {
expect(url).to.contain(item.id);
});
});
});

it('copy many items from folder to folder', () => {
const parentItem = PackedFolderItemFactory();
const folders = [
PackedFolderItemFactory({ parentItem }),
PackedFolderItemFactory({ parentItem }),
PackedFolderItemFactory({ parentItem }),
];
const toItem = PackedFolderItemFactory();
cy.setUpApi({
items: [...folders, parentItem, toItem],
});

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

folders.forEach((item) => {
cy.selectItem(item.id);
});

// copy on home
copyItems({ toItemPath: toItem.path });

cy.wait('@copyItems').then(({ request: { url, body } }) => {
expect(body.parentId).to.eq(toItem.id);
folders.forEach((item) => {
expect(url).to.contain(item.id);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { HOME_PATH, buildItemPath } from '../../../../src/config/paths';
import {
ITEM_MENU_MOVE_BUTTON_CLASS,
MOVE_MANY_ITEMS_BUTTON_SELECTOR,
MY_GRAASP_ITEM_PATH,
buildItemsGridMoreButtonSelector,
buildNavigationModalItemId,
Expand All @@ -24,6 +25,17 @@ const openMoveModal = ({ id: movedItemId }: { id: string }) => {
cy.get(`.${ITEM_MENU_MOVE_BUTTON_CLASS}`).click();
};

const moveItems = ({
toItemPath,
rootId,
}: {
toItemPath: string;
rootId?: string;
}) => {
cy.get(MOVE_MANY_ITEMS_BUTTON_SELECTOR).click();
cy.handleTreeMenu(toItemPath, rootId);
};

const moveItem = ({
id: movedItemId,
toItemPath,
Expand All @@ -37,7 +49,7 @@ const moveItem = ({
cy.handleTreeMenu(toItemPath, rootId);
};

describe('Move Item', () => {
describe('Move Items', () => {
it('move item on Home', () => {
cy.setUpApi({ items });
cy.visit(HOME_PATH);
Expand Down Expand Up @@ -118,4 +130,90 @@ describe('Move Item', () => {
expect(url).to.contain(movedItem);
});
});

it('move many items from Home to folder', () => {
const folders = [
PackedFolderItemFactory(),
PackedFolderItemFactory(),
PackedFolderItemFactory(),
];
const toItem = PackedFolderItemFactory();
cy.setUpApi({
items: [...folders, toItem],
});

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

folders.forEach((item) => {
cy.selectItem(item.id);
});

moveItems({ toItemPath: toItem.path });

cy.wait('@moveItems').then(({ request: { url, body } }) => {
expect(body.parentId).to.eq(toItem.id);
folders.forEach((item) => {
expect(url).to.contain(item.id);
});
});
});

it('move many items from folder to folder', () => {
const parentItem = PackedFolderItemFactory();
const folders = [
PackedFolderItemFactory({ parentItem }),
PackedFolderItemFactory({ parentItem }),
PackedFolderItemFactory({ parentItem }),
];
const toItem = PackedFolderItemFactory();
cy.setUpApi({
items: [...folders, parentItem, toItem],
});

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

folders.forEach((item) => {
cy.selectItem(item.id);
});

moveItems({ toItemPath: toItem.path });

cy.wait('@moveItems').then(({ request: { url, body } }) => {
expect(body.parentId).to.eq(toItem.id);
folders.forEach((item) => {
expect(url).to.contain(item.id);
});
});
});

it('move many items from folder to Home', () => {
const parentItem = PackedFolderItemFactory();
const folders = [
PackedFolderItemFactory({ parentItem }),
PackedFolderItemFactory({ parentItem }),
PackedFolderItemFactory({ parentItem }),
];
cy.setUpApi({
items: [...folders, parentItem],
});

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

folders.forEach((item) => {
cy.selectItem(item.id);
});

moveItems({ toItemPath: '' });

cy.wait('@moveItems').then(({ request: { url, body } }) => {
// eslint-disable-next-line no-unused-expressions
expect(body.parentId).to.be.undefined;
folders.forEach((item) => {
expect(url).to.contain(item.id);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PackedRecycledItemDataFactory } from '@graasp/sdk';
import { RECYCLE_BIN_PATH } from '../../../../src/config/paths';
import {
CONFIRM_DELETE_BUTTON_ID,
RECYCLE_BIN_DELETE_MANY_ITEMS_BUTTON_ID,
buildItemCard,
} from '../../../../src/config/selectors';

Expand All @@ -11,18 +12,26 @@ const deleteItem = (id: string) => {
cy.get(`#${CONFIRM_DELETE_BUTTON_ID}`).click();
};

describe('Delete Item', () => {
it('delete item', () => {
const recycledItemData = [
PackedRecycledItemDataFactory(),
PackedRecycledItemDataFactory(),
];
const deleteItems = () => {
cy.get(`#${RECYCLE_BIN_DELETE_MANY_ITEMS_BUTTON_ID}`).click();
cy.get(`#${CONFIRM_DELETE_BUTTON_ID}`).click();
};

const recycledItemData = [
PackedRecycledItemDataFactory(),
PackedRecycledItemDataFactory(),
];

describe('Delete Items', () => {
beforeEach(() => {
cy.setUpApi({
items: recycledItemData.map(({ item }) => item),
recycledItemData,
});
cy.visit(RECYCLE_BIN_PATH);
});

it('delete item', () => {
const { id } = recycledItemData[0].item;

// delete
Expand All @@ -32,4 +41,18 @@ describe('Delete Item', () => {
});
cy.wait('@getRecycledItems');
});

it('delete many items', () => {
recycledItemData.forEach(({ item }) => {
cy.selectItem(item.id);
});

deleteItems();

cy.wait('@deleteItems').then(({ request: { url } }) => {
recycledItemData.forEach(({ item }) => {
expect(url).to.contain(item.id);
});
});
});
});
Loading

0 comments on commit 3440849

Please sign in to comment.