From 4e01309531f4fd0dfa527fd3768629b8b27bf55f Mon Sep 17 00:00:00 2001 From: "Cleopatra Enjeck M." Date: Wed, 22 Jan 2025 07:54:31 +0000 Subject: [PATCH 1/2] tests(Cypress): add tests for application navigation display Signed-off-by: Cleopatra Enjeck M. --- cypress/e2e/context-navigation.cy.js | 89 ++++++++++++++++++++++++++++ cypress/support/commands.js | 5 +- 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 cypress/e2e/context-navigation.cy.js diff --git a/cypress/e2e/context-navigation.cy.js b/cypress/e2e/context-navigation.cy.js new file mode 100644 index 000000000..7198384eb --- /dev/null +++ b/cypress/e2e/context-navigation.cy.js @@ -0,0 +1,89 @@ +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +let localUser +let nonLocalUser +let contextTitlePrefix = 'test application' +let contextTitle = contextTitlePrefix +let testNumber = 0 + +describe('Test context navigation', () => { + before(function () { + cy.createRandomUser().then(user => { + localUser = user + }) + + cy.createRandomUser().then(user => { + nonLocalUser = user + }) + }) + + beforeEach(function () { + testNumber += 1 + contextTitle = contextTitlePrefix + ' ' + testNumber + cy.login(localUser) + cy.visit('apps/tables') + cy.wait(1000) + }) + + it('Create context that is hidden in nav by default', () => { + cy.createContext(contextTitle, false) + cy.visit('apps/tables') + + // Confirming that the context is not shown in the navigation for the owner + cy.get(`#header .app-menu-entry [title="${contextTitle}"]`).should('not.exist') + + cy.loadContext(contextTitle) + cy.wait(1000) + cy.openContextEditModal(contextTitle) + cy.get('[data-cy="contextResourceShare"] input').clear().type(nonLocalUser.userId) + cy.get(`.vs__dropdown-menu [id="${nonLocalUser.userId}"]`).click() + cy.get('[data-cy="contextResourceShare"] span').contains(nonLocalUser.userId).should('exist') + cy.get('[data-cy="editContextSubmitBtn"]').click() + + // Confirming that the context is still not shown by default + // in the navigation for the shared user + cy.login(nonLocalUser) + cy.visit('apps/tables') + cy.get(`#header .app-menu-entry [title="${contextTitle}"]`).should('not.exist') + + // Showing the context in nav for the shared user + cy.loadContext(contextTitle) + cy.get('[data-cy="navigationContextItem"]').contains(`${contextTitle}"`).find('button').click({ force: true }) + cy.get('[data-cy="navigationContextShowInNavSwitch"]').should('not.be.checked') + cy.get('[data-cy="navigationContextShowInNavSwitch"]').click() + cy.get('[data-cy="navigationContextShowInNavSwitch"]').should('be.checked') + cy.get(`#header .app-menu-entry [title="${contextTitle}"]`).should('exist') + }) + + it('Create context that shows in nav by default', () => { + cy.createContext(contextTitle, true) + cy.visit('apps/tables') + + // Confirming that the context is shown in the navigation for the owner + cy.get(`#header .app-menu-entry [title="${contextTitle}"]`).should('exist') + + cy.loadContext(contextTitle) + cy.wait(1000) + cy.openContextEditModal(contextTitle) + cy.get('[data-cy="contextResourceShare"] input').clear().type(nonLocalUser.userId) + cy.get(`.vs__dropdown-menu [id="${nonLocalUser.userId}"]`).click() + cy.get('[data-cy="contextResourceShare"] span').contains(nonLocalUser.userId).should('exist') + cy.get('[data-cy="editContextSubmitBtn"]').click() + + // Hiding the context from nav for the current user + cy.get('[data-cy="navigationContextItem"]').contains(`${contextTitle}"`).find('button').click({ force: true }) + cy.get('[data-cy="navigationContextShowInNavSwitch"]').should('be.checked') + cy.get('[data-cy="navigationContextShowInNavSwitch"]').click() + cy.get('[data-cy="navigationContextShowInNavSwitch"]').should('not.be.checked') + cy.get(`#header .app-menu-entry [title="${contextTitle}"]`).should('not.exist') + + // Confirming that the context is still shown by default + // in the navigation for the shared user + cy.login(nonLocalUser) + cy.visit('apps/tables') + cy.get(`#header .app-menu-entry [title="${contextTitle}"]`).should('exist') + }) +}) \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index b10164650..0c8cdbf34 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -127,10 +127,13 @@ Cypress.Commands.add('openCreateColumnModal', (isFirstColumn) => { } }) -Cypress.Commands.add('createContext', (title) => { +Cypress.Commands.add('createContext', (title, showInNav = false) => { cy.get('ul:nth-of-type(2) [data-cy="createContextIcon"]').click({ force: true }) cy.get('[data-cy="createContextModal"]').should('be.visible') cy.get('[data-cy="createContextTitle"]').clear().type(title) + if (showInNav) { + cy.get('[data-cy="createContextShowInNavSwitch"]').click() + } cy.get('[data-cy="createContextSubmitBtn"]').click() // verify context was created properly From b0bbfe906083aa6c6f08858e5976d6afe9549f86 Mon Sep 17 00:00:00 2001 From: "Cleopatra Enjeck M." Date: Fri, 21 Feb 2025 08:25:37 +0000 Subject: [PATCH 2/2] fix: context nav test selector Signed-off-by: Cleopatra Enjeck M. --- cypress/e2e/context-navigation.cy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/context-navigation.cy.js b/cypress/e2e/context-navigation.cy.js index 7198384eb..8c65d7e27 100644 --- a/cypress/e2e/context-navigation.cy.js +++ b/cypress/e2e/context-navigation.cy.js @@ -51,7 +51,7 @@ describe('Test context navigation', () => { // Showing the context in nav for the shared user cy.loadContext(contextTitle) - cy.get('[data-cy="navigationContextItem"]').contains(`${contextTitle}"`).find('button').click({ force: true }) + cy.get('[data-cy="navigationContextItem"]').contains(`${contextTitle}`).find('button').click({ force: true }) cy.get('[data-cy="navigationContextShowInNavSwitch"]').should('not.be.checked') cy.get('[data-cy="navigationContextShowInNavSwitch"]').click() cy.get('[data-cy="navigationContextShowInNavSwitch"]').should('be.checked') @@ -74,7 +74,7 @@ describe('Test context navigation', () => { cy.get('[data-cy="editContextSubmitBtn"]').click() // Hiding the context from nav for the current user - cy.get('[data-cy="navigationContextItem"]').contains(`${contextTitle}"`).find('button').click({ force: true }) + cy.get('[data-cy="navigationContextItem"]').contains(`${contextTitle}`).find('button').click({ force: true }) cy.get('[data-cy="navigationContextShowInNavSwitch"]').should('be.checked') cy.get('[data-cy="navigationContextShowInNavSwitch"]').click() cy.get('[data-cy="navigationContextShowInNavSwitch"]').should('not.be.checked')