From 6357ad048862cf65271e7dbbd040028972c87f78 Mon Sep 17 00:00:00 2001 From: LinaYahya Date: Thu, 7 Sep 2023 15:53:05 +0200 Subject: [PATCH 1/3] fix: validate white spaces for creating new item --- src/utils/item.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/item.ts b/src/utils/item.ts index 492f6c1b0..f56974de9 100644 --- a/src/utils/item.ts +++ b/src/utils/item.ts @@ -103,7 +103,7 @@ export const isItemValid = (item: Partial): boolean => { return false; } - const shouldHaveName = Boolean(item.name); + const shouldHaveName = Boolean(item.name?.trim()); // item should have a type let hasValidTypeProperties = From fd40cb0e9d209215a39f779f7c1bbf1f983365c0 Mon Sep 17 00:00:00 2001 From: LinaYahya Date: Thu, 7 Sep 2023 15:54:23 +0200 Subject: [PATCH 2/3] test: create a test for whitespaces new item name --- cypress/e2e/item/create/createFolder.cy.ts | 23 +++++++++++++++++----- cypress/fixtures/items.ts | 6 ++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/item/create/createFolder.cy.ts b/cypress/e2e/item/create/createFolder.cy.ts index bf02df2f0..109b0ebb6 100644 --- a/cypress/e2e/item/create/createFolder.cy.ts +++ b/cypress/e2e/item/create/createFolder.cy.ts @@ -1,11 +1,16 @@ import { HOME_PATH, buildItemPath } from '../../../../src/config/paths'; import { CREATE_ITEM_BUTTON_ID, + ITEM_FORM_CONFIRM_BUTTON_ID, ITEM_FORM_NAME_INPUT_ID, buildItemsTableRowIdAttribute, } from '../../../../src/config/selectors'; import ITEM_LAYOUT_MODES from '../../../../src/enums/itemLayoutModes'; -import { CREATED_ITEM, SAMPLE_ITEMS } from '../../../fixtures/items'; +import { + CREATED_BLANK_NAME_ITEM, + CREATED_ITEM, + SAMPLE_ITEMS, +} from '../../../fixtures/items'; import { createFolder } from '../../../support/createUtils'; describe('Create Folder', () => { @@ -33,11 +38,19 @@ describe('Create Folder', () => { // create createFolder(CREATED_ITEM); + }); - cy.wait('@postItem').then(() => { - // expect update - cy.wait('@getItem').its('response.url').should('contain', id); - }); + it('create folder with blank name in item', () => { + // create + cy.setUpApi(); + cy.visit(HOME_PATH); + createFolder(CREATED_BLANK_NAME_ITEM, { confirm: false }); + + cy.get(`#${ITEM_FORM_CONFIRM_BUTTON_ID}`).should( + 'have.prop', + 'disabled', + true, + ); }); }); diff --git a/cypress/fixtures/items.ts b/cypress/fixtures/items.ts index c9ea49a42..82da12d75 100644 --- a/cypress/fixtures/items.ts +++ b/cypress/fixtures/items.ts @@ -43,6 +43,12 @@ export const CREATED_ITEM: Partial = { extra: { [ItemType.FOLDER]: { childrenOrder: [] } }, }; +export const CREATED_BLANK_NAME_ITEM: Partial = { + name: ' ', + type: ItemType.FOLDER, + extra: { [ItemType.FOLDER]: { childrenOrder: [] } }, +}; + export const EDITED_FIELDS = { name: 'new name', }; From 4b8970c4c2cc37cadd4dd57b11515584300a84af Mon Sep 17 00:00:00 2001 From: LinaYahya Date: Fri, 8 Sep 2023 10:18:31 +0200 Subject: [PATCH 3/3] test: creating document with blank name led to have inactive btn --- cypress/e2e/item/create/createDocument.cy.ts | 21 +++++++++++++++++++- cypress/e2e/item/create/createFolder.cy.ts | 2 +- cypress/fixtures/documents.ts | 15 ++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/item/create/createDocument.cy.ts b/cypress/e2e/item/create/createDocument.cy.ts index 9f1ce9e4d..f835db31f 100644 --- a/cypress/e2e/item/create/createDocument.cy.ts +++ b/cypress/e2e/item/create/createDocument.cy.ts @@ -1,6 +1,11 @@ +import { ITEM_FORM_CONFIRM_BUTTON_ID } from '@/config/selectors'; + import { HOME_PATH, buildItemPath } from '../../../../src/config/paths'; import ITEM_LAYOUT_MODES from '../../../../src/enums/itemLayoutModes'; -import { GRAASP_DOCUMENT_ITEM } from '../../../fixtures/documents'; +import { + GRAASP_DOCUMENT_BLANK_NAME_ITEM, + GRAASP_DOCUMENT_ITEM, +} from '../../../fixtures/documents'; import { SAMPLE_ITEMS } from '../../../fixtures/items'; import { createDocument } from '../../../support/createUtils'; @@ -37,4 +42,18 @@ describe('Create Document', () => { cy.wait('@getItem').its('response.url').should('contain', id); }); }); + + it('cannot create Document with blank name', () => { + cy.setUpApi(); + cy.visit(HOME_PATH); + + cy.switchMode(ITEM_LAYOUT_MODES.LIST); + createDocument(GRAASP_DOCUMENT_BLANK_NAME_ITEM, { confirm: false }); + + cy.get(`#${ITEM_FORM_CONFIRM_BUTTON_ID}`).should( + 'have.prop', + 'disabled', + true, + ); + }); }); diff --git a/cypress/e2e/item/create/createFolder.cy.ts b/cypress/e2e/item/create/createFolder.cy.ts index 109b0ebb6..54a6b555e 100644 --- a/cypress/e2e/item/create/createFolder.cy.ts +++ b/cypress/e2e/item/create/createFolder.cy.ts @@ -40,7 +40,7 @@ describe('Create Folder', () => { createFolder(CREATED_ITEM); }); - it('create folder with blank name in item', () => { + it('cannot create folder with blank name in item', () => { // create cy.setUpApi(); cy.visit(HOME_PATH); diff --git a/cypress/fixtures/documents.ts b/cypress/fixtures/documents.ts index c41760950..aba89811c 100644 --- a/cypress/fixtures/documents.ts +++ b/cypress/fixtures/documents.ts @@ -19,6 +19,21 @@ export const GRAASP_DOCUMENT_ITEM: DocumentItemType = { }), }; +export const GRAASP_DOCUMENT_BLANK_NAME_ITEM: DocumentItemType = { + id: 'ecafbd2a-5688-12eb-ae91-0242ac130004', + type: ItemType.DOCUMENT, + name: ' ', + description: 'a description for graasp text', + path: 'ecafbd2a_5688_12eb_ae93_0242ac130002', + settings: {}, + createdAt: new Date(), + updatedAt: new Date(), + creator: CURRENT_USER, + extra: buildDocumentExtra({ + content: '

Some Title

', + }), +}; + export const GRAASP_DOCUMENT_PARENT_FOLDER: Item = { ...DEFAULT_FOLDER_ITEM, id: 'bdf09f5a-5688-11eb-ae93-0242ac130002',