From 22ba7c7fe0ad9a1d8f40342cd1ee4ea3ac6c6e30 Mon Sep 17 00:00:00 2001 From: Louise Wang Date: Wed, 19 Jan 2022 14:52:25 +0100 Subject: [PATCH] fix: factor out selectors and index --- cypress/integration/item/share/categories.spec.js | 15 ++++++++------- src/config/selectors.js | 8 +++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cypress/integration/item/share/categories.spec.js b/cypress/integration/item/share/categories.spec.js index 967bdc191..b7152dc0a 100644 --- a/cypress/integration/item/share/categories.spec.js +++ b/cypress/integration/item/share/categories.spec.js @@ -1,4 +1,5 @@ import { + buildCategoryMenuOptions, buildShareButtonId, CATEGORIES_SELECTION_VALUE_SELECTOR, SHARE_ITEM_CATEGORY_DISCIPLINE, @@ -22,15 +23,13 @@ const findCategoryNameById = (id) => export const deleteOption = (index) => { cy.get(`#${SHARE_ITEM_CATEGORY_LEVEL}`).click(); - cy.get( - `#${SHARE_ITEM_CATEGORY_LEVEL}-popup li[data-option-index="${index}"]`, - ).click(); + cy.get(buildCategoryMenuOptions(SHARE_ITEM_CATEGORY_LEVEL, index)).click(); }; export const addOption = (index) => { cy.get(`#${SHARE_ITEM_CATEGORY_DISCIPLINE}`).click(); cy.get( - `#${SHARE_ITEM_CATEGORY_DISCIPLINE}-popup li[data-option-index="${index}"]`, + buildCategoryMenuOptions(SHARE_ITEM_CATEGORY_DISCIPLINE, index), ).click(); }; @@ -58,9 +57,10 @@ describe('Categories', () => { it('Delete a category option', () => { // delete selection - deleteOption(0); + const optionIndex = 0; + deleteOption(optionIndex); cy.wait('@deleteItemCategory').then((data) => { - const entryId = item.categories[0].id; + const entryId = item.categories[optionIndex].id; const { request: { url }, } = data; @@ -69,7 +69,8 @@ describe('Categories', () => { }); it('Add a category option', () => { - addOption(0); + const optionIndex = 0; + addOption(optionIndex); cy.wait('@postItemCategory').then((data) => { const { request: { url }, diff --git a/src/config/selectors.js b/src/config/selectors.js index d8cbb2f7c..c99cf3f60 100644 --- a/src/config/selectors.js +++ b/src/config/selectors.js @@ -165,9 +165,11 @@ export const MEMBER_PROFILE_AVATAR_UPLOAD_BUTTON_CLASSNAME = export const ZIP_DASHBOARD_UPLOADER_ID = 'zipDashboardUploader'; export const ITEM_TAGS_EDIT_INPUT_ID = 'itemTagsEditInput'; -export const ITEM_TAGS_EDIT_SUBMIT_BUTTON_ID = 'itemTagsEditSubmitButton' +export const ITEM_TAGS_EDIT_SUBMIT_BUTTON_ID = 'itemTagsEditSubmitButton'; export const buildCustomizedTagsSelector = (index) => `customizedTagsPreview-${index}`; -export const CATEGORIES_SELECTION_VALUE_SELECTOR = - `#${SHARE_ITEM_CATEGORY_LEVEL_TITLE_ID}+div span`; +export const CATEGORIES_SELECTION_VALUE_SELECTOR = `#${SHARE_ITEM_CATEGORY_LEVEL_TITLE_ID}+div span`; + +export const buildCategoryMenuOptions = (menuName, optionIndex) => + `${menuName}-popup li[data-option-index="${optionIndex}"]`;