diff --git a/cypress/e2e/account/homePage.cy.ts b/cypress/e2e/account/homePage.cy.ts index 87eed4855..6d024b0be 100644 --- a/cypress/e2e/account/homePage.cy.ts +++ b/cypress/e2e/account/homePage.cy.ts @@ -56,7 +56,7 @@ class TestHelper { { method: HttpMethod.Get, url: new RegExp( - `${API_HOST}/members/${ID_FORMAT}/avatar/(original|large|medium|small)\\?replyUrl\\=true`, + String.raw`${API_HOST}/members/${ID_FORMAT}/avatar/(original|large|medium|small)\?replyUrl\=true`, ), }, ({ reply }) => { diff --git a/cypress/e2e/account/settings/storage.cy.ts b/cypress/e2e/account/settings/storage.cy.ts index 467dc0ce5..a164cd1bc 100644 --- a/cypress/e2e/account/settings/storage.cy.ts +++ b/cypress/e2e/account/settings/storage.cy.ts @@ -49,8 +49,7 @@ describe('Storage files', () => { const numberPages = Math.ceil(files.length / filesPerPage); for (let i = 1; i <= numberPages; i += 1) { - const currentNbOfFiles = - files.length > i * filesPerPage ? i * filesPerPage : files.length; + const currentNbOfFiles = Math.min(files.length, i * filesPerPage); cy.get('tbody tr').should('have.length', currentNbOfFiles); files.slice(0, currentNbOfFiles).forEach((file, fileIndex) => { diff --git a/cypress/e2e/builder/item/authorization/itemLogin/itemLoginSetting.cy.ts b/cypress/e2e/builder/item/authorization/itemLogin/itemLoginSetting.cy.ts index 1a012d168..f39ae38a0 100644 --- a/cypress/e2e/builder/item/authorization/itemLogin/itemLoginSetting.cy.ts +++ b/cypress/e2e/builder/item/authorization/itemLogin/itemLoginSetting.cy.ts @@ -21,24 +21,17 @@ import { addItemLoginSchema } from './utils'; const ALERT_BUTTON = `[role="alert"] button`; const DIALOG_SELECTOR = `[role="dialog"]`; -const checkItemLoginSetting = ({ - mode, - disabled = false, -}: { - mode: string; - disabled?: boolean; -}) => { - if (!disabled) { - cy.get(`#${SHARE_ITEM_PSEUDONYMIZED_SCHEMA_ID} + input`).should( - 'have.value', - mode, - ); - } else { - cy.get(`#${SHARE_ITEM_PSEUDONYMIZED_SCHEMA_ID}`).then((el) => { - // test classnames are 'disabled' - expect(el.parent().html()).to.contain('disabled'); - }); - } +const checkItemLoginSettingIsEnabled = ({ mode }: { mode: string }) => { + cy.get(`#${SHARE_ITEM_PSEUDONYMIZED_SCHEMA_ID} + input`).should( + 'have.value', + mode, + ); +}; +const checkItemLoginSettingIsDisabled = () => { + cy.get(`#${SHARE_ITEM_PSEUDONYMIZED_SCHEMA_ID}`).then((el) => { + // test classnames are 'disabled' + expect(el.parent().html()).to.contain('disabled'); + }); }; const editItemLoginSetting = (mode: string) => { @@ -77,7 +70,7 @@ describe('Item Login', () => { cy.visit(buildItemPath(item.id)); cy.get(`#${buildShareButtonId(item.id)}`).click(); - checkItemLoginSetting({ + checkItemLoginSettingIsEnabled({ mode: ItemLoginSchemaType.Username, }); editItemLoginSetting(ItemLoginSchemaType.UsernameAndPassword); @@ -85,10 +78,7 @@ describe('Item Login', () => { // disabled at child level cy.visit(buildItemPath(child.id)); cy.get(`#${buildShareButtonId(child.id)}`).click(); - checkItemLoginSetting({ - mode: ItemLoginSchemaType.UsernameAndPassword, - disabled: true, - }); + checkItemLoginSettingIsDisabled(); }); it('read permission', () => { diff --git a/cypress/e2e/builder/item/edit/editLink.cy.ts b/cypress/e2e/builder/item/edit/editLink.cy.ts index 8ca432be9..7c6b75a62 100644 --- a/cypress/e2e/builder/item/edit/editLink.cy.ts +++ b/cypress/e2e/builder/item/edit/editLink.cy.ts @@ -1,18 +1,18 @@ import { HttpMethod, PackedLinkItemFactory, buildLinkExtra } from '@graasp/sdk'; import { - ACCESSIBLE_ITEMS_TABLE_ID, - EDIT_ITEM_BUTTON_CLASS, - EDIT_ITEM_MODAL_CANCEL_BUTTON_ID, - EDIT_MODAL_ID, - ITEM_FORM_CONFIRM_BUTTON_ID, - ITEM_FORM_LINK_INPUT_ID, - ITEM_FORM_NAME_INPUT_ID, - ITEM_MAIN_CLASS, - TEXT_EDITOR_CLASS, - buildDataCyWrapper, - buildEditButtonId, - buildItemMenuDataCy, + ACCESSIBLE_ITEMS_TABLE_ID, + EDIT_ITEM_BUTTON_CLASS, + EDIT_ITEM_MODAL_CANCEL_BUTTON_ID, + EDIT_MODAL_ID, + ITEM_FORM_CONFIRM_BUTTON_ID, + ITEM_FORM_LINK_INPUT_ID, + ITEM_FORM_NAME_INPUT_ID, + ITEM_MAIN_CLASS, + TEXT_EDITOR_CLASS, + buildDataCyWrapper, + buildEditButtonId, + buildItemMenuDataCy, } from '../../../../../src/config/selectors'; import { CURRENT_MEMBER } from '../../../../fixtures/members'; import { EDIT_ITEM_PAUSE } from '../../../../support/constants'; @@ -124,7 +124,8 @@ describe('Edit Link', () => { cy.get(buildDataCyWrapper(buildItemMenuDataCy(itemToEdit.id))).click(); editItemLink({ ...itemToEdit, - ...{ name: newName, url: newUrl }, + name: newName, + url: newUrl, }); cy.wait('@editItemLink').then( diff --git a/cypress/e2e/builder/item/order/reorderItems.cy.ts b/cypress/e2e/builder/item/order/reorderItems.cy.ts index 021a25110..a0c009752 100644 --- a/cypress/e2e/builder/item/order/reorderItems.cy.ts +++ b/cypress/e2e/builder/item/order/reorderItems.cy.ts @@ -27,7 +27,7 @@ describe('Order Items', () => { cy.intercept( { method: HttpMethod.Get, - url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/children`), + url: new RegExp(String.raw`${API_HOST}/items/${ID_FORMAT}/children`), }, ({ reply }) => reply(orderedItems), ).as('getChildren'); diff --git a/cypress/e2e/builder/memberships/editItemMembership.cy.ts b/cypress/e2e/builder/memberships/editItemMembership.cy.ts index 7479a0a1b..15b3f677a 100644 --- a/cypress/e2e/builder/memberships/editItemMembership.cy.ts +++ b/cypress/e2e/builder/memberships/editItemMembership.cy.ts @@ -11,8 +11,7 @@ import { buildPermissionOptionId, buildShareButtonId, } from '../../../../src/config/selectors'; -import { CURRENT_MEMBER } from '../../../fixtures/members'; -import { MEMBERS } from '../../../fixtures/members'; +import { CURRENT_MEMBER, MEMBERS } from '../../../fixtures/members'; import { ItemForTest } from '../../../support/types'; import { ITEMS_WITH_MEMBERSHIPS } from '../fixtures/memberships'; import { buildItemPath, buildItemSharePath } from '../utils'; diff --git a/cypress/e2e/player/shuffle.cy.ts b/cypress/e2e/player/shuffle.cy.ts index ec1c89e18..8aed2f786 100644 --- a/cypress/e2e/player/shuffle.cy.ts +++ b/cypress/e2e/player/shuffle.cy.ts @@ -73,9 +73,7 @@ describe.skip('Shuffle', () => { const shuffledOrder = [2, 4, 1, 3, 5]; // last should always be last - expect(shuffledOrder[shuffledOrder.length - 1]).to.equal( - shuffledOrder.length, - ); + expect(shuffledOrder.at(-1)).to.equal(shuffledOrder.length); cy.get(`.${buildTreeItemClass(root.id)}`) .siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`) @@ -112,9 +110,7 @@ describe.skip('Shuffle', () => { const shuffledOrder = [2, 4, 1, 3, 5]; // last should always be last - expect(shuffledOrder[shuffledOrder.length - 1]).to.equal( - shuffledOrder.length, - ); + expect(shuffledOrder.at(-1)).to.equal(shuffledOrder.length); cy.get(`.${buildTreeItemClass(root.id)}`) .siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`) @@ -151,9 +147,7 @@ describe.skip('Shuffle', () => { const shuffledOrder = [2, 4, 1, 3, 5]; // last should always be last - expect(shuffledOrder[shuffledOrder.length - 1]).to.equal( - shuffledOrder.length, - ); + expect(shuffledOrder.at(-1)).to.equal(shuffledOrder.length); cy.get(`.${buildTreeItemClass(root.id)}`) .siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`) @@ -191,9 +185,7 @@ describe.skip('Shuffle', () => { const shuffledOrder = [1, 4, 3, 2, 5]; // last should always be last - expect(shuffledOrder[shuffledOrder.length - 1]).to.equal( - shuffledOrder.length, - ); + expect(shuffledOrder.at(-1)).to.equal(shuffledOrder.length); cy.get(`.${buildTreeItemClass(root.id)}`) .siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`) @@ -244,9 +236,7 @@ describe.skip('Shuffle', () => { const shuffledOrder = [1, 2, 3, 4, 5]; // last should always be last - expect(shuffledOrder[shuffledOrder.length - 1]).to.equal( - shuffledOrder.length, - ); + expect(shuffledOrder.at(-1)).to.equal(shuffledOrder.length); cy.get(`.${buildTreeItemClass(root.id)}`) .siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`) @@ -285,9 +275,7 @@ describe.skip('Shuffle', () => { const shuffledOrder = [3, 4, 2, 1, 5]; // last should always be last - expect(shuffledOrder[shuffledOrder.length - 1]).to.equal( - shuffledOrder.length, - ); + expect(shuffledOrder.at(-1)).to.equal(shuffledOrder.length); cy.get(`.${buildTreeItemClass(root.id)}`) .siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`) @@ -340,9 +328,7 @@ describe.skip('Shuffle', () => { const shuffledOrder = [3, 2, 1, 4, 5]; // last should always be last - expect(shuffledOrder[shuffledOrder.length - 1]).to.equal( - shuffledOrder.length, - ); + expect(shuffledOrder.at(-1)).to.equal(shuffledOrder.length); cy.get(`.${buildTreeItemClass(root.id)}`) .siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`) @@ -380,9 +366,7 @@ describe.skip('Shuffle', () => { const shuffledOrder = [3, 2, 1, 4, 5]; // last should always be last - expect(shuffledOrder[shuffledOrder.length - 1]).to.equal( - shuffledOrder.length, - ); + expect(shuffledOrder.at(-1)).to.equal(shuffledOrder.length); cy.get(`.${buildTreeItemClass(root.id)}`) .siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`) @@ -423,9 +407,7 @@ describe.skip('Shuffle', () => { const shuffledOrder = [3, 4, 1, 2, 5]; // last should always be last - expect(shuffledOrder[shuffledOrder.length - 1]).to.equal( - shuffledOrder.length, - ); + expect(shuffledOrder.at(-1)).to.equal(shuffledOrder.length); cy.get(`.${buildTreeItemClass(root.id)}`) .siblings(`ul.${TREE_NODE_GROUP_CLASS}:first`) diff --git a/cypress/fixtures/items.ts b/cypress/fixtures/items.ts index bdfe9121f..b1708f1db 100644 --- a/cypress/fixtures/items.ts +++ b/cypress/fixtures/items.ts @@ -473,7 +473,7 @@ export const generateLotsOfFoldersOnHome = ({ creator?: ItemForTest['creator']; memberships?: ItemForTest['memberships']; }): ItemForTest[] => - Array.from(Array(folderCount)).map(() => { + Array.from(new Array(folderCount)).map(() => { const itemId = v4(); return { ...DEFAULT_FOLDER_ITEM, diff --git a/cypress/support/server.ts b/cypress/support/server.ts index 06fdf8bcb..4b22ea8b3 100644 --- a/cypress/support/server.ts +++ b/cypress/support/server.ts @@ -317,7 +317,7 @@ export const mockPutItemLoginSchema = ( cy.intercept( { method: HttpMethod.Put, - url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/login-schema$`), + url: new RegExp(String.raw`${API_HOST}/items/${ID_FORMAT}/login-schema$`), }, ({ reply }) => { if (shouldThrowError) { @@ -336,7 +336,7 @@ export const mockDeleteItemLoginSchema = (): void => { cy.intercept( { method: HttpMethod.Delete, - url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/login-schema$`), + url: new RegExp(String.raw`${API_HOST}/items/${ID_FORMAT}/login-schema$`), }, ({ reply }) => { // check query match item login schema @@ -372,7 +372,9 @@ export const mockGetItemLoginSchema = (items: ItemForTest[]): void => { { method: HttpMethod.Get, // TODO: use build url - url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/login\\-schema$`), + url: new RegExp( + String.raw`${API_HOST}/items/${ID_FORMAT}/login\-schema$`, + ), }, ({ reply, url }) => { const itemId = url.slice(API_HOST.length).split('/')[2]; @@ -395,7 +397,9 @@ export const mockGetItemLoginSchemaType = (items: ItemForTest[]): void => { cy.intercept( { method: HttpMethod.Get, - url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/login\\-schema\\-type$`), + url: new RegExp( + String.raw`${API_HOST}/items/${ID_FORMAT}/login\-schema\-type$`, + ), }, ({ reply, url }) => { const itemId = url.slice(API_HOST.length).split('/')[2]; @@ -1197,7 +1201,7 @@ export const mockGetChildren = ({ items }: { items: ItemForTest[] }): void => { cy.intercept( { method: HttpMethod.Get, - url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/children`), + url: new RegExp(String.raw`${API_HOST}/items/${ID_FORMAT}/children`), }, ({ url, reply }) => { const id = url.slice(API_HOST.length).split('/')[2]; @@ -1898,7 +1902,7 @@ export const mockGetDescendants = ( cy.intercept( { method: HttpMethod.Get, - url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/descendants`), + url: new RegExp(String.raw`${API_HOST}/items/${ID_FORMAT}/descendants`), }, ({ url, reply }) => { const id = url.slice(API_HOST.length).split('/')[2]; @@ -2319,7 +2323,9 @@ export const mockGetMembershipRequestsForItem = ( cy.intercept( { method: HttpMethod.Get, - url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/memberships/requests$`), + url: new RegExp( + String.raw`${API_HOST}/items/${ID_FORMAT}/memberships/requests$`, + ), }, ({ reply, url }) => { const urlParams = url.split('/'); @@ -2362,7 +2368,7 @@ export const mockGetItemMembershipsForItem = ( cy.intercept( { method: HttpMethod.Get, - url: new RegExp(`${API_HOST}/items/${ID_FORMAT}/memberships$`), + url: new RegExp(String.raw`${API_HOST}/items/${ID_FORMAT}/memberships$`), }, ({ reply, url }) => { const itemId = url.split('/')[4]; diff --git a/src/components/chatbox/Chatbox/MessageActions.tsx b/src/components/chatbox/Chatbox/MessageActions.tsx index 6d7a259f2..57ccbc160 100644 --- a/src/components/chatbox/Chatbox/MessageActions.tsx +++ b/src/components/chatbox/Chatbox/MessageActions.tsx @@ -1,4 +1,4 @@ -import { type MouseEvent, useState } from 'react'; +import { type JSX, type MouseEvent, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Delete, Edit, MoreVert } from '@mui/icons-material'; @@ -36,7 +36,11 @@ const StyledListItemIcon = styled(ListItemIcon)({ }, }); -export function MessageActions({ message, isOwn = false, itemId }: Props) { +export function MessageActions({ + message, + isOwn = false, + itemId, +}: Readonly): JSX.Element { const [menuOpen, setMenuOpen] = useState(false); const [menuAnchor, setMenuAnchor] = useState(null); const { t } = useTranslation(NS.Chatbox);