44 */
55
66import { User } from '@nextcloud/e2e-test-server/cypress'
7+ import { clearState } from '../../support/commonUtils.ts'
78import { randomString } from '../../support/utils/randomString.ts'
89import { assertNotExistOrNotVisible , getUserListRow , handlePasswordConfirmation , toggleEditButton } from './usersUtils.ts'
910
1011const admin = new User ( 'admin' , 'admin' )
1112
1213describe ( 'Settings: Create groups' , ( ) => {
14+ let groupName : string
15+
16+ after ( ( ) => {
17+ cy . runOccCommand ( `group:delete '${ groupName ! } '` )
18+ } )
19+
1320 before ( ( ) => {
1421 cy . login ( admin )
1522 cy . visit ( '/settings/users' )
@@ -18,7 +25,7 @@ describe('Settings: Create groups', () => {
1825 it ( 'Can create a group' , ( ) => {
1926 cy . intercept ( 'POST' , '**/ocs/v2.php/cloud/groups' ) . as ( 'createGroups' )
2027
21- const groupName = randomString ( 7 )
28+ groupName = randomString ( 7 )
2229 // open the Create group menu
2330 cy . get ( 'button[aria-label="Create group"]' ) . click ( )
2431
@@ -49,8 +56,14 @@ describe('Settings: Assign user to a group', { testIsolation: false }, () => {
4956 const groupName = randomString ( 7 )
5057 let testUser : User
5158
52- after ( ( ) => cy . deleteUser ( testUser ) )
59+ after ( ( ) => {
60+ cy . deleteUser ( testUser )
61+ cy . runOccCommand ( `group:delete '${ groupName } '` )
62+ } )
63+
5364 before ( ( ) => {
65+ clearState ( )
66+
5467 cy . createRandomUser ( ) . then ( ( user ) => {
5568 testUser = user
5669 } )
@@ -120,6 +133,9 @@ describe('Settings: Assign user to a group', { testIsolation: false }, () => {
120133describe ( 'Settings: Delete an empty group' , { testIsolation : false } , ( ) => {
121134 const groupName = randomString ( 7 )
122135
136+ after ( ( ) => {
137+ cy . runOccCommand ( `group:delete '${ groupName } '` , { failOnNonZeroExit : false } )
138+ } )
123139 before ( ( ) => {
124140 cy . runOccCommand ( `group:add '${ groupName } '` )
125141 cy . login ( admin )
@@ -151,7 +167,8 @@ describe('Settings: Delete an empty group', { testIsolation: false }, () => {
151167
152168 it ( 'deleted group is not shown anymore' , ( ) => {
153169 // see that the list of groups does not contain the group
154- cy . get ( 'ul[data-cy-users-settings-navigation-groups="custom"]' ) . find ( 'li' ) . contains ( groupName )
170+ cy . get ( 'ul[data-cy-users-settings-navigation-groups="custom"]' )
171+ . find ( 'li' )
155172 . should ( 'not.exist' )
156173 // and also not in database
157174 cy . runOccCommand ( 'group:list --output=json' ) . then ( ( $response ) => {
@@ -165,6 +182,10 @@ describe('Settings: Delete a non empty group', () => {
165182 let testUser : User
166183 const groupName = randomString ( 7 )
167184
185+ after ( ( ) => {
186+ cy . runOccCommand ( `group:delete '${ groupName } '` , { failOnNonZeroExit : false } )
187+ } )
188+
168189 before ( ( ) => {
169190 cy . runOccCommand ( `group:add '${ groupName } '` )
170191 cy . createRandomUser ( ) . then ( ( $user ) => {
@@ -202,7 +223,8 @@ describe('Settings: Delete a non empty group', () => {
202223
203224 it ( 'deleted group is not shown anymore' , ( ) => {
204225 // see that the list of groups does not contain the group foo
205- cy . get ( 'ul[data-cy-users-settings-navigation-groups="custom"]' ) . find ( 'li' ) . contains ( groupName )
226+ cy . get ( 'ul[data-cy-users-settings-navigation-groups="custom"]' )
227+ . find ( 'li' )
206228 . should ( 'not.exist' )
207229 // and also not in database
208230 cy . runOccCommand ( 'group:list --output=json' ) . then ( ( $response ) => {
@@ -215,12 +237,7 @@ describe('Settings: Delete a non empty group', () => {
215237describe ( 'Settings: Sort groups in the UI' , ( ) => {
216238 before ( ( ) => {
217239 // Clear state
218- cy . runOccCommand ( 'group:list --output json' ) . then ( ( output ) => {
219- const groups = Object . keys ( JSON . parse ( output . stdout ) ) . filter ( ( group ) => group !== 'admin' )
220- groups . forEach ( ( group ) => {
221- cy . runOccCommand ( `group:delete '${ group } '` )
222- } )
223- } )
240+ clearState ( )
224241
225242 // Add two groups and add one user to group B
226243 cy . runOccCommand ( 'group:add A' )
0 commit comments