Skip to content

Commit a7c8851

Browse files
committed
chore(cypress): Move clearState from user utils to shared common utils
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent bfc8b0b commit a7c8851

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

cypress/e2e/settings/access-levels.cy.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
*/
2222

2323
import { User } from '@nextcloud/cypress'
24-
import { clearState } from './usersUtils'
25-
import { getNextcloudUserMenu, getNextcloudUserMenuToggle } from '../../support/commonUtils'
24+
import { clearState, getNextcloudUserMenu, getNextcloudUserMenuToggle } from '../../support/commonUtils'
2625

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

cypress/e2e/settings/usersUtils.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,6 @@ export function assertNotExistOrNotVisible(element: JQuery<HTMLElement>) {
3535
expect(doesNotExist || isNotVisible, 'does not exist or is not visible').to.be.true
3636
}
3737

38-
/**
39-
* Helper function ensure users and groups in this tests have a clean state
40-
*/
41-
export function clearState() {
42-
// cleanup ignoring any failures
43-
cy.runOccCommand('group:list --output=json').then(($result) => {
44-
const groups = Object.keys(JSON.parse($result.stdout)).filter((name) => name !== 'admin')
45-
groups.forEach((groupID) => cy.runOccCommand(`group:delete '${groupID}'`))
46-
})
47-
48-
cy.runOccCommand('user:list --output=json').then(($result) => {
49-
const users = Object.keys(JSON.parse($result.stdout)).filter((name) => name !== 'admin')
50-
users.forEach((userID) => cy.runOccCommand(`user:delete '${userID}'`))
51-
})
52-
}
53-
5438
/**
5539
* Get the settings users list
5640
* @return Cypress chainable object

cypress/e2e/settings/users_disable.cy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
*/
2222

2323
import { User } from '@nextcloud/cypress'
24-
import { clearState, getUserListRow } from './usersUtils'
24+
import { getUserListRow } from './usersUtils'
25+
import { clearState } from '../../support/commonUtils'
2526

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

cypress/e2e/settings/users_modify.cy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
*/
2222

2323
import { User } from '@nextcloud/cypress'
24-
import { clearState, getUserListRow, handlePasswordConfirmation, toggleEditButton, waitLoading } from './usersUtils'
24+
import { getUserListRow, handlePasswordConfirmation, toggleEditButton, waitLoading } from './usersUtils'
25+
import { clearState } from '../../support/commonUtils'
2526

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

cypress/support/commonUtils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,20 @@ export function getNextcloudUserMenu() {
1818
export function getNextcloudUserMenuToggle() {
1919
return getNextcloudUserMenu().find('.header-menu__trigger').should('have.length', 1)
2020
}
21+
22+
/**
23+
* Helper function ensure users and groups in this tests have a clean state
24+
* Deletes all users (except admin) and groups
25+
*/
26+
export function clearState() {
27+
// cleanup ignoring any failures
28+
cy.runOccCommand('group:list --output=json').then(($result) => {
29+
const groups = Object.keys(JSON.parse($result.stdout)).filter((name) => name !== 'admin')
30+
groups.forEach((groupID) => cy.runOccCommand(`group:delete '${groupID}'`))
31+
})
32+
33+
cy.runOccCommand('user:list --output=json').then(($result) => {
34+
const users = Object.keys(JSON.parse($result.stdout)).filter((name) => name !== 'admin')
35+
users.forEach((userID) => cy.runOccCommand(`user:delete '${userID}'`))
36+
})
37+
}

0 commit comments

Comments
 (0)