Skip to content

Commit

Permalink
fix(settings): Stablize user list cypress tests
Browse files Browse the repository at this point in the history
* Use common `data-testid` to identify elements rather than to depend on internal classes or properties
* Force clean the state for the user tests

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Oct 21, 2023
1 parent 64839ed commit e1cac5b
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 162 deletions.
2 changes: 1 addition & 1 deletion apps/settings/src/components/UserList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
:data-component="UserRow"
:data-sources="filteredUsers"
data-key="id"
data-test-id="userList"
data-testid="userList"
:item-height="rowHeight"
:style="style"
:extra-props="{
Expand Down
32 changes: 16 additions & 16 deletions apps/settings/src/components/Users/UserRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
:user="user.id" />
</td>

<td class="row__cell row__cell--displayname" data-test-id="cell-displayname">
<td class="row__cell row__cell--displayname" data-testid="cell-displayname">
<template v-if="editing && user.backendCapabilities.setDisplayName">
<NcTextField ref="displayNameField"
class="user-row-text-field"
data-test-id="input-displayName"
data-testid="input-displayName"
:data-test-loading="`${loading.displayName}`"
:trailing-button-label="t('settings', 'Submit')"
:class="{ 'icon-loading-small': loading.displayName }"
Expand All @@ -63,12 +63,12 @@
</template>
</td>

<td data-test-id="cell-password"
<td data-testid="cell-password"
class="row__cell"
:class="{ 'row__cell--obfuscated': hasObfuscated }">
<template v-if="editing && settings.canChangePassword && user.backendCapabilities.setPassword">
<NcTextField class="user-row-text-field"
data-test-id="input-password"
data-testid="input-password"
:data-test-loading="`${loading.password}`"
:trailing-button-label="t('settings', 'Submit')"
:class="{'icon-loading-small': loading.password}"
Expand All @@ -91,11 +91,11 @@
</span>
</td>

<td class="row__cell" data-test-id="cell-email">
<td class="row__cell" data-testid="cell-email">
<template v-if="editing">
<NcTextField class="user-row-text-field"
:class="{'icon-loading-small': loading.mailAddress}"
data-test-id="input-email"
data-testid="input-email"
:data-test-loading="`${loading.mailAddress}`"
:show-trailing-button="true"
:trailing-button-label="t('settings', 'Submit')"
Expand All @@ -115,7 +115,7 @@
</span>
</td>

<td class="row__cell row__cell--large row__cell--multiline" data-test-id="cell-groups">
<td class="row__cell row__cell--large row__cell--multiline" data-testid="cell-groups">
<template v-if="editing">
<label class="hidden-visually"
:for="'groups' + uniqueId">
Expand Down Expand Up @@ -145,7 +145,7 @@
</td>

<td v-if="subAdminsGroups.length > 0 && settings.isAdmin"
data-test-id="cell-subadmins"
data-testid="cell-subadmins"
class="row__cell row__cell--large row__cell--multiline">
<template v-if="editing && settings.isAdmin && subAdminsGroups.length > 0">
<label class="hidden-visually"
Expand All @@ -172,7 +172,7 @@
</span>
</td>

<td class="row__cell" data-test-id="cell-quota">
<td class="row__cell" data-testid="cell-quota">
<template v-if="editing">
<label class="hidden-visually"
:for="'quota' + uniqueId">
Expand All @@ -181,7 +181,7 @@
<NcSelect v-model="editedUserQuota"
:close-on-select="true"
:create-option="validateQuota"
data-test-id="input-quota"
data-testid="input-quota"
:data-test-loading="`${loading.quota}`"
:disabled="isLoadingField"
:loading="loading.quota"
Expand All @@ -206,7 +206,7 @@

<td v-if="showConfig.showLanguages"
class="row__cell row__cell--large"
data-test-id="cell-language">
data-testid="cell-language">
<template v-if="editing">
<label class="hidden-visually"
:for="'language' + uniqueId">
Expand All @@ -230,7 +230,7 @@
</td>

<td v-if="showConfig.showUserBackend || showConfig.showStoragePath"
data-test-id="cell-storageLocation"
data-testid="cell-storageLocation"
class="row__cell row__cell--large">
<template v-if="!isObfuscated">
<span v-if="showConfig.showUserBackend">{{ user.backend }}</span>
Expand All @@ -245,19 +245,19 @@
<td v-if="showConfig.showLastLogin"
:title="userLastLoginTooltip"
class="row__cell"
data-test-id="cell-lastLogin">
data-testid="cell-lastLogin">
<span v-if="!isObfuscated">{{ userLastLogin }}</span>
</td>

<td class="row__cell row__cell--large row__cell--fill" data-test-id="cell-manager">
<td class="row__cell row__cell--large row__cell--fill" data-testid="cell-manager">
<template v-if="editing">
<label class="hidden-visually"
:for="'manager' + uniqueId">
{{ managerLabel }}
</label>
<NcSelect v-model="currentManager"
class="select--fill"
data-test-id="input-manager"
data-testid="input-manager"
:data-test-loading="`${loading.manager}`"
:input-id="'manager' + uniqueId"
:close-on-select="true"
Expand All @@ -277,7 +277,7 @@
</span>
</td>

<td class="row__cell row__cell--actions" data-test-id="cell-actions">
<td class="row__cell row__cell--actions" data-testid="cell-actions">
<UserRowActions v-if="visible && !isObfuscated && canEdit && !loading.all"
:actions="userActions"
:disabled="isLoadingField"
Expand Down
2 changes: 1 addition & 1 deletion apps/settings/src/components/Users/UserRowActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<NcActions :aria-label="t('settings', 'Toggle user actions menu')"
:disabled="disabled"
:inline="1">
<NcActionButton data-test-id="button-toggleEdit"
<NcActionButton data-testid="button-toggleEdit"
:data-test="`${edit}`"
:disabled="disabled"
@click="toggleEdit">
Expand Down
24 changes: 23 additions & 1 deletion cypress/e2e/settings/usersUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*
*/

import type { User } from '@nextcloud/cypress'

/**
* Assert that `element` does not exist or is not visible
* Useful in cases such as when NcModal is opened/closed rapidly
Expand All @@ -38,7 +40,7 @@ export function assertNotExistOrNotVisible(element: JQuery<HTMLElement>) {
* @return Cypress chainable object
*/
export function getUserList() {
return cy.get('[data-test-id="userList"]')
return cy.get('[data-testid="userList"]')
}

/**
Expand Down Expand Up @@ -73,3 +75,23 @@ export function handlePasswordConfirmation(adminPassword = 'admin') {
.root().closest('body')
.then(($body) => handleModal(cy.wrap($body)))
}

/**
* Toggle the edit button of the user row
* @param user The user row to edit
* @param toEdit True if it should be switch to edit mode, false to switch to read-only
*/
export function toggleEditButton(user: User, toEdit = true) {
// see that the list of users contains the user
getUserListRow(user.userId).should('exist')
// toggle the edit mode for the user
.find('[data-testid="cell-actions"]')
// replace with following (more error resilent) with nextcloud-vue 8
// find('[data-testid="button-toggleEdit"]')
.find(`button[aria-label="${toEdit ? 'Edit' : 'Done'}"]`)
.if()
.click({ force: true })
.else()
// otherwise ensure the button is already in edit mode
.then(() => getUserListRow(user.userId).find(`[data-testid="cell-actions"] button[aria-label="${toEdit ? 'Done' : 'Edit'}"]`).should('exist'))
}
6 changes: 3 additions & 3 deletions cypress/e2e/settings/users_columns.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Settings: Show and hide columns', function() {

// see that the language column is in all user rows
getUserList().find('tbody tr').each(($row) => {
cy.wrap($row).get('[data-test-id="cell-language"]').should('exist')
cy.wrap($row).get('[data-testid="cell-language"]').should('exist')
})
})

Expand All @@ -90,7 +90,7 @@ describe('Settings: Show and hide columns', function() {

// see that the last login column is in all user rows
getUserList().find('tbody tr').each(($row) => {
cy.wrap($row).get('[data-test-id="cell-lastLogin"]').should('exist')
cy.wrap($row).get('[data-testid="cell-lastLogin"]').should('exist')
})

// open the settings dialog
Expand All @@ -113,7 +113,7 @@ describe('Settings: Show and hide columns', function() {

// see that the last login column is not in all user rows
getUserList().find('tbody tr').each(($row) => {
cy.wrap($row).get('[data-test-id="cell-lastLogin"]').should('not.exist')
cy.wrap($row).get('[data-testid="cell-lastLogin"]').should('not.exist')
})
})
})
8 changes: 4 additions & 4 deletions cypress/e2e/settings/users_groups.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ describe('Settings: Assign user to a group', { testIsolation: false }, () => {

it('switch into user edit mode', () => {
getUserListRow(testUser.userId)
.find('[data-test-id="cell-actions"] button[aria-label="Edit"]')
.find('[data-testid="cell-actions"] button[aria-label="Edit"]')
.click({ force: true })
getUserListRow(testUser.userId)
.find('[data-test-id="cell-groups"] input')
.find('[data-testid="cell-groups"] input')
.should('exist')
})

it('assign the group', () => {
// focus inside the input
getUserListRow(testUser.userId)
.find('[data-test-id="cell-groups"] input')
.find('[data-testid="cell-groups"] input')
.click({ force: true })
// enter the group name
getUserListRow(testUser.userId)
.find('[data-test-id="cell-groups"] input')
.find('[data-testid="cell-groups"] input')
.type(`${groupName.slice(0, 5)}`) // only type part as otherwise we would create a new one with the same name
cy.contains('li.vs__dropdown-option', groupName)
.click({ force: true })
Expand Down
Loading

0 comments on commit e1cac5b

Please sign in to comment.