Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(Cypress): add tests for Application navigation display #1553

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions cypress/e2e/context-navigation.cy.js
Original file line number Diff line number Diff line change
@@ -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')
})
})
5 changes: 4 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading