From f7d09ebdba8834d82038c531e9a3abbbab2d2d70 Mon Sep 17 00:00:00 2001 From: Cleopatra Enjeck M Date: Mon, 8 Jul 2024 05:40:40 +0100 Subject: [PATCH] test: add Cypress tests for usergroup column Signed-off-by: Cleopatra Enjeck M --- cypress/e2e/column-usergroup.cy.js | 66 ++++++++++++ cypress/support/commands.js | 165 +++++++++++++---------------- 2 files changed, 140 insertions(+), 91 deletions(-) create mode 100644 cypress/e2e/column-usergroup.cy.js diff --git a/cypress/e2e/column-usergroup.cy.js b/cypress/e2e/column-usergroup.cy.js new file mode 100644 index 000000000..5aaa8bbdb --- /dev/null +++ b/cypress/e2e/column-usergroup.cy.js @@ -0,0 +1,66 @@ +let localUser +let nonLocalUser +const columnTitle = 'usergroup' +const tableTitlePrefix = 'Test usergroup' +let tableTitle = tableTitlePrefix +let testNumber = 0 + +describe('Test column ' + columnTitle, () => { + + before(function() { + cy.createRandomUser().then(user => { + localUser = user + }) + + cy.createRandomUser().then(user => { + nonLocalUser = user + }) + }) + + beforeEach(function() { + testNumber += 1 + tableTitle = `${tableTitlePrefix} ${testNumber}` + cy.login(localUser) + cy.visit('apps/tables') + }) + + it('Create column and rows with default values', () => { + cy.createTable(tableTitle) + cy.loadTable(tableTitle) + cy.createUsergroupColumn(columnTitle, true, true, true, [localUser.userId, nonLocalUser.userId], true) + cy.get('button').contains('Create row').click() + cy.get('[data-cy="createRowSaveButton"]').click() + cy.get('[data-cy="ncTable"] table tr td .userInfo').contains(localUser.userId).should('be.visible') + cy.get('[data-cy="ncTable"] table tr td .userInfo').contains(nonLocalUser.userId).should('be.visible') + }) + + it('Create column and rows without default values', () => { + cy.createTable(tableTitle) + cy.loadTable(tableTitle) + cy.createUsergroupColumn(columnTitle, true, false, false, [], true) + + cy.get('button').contains('Create row').click() + cy.get('[data-cy="usergroupRowSelect"] input').type(nonLocalUser.userId) + cy.get(`.vs__dropdown-menu [id="${nonLocalUser.userId}"]`).click() + cy.get('[data-cy="createRowSaveButton"]').click() + cy.get('[data-cy="ncTable"] table tr td .userInfo').contains(nonLocalUser.userId).should('be.visible') + }) + + it('Create and edit rows', () => { + cy.createTable(tableTitle) + cy.loadTable(tableTitle) + cy.createUsergroupColumn(columnTitle, true, true, true, [localUser.userId], true) + cy.get('button').contains('Create row').click() + cy.get('[data-cy="createRowSaveButton"]').click() + cy.get('[data-cy="ncTable"] table tr td .userInfo').contains(localUser.userId).should('be.visible') + + cy.get('[data-cy="ncTable"] [data-cy="editRowBtn"]').click() + cy.get('[data-cy="usergroupRowSelect"] input').clear().type(nonLocalUser.userId) + cy.get(`.vs__dropdown-menu [id="${nonLocalUser.userId}"]`).click() + cy.get('[data-cy="editRowSaveButton"]').click() + cy.get('[data-cy="ncTable"] table tr td .userInfo').contains(localUser.userId).should('not.exist') + cy.get('[data-cy="ncTable"] table tr td .userInfo').contains(nonLocalUser.userId).should('be.visible') + }) + + +}) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 984e12f97..bdd8e23be 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -56,6 +56,15 @@ Cypress.Commands.add('createView', (title) => { cy.contains('.app-navigation-entry-link span', title).should('exist') }) +Cypress.Commands.add('openCreateColumnModal', (isFirstColumn) => { + if (isFirstColumn) { + cy.get('.button-vue__text').contains('Create column').click({ force: true }) + } else { + cy.get('[data-cy="customTableAction"] button').click() + cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) + } +}) + Cypress.Commands.add('createContext', (title) => { cy.get('ul:nth-of-type(2) [data-cy="createContextIcon"]').click({ force: true }) cy.get('[data-cy="createContextModal"]').should('be.visible') @@ -67,10 +76,6 @@ Cypress.Commands.add('createContext', (title) => { cy.contains('h1', title).should('exist') }) -Cypress.Commands.add('loadContext', (title) => { - cy.get('[data-cy="navigationContextItem"]').contains(title).click({ force: true }) -}) - Cypress.Commands.add('openContextEditModal', (title) => { cy.get(`[data-cy="navigationContextItem"]:contains("${title}")`).find('button').click({ force: true }) cy.get('[data-cy="navigationContextEditBtn"]').contains('Edit application').click({ force: true }) @@ -99,21 +104,48 @@ Cypress.Commands.add('loadView', (name) => { cy.get('[data-cy="navigationViewItem"] a[title="' + name + '"]').click({ force: true }) }) +Cypress.Commands.add('loadContext', (title) => { + cy.get('[data-cy="navigationContextItem"]').contains(title).click({ force: true }) +}) + Cypress.Commands.add('unifiedSearch', (term) => { cy.get('#unified-search').click() cy.get('#unified-search__input').type(term) cy.get('.unified-search__results .unified-search__result-line-one span').contains(term, { matchCase: false }).should('exist') }) -Cypress.Commands.add('createTextLinkColumn', (title, ressourceProvider, firstColumn) => { - if (firstColumn) { - cy.get('.button-vue__text').contains('Create column').click({ force: true }) - } else { - cy.get('[data-cy="customTableAction"] button').click() - cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) +Cypress.Commands.add('createUsergroupColumn', (title, selectUsers, selectGroups, hasMultipleValues, defaultValue, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) + cy.get('.columnTypeSelection .vs__open-indicator').click({ force: true }) + cy.get('.multiSelectOptionLabel').contains('Users and groups').click({ force: true }) + + if (hasMultipleValues) { + cy.get('[data-cy="usergroupMultipleSwitch"] .checkbox-content').click({ force: true }) + } + + if (selectUsers && selectGroups) { + cy.get('[data-cy="userAndGroupSwitch"] .checkbox-content').click() + } else if (selectUsers) { + cy.get('[data-cy="userSwitch"] .checkbox-content').click() + } else if (selectGroups) { + cy.get('[data-cy="groupSwitch"] .checkbox-content').click() } - cy.get('.modal-container').get('input[placeholder*="Enter a column title"]').clear().type(title) + defaultValue.forEach((value) => { + cy.get('[data-cy="usergroupDefaultSelect"] input').type(value) + cy.get(`.vs__dropdown-menu [id="${value}"]`).click() + }) + + cy.get('[data-cy="createColumnSaveBtn"]').click() + cy.wait(10).get('.toastify.toast-success').should('be.visible') + cy.get('[data-cy="ncTable"] table tr th').contains(title).should('exist') +}) + +Cypress.Commands.add('createTextLinkColumn', (title, ressourceProvider, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) + + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) cy.get('.columnTypeSelection .vs__open-indicator').click({ force: true }) cy.get('.multiSelectOptionLabel').contains('Link').click({ force: true }) // deactivate unwanted provider @@ -131,15 +163,10 @@ Cypress.Commands.add('createTextLinkColumn', (title, ressourceProvider, firstCol cy.get('.custom-table table tr th .cell').contains(title).should('exist') }) -Cypress.Commands.add('createSelectionColumn', (title, options, defaultOption, firstColumn) => { - if (firstColumn) { - cy.get('.button-vue__text').contains('Create column').click({ force: true }) - } else { - cy.get('[data-cy="customTableAction"] button').click() - cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) - } +Cypress.Commands.add('createSelectionColumn', (title, options, defaultOption, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) - cy.get('.modal-container').get('input[placeholder*="Enter a column title"]').clear().type(title) + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) cy.get('.columnTypeSelection .vs__open-indicator').click({ force: true }) cy.get('.multiSelectOptionLabel').contains('Selection').click({ force: true }) // remove default option @@ -160,15 +187,11 @@ Cypress.Commands.add('createSelectionColumn', (title, options, defaultOption, fi cy.get('.custom-table table tr th .cell').contains(title).should('exist') }) -Cypress.Commands.add('createSelectionMultiColumn', (title, options, defaultOptions, firstColumn) => { - if (firstColumn) { - cy.get('.button-vue__text').contains('Create column').click({ force: true }) - } else { - cy.get('[data-cy="customTableAction"] button').click() - cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) - } - cy.get('.modal-container').get('input[placeholder*="Enter a column title"]').clear().type(title) +Cypress.Commands.add('createSelectionMultiColumn', (title, options, defaultOptions, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) + + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) cy.get('.columnTypeSelection .vs__open-indicator').click({ force: true }) cy.get('.multiSelectOptionLabel').contains('Selection').click({ force: true }) cy.get('[data-cy="createColumnMultipleSelectionSwitch"]').contains('Multiple selection').click() @@ -191,14 +214,9 @@ Cypress.Commands.add('createSelectionMultiColumn', (title, options, defaultOptio cy.get('.custom-table table tr th .cell').contains(title).should('exist') }) -Cypress.Commands.add('createTextLineColumn', (title, defaultValue, maxLength, firstColumn) => { - if (firstColumn) { - cy.get('.button-vue__text').contains('Create column').click({ force: true }) - } else { - cy.get('[data-cy="customTableAction"] button').click() - cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) - } - cy.get('.modal-container').get('input[placeholder*="Enter a column title"]').clear().type(title) +Cypress.Commands.add('createTextLineColumn', (title, defaultValue, maxLength, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) if (defaultValue) { cy.get('[data-cy="TextLineForm"] input').first().type(defaultValue) } @@ -210,14 +228,9 @@ Cypress.Commands.add('createTextLineColumn', (title, defaultValue, maxLength, fi cy.get('.custom-table table tr th .cell').contains(title).should('exist') }) -Cypress.Commands.add('createDatetimeColumn', (title, setNow, firstColumn) => { - if (firstColumn) { - cy.get('.button-vue__text').contains('Create column').click({ force: true }) - } else { - cy.get('[data-cy="customTableAction"] button').click() - cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) - } - cy.get('.modal-container').get('input[placeholder*="Enter a column title"]').clear().type(title) +Cypress.Commands.add('createDatetimeColumn', (title, setNow, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) cy.get('.columnTypeSelection .vs__open-indicator').click({ force: true }) cy.get('.multiSelectOptionLabel').contains('Date and time').click({ force: true }) @@ -230,14 +243,9 @@ Cypress.Commands.add('createDatetimeColumn', (title, setNow, firstColumn) => { cy.get('.custom-table table tr th .cell').contains(title).should('exist') }) -Cypress.Commands.add('createDatetimeDateColumn', (title, setNow, firstColumn) => { - if (firstColumn) { - cy.get('.button-vue__text').contains('Create column').click({ force: true }) - } else { - cy.get('[data-cy="customTableAction"] button').click() - cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) - } - cy.get('.modal-container').get('input[placeholder*="Enter a column title"]').clear().type(title) +Cypress.Commands.add('createDatetimeDateColumn', (title, setNow, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) cy.get('.columnTypeSelection .vs__open-indicator').click({ force: true }) cy.get('.multiSelectOptionLabel').contains('Date and time').click({ force: true }) cy.get('[data-cy="createColumnDateSwitch"]').contains('Date').click() @@ -251,14 +259,9 @@ Cypress.Commands.add('createDatetimeDateColumn', (title, setNow, firstColumn) => cy.get('.custom-table table tr th .cell').contains(title).should('exist') }) -Cypress.Commands.add('createDatetimeTimeColumn', (title, setNow, firstColumn) => { - if (firstColumn) { - cy.get('.button-vue__text').contains('Create column').click({ force: true }) - } else { - cy.get('[data-cy="customTableAction"] button').click() - cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) - } - cy.get('.modal-container').get('input[placeholder*="Enter a column title"]').clear().type(title) +Cypress.Commands.add('createDatetimeTimeColumn', (title, setNow, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) cy.get('.columnTypeSelection .vs__open-indicator').click({ force: true }) cy.get('.multiSelectOptionLabel').contains('Date and time').click({ force: true }) cy.get('[data-cy="createColumnTimeSwitch"]').contains('Time').click() @@ -272,14 +275,9 @@ Cypress.Commands.add('createDatetimeTimeColumn', (title, setNow, firstColumn) => cy.get('.custom-table table tr th .cell').contains(title).should('exist') }) -Cypress.Commands.add('createNumberColumn', (title, defaultValue, decimals, min, max, prefix, suffix, firstColumn) => { - if (firstColumn) { - cy.get('.button-vue__text').contains('Create column').click({ force: true }) - } else { - cy.get('[data-cy="customTableAction"] button').click() - cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) - } - cy.get('.modal-container').get('input[placeholder*="Enter a column title"]').clear().type(title) +Cypress.Commands.add('createNumberColumn', (title, defaultValue, decimals, min, max, prefix, suffix, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) cy.get('.columnTypeSelection .vs__open-indicator').click({ force: true }) cy.get('.multiSelectOptionLabel').contains('Number').click({ force: true }) @@ -306,14 +304,9 @@ Cypress.Commands.add('createNumberColumn', (title, defaultValue, decimals, min, cy.get('.custom-table table tr th .cell').contains(title).should('exist') }) -Cypress.Commands.add('createNumberProgressColumn', (title, defaultValue, firstColumn) => { - if (firstColumn) { - cy.get('.button-vue__text').contains('Create column').click({ force: true }) - } else { - cy.get('[data-cy="customTableAction"] button').click() - cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) - } - cy.get('.modal-container').get('input[placeholder*="Enter a column title"]').clear().type(title) +Cypress.Commands.add('createNumberProgressColumn', (title, defaultValue, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) cy.get('.columnTypeSelection .vs__open-indicator').click({ force: true }) cy.get('.multiSelectOptionLabel').contains('Progress').click({ force: true }) @@ -325,14 +318,9 @@ Cypress.Commands.add('createNumberProgressColumn', (title, defaultValue, firstCo cy.get('.custom-table table tr th .cell').contains(title).should('exist') }) -Cypress.Commands.add('createNumberStarsColumn', (title, defaultValue, firstColumn) => { - if (firstColumn) { - cy.get('.button-vue__text').contains('Create column').click({ force: true }) - } else { - cy.get('[data-cy="customTableAction"] button').click() - cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) - } - cy.get('.modal-container').get('input[placeholder*="Enter a column title"]').clear().type(title) +Cypress.Commands.add('createNumberStarsColumn', (title, defaultValue, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) cy.get('.columnTypeSelection .vs__open-indicator').click({ force: true }) cy.get('.multiSelectOptionLabel').contains('Stars rating').click({ force: true }) @@ -346,14 +334,9 @@ Cypress.Commands.add('createNumberStarsColumn', (title, defaultValue, firstColum cy.get('.custom-table table tr th .cell').contains(title).should('exist') }) -Cypress.Commands.add('createSelectionCheckColumn', (title, defaultValue, firstColumn) => { - if (firstColumn) { - cy.get('.button-vue__text').contains('Create column').click({ force: true }) - } else { - cy.get('[data-cy="customTableAction"] button').click() - cy.get('[data-cy="dataTableCreateColumnBtn"]').contains('Create column').click({ force: true }) - } - cy.get('.modal-container').get('input[placeholder*="Enter a column title"]').clear().type(title) +Cypress.Commands.add('createSelectionCheckColumn', (title, defaultValue, isFirstColumn) => { + cy.openCreateColumnModal(isFirstColumn) + cy.get('[data-cy="columnTypeFormInput"]').clear().type(title) cy.get('.columnTypeSelection .vs__open-indicator').click({ force: true }) cy.get('.multiSelectOptionLabel').contains('Selection').click({ force: true }) cy.get('[data-cy="createColumnYesNoSwitch"').contains('Yes/No').click()