Skip to content

Commit

Permalink
test(settings): Create and delete groups
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Oct 11, 2023
1 parent 58569eb commit 4386803
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions cypress/e2e/settings/users_groups.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @copyright 2023 Christopher Ng <[email protected]>
*
* @author Christopher Ng <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { User } from '@nextcloud/cypress'

const admin = new User('admin', 'admin')

describe('Settings: Create and delete groups', () => {
before(() => {
cy.login(admin)
// open the User settings
cy.visit('/settings/users')
})

it('Can create a group', () => {
// open the Create group menu
cy.get('button[aria-label="Create group"]').click()

cy.get('.action-item__popper ul[role="menu"]').within(() => {
// see that the group name is ""
cy.get('input[placeholder="Group name"]').should('exist').and('have.value', '')
// set the group name to foo
cy.get('input[placeholder="Group name"]').type('foo')
// see that the group name is foo
cy.get('input[placeholder="Group name"]').should('have.value', 'foo')
// submit the group name
cy.get('input[placeholder="Group name"] ~ button').click()
})

// Ignore failure if modal is not shown
cy.once('fail', (error) => {
expect(error.name).to.equal('AssertionError')
expect(error).to.have.property('node', '.modal-container')
})
// Make sure no confirmation modal is shown
cy.get('body').find('.modal-container').then(($modals) => {
if ($modals.length > 0) {
cy.wrap($modals.first()).find('input[type="password"]').type(admin.password)
cy.wrap($modals.first()).find('button').contains('Confirm').click()
}
})

// see that the created group is in the list
cy.get('ul.app-navigation__list').within(() => {
// see that the list of groups contains the group foo
cy.contains('foo').should('exist')
})
})

it('Can delete a group', () => {
// see that the group is in the list
cy.get('ul.app-navigation__list').within(() => {
// see that the list of groups contains the group foo
cy.contains('foo').should('exist')
// open the actions menu for the group
cy.contains('li', 'foo').within(() => {
cy.get('button.action-item__menutoggle').click()
})
})

// The "Remove group" action in the actions menu is shown and clicked
cy.get('.action-item__popper button').contains('Remove group').should('exist').click()
// And confirmation dialog accepted
cy.get('.modal-container button').contains('Confirm').click()

// Ignore failure if modal is not shown
cy.once('fail', (error) => {
expect(error.name).to.equal('AssertionError')
expect(error).to.have.property('node', '.modal-container')
})
// Make sure no confirmation modal is shown
cy.get('body').find('.modal-container').then(($modals) => {
if ($modals.length > 0) {
cy.wrap($modals.first()).find('input[type="password"]').type(admin.password)
cy.wrap($modals.first()).find('button').contains('Confirm').click()
}
})

// deleted group is not shown anymore
cy.get('ul.app-navigation__list').within(() => {
// see that the list of groups does not contain the group foo
cy.contains('foo').should('not.exist')
})
})
})

0 comments on commit 4386803

Please sign in to comment.