Skip to content

Commit

Permalink
fix(test): update coEditorSettings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ReidyT committed May 31, 2024
1 parent 7be28e7 commit c6a0523
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
53 changes: 20 additions & 33 deletions cypress/e2e/item/publish/coEditorSettings.cy.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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];
Expand All @@ -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);
});
});

Expand Down
6 changes: 5 additions & 1 deletion src/components/item/publish/CoEditorsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -76,6 +79,7 @@ export const CoEditorsContainer = ({
{t(BUILDER.ITEM_SETTINGS_CO_EDITORS_TITLE)}
</Typography>
<FormControlLabel
data-cy={CO_EDITOR_SETTINGS_CHECKBOX_ID}
onChange={(_e, checked) => handleDisplayCoEditorsChange(checked)}
control={<Checkbox size="small" checked={displayCoEditors} />}
label={t(BUILDER.ITEM_SETTINGS_CO_EDITORS_INFORMATIONS)}
Expand Down
4 changes: 1 addition & 3 deletions src/config/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit c6a0523

Please sign in to comment.