enso/app/gui/integration-test/dashboard/userSettings.spec.ts
somebody1234 b83c5a15eb
Clean up integration tests and add listeners for backend calls (#11847)
- Close https://github.com/enso-org/cloud-v2/issues/1604
- Add ability to track backend calls
- Remove inconsistent integration test code
- Add skeleton classes for settings pages

# Important Notes
None
2024-12-12 09:49:58 +00:00

81 lines
2.6 KiB
TypeScript

/** @file Test the user settings tab. */
import { expect, test } from '@playwright/test'
import { INVALID_PASSWORD, TEXT, VALID_PASSWORD, mockAllAndLogin } from './actions'
const NEW_USERNAME = 'another user-name'
const NEW_PASSWORD = '1234!' + VALID_PASSWORD
const PROFILE_PICTURE_FILENAME = 'foo.png'
const PROFILE_PICTURE_CONTENT = 'a profile picture'
const PROFILE_PICTURE_MIMETYPE = 'image/png'
test('user settings', ({ page }) =>
mockAllAndLogin({ page })
.do((_, { api }) => {
expect(api.currentUser()?.name).toBe(api.defaultName)
})
.goToPage.settings()
.accountForm()
.fillName(NEW_USERNAME)
.save()
.do((_, { api }) => {
expect(api.currentUser()?.name).toBe(NEW_USERNAME)
expect(api.currentOrganization()?.name).not.toBe(NEW_USERNAME)
}))
test('change password form', ({ page }) =>
mockAllAndLogin({ page })
.do((_, { api }) => {
expect(api.currentPassword()).toBe(VALID_PASSWORD)
})
.goToPage.settings()
.changePasswordForm()
.fillCurrentPassword(VALID_PASSWORD)
.fillNewPassword(INVALID_PASSWORD)
.fillConfirmNewPassword(INVALID_PASSWORD)
.save()
.step('Invalid new password should fail', async (page) => {
await expect(
page
.getByRole('group', { name: /^New password/, exact: true })
.locator('.text-danger')
.last(),
).toHaveText(TEXT.passwordValidationError)
})
.changePasswordForm()
.fillCurrentPassword(VALID_PASSWORD)
.fillNewPassword(VALID_PASSWORD)
.fillConfirmNewPassword(VALID_PASSWORD + 'a')
.save()
.step('Invalid new password confirmation should fail', async (page) => {
await expect(
page
.getByRole('group', { name: /^Confirm new password/, exact: true })
.locator('.text-danger')
.last(),
).toHaveText(TEXT.passwordMismatchError)
})
.changePasswordForm()
.fillCurrentPassword(VALID_PASSWORD)
.fillNewPassword(NEW_PASSWORD)
.fillConfirmNewPassword(NEW_PASSWORD)
.save()
// TODO: consider checking that password inputs are now empty.
.step('Password change should be successful', (_, { api }) => {
expect(api.currentPassword()).toBe(NEW_PASSWORD)
}))
test('upload profile picture', ({ page }) =>
mockAllAndLogin({ page })
.goToPage.settings()
.uploadProfilePicture(
PROFILE_PICTURE_FILENAME,
PROFILE_PICTURE_CONTENT,
PROFILE_PICTURE_MIMETYPE,
)
.step('Profile picture should be updated', async (_, { api }) => {
await expect(() => {
expect(api.currentProfilePicture()).toEqual(PROFILE_PICTURE_CONTENT)
}).toPass()
}))