Skip to content

Commit

Permalink
fix: factor out selectors and index
Browse files Browse the repository at this point in the history
  • Loading branch information
louisewang1 committed Jan 19, 2022
1 parent 5f406a0 commit 22ba7c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 8 additions & 7 deletions cypress/integration/item/share/categories.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
buildCategoryMenuOptions,
buildShareButtonId,
CATEGORIES_SELECTION_VALUE_SELECTOR,
SHARE_ITEM_CATEGORY_DISCIPLINE,
Expand All @@ -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();
};

Expand Down Expand Up @@ -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;
Expand All @@ -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 },
Expand Down
8 changes: 5 additions & 3 deletions src/config/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}"]`;

0 comments on commit 22ba7c7

Please sign in to comment.