This repository has been archived by the owner on Jan 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add duplicate item action (#932)
* feat: add duplicate item action * build: remove name at duplicate item payload * fix: renaming parent to parentsIDs * fix: remove unused copy translation * feat: add duplicate tests * test: test parentId to be first parent of item at duplicate item * test: refactor test for duplicate item * test: add a test for parent id when duplicating item on home * test: refactor duplicate tests for different views --------- Co-authored-by: Kim Lan Phan Hoang <pyphilia@gmail.com>
- Loading branch information
Showing
6 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { getParentsIdsFromPath } from '@/utils/item'; | ||
|
||
import { HOME_PATH, buildItemPath } from '../../../../src/config/paths'; | ||
import ITEM_LAYOUT_MODES from '../../../../src/enums/itemLayoutModes'; | ||
import { SAMPLE_ITEMS } from '../../../fixtures/items'; | ||
import duplicateItem from '../../../support/actionsUtils'; | ||
|
||
describe('duplicate Item in Home', () => { | ||
Object.values(ITEM_LAYOUT_MODES).forEach((view) => { | ||
it(`duplicate item on Home in ${view} view`, () => { | ||
cy.setUpApi(SAMPLE_ITEMS); | ||
cy.visit(HOME_PATH); | ||
cy.switchMode(view); | ||
|
||
// duplicate | ||
const { id: duplicateItemId } = SAMPLE_ITEMS.items[0]; | ||
duplicateItem({ id: duplicateItemId }); | ||
|
||
cy.wait('@copyItems').then(({ request: { url, body } }) => { | ||
expect(url).to.contain(duplicateItemId); | ||
// as we duplicate on home parentId will be undefined | ||
expect(body.parentId).to.equal(undefined); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('duplicate Item in item', () => { | ||
Object.values(ITEM_LAYOUT_MODES).forEach((view) => { | ||
it(`duplicate item in item in ${view} view`, () => { | ||
cy.setUpApi(SAMPLE_ITEMS); | ||
const { id, path } = SAMPLE_ITEMS.items[0]; | ||
const parentsIds = getParentsIdsFromPath(path); | ||
|
||
// go to children item | ||
cy.visit(buildItemPath(id)); | ||
cy.switchMode(view); | ||
|
||
// duplicate | ||
const { id: duplicateItemId } = SAMPLE_ITEMS.items[2]; | ||
duplicateItem({ id: duplicateItemId }); | ||
|
||
cy.wait('@copyItems').then(({ request: { url, body } }) => { | ||
expect(url).to.contain(duplicateItemId); | ||
expect(body.parentId).to.equal(parentsIds[0]); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { | ||
ITEM_MENU_DUPLICATE_BUTTON_CLASS, | ||
buildItemMenu, | ||
buildItemMenuButtonId, | ||
} from '@/config/selectors'; | ||
|
||
const duplicateItem = ({ id }: { id: string }): void => { | ||
cy.get(`#${buildItemMenuButtonId(id)}`).click(); | ||
cy.get(`#${buildItemMenu(id)} .${ITEM_MENU_DUPLICATE_BUTTON_CLASS}`).click(); | ||
}; | ||
|
||
export default duplicateItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters