Files
ocis/web/packages/web-runtime/tests/unit/helpers/theme.spec.ts
Gaurav Soni 29392cea9c fix: [OCISDEV-115] address post-merge review on coloured tags (#12923)
Five review comments landed on #12892 after it merged.

**The tag overflow popover dismissed itself on click.** `mode="hover"` maps to
tippy's `mouseenter focus` trigger, and `hideOnClick` is hardcoded true in
`OcDrop`. tippy only skips its document-press hide when the trigger contains
`click`, so a click on the button fell through to `hide()` and set
`didHideDueToDocumentMouseDown`, which then blocked the focus trigger from
reopening it — the pointer had to leave and come back.

`mode="click"` fixes it without touching the design system: tippy toggles a
click-triggered instance, so the button opens and closes it, Enter/Space work
because a native button activation dispatches a click, and Escape still closes
via the `hideOnEsc` plugin with a click able to reopen it. Under `hover` that
last one was a dead end — Escape hid the popover and no new focus event could
follow. The trade is that hovering no longer reveals the tags; a disclosure
that answers to the keyboard is worth more than a hover shortcut.

That click also had to stop propagating: the button sits inside the `<tr>` that
`OcTable` highlights on click, so opening the popover selected the file as
well. tippy's listener is on the same element, so stopping propagation still
toggles the popover.

`is-nested` goes with it. It was set purely to suppress the `hideAll` that ran
when a pointer crossed the button, and pointer movement no longer opens
anything. Dropping it also un-silences `showDrop`/`hideDrop`, which `OcDrop`
only emits for drops that are not nested.

**The button claimed to be a popover trigger without saying so.** It now
carries `aria-haspopup` and an `aria-expanded` driven by those two events.
tippy manages `aria-expanded` itself only when the reference does not already
have one (`hasAriaExpanded` is read once at create time), and Vue renders the
attribute before `OcDrop` mounts, so there is one owner, not two.

**The accessible name dropped the visible text.** WCAG 2.5.3 Label in Name
wants the visible `+ 3` inside the name; `Show 3 more tags` left speech input
with nothing to match. The count now leads the string.

**The read-only tag lock was invisible to screen readers.** No
`accessible-label` means `OcIcon` renders it `aria-hidden`, so the only signal
that a tag cannot be removed was the absent deselect button.

**Themes inherited no tag palette.** `tagColorsList` was missing from
`defaults.designTokens`, so a deployment serving its own theme.json gets grey
chips. Seeding the defaults with the light palette turned out to be the wrong
place for it: every other value in that block is an empty-string placeholder,
because supplying colours is a theme's responsibility. The defaults stay
colourless. `useTagColor` already returns -1 without a list and `OcTag` then
renders the plain chip, which is what tags looked like before this feature.
2026-09-10 15:44:25 +02:00

108 lines
3.6 KiB
TypeScript

import { loadTheme } from '../../../src/helpers/theme'
import defaultTheme from '../../../themes/owncloud/theme.json'
import merge from 'lodash-es/merge'
import { ThemingConfig, WebThemeConfig } from '@ownclouders/web-pkg'
import { mock } from 'vitest-mock-extended'
vi.mock('@ownclouders/web-pkg', async (importOriginal) => {
const actual = await importOriginal<any>()
return {
...actual,
ThemingConfig: {
parse: vi.fn((arg) => arg),
safeParse: (arg: unknown) => actual.ThemingConfig.safeParse(arg)
}
}
})
vi.spyOn(console, 'error').mockImplementation(() => undefined)
const defaultOwnCloudTheme = {
defaults: {
...defaultTheme.clients.web.defaults,
common: defaultTheme.common
},
themes: defaultTheme.clients.web.themes
}
describe('theme loading and error reporting', () => {
it('the locally included theme should be valid', () => {
const { success } = ThemingConfig.safeParse(defaultTheme)
expect(success).toBeTruthy()
})
it('the default web theme should be valid', () => {
const { success } = WebThemeConfig.safeParse(defaultOwnCloudTheme)
expect(success).toBeTruthy()
})
it('every theme carries a tag colour list of the same length', () => {
const lengths = defaultTheme.clients.web.themes.map(
(theme) => theme.designTokens.tagColorsList.length
)
expect(lengths.length).toBeGreaterThan(0)
expect(new Set(lengths).size).toBe(1)
expect(lengths[0]).toBeGreaterThan(0)
})
it('should load the default theme if location is empty', async () => {
const theme = await loadTheme()
expect(theme).toMatchObject(defaultOwnCloudTheme)
})
it('should load the default theme if location is not a json file extension', async () => {
const theme = await loadTheme('some_location_without_json_file_ending.xml')
expect(theme).toMatchObject(defaultOwnCloudTheme)
})
it('should load the default theme if location is not found', async () => {
vi.spyOn(global, 'fetch').mockResolvedValue(mock<Response>({ status: 404 }))
const theme = await loadTheme('http://www.owncloud.com/unknown.json')
expect(theme).toMatchObject(defaultOwnCloudTheme)
})
it('should load the default theme if location is not a valid json file', async () => {
const customTheme = merge({}, defaultTheme, { default: { logo: { login: 'custom.svg' } } })
vi.spyOn(global, 'fetch').mockResolvedValue(
mock<Response>({ status: 404, json: () => Promise.resolve(customTheme) })
)
const theme = await loadTheme('http://www.owncloud.com/invalid.json')
expect(theme).toMatchObject(defaultOwnCloudTheme)
})
it('should load the default theme if server errors', async () => {
vi.spyOn(global, 'fetch').mockRejectedValue(new Error())
const theme = await loadTheme('http://www.owncloud.com')
expect(theme).toMatchObject(defaultOwnCloudTheme)
})
it('should load the custom theme if a custom location is given', async () => {
const customTheme = merge({}, defaultOwnCloudTheme, {
defaults: { logo: { login: 'custom.svg' } }
})
vi.spyOn(global, 'fetch').mockResolvedValue(
mock<Response>({
status: 404,
json: () =>
Promise.resolve({
common: defaultTheme.common,
clients: {
web: {
defaults: customTheme.defaults,
themes: customTheme.themes
}
}
})
})
)
const theme1 = await loadTheme('http://www.owncloud.com/custom.json')
const theme2 = await loadTheme('/custom.json')
expect(theme1).toMatchObject(customTheme)
expect(theme2).toMatchObject(customTheme)
})
})