test(cabana): cover My account profile, password and avatar
- account_internal_test: metadata subtitle reader and writer (NULL, blank, null, [], invalid JSON, non-objects, key preservation, NULL on the last key), the attachOne contract, avatar cap, unique-violation mapping, English fallbacks, and 401 for non-backend principals on all three routes - account_test (Postgres): profile payload incl. copied WinterCMS metadata and avatar rows, trimmed profile saves and metadata keys, the forbidden-key allow-list with unchanged rows, email rules, password rules, the failed attempt log, Bearer and cookie session effects, CSRF, avatar upload, refusals (SVG, HTML as PNG, size, part shape, 413, no bucket) with no row or blob left, replace and remove with blob cleanup - lagoon: TestBackendAdminMetadataColumn covers type, Winter row round trip, rollback of only the column and re-migrate - SPA: AccountView, the user menu account item and avatar image, setCurrentUser and profileInitials; lang fixture gains myaccount keys
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
||||
import type { AdminProfile } from '../../src/api/types'
|
||||
import UserMenu from '../../src/components/shell/UserMenu.vue'
|
||||
import { currentUser } from '../../src/state/useAuth'
|
||||
import { API, profile, requestsTo, resetState, routerAt, signIn, wait } from '../helpers'
|
||||
|
||||
async function mountMenu(user: Partial<typeof profile.data> | null) {
|
||||
async function mountMenu(user: Partial<AdminProfile> | null) {
|
||||
let calls: Request[] = []
|
||||
if (user) {
|
||||
calls = await signIn({
|
||||
@@ -68,6 +69,48 @@ describe('user menu', () => {
|
||||
expect(wrapper.find('[data-user-initials]').text()).toBe('')
|
||||
})
|
||||
|
||||
it('opens My account from the menu', async () => {
|
||||
const { wrapper, router } = await mountMenu({})
|
||||
const content = await open(wrapper)
|
||||
const items = [...content.querySelectorAll<HTMLElement>('[role="menuitem"]')].map((item) => item.dataset.action)
|
||||
expect(items).toEqual(['account', 'logout'])
|
||||
const item = content.querySelector<HTMLElement>('[data-action="account"]')!
|
||||
expect(item.getAttribute('role')).toBe('menuitem')
|
||||
expect(item.textContent?.trim()).toBe('Moje konto')
|
||||
|
||||
item.click()
|
||||
await flushPromises()
|
||||
await wait(0)
|
||||
await flushPromises()
|
||||
expect(router.currentRoute.value.name).toBe('account')
|
||||
expect(router.currentRoute.value.fullPath).toBe('/account')
|
||||
expect(currentUser.value).not.toBeNull()
|
||||
})
|
||||
|
||||
it('shows the avatar thumbnail in place of the initials in the trigger and the menu', async () => {
|
||||
const avatar = { url: '/storage/uploads/a/b/c/abc.png', thumb_url: '/storage/uploads/a/b/c/thumb_1_250_250_0_0_crop.png' }
|
||||
const { wrapper } = await mountMenu({ avatar })
|
||||
const image = wrapper.find('[data-user-avatar]')
|
||||
expect(image.attributes('src')).toBe(avatar.thumb_url)
|
||||
expect(image.attributes('alt')).toBe('')
|
||||
expect(image.classes()).toEqual(expect.arrayContaining(['rounded-full', 'object-cover', 'size-[34px]']))
|
||||
expect(wrapper.find('[data-user-initials]').exists()).toBe(false)
|
||||
const content = await open(wrapper)
|
||||
const header = content.querySelector<HTMLImageElement>('img[data-user-avatar]')!
|
||||
expect(header.getAttribute('src')).toBe(avatar.thumb_url)
|
||||
expect(header.classList.contains('size-10')).toBe(true)
|
||||
})
|
||||
|
||||
it('falls back to the full image without a thumbnail, and to the initials without an avatar', async () => {
|
||||
const { wrapper } = await mountMenu({ avatar: { url: '/storage/uploads/a/b/c/abc.png' } })
|
||||
expect(wrapper.find('[data-user-avatar]').attributes('src')).toBe('/storage/uploads/a/b/c/abc.png')
|
||||
wrapper.unmount()
|
||||
resetState()
|
||||
const plain = await mountMenu({})
|
||||
expect(plain.wrapper.find('[data-user-avatar]').exists()).toBe(false)
|
||||
expect(plain.wrapper.find('[data-user-initials]').text()).toBe('DD')
|
||||
})
|
||||
|
||||
it('opens a menu with the e-mail and logs out to the login route', async () => {
|
||||
const { wrapper, router, calls } = await mountMenu({})
|
||||
const content = await open(wrapper)
|
||||
|
||||
Reference in New Issue
Block a user