From 0265fc85cb4ebb8ae210625d2bc17dcd1fe953e1 Mon Sep 17 00:00:00 2001 From: Julien Torrent Date: Fri, 15 Oct 2021 16:32:20 +0200 Subject: [PATCH] test: improve test based on PR comments --- .../item/settings/itemSettings.spec.js | 102 +++++++++++++----- src/components/item/settings/ItemSettings.js | 8 +- src/config/selectors.js | 4 +- 3 files changed, 81 insertions(+), 33 deletions(-) diff --git a/cypress/integration/item/settings/itemSettings.spec.js b/cypress/integration/item/settings/itemSettings.spec.js index d57fe09b3..974d922be 100644 --- a/cypress/integration/item/settings/itemSettings.spec.js +++ b/cypress/integration/item/settings/itemSettings.spec.js @@ -1,61 +1,109 @@ import { buildItemPath } from '../../../../src/config/paths'; import { ITEM_SETTINGS_BUTTON_CLASS, - SETTINGS_CHATBOX_TOGGLE, - SETTINGS_PINNED_TOGGLE, + SETTINGS_CHATBOX_TOGGLE_ID, + SETTINGS_PINNED_TOGGLE_ID, } from '../../../../src/config/selectors'; import { ITEMS_SETTINGS } from '../../../fixtures/items'; +import { EDIT_ITEM_PAUSE } from '../../../support/constants'; describe('Item Settings', () => { beforeEach(() => { - cy.setUpApi(ITEMS_SETTINGS); + cy.setUpApi({...ITEMS_SETTINGS}); }); describe('Chatbox Settings', () => { it('Disabling Chatbox', () => { - cy.visit(buildItemPath(ITEMS_SETTINGS.items[0].id)); - cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click(); - - cy.get(`#${SETTINGS_CHATBOX_TOGGLE}`).should('be.checked'); + const itemId = ITEMS_SETTINGS.items[0].id; - cy.get(`#${SETTINGS_CHATBOX_TOGGLE}`).click(); + cy.visit(buildItemPath(itemId)); + cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click(); - cy.get(`#${SETTINGS_CHATBOX_TOGGLE}`).should('not.be.checked'); + cy.get(`#${SETTINGS_CHATBOX_TOGGLE_ID}`).should('be.checked'); + + cy.get(`#${SETTINGS_CHATBOX_TOGGLE_ID}`).click(); + + cy.wait('@editItem').then( + ({ + response: { + body: { settings }, + } + }) => { + expect(settings.showChatbox).equals(false); + cy.wait(EDIT_ITEM_PAUSE); + cy.get('@getItem').its('response.url').should('contain', itemId); + }, + ); }); it('Enabling Chatbox', () => { - cy.visit(buildItemPath(ITEMS_SETTINGS.items[1].id)); - cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click(); - - cy.get(`#${SETTINGS_CHATBOX_TOGGLE}`).should('not.be.checked'); + const itemId = ITEMS_SETTINGS.items[1].id; - cy.get(`#${SETTINGS_CHATBOX_TOGGLE}`).click(); + cy.visit(buildItemPath(itemId)); + cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click(); - cy.get(`#${SETTINGS_CHATBOX_TOGGLE}`).should('be.checked'); + cy.get(`#${SETTINGS_CHATBOX_TOGGLE_ID}`).should('not.be.checked'); + + cy.get(`#${SETTINGS_CHATBOX_TOGGLE_ID}`).click(); + + cy.wait('@editItem').then( + ({ + response: { + body: { settings }, + } + }) => { + expect(settings.showChatbox).equals(true); + cy.wait(EDIT_ITEM_PAUSE); + cy.get('@getItem').its('response.url').should('contain', itemId); + }, + ); }); }); describe('Pinned Settings', () => { it('Unpin Items', () => { - cy.visit(buildItemPath(ITEMS_SETTINGS.items[0].id)); - cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click(); - - cy.get(`#${SETTINGS_PINNED_TOGGLE}`).should('be.checked'); + const itemId = ITEMS_SETTINGS.items[0].id; - cy.get(`#${SETTINGS_PINNED_TOGGLE}`).click(); + cy.visit(buildItemPath(itemId)); + cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click(); - cy.get(`#${SETTINGS_PINNED_TOGGLE}`).should('not.be.checked'); + cy.get(`#${SETTINGS_PINNED_TOGGLE_ID}`).should('be.checked'); + + cy.get(`#${SETTINGS_PINNED_TOGGLE_ID}`).click(); + + cy.wait('@editItem').then( + ({ + response: { + body: { settings }, + } + }) => { + expect(settings.isPinned).equals(false); + cy.wait(EDIT_ITEM_PAUSE); + cy.get('@getItem').its('response.url').should('contain', itemId); + }, + ); }); it('Pin Item', () => { - cy.visit(buildItemPath(ITEMS_SETTINGS.items[1].id)); + const itemId = ITEMS_SETTINGS.items[1].id; + cy.visit(buildItemPath(itemId)); cy.get(`.${ITEM_SETTINGS_BUTTON_CLASS}`).click(); - cy.get(`#${SETTINGS_PINNED_TOGGLE}`).should('not.be.checked'); - - cy.get(`#${SETTINGS_PINNED_TOGGLE}`).click(); - - cy.get(`#${SETTINGS_PINNED_TOGGLE}`).should('be.checked'); + cy.get(`#${SETTINGS_PINNED_TOGGLE_ID}`).should('not.be.checked'); + + cy.get(`#${SETTINGS_PINNED_TOGGLE_ID}`).click(); + + cy.wait('@editItem').then( + ({ + response: { + body: { settings }, + } + }) => { + expect(settings.isPinned).equals(true); + cy.wait(EDIT_ITEM_PAUSE); + cy.get('@getItem').its('response.url').should('contain', itemId); + }, + ); }); }); }); diff --git a/src/components/item/settings/ItemSettings.js b/src/components/item/settings/ItemSettings.js index fa1fe7188..7d9281811 100644 --- a/src/components/item/settings/ItemSettings.js +++ b/src/components/item/settings/ItemSettings.js @@ -12,8 +12,8 @@ import { import { MUTATION_KEYS } from '@graasp/query-client'; import { useMutation } from '../../../config/queryClient'; import { - SETTINGS_CHATBOX_TOGGLE, - SETTINGS_PINNED_TOGGLE, + SETTINGS_CHATBOX_TOGGLE_ID, + SETTINGS_PINNED_TOGGLE_ID, } from '../../../config/selectors'; const useStyles = makeStyles((theme) => ({ @@ -68,7 +68,7 @@ const ItemSettings = ({ item }) => { label={t('Pin')} control={( { label={t('Show Chat')} control={( `itemsTable-${id}`; -export const SETTINGS_PINNED_TOGGLE = 'pinned'; -export const SETTINGS_CHATBOX_TOGGLE = 'chatbox'; +export const SETTINGS_PINNED_TOGGLE_ID = 'pinned'; +export const SETTINGS_CHATBOX_TOGGLE_ID = 'chatbox';