diff --git a/cypress/e2e/item/publish/coEditorSettings.cy.ts b/cypress/e2e/item/publish/coEditorSettings.cy.ts index 790a3f260..1b16b2c08 100644 --- a/cypress/e2e/item/publish/coEditorSettings.cy.ts +++ b/cypress/e2e/item/publish/coEditorSettings.cy.ts @@ -1,15 +1,12 @@ import { ItemTagType, PackedFolderItemFactory } from '@graasp/sdk'; -import { - DISPLAY_CO_EDITORS_OPTIONS, - SETTINGS, -} from '../../../../src/config/constants'; +import { DISPLAY_CO_EDITORS_OPTIONS } from '../../../../src/config/constants'; import { buildItemPath } from '../../../../src/config/paths'; import { + CO_EDITOR_SETTINGS_CHECKBOX_ID, CO_EDITOR_SETTINGS_RADIO_GROUP_ID, ITEM_HEADER_ID, - SHARE_ITEM_VISIBILITY_SELECT_ID, - buildCoEditorSettingsRadioButtonId, + buildDataCyWrapper, buildPublishButtonId, } from '../../../../src/config/selectors'; import { ITEM_WITH_CATEGORIES_CONTEXT } from '../../../fixtures/categories'; @@ -19,12 +16,6 @@ import { EDIT_TAG_REQUEST_TIMEOUT } from '../../../support/constants'; const openPublishItemTab = (id: string) => { cy.get(`#${buildPublishButtonId(id)}`).click(); }; - -const changeVisibility = (value: string): void => { - cy.get(`#${SHARE_ITEM_VISIBILITY_SELECT_ID}`).click(); - cy.get(`li[data-value="${value}"]`, { timeout: 1000 }).click(); -}; - const visitItemPage = () => { cy.setUpApi(ITEM_WITH_CATEGORIES_CONTEXT); const item = ITEM_WITH_CATEGORIES_CONTEXT.items[0]; @@ -36,31 +27,27 @@ describe('Co-editor Setting', () => { it('Display choices', () => { visitItemPage(); - Object.values(DISPLAY_CO_EDITORS_OPTIONS).forEach((option) => { - cy.get(`#${buildCoEditorSettingsRadioButtonId(option.value)}`) - .scrollIntoView() - .should('be.visible'); - }); + cy.get(buildDataCyWrapper(CO_EDITOR_SETTINGS_CHECKBOX_ID)).should( + 'be.visible', + ); }); +}); - it('Change choice', () => { - visitItemPage(); - const item = ITEM_WITH_CATEGORIES_CONTEXT.items[0]; - - const newOptionValue = DISPLAY_CO_EDITORS_OPTIONS.NO.value; +it('Change choice', () => { + visitItemPage(); + const item = ITEM_WITH_CATEGORIES_CONTEXT.items[0]; + const newOptionValue = DISPLAY_CO_EDITORS_OPTIONS.NO.value; - changeVisibility(SETTINGS.ITEM_PUBLIC.name); - cy.wait('@getLatestValidationGroup').then(() => { - cy.get(`#${buildCoEditorSettingsRadioButtonId(newOptionValue)}`).click(); - }); + cy.wait('@getLatestValidationGroup').then(() => { + cy.get(buildDataCyWrapper(CO_EDITOR_SETTINGS_CHECKBOX_ID)).click(); + }); - cy.wait('@editItem', { timeout: EDIT_TAG_REQUEST_TIMEOUT }).then((data) => { - const { - request: { url, body }, - } = data; - expect(url.split('/')).contains(item.id); - expect(body.settings.displayCoEditors).equals(newOptionValue); - }); + cy.wait('@editItem', { timeout: EDIT_TAG_REQUEST_TIMEOUT }).then((data) => { + const { + request: { url, body }, + } = data; + expect(url.split('/')).contains(item.id); + expect(body.settings.displayCoEditors).equals(newOptionValue); }); }); diff --git a/src/components/item/publish/CoEditorsContainer.tsx b/src/components/item/publish/CoEditorsContainer.tsx index ad84cc628..4b395ca6e 100644 --- a/src/components/item/publish/CoEditorsContainer.tsx +++ b/src/components/item/publish/CoEditorsContainer.tsx @@ -8,7 +8,10 @@ import { useDataSyncContext } from '@/components/context/DataSyncContext'; import usePublicationStatus from '@/components/hooks/usePublicationStatus'; import { useBuilderTranslation } from '@/config/i18n'; import { mutations } from '@/config/queryClient'; -import { EMAIL_NOTIFICATION_CHECKBOX } from '@/config/selectors'; +import { + CO_EDITOR_SETTINGS_CHECKBOX_ID, + EMAIL_NOTIFICATION_CHECKBOX, +} from '@/config/selectors'; import { BUILDER } from '@/langs/constants'; import { PublicationStatus } from '@/types/publication'; @@ -76,6 +79,7 @@ export const CoEditorsContainer = ({ {t(BUILDER.ITEM_SETTINGS_CO_EDITORS_TITLE)} handleDisplayCoEditorsChange(checked)} control={} label={t(BUILDER.ITEM_SETTINGS_CO_EDITORS_INFORMATIONS)} diff --git a/src/config/selectors.ts b/src/config/selectors.ts index 805b07192..1fd773ba4 100644 --- a/src/config/selectors.ts +++ b/src/config/selectors.ts @@ -269,9 +269,7 @@ export const HEADER_MEMBER_MENU_SIGN_OUT_BUTTON_ID = export const buildMemberMenuItemId = (id: string): string => `memberMenuItem-${id}`; export const CO_EDITOR_SETTINGS_RADIO_GROUP_ID = 'coEditorSettingsRadioGroup'; -export const buildCoEditorSettingsRadioButtonId = ( - id: string | boolean, -): string => `coEditorSettingsRadioButton-${id}`; +export const CO_EDITOR_SETTINGS_CHECKBOX_ID = `coEditorSettingsCheckBox`; export const EMAIL_NOTIFICATION_CHECKBOX = 'emailNotificationCheckbox'; export const MEMBER_CURRENT_PASSWORD_ID = 'memberCurrentPassword';