Skip to content

Commit

Permalink
chore(cypress): Move clearState from user utils to shared common utils
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Oct 29, 2023
1 parent bfc8b0b commit a7c8851
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
3 changes: 1 addition & 2 deletions cypress/e2e/settings/access-levels.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
*/

import { User } from '@nextcloud/cypress'
import { clearState } from './usersUtils'
import { getNextcloudUserMenu, getNextcloudUserMenuToggle } from '../../support/commonUtils'
import { clearState, getNextcloudUserMenu, getNextcloudUserMenuToggle } from '../../support/commonUtils'

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

Expand Down
16 changes: 0 additions & 16 deletions cypress/e2e/settings/usersUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@ export function assertNotExistOrNotVisible(element: JQuery<HTMLElement>) {
expect(doesNotExist || isNotVisible, 'does not exist or is not visible').to.be.true
}

/**
* Helper function ensure users and groups in this tests have a clean state
*/
export function clearState() {
// cleanup ignoring any failures
cy.runOccCommand('group:list --output=json').then(($result) => {
const groups = Object.keys(JSON.parse($result.stdout)).filter((name) => name !== 'admin')
groups.forEach((groupID) => cy.runOccCommand(`group:delete '${groupID}'`))
})

cy.runOccCommand('user:list --output=json').then(($result) => {
const users = Object.keys(JSON.parse($result.stdout)).filter((name) => name !== 'admin')
users.forEach((userID) => cy.runOccCommand(`user:delete '${userID}'`))
})
}

/**
* Get the settings users list
* @return Cypress chainable object
Expand Down
3 changes: 2 additions & 1 deletion cypress/e2e/settings/users_disable.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
*/

import { User } from '@nextcloud/cypress'
import { clearState, getUserListRow } from './usersUtils'
import { getUserListRow } from './usersUtils'
import { clearState } from '../../support/commonUtils'

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

Expand Down
3 changes: 2 additions & 1 deletion cypress/e2e/settings/users_modify.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
*/

import { User } from '@nextcloud/cypress'
import { clearState, getUserListRow, handlePasswordConfirmation, toggleEditButton, waitLoading } from './usersUtils'
import { getUserListRow, handlePasswordConfirmation, toggleEditButton, waitLoading } from './usersUtils'
import { clearState } from '../../support/commonUtils'

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

Expand Down
17 changes: 17 additions & 0 deletions cypress/support/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,20 @@ export function getNextcloudUserMenu() {
export function getNextcloudUserMenuToggle() {
return getNextcloudUserMenu().find('.header-menu__trigger').should('have.length', 1)
}

/**
* Helper function ensure users and groups in this tests have a clean state
* Deletes all users (except admin) and groups
*/
export function clearState() {
// cleanup ignoring any failures
cy.runOccCommand('group:list --output=json').then(($result) => {
const groups = Object.keys(JSON.parse($result.stdout)).filter((name) => name !== 'admin')
groups.forEach((groupID) => cy.runOccCommand(`group:delete '${groupID}'`))
})

cy.runOccCommand('user:list --output=json').then(($result) => {
const users = Object.keys(JSON.parse($result.stdout)).filter((name) => name !== 'admin')
users.forEach((userID) => cy.runOccCommand(`user:delete '${userID}'`))
})
}

0 comments on commit a7c8851

Please sign in to comment.