@m3ui-vue/m3ui-vue 0.9.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -29
- package/dist/API.md +242 -22
- package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
- package/dist/MIcon-DLOkQduI.js.map +1 -0
- package/dist/{MTextField-Ck0oWDMk.js → MTextField-TZ7lfr09.js} +551 -216
- package/dist/MTextField-TZ7lfr09.js.map +1 -0
- package/dist/THIRD_PARTY_LICENSES.md +547 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MAppBarWithSearch.vue.d.ts +70 -0
- package/dist/components/MBottomAppBar.vue.d.ts +37 -0
- package/dist/components/MBottomSheetScaffold.vue.d.ts +40 -0
- package/dist/components/MButton.vue.d.ts +4 -2
- package/dist/components/MButtonGroup.vue.d.ts +2 -0
- package/dist/components/MChatBubble.vue.d.ts +1 -1
- package/dist/components/MChip.vue.d.ts +19 -2
- package/dist/components/MContainer.vue.d.ts +1 -1
- package/dist/components/MDataTable.vue.d.ts +1 -1
- package/dist/components/MDialog.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +15 -4
- package/dist/components/MIcon.vue.d.ts +3 -0
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MListItem.vue.d.ts +2 -2
- package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
- package/dist/components/MMenuItem.vue.d.ts +17 -4
- package/dist/components/MNavigationRail.vue.d.ts +6 -0
- package/dist/components/MSearchBar.vue.d.ts +5 -3
- package/dist/components/MShortNavigationBar.vue.d.ts +1 -1
- package/dist/components/MSplitButton.vue.d.ts +2 -0
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTabs.vue.d.ts +6 -0
- package/dist/components/MTimePickerModal.vue.d.ts +3 -0
- package/dist/components/MTimeScroll.vue.d.ts +22 -0
- package/dist/components/MToggleButton.vue.d.ts +2 -0
- package/dist/components/MTopAppBar.vue.d.ts +33 -2
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
- package/dist/composables/_searchAppBar.d.ts +6 -0
- package/dist/composables/_themeTransition.d.ts +2 -0
- package/dist/composables/_useSpring.d.ts +5 -5
- package/dist/composables/motion.d.ts +101 -0
- package/dist/composables/useColorPalette.d.ts +10 -0
- package/dist/composables/useLocale.d.ts +9 -0
- package/dist/directives/vRipple.d.ts +16 -0
- package/dist/emoji-names-de-BphO5XpV.js.map +1 -1
- package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -1
- package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -1
- package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -1
- package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -1
- package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -1
- package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -1
- package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/locales/index.js +63 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7716 -6768
- package/dist/m3ui.js.map +1 -1
- package/dist/plugin.d.ts +7 -0
- package/dist/rich-text-editor.js +22 -22
- package/dist/styles/palettes-contrast.css +7764 -0
- package/dist/styles/theme.css +59 -2
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-CFW8cIzL.js → useLocale-CuvWRZ1h.js} +10 -1
- package/dist/useLocale-CuvWRZ1h.js.map +1 -0
- package/package.json +4 -2
- package/src/__tests__/MAppBarWithSearch.test.ts +96 -0
- package/src/__tests__/MBottomAppBar.test.ts +71 -0
- package/src/__tests__/MBottomSheetScaffold.test.ts +101 -0
- package/src/__tests__/MChip.test.ts +63 -0
- package/src/__tests__/MFab.test.ts +36 -0
- package/src/__tests__/MIconButton.test.ts +60 -0
- package/src/__tests__/MMenuItem.test.ts +84 -0
- package/src/__tests__/MNavigationRail.test.ts +77 -0
- package/src/__tests__/MScrollField.test.ts +28 -0
- package/src/__tests__/MTabs.test.ts +39 -0
- package/src/__tests__/MTimePickerModal.test.ts +52 -0
- package/src/__tests__/MTimeScroll.test.ts +44 -0
- package/src/__tests__/MTopAppBar.test.ts +99 -0
- package/src/__tests__/contrast.test.ts +64 -0
- package/src/__tests__/dynamicColor.test.ts +17 -0
- package/src/__tests__/motion.test.ts +37 -0
- package/src/__tests__/themeTransition.test.ts +119 -0
- package/src/__tests__/vRipple.test.ts +92 -0
- package/src/components/MAppBarWithSearch.vue +236 -0
- package/src/components/MBottomAppBar.vue +181 -0
- package/src/components/MBottomSheetScaffold.vue +296 -0
- package/src/components/MBreadcrumbs.vue +1 -1
- package/src/components/MButton.vue +4 -13
- package/src/components/MButtonGroup.vue +4 -11
- package/src/components/MChip.vue +137 -5
- package/src/components/MFab.vue +81 -27
- package/src/components/MIcon.vue +4 -2
- package/src/components/MIconButton.vue +96 -24
- package/src/components/MMenuItem.vue +115 -13
- package/src/components/MNavigationDrawer.vue +2 -2
- package/src/components/MNavigationRail.vue +135 -8
- package/src/components/MScrollField.vue +10 -2
- package/src/components/MSearchBar.vue +28 -12
- package/src/components/MSplitButton.vue +5 -12
- package/src/components/MTabs.vue +16 -5
- package/src/components/MTimePickerModal.vue +48 -8
- package/src/components/MTimeScroll.vue +161 -0
- package/src/components/MToggleButton.vue +5 -12
- package/src/components/MTopAppBar.vue +252 -28
- package/src/composables/_carouselStrategy.ts +3 -0
- package/src/composables/_searchAppBar.ts +9 -0
- package/src/composables/_themeColor.ts +11 -4
- package/src/composables/_themeTransition.ts +71 -0
- package/src/composables/_useSpring.ts +12 -20
- package/src/composables/motion.ts +73 -0
- package/src/composables/useColorPalette.ts +103 -20
- package/src/composables/useLocale.ts +18 -0
- package/src/composables/useTheme.ts +4 -12
- package/src/data/emoji-names/emoji-names-de.ts +1 -0
- package/src/data/emoji-names/emoji-names-en.ts +1 -0
- package/src/data/emoji-names/emoji-names-es.ts +1 -0
- package/src/data/emoji-names/emoji-names-fr.ts +1 -0
- package/src/data/emoji-names/emoji-names-ja.ts +1 -0
- package/src/data/emoji-names/emoji-names-ko.ts +1 -0
- package/src/data/emoji-names/emoji-names-pt.ts +1 -0
- package/src/data/emoji-names/emoji-names-zh.ts +1 -0
- package/src/data/emojis.ts +1 -0
- package/src/directives/vRipple.ts +73 -0
- package/src/index.ts +13 -1
- package/src/locales/de.ts +9 -0
- package/src/locales/es.ts +9 -0
- package/src/locales/fr.ts +9 -0
- package/src/locales/ja.ts +9 -0
- package/src/locales/ko.ts +9 -0
- package/src/locales/pt.ts +9 -0
- package/src/locales/zh.ts +9 -0
- package/src/plugin.ts +11 -1
- package/src/styles/palettes-contrast.css +7764 -0
- package/src/styles/theme.css +59 -2
- package/dist/MIcon-CaEooCmZ.js.map +0 -1
- package/dist/MTextField-Ck0oWDMk.js.map +0 -1
- package/dist/useLocale-CFW8cIzL.js.map +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MChip from '../components/MChip.vue'
|
|
5
|
+
|
|
6
|
+
const chip = (props: Record<string, unknown>, slots: Record<string, string> = {}) =>
|
|
7
|
+
mount(MChip, { props, slots: { default: 'Label', ...slots } })
|
|
8
|
+
|
|
9
|
+
describe('MChip', () => {
|
|
10
|
+
it('keeps the generic tone chip without a type', () => {
|
|
11
|
+
const w = chip({ tone: 'primary' })
|
|
12
|
+
expect(w.element.tagName).toBe('SPAN')
|
|
13
|
+
expect(w.classes()).toContain('bg-primary-container')
|
|
14
|
+
expect(w.find('button').exists()).toBe(false)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('labels the generic remove button from the locale', () => {
|
|
18
|
+
expect(chip({ removable: true }).find('button').attributes('aria-label')).toBe('Remove')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('draws an outlined assist chip with a primary icon and 8px corners', () => {
|
|
22
|
+
const w = chip({ type: 'assist', icon: 'event' })
|
|
23
|
+
expect(w.classes()).toEqual(expect.arrayContaining(['border', 'border-outline-variant', 'text-on-surface', 'rounded-sm']))
|
|
24
|
+
expect(w.find('.material-symbols-outlined').classes()).toContain('text-primary')
|
|
25
|
+
expect(w.find('button').classes()).toContain('pl-2')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('draws an elevated suggestion chip without an outline', () => {
|
|
29
|
+
const w = chip({ type: 'suggestion', elevated: true })
|
|
30
|
+
expect(w.classes()).toEqual(expect.arrayContaining(['bg-surface-container-low', 'shadow-elevation-1', 'text-on-surface-variant']))
|
|
31
|
+
expect(w.classes()).not.toContain('border')
|
|
32
|
+
expect(w.find('button').classes()).toEqual(expect.arrayContaining(['pl-4', 'pr-4']))
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('toggles a filter chip with v-model:selected, filling it and morphing to a pill', async () => {
|
|
36
|
+
const w = chip({ type: 'filter', selected: false })
|
|
37
|
+
await w.find('button').trigger('click')
|
|
38
|
+
expect(w.emitted('update:selected')).toEqual([[true]])
|
|
39
|
+
expect(w.emitted('click')).toHaveLength(1)
|
|
40
|
+
await w.setProps({ selected: true })
|
|
41
|
+
expect(w.classes()).toContain('bg-secondary-container')
|
|
42
|
+
expect(w.find('button').attributes('aria-pressed')).toBe('true')
|
|
43
|
+
expect(w.find('[aria-hidden="true"]').text()).toBe('check')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('makes an input chip with an avatar and a separate remove button', async () => {
|
|
47
|
+
const w = chip({ type: 'input', removable: true }, { avatar: '<img alt="" src="a.png">' })
|
|
48
|
+
const buttons = w.findAll('button')
|
|
49
|
+
expect(buttons).toHaveLength(2)
|
|
50
|
+
expect(buttons[0]!.find('img').exists()).toBe(true)
|
|
51
|
+
expect(buttons[0]!.classes()).toEqual(expect.arrayContaining(['pl-1', 'pr-2']))
|
|
52
|
+
await buttons[1]!.trigger('click')
|
|
53
|
+
expect(w.emitted('remove')).toHaveLength(1)
|
|
54
|
+
expect(w.emitted('click')).toBeUndefined()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('disables a typed chip', async () => {
|
|
58
|
+
const w = chip({ type: 'filter', disabled: true })
|
|
59
|
+
expect(w.find('button').attributes('disabled')).toBeDefined()
|
|
60
|
+
expect(w.classes()).toContain('text-on-surface/38')
|
|
61
|
+
await nextTick()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MFab from '../components/MFab.vue'
|
|
5
|
+
|
|
6
|
+
const fab = (props: Record<string, unknown>) => mount(MFab, { props: { icon: 'edit', ...props } })
|
|
7
|
+
|
|
8
|
+
describe('MFab', () => {
|
|
9
|
+
it('keeps the baseline extended FAB for the regular size', () => {
|
|
10
|
+
const b = fab({ label: 'Compose' }).find('button')
|
|
11
|
+
expect(b.classes()).toEqual(expect.arrayContaining(['h-14', 'min-w-20', 'pl-4', 'pr-5']))
|
|
12
|
+
expect(b.find('span.whitespace-nowrap').classes()).toContain('text-label-large')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it.each([
|
|
16
|
+
['small', 'h-14', 'text-title-medium', '8px'],
|
|
17
|
+
['medium', 'h-20', 'text-title-large', '12px'],
|
|
18
|
+
['large', 'h-24', 'text-headline-small', '16px'],
|
|
19
|
+
])('sizes the %s extended FAB from ExtendedFab tokens', (size, height, text, gap) => {
|
|
20
|
+
const b = fab({ label: 'Compose', size }).find('button')
|
|
21
|
+
expect(b.classes()).toContain(height)
|
|
22
|
+
const label = b.find('span.whitespace-nowrap')
|
|
23
|
+
expect(label.classes()).toContain(text)
|
|
24
|
+
expect((label.element as HTMLElement).style.paddingLeft).toBe(gap)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('collapses to the icon with expanded false, keeping the label as its accessible name', async () => {
|
|
28
|
+
const w = fab({ label: 'Compose', expanded: false })
|
|
29
|
+
await nextTick()
|
|
30
|
+
const b = w.find('button')
|
|
31
|
+
expect(b.attributes('aria-label')).toBe('Compose')
|
|
32
|
+
const label = b.find('span.whitespace-nowrap').element as HTMLElement
|
|
33
|
+
expect(label.style.display).toBe('none')
|
|
34
|
+
expect((b.element as HTMLElement).style.width).toBe('56px')
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MIconButton from '../components/MIconButton.vue'
|
|
4
|
+
|
|
5
|
+
describe('MIconButton', () => {
|
|
6
|
+
it('is a plain button without checked', async () => {
|
|
7
|
+
const w = mount(MIconButton, { props: { icon: 'favorite' } })
|
|
8
|
+
expect(w.attributes('aria-pressed')).toBeUndefined()
|
|
9
|
+
await w.trigger('click')
|
|
10
|
+
expect(w.emitted('update:checked')).toBeUndefined()
|
|
11
|
+
expect(w.find('.material-symbols-outlined').attributes('style')).not.toContain('FILL')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('toggles through v-model:checked', async () => {
|
|
15
|
+
const w = mount(MIconButton, { props: { icon: 'favorite', checked: false } })
|
|
16
|
+
expect(w.attributes('aria-pressed')).toBe('false')
|
|
17
|
+
await w.trigger('click')
|
|
18
|
+
expect(w.emitted('update:checked')).toEqual([[true]])
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('does not toggle while disabled', async () => {
|
|
22
|
+
const w = mount(MIconButton, { props: { icon: 'favorite', checked: false, disabled: true } })
|
|
23
|
+
await w.trigger('click')
|
|
24
|
+
expect(w.emitted('update:checked')).toBeUndefined()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('fills the icon and swaps to checkedIcon when checked', () => {
|
|
28
|
+
const w = mount(MIconButton, { props: { icon: 'play_arrow', checkedIcon: 'pause', checked: true } })
|
|
29
|
+
const icon = w.find('.material-symbols-outlined')
|
|
30
|
+
expect(icon.text()).toBe('pause')
|
|
31
|
+
expect(icon.attributes('style')).toContain("'FILL' 1")
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('uses the selected colors of each variant', () => {
|
|
35
|
+
const cases: [string, string, string][] = [
|
|
36
|
+
['standard', 'text-on-surface-variant', 'text-primary'],
|
|
37
|
+
['filled', 'bg-surface-container', 'bg-primary'],
|
|
38
|
+
['tonal', 'bg-secondary-container', 'bg-secondary'],
|
|
39
|
+
['outlined', 'border-current', 'bg-inverse-surface'],
|
|
40
|
+
]
|
|
41
|
+
for (const [variant, off, on] of cases) {
|
|
42
|
+
expect(mount(MIconButton, { props: { icon: 'x', variant: variant as any, checked: false } }).classes()).toContain(off)
|
|
43
|
+
expect(mount(MIconButton, { props: { icon: 'x', variant: variant as any, checked: true } }).classes()).toContain(on)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('renders a button, not a link, when it is a toggle', () => {
|
|
48
|
+
const w = mount(MIconButton, { props: { icon: 'x', checked: false, to: '/somewhere' } })
|
|
49
|
+
expect(w.element.tagName).toBe('BUTTON')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('sets the toggle shape on mount: round squares off when checked', () => {
|
|
53
|
+
const off = mount(MIconButton, { props: { icon: 'x', checked: false } })
|
|
54
|
+
expect((off.element as HTMLElement).style.borderRadius).toBe('20px')
|
|
55
|
+
const on = mount(MIconButton, { props: { icon: 'x', checked: true } })
|
|
56
|
+
expect((on.element as HTMLElement).style.borderRadius).toBe('12px')
|
|
57
|
+
const square = mount(MIconButton, { props: { icon: 'x', checked: true, shape: 'squared' } })
|
|
58
|
+
expect((square.element as HTMLElement).style.borderRadius).toBe('20px')
|
|
59
|
+
})
|
|
60
|
+
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, provide } from 'vue'
|
|
4
|
+
import MMenuItem from '../components/MMenuItem.vue'
|
|
5
|
+
|
|
6
|
+
// Mounts the item inside a stand-in for MMenu that records close() calls
|
|
7
|
+
function inMenu(props: Record<string, unknown>) {
|
|
8
|
+
const closes: number[] = []
|
|
9
|
+
const Host = defineComponent({
|
|
10
|
+
setup() {
|
|
11
|
+
provide('m-menu-close', () => closes.push(1))
|
|
12
|
+
return () => h(MMenuItem, props, () => 'Item')
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
const w = mount(Host)
|
|
16
|
+
return { item: w.findComponent(MMenuItem), button: w.find('button'), closes }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('MMenuItem', () => {
|
|
20
|
+
it('stays a plain item without selected or checked', () => {
|
|
21
|
+
const { button } = inMenu({})
|
|
22
|
+
expect(button.attributes('role')).toBeUndefined()
|
|
23
|
+
expect(button.attributes('aria-checked')).toBeUndefined()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('is a radio item with selected, closing the menu on click', async () => {
|
|
27
|
+
const { button, closes } = inMenu({ selected: true })
|
|
28
|
+
expect(button.attributes('role')).toBe('menuitemradio')
|
|
29
|
+
expect(button.attributes('aria-checked')).toBe('true')
|
|
30
|
+
expect(button.classes()).toContain('bg-tertiary-container')
|
|
31
|
+
await button.trigger('click')
|
|
32
|
+
expect(closes).toHaveLength(1)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('is a checkbox item with checked, toggling v-model:checked and keeping the menu open', async () => {
|
|
36
|
+
const { item, button, closes } = inMenu({ checked: false })
|
|
37
|
+
expect(button.attributes('role')).toBe('menuitemcheckbox')
|
|
38
|
+
expect(button.attributes('aria-checked')).toBe('false')
|
|
39
|
+
await button.trigger('click')
|
|
40
|
+
expect(item.emitted('update:checked')).toEqual([[true]])
|
|
41
|
+
expect(item.emitted('click')).toHaveLength(1)
|
|
42
|
+
expect(closes).toHaveLength(0)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('closes after a checked item when keepOpen is false', async () => {
|
|
46
|
+
const { button, closes } = inMenu({ checked: true, keepOpen: false })
|
|
47
|
+
await button.trigger('click')
|
|
48
|
+
expect(closes).toHaveLength(1)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('rounds the outer corners of a run of selectable items, and all corners of the selected one', async () => {
|
|
52
|
+
const w = mount(defineComponent({
|
|
53
|
+
setup: () => () => h('div', [
|
|
54
|
+
h(MMenuItem, { selected: false }, () => 'A'),
|
|
55
|
+
h(MMenuItem, { selected: true }, () => 'B'),
|
|
56
|
+
h(MMenuItem, { selected: false }, () => 'C'),
|
|
57
|
+
h(MMenuItem, { selected: false }, () => 'D'),
|
|
58
|
+
h('hr'),
|
|
59
|
+
h(MMenuItem, { checked: false }, () => 'E'),
|
|
60
|
+
h(MMenuItem, {}, () => 'Plain'),
|
|
61
|
+
]),
|
|
62
|
+
}), { attachTo: document.body })
|
|
63
|
+
await nextTick()
|
|
64
|
+
// (the DOM shortens four equal corners to one value)
|
|
65
|
+
const radius = w.findAll('button').map((b) => b.element.style.borderRadius)
|
|
66
|
+
expect(radius).toEqual([
|
|
67
|
+
'12px 12px 4px 4px', // first
|
|
68
|
+
'12px', // selected
|
|
69
|
+
'4px', // middle
|
|
70
|
+
'4px 4px 12px 12px', // last
|
|
71
|
+
'4px', // alone after the divider
|
|
72
|
+
'', // plain items keep their own shape
|
|
73
|
+
])
|
|
74
|
+
w.unmount()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('shows a sliding check without an icon, and swaps or fills the icon with one', () => {
|
|
78
|
+
expect(inMenu({ checked: true }).button.find('span.overflow-hidden').text()).toBe('check')
|
|
79
|
+
const swapped = inMenu({ selected: true, icon: 'play_arrow', selectedIcon: 'pause' }).button
|
|
80
|
+
expect(swapped.text()).toContain('pause')
|
|
81
|
+
const filled = inMenu({ selected: true, icon: 'star' }).button.find('.material-symbols-outlined')
|
|
82
|
+
expect(filled.attributes('style')).toContain('FILL')
|
|
83
|
+
})
|
|
84
|
+
})
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import MNavigationRail from '../components/MNavigationRail.vue'
|
|
4
|
+
|
|
5
|
+
const items = [
|
|
6
|
+
{ value: 'inbox', label: 'Inbox', icon: 'inbox' },
|
|
7
|
+
{ value: 'sent', label: 'Sent', icon: 'send' },
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
let wrapper: VueWrapper | undefined
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
wrapper?.unmount()
|
|
13
|
+
wrapper = undefined
|
|
14
|
+
document.body.innerHTML = ''
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
function open(props: Record<string, unknown> = {}) {
|
|
18
|
+
wrapper = mount(MNavigationRail, {
|
|
19
|
+
props: { modelValue: 'inbox', items, modal: true, hideOnCollapse: true, expanded: true, ...props },
|
|
20
|
+
attachTo: document.body,
|
|
21
|
+
global: { stubs: { transition: false } },
|
|
22
|
+
})
|
|
23
|
+
return document.body.querySelector<HTMLElement>('.wnr-panel')!
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Moves 25px per step, `msPerStep` apart (the events' timeStamp is what the fling velocity is measured from)
|
|
27
|
+
function swipe(panel: HTMLElement, from: number, to: number, msPerStep = 100) {
|
|
28
|
+
let t = 1000
|
|
29
|
+
const send = (type: string, x: number) => {
|
|
30
|
+
const e = new PointerEvent(type, { pointerId: 1, button: 0, bubbles: true, clientY: 300, clientX: x })
|
|
31
|
+
Object.defineProperty(e, 'timeStamp', { value: t })
|
|
32
|
+
panel.dispatchEvent(e)
|
|
33
|
+
}
|
|
34
|
+
send('pointerdown', from)
|
|
35
|
+
for (let x = from; x >= to; x -= 25) {
|
|
36
|
+
t += msPerStep
|
|
37
|
+
send('pointermove', x)
|
|
38
|
+
}
|
|
39
|
+
send('pointerup', to)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('MNavigationRail', () => {
|
|
43
|
+
it('shows no collapsed rail with hideOnCollapse, only the modal panel', () => {
|
|
44
|
+
const panel = open()
|
|
45
|
+
expect(panel).not.toBeNull()
|
|
46
|
+
expect(wrapper!.find('nav').exists()).toBe(false)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('keeps the collapsed rail on screen in the default modal', () => {
|
|
50
|
+
open({ hideOnCollapse: false })
|
|
51
|
+
expect(wrapper!.find('nav').exists()).toBe(true)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('closes when slowly swiped past half its width, and springs back from a short swipe', () => {
|
|
55
|
+
const panel = open()
|
|
56
|
+
swipe(panel, 200, 150, 400)
|
|
57
|
+
expect(wrapper!.emitted('update:expanded')).toBeUndefined()
|
|
58
|
+
swipe(panel, 200, 50, 400)
|
|
59
|
+
expect(wrapper!.emitted('update:expanded')).toEqual([[false]])
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('closes on a quick flick even when it moved less than half', () => {
|
|
63
|
+
const panel = open()
|
|
64
|
+
swipe(panel, 200, 150, 16)
|
|
65
|
+
expect(wrapper!.emitted('update:expanded')).toEqual([[false]])
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('ignores a vertical drag (the items scroll)', () => {
|
|
69
|
+
const panel = open()
|
|
70
|
+
const opts = { pointerId: 1, button: 0, bubbles: true, clientX: 200 }
|
|
71
|
+
panel.dispatchEvent(new PointerEvent('pointerdown', { ...opts, clientY: 300 }))
|
|
72
|
+
panel.dispatchEvent(new PointerEvent('pointermove', { ...opts, clientX: 190, clientY: 200 }))
|
|
73
|
+
panel.dispatchEvent(new PointerEvent('pointermove', { ...opts, clientX: 40, clientY: 200 }))
|
|
74
|
+
panel.dispatchEvent(new PointerEvent('pointerup', { ...opts, clientX: 40, clientY: 200 }))
|
|
75
|
+
expect(wrapper!.emitted('update:expanded')).toBeUndefined()
|
|
76
|
+
})
|
|
77
|
+
})
|
|
@@ -34,6 +34,34 @@ describe('MScrollField', () => {
|
|
|
34
34
|
expect(seen).toEqual([59, 0, 1])
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
+
// Regression: the wheel took its own value, handed back through v-model mid-flight, for an outside change
|
|
38
|
+
// and retargeted toward it, so it stopped short (and on a 4-item wheel scrolled back and forth forever)
|
|
39
|
+
it('ignores its own value coming back through v-model while it is still moving (wheel)', async () => {
|
|
40
|
+
wrapper = mount(MScrollField, {
|
|
41
|
+
props: { modelValue: 0, count: 4, 'onUpdate:modelValue': (v: number) => wrapper!.setProps({ modelValue: v }) },
|
|
42
|
+
attachTo: document.body,
|
|
43
|
+
})
|
|
44
|
+
const field = wrapper.find('[role="slider"]')
|
|
45
|
+
// 120px = 3 steps in one go: 0 → 3
|
|
46
|
+
await field.trigger('wheel', { deltaY: 120 })
|
|
47
|
+
await wait(1000)
|
|
48
|
+
const seen = wrapper.emitted<[number]>('update:modelValue')!.map((e) => e[0])
|
|
49
|
+
expect(seen).toEqual([1, 2, 3])
|
|
50
|
+
expect(field.attributes('aria-valuetext')).toBe('03')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('ignores its own value coming back through v-model while it is still moving (keys)', async () => {
|
|
54
|
+
wrapper = mount(MScrollField, {
|
|
55
|
+
props: { modelValue: 10, count: 60, 'onUpdate:modelValue': (v: number) => wrapper!.setProps({ modelValue: v }) },
|
|
56
|
+
attachTo: document.body,
|
|
57
|
+
})
|
|
58
|
+
const field = wrapper.find('[role="slider"]')
|
|
59
|
+
for (let i = 0; i < 4; i++) await field.trigger('keydown', { key: 'ArrowDown' })
|
|
60
|
+
await wait(1000)
|
|
61
|
+
expect(wrapper.emitted<[number]>('update:modelValue')!.at(-1)).toEqual([14])
|
|
62
|
+
expect(field.attributes('aria-valuetext')).toBe('14')
|
|
63
|
+
})
|
|
64
|
+
|
|
37
65
|
it('uses a custom format', () => {
|
|
38
66
|
wrapper = mount(MScrollField, { props: { modelValue: 1, count: 2, format: (i: number) => ['L', 'oz'][i]! } })
|
|
39
67
|
expect(wrapper.find('[role="slider"]').attributes('aria-valuetext')).toBe('oz')
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MTabs from '../components/MTabs.vue'
|
|
4
|
+
|
|
5
|
+
const tabs = [
|
|
6
|
+
{ value: 'flights', label: 'Flights', icon: 'flight' },
|
|
7
|
+
{ value: 'hotels', label: 'Hotels', icon: 'hotel' },
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
const firstTab = (props: Record<string, unknown>) =>
|
|
11
|
+
mount(MTabs, { props: { modelValue: 'flights', tabs, ...props } }).find('button').classes()
|
|
12
|
+
|
|
13
|
+
describe('MTabs', () => {
|
|
14
|
+
it('stacks primary icons above the label in a 64px tab by default', () => {
|
|
15
|
+
const c = firstTab({})
|
|
16
|
+
expect(c).toContain('flex-col')
|
|
17
|
+
expect(c).toContain('h-16')
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('puts the icon beside the label in a 48px tab with iconPosition="leading" (LeadingIconTab)', () => {
|
|
21
|
+
const c = firstTab({ iconPosition: 'leading' })
|
|
22
|
+
expect(c).toContain('flex-row')
|
|
23
|
+
expect(c).toContain('h-12')
|
|
24
|
+
expect(c).toContain('gap-2')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('keeps secondary icons beside the label by default and stacks them with iconPosition="top"', () => {
|
|
28
|
+
expect(firstTab({ variant: 'secondary' })).toContain('flex-row')
|
|
29
|
+
const c = firstTab({ variant: 'secondary', iconPosition: 'top' })
|
|
30
|
+
expect(c).toContain('flex-col')
|
|
31
|
+
expect(c).toContain('h-16')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('emits the picked tab', async () => {
|
|
35
|
+
const w = mount(MTabs, { props: { modelValue: 'flights', tabs } })
|
|
36
|
+
await w.findAll('button')[1]!.trigger('click')
|
|
37
|
+
expect(w.emitted('update:modelValue')).toEqual([['hotels']])
|
|
38
|
+
})
|
|
39
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MTimePickerModal from '../components/MTimePickerModal.vue'
|
|
5
|
+
import MTimeScroll from '../components/MTimeScroll.vue'
|
|
6
|
+
|
|
7
|
+
let wrapper: VueWrapper | undefined
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
wrapper?.unmount()
|
|
10
|
+
wrapper = undefined
|
|
11
|
+
document.body.innerHTML = ''
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
async function open(props: Record<string, unknown>) {
|
|
15
|
+
wrapper = mount(MTimePickerModal, { props: { modelValue: null, ...props }, attachTo: document.body })
|
|
16
|
+
await wrapper.setProps({ show: true })
|
|
17
|
+
await nextTick()
|
|
18
|
+
return wrapper
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const button = (text: string) => [...document.body.querySelectorAll('button')].find((b) => b.textContent?.trim() === text)!
|
|
22
|
+
|
|
23
|
+
describe('MTimePickerModal', () => {
|
|
24
|
+
it('shows the clock dial by default', async () => {
|
|
25
|
+
const w = await open({ modelValue: '09:30' })
|
|
26
|
+
expect(w.findComponent(MTimeScroll).exists()).toBe(false)
|
|
27
|
+
expect(document.body.textContent).toContain('09')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('picks the time with scroll wheels in scroll mode and confirms it as 24-hour', async () => {
|
|
31
|
+
const w = await open({ modelValue: '21:07', mode: 'scroll' })
|
|
32
|
+
const scroll = w.findComponent(MTimeScroll)
|
|
33
|
+
expect(scroll.exists()).toBe(true)
|
|
34
|
+
// The minute wheel only shows multiples of minuteStep (5): it starts on 05
|
|
35
|
+
expect(scroll.props('modelValue')).toBe('21:05')
|
|
36
|
+
await scroll.vm.$emit('update:modelValue', '08:45')
|
|
37
|
+
button('OK').click()
|
|
38
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['08:45'])
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('switches between scroll and keyboard input', async () => {
|
|
42
|
+
const w = await open({ modelValue: '14:00', mode: 'scroll', use24h: true })
|
|
43
|
+
const toggle = document.body.querySelector<HTMLButtonElement>('[aria-label="Switch to text input mode"]')!
|
|
44
|
+
toggle.click()
|
|
45
|
+
await nextTick()
|
|
46
|
+
expect(w.findComponent(MTimeScroll).exists()).toBe(false)
|
|
47
|
+
expect(document.body.querySelectorAll('input')).toHaveLength(2)
|
|
48
|
+
document.body.querySelector<HTMLButtonElement>('[aria-label="Switch to scroll mode"]')!.click()
|
|
49
|
+
await nextTick()
|
|
50
|
+
expect(w.findComponent(MTimeScroll).props('modelValue')).toBe('14:00')
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MTimeScroll from '../components/MTimeScroll.vue'
|
|
4
|
+
import MScrollField from '../components/MScrollField.vue'
|
|
5
|
+
|
|
6
|
+
describe('MTimeScroll', () => {
|
|
7
|
+
it('maps a 12-hour time onto the wheels (12 o\'clock is the last hour item)', () => {
|
|
8
|
+
const w = mount(MTimeScroll, { props: { modelValue: '00:30' } })
|
|
9
|
+
const [hours, minutes] = w.findAllComponents(MScrollField)
|
|
10
|
+
expect(hours!.props('count')).toBe(12)
|
|
11
|
+
expect(hours!.props('modelValue')).toBe(11)
|
|
12
|
+
expect(minutes!.props('modelValue')).toBe(30)
|
|
13
|
+
expect(w.find('[role="radio"][aria-checked="true"]').text()).toMatch(/AM/i)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('keeps AM/PM when the hour wheel turns', async () => {
|
|
17
|
+
const w = mount(MTimeScroll, { props: { modelValue: '15:00' } })
|
|
18
|
+
await w.findAllComponents(MScrollField)[0]!.vm.$emit('update:modelValue', 0)
|
|
19
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['13:00'])
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('switches period with the toggle', async () => {
|
|
23
|
+
const w = mount(MTimeScroll, { props: { modelValue: '09:15' } })
|
|
24
|
+
await w.findAll('[role="radio"]')[1]!.trigger('click')
|
|
25
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['21:15'])
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('uses a 24-hour wheel without the toggle', async () => {
|
|
29
|
+
const w = mount(MTimeScroll, { props: { modelValue: '18:40', use24h: true } })
|
|
30
|
+
const [hours] = w.findAllComponents(MScrollField)
|
|
31
|
+
expect(hours!.props('count')).toBe(24)
|
|
32
|
+
expect(hours!.props('modelValue')).toBe(18)
|
|
33
|
+
expect(w.find('[role="radiogroup"]').exists()).toBe(false)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('steps minutes by minuteStep', async () => {
|
|
37
|
+
const w = mount(MTimeScroll, { props: { modelValue: '10:07', minuteStep: 5 } })
|
|
38
|
+
const minutes = w.findAllComponents(MScrollField)[1]!
|
|
39
|
+
expect(minutes.props('count')).toBe(12)
|
|
40
|
+
expect(minutes.props('modelValue')).toBe(1)
|
|
41
|
+
await minutes.vm.$emit('update:modelValue', 3)
|
|
42
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['10:15'])
|
|
43
|
+
})
|
|
44
|
+
})
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MTopAppBar from '../components/MTopAppBar.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrapper?.unmount()
|
|
9
|
+
wrapper = undefined
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
function bar(props: Record<string, unknown>) {
|
|
14
|
+
wrapper = mount(MTopAppBar, { props: { title: 'Inbox', ...props }, attachTo: document.body })
|
|
15
|
+
const bottomRow = () => wrapper!.find('.items-end').element as HTMLElement
|
|
16
|
+
return { bar: wrapper.find('header').element as HTMLElement, bottomRow }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function scroller() {
|
|
20
|
+
const el = document.createElement('div')
|
|
21
|
+
document.body.appendChild(el)
|
|
22
|
+
return {
|
|
23
|
+
el,
|
|
24
|
+
to(y: number) {
|
|
25
|
+
el.scrollTop = y
|
|
26
|
+
el.dispatchEvent(new Event('scroll'))
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('MTopAppBar', () => {
|
|
32
|
+
it.each([
|
|
33
|
+
[{ variant: 'medium' }, '48px'],
|
|
34
|
+
[{ variant: 'large' }, '88px'],
|
|
35
|
+
[{ variant: 'medium', flexible: true }, '48px'],
|
|
36
|
+
[{ variant: 'medium', flexible: true, subtitle: 'Work' }, '72px'],
|
|
37
|
+
[{ variant: 'large', flexible: true }, '56px'],
|
|
38
|
+
[{ variant: 'large', flexible: true, subtitle: 'Work' }, '88px'],
|
|
39
|
+
])('sizes the title row of %o from the app bar tokens', (props, height) => {
|
|
40
|
+
expect(bar(props).bottomRow().style.height).toBe(height)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('uses the flexible title and subtitle styles', () => {
|
|
44
|
+
bar({ variant: 'large', flexible: true, subtitle: 'Work' })
|
|
45
|
+
expect(wrapper!.find('h1').classes()).toContain('text-display-small')
|
|
46
|
+
expect(wrapper!.find('.items-end p').classes()).toContain('text-title-medium')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('shows a subtitle under a small title', () => {
|
|
50
|
+
bar({ subtitle: '3 unread' })
|
|
51
|
+
expect(wrapper!.find('p').text()).toBe('3 unread')
|
|
52
|
+
expect(wrapper!.find('p').classes()).toContain('text-label-medium')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('collapses a medium bar with the content and swaps the titles (exit-until-collapsed)', async () => {
|
|
56
|
+
const s = scroller()
|
|
57
|
+
const { bar: el, bottomRow } = bar({ variant: 'medium', scrollBehavior: 'exit-until-collapsed', scrollTarget: s.el })
|
|
58
|
+
expect(wrapper!.find('header').classes()).toContain('sticky')
|
|
59
|
+
s.to(30)
|
|
60
|
+
expect(el.style.height).toBe('82px')
|
|
61
|
+
// The bottom margin keeps the expanded 112px in the layout
|
|
62
|
+
expect(el.style.marginBottom).toBe('30px')
|
|
63
|
+
expect(bottomRow().style.height).toBe('18px')
|
|
64
|
+
s.to(200)
|
|
65
|
+
expect(el.style.height).toBe('64px')
|
|
66
|
+
const [small, big] = wrapper!.findAll('.min-w-0').map((w) => w.element as HTMLElement)
|
|
67
|
+
expect(small!.style.opacity).toBe('1')
|
|
68
|
+
expect(big!.style.opacity).toBe('0')
|
|
69
|
+
// Only back at the top does it expand again
|
|
70
|
+
s.to(10)
|
|
71
|
+
expect(el.style.height).toBe('102px')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('hides a small bar while scrolling down and brings it back scrolling up (enter-always)', () => {
|
|
75
|
+
const s = scroller()
|
|
76
|
+
const { bar: el } = bar({ scrollBehavior: 'enter-always', scrollTarget: s.el })
|
|
77
|
+
s.to(40)
|
|
78
|
+
expect(el.style.height).toBe('24px')
|
|
79
|
+
s.to(300)
|
|
80
|
+
expect(el.style.height).toBe('0px')
|
|
81
|
+
s.to(280)
|
|
82
|
+
expect(el.style.height).toBe('20px')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('keeps the navigation button a grandchild of the header (consumers select header > div > button)', () => {
|
|
86
|
+
bar({ navigationIcon: 'menu' })
|
|
87
|
+
expect(wrapper!.find('header > div > button').exists()).toBe(true)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('takes the scrolled color when content moves under a pinned bar', async () => {
|
|
91
|
+
const s = scroller()
|
|
92
|
+
const { bar: el } = bar({ scrollBehavior: 'pinned', scrollTarget: s.el })
|
|
93
|
+
expect(el.classList).toContain('bg-surface')
|
|
94
|
+
s.to(5)
|
|
95
|
+
await nextTick()
|
|
96
|
+
expect(el.classList).toContain('bg-surface-container')
|
|
97
|
+
expect(el.style.height).toBe('')
|
|
98
|
+
})
|
|
99
|
+
})
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick } from 'vue'
|
|
4
|
+
import { readFileSync } from 'node:fs'
|
|
5
|
+
import { resolve } from 'node:path'
|
|
6
|
+
import { useColorPalette, palettes } from '../composables/useColorPalette'
|
|
7
|
+
|
|
8
|
+
function withSetup() {
|
|
9
|
+
let result!: ReturnType<typeof useColorPalette>
|
|
10
|
+
mount(defineComponent({
|
|
11
|
+
setup() {
|
|
12
|
+
result = useColorPalette()
|
|
13
|
+
return () => h('div')
|
|
14
|
+
},
|
|
15
|
+
}))
|
|
16
|
+
return result
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('contrast levels', () => {
|
|
20
|
+
afterEach(async () => {
|
|
21
|
+
withSetup().setContrast('standard')
|
|
22
|
+
await nextTick()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('sets data-contrast on <html> and remembers the level', async () => {
|
|
26
|
+
const { setContrast, contrast, activeContrast } = withSetup()
|
|
27
|
+
setContrast('high')
|
|
28
|
+
await nextTick()
|
|
29
|
+
expect(contrast.value).toBe('high')
|
|
30
|
+
expect(activeContrast.value).toBe('high')
|
|
31
|
+
expect(document.documentElement.getAttribute('data-contrast')).toBe('high')
|
|
32
|
+
expect(localStorage.getItem('m3-contrast')).toBe('high')
|
|
33
|
+
setContrast('standard')
|
|
34
|
+
await nextTick()
|
|
35
|
+
expect(document.documentElement.hasAttribute('data-contrast')).toBe(false)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('resolves system to the OS preference (standard without prefers-contrast: more)', async () => {
|
|
39
|
+
const { setContrast, activeContrast } = withSetup()
|
|
40
|
+
setContrast('system')
|
|
41
|
+
await nextTick()
|
|
42
|
+
expect(activeContrast.value).toBe('standard')
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
describe('palettes-contrast.css', () => {
|
|
47
|
+
const css = readFileSync(resolve(__dirname, '../styles/palettes-contrast.css'), 'utf8')
|
|
48
|
+
|
|
49
|
+
it('has medium and high, light and dark, for every built-in palette', () => {
|
|
50
|
+
for (const { id } of palettes) {
|
|
51
|
+
const base = id === 'purple' ? 'html:not([data-palette])' : `[data-palette='${id}']`
|
|
52
|
+
for (const level of ['medium', 'high']) {
|
|
53
|
+
expect(css).toContain(`${base}[data-contrast='${level}']:not(.dark) {`)
|
|
54
|
+
expect(css).toContain(`${base}[data-contrast='${level}'].dark {`)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('raises contrast: high-contrast on-surface is black in light and white in dark', () => {
|
|
60
|
+
const block = (selector: string) => css.slice(css.indexOf(`${selector} {`)).split('}')[0]!
|
|
61
|
+
expect(block("[data-palette='teal'][data-contrast='high']:not(.dark)")).toContain('--color-on-surface: #000000;')
|
|
62
|
+
expect(block("[data-palette='teal'][data-contrast='high'].dark")).toContain('--color-on-surface: #FFFFFF;')
|
|
63
|
+
})
|
|
64
|
+
})
|