Skip to content

Commit

Permalink
tests(Cypress): add tests for application navigation display
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M. <[email protected]>
  • Loading branch information
enjeck committed Jan 26, 2025
1 parent 2a98322 commit d2eb387
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
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 @@ -110,10 +110,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

0 comments on commit d2eb387

Please sign in to comment.