@m3ui-vue/m3ui-vue 0.9.0 → 0.9.2
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 +53 -2
- package/dist/API.md +3806 -0
- package/dist/MIcon-CaEooCmZ.js.map +1 -1
- package/dist/{MTextField-B0wGv1Mx.js → MTextField-Ck0oWDMk.js} +9 -3
- package/dist/MTextField-Ck0oWDMk.js.map +1 -0
- package/dist/api.json +1 -0
- package/dist/barcode.js.map +1 -1
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/code-editor.js.map +1 -1
- package/dist/components/MAbsolute.vue.d.ts +12 -0
- package/dist/components/MAlert.vue.d.ts +4 -0
- package/dist/components/MAppBar.vue.d.ts +12 -0
- package/dist/components/MAppLayout.vue.d.ts +2 -0
- package/dist/components/MAspectRatio.vue.d.ts +1 -0
- package/dist/components/MAutocomplete.vue.d.ts +18 -0
- package/dist/components/MAvatar.vue.d.ts +3 -0
- package/dist/components/MBadge.vue.d.ts +6 -0
- package/dist/components/MBar.vue.d.ts +5 -0
- package/dist/components/MBarcode.vue.d.ts +9 -0
- package/dist/components/MBottomSheet.vue.d.ts +3 -0
- package/dist/components/MBox.vue.d.ts +8 -2
- package/dist/components/MBreadcrumbs.vue.d.ts +2 -0
- package/dist/components/MButton.vue.d.ts +14 -4
- package/dist/components/MButtonGroup.vue.d.ts +7 -0
- package/dist/components/MCalendar.vue.d.ts +8 -0
- package/dist/components/MCard.vue.d.ts +17 -0
- package/dist/components/MCarousel.vue.d.ts +7 -1
- package/dist/components/MCenter.vue.d.ts +1 -0
- package/dist/components/MChart.vue.d.ts +7 -0
- package/dist/components/MChatBubble.vue.d.ts +10 -0
- package/dist/components/MCheckbox.vue.d.ts +5 -0
- package/dist/components/MChip.vue.d.ts +9 -0
- package/dist/components/MCircleProgressBar.vue.d.ts +7 -0
- package/dist/components/MCodeEditor.vue.d.ts +9 -0
- package/dist/components/MColorPicker.vue.d.ts +20 -0
- package/dist/components/MColorPickerModal.vue.d.ts +16 -0
- package/dist/components/MCommandPalette.vue.d.ts +8 -0
- package/dist/components/MConfirmDialog.vue.d.ts +7 -0
- package/dist/components/MContainer.vue.d.ts +4 -0
- package/dist/components/MContextMenu.vue.d.ts +3 -6
- package/dist/components/MCopyButton.vue.d.ts +10 -0
- package/dist/components/MDataTable.vue.d.ts +33 -12
- package/dist/components/MDatePicker.vue.d.ts +16 -0
- package/dist/components/MDatePickerModal.vue.d.ts +9 -0
- package/dist/components/MDateRangePicker.vue.d.ts +18 -0
- package/dist/components/MDateRangePickerModal.vue.d.ts +9 -0
- package/dist/components/MDialog.vue.d.ts +9 -7
- package/dist/components/MDivider.vue.d.ts +6 -0
- package/dist/components/MDragDropList.vue.d.ts +6 -0
- package/dist/components/MDragHandle.vue.d.ts +12 -0
- package/dist/components/MEmoji.vue.d.ts +6 -0
- package/dist/components/MEmojiButton.vue.d.ts +5 -0
- package/dist/components/MEmojiSelector.vue.d.ts +1 -1
- package/dist/components/MEmptyState.vue.d.ts +4 -0
- package/dist/components/MExpansionPanel.vue.d.ts +9 -0
- package/dist/components/MExportButton.vue.d.ts +8 -0
- package/dist/components/MFab.vue.d.ts +10 -1
- package/dist/components/MFabMenu.vue.d.ts +15 -1
- package/dist/components/MFileUpload.vue.d.ts +8 -0
- package/dist/components/MFixed.vue.d.ts +10 -0
- package/dist/components/MFlex.vue.d.ts +6 -0
- package/dist/components/MFooter.vue.d.ts +11 -0
- package/dist/components/MFullscreen.vue.d.ts +2 -0
- package/dist/components/MGrid.vue.d.ts +7 -0
- package/dist/components/MHotkeys.vue.d.ts +4 -0
- package/dist/components/MIcon.vue.d.ts +2 -0
- package/dist/components/MIconButton.vue.d.ts +10 -0
- package/dist/components/MInfiniteScroll.vue.d.ts +6 -0
- package/dist/components/MJsonEditor.vue.d.ts +8 -0
- package/dist/components/MJsonViewer.vue.d.ts +4 -0
- package/dist/components/MKanban.vue.d.ts +2 -0
- package/dist/components/MKbd.vue.d.ts +2 -0
- package/dist/components/MLightbox.vue.d.ts +4 -0
- package/dist/components/MList.vue.d.ts +7 -0
- package/dist/components/MListItem.vue.d.ts +29 -5
- package/dist/components/MListSubheader.vue.d.ts +6 -0
- package/dist/components/MLoadingIndicator.vue.d.ts +10 -0
- package/dist/components/MLoadingOverlay.vue.d.ts +5 -0
- package/dist/components/MMarkdown.vue.d.ts +3 -0
- package/dist/components/MMaskField.vue.d.ts +15 -0
- package/dist/components/MMasonry.vue.d.ts +5 -0
- package/dist/components/MMenu.vue.d.ts +3 -6
- package/dist/components/MMenuDivider.vue.d.ts +4 -0
- package/dist/components/MMenuItem.vue.d.ts +5 -0
- package/dist/components/MMultiAutocomplete.vue.d.ts +20 -0
- package/dist/components/MMultiSelect.vue.d.ts +21 -0
- package/dist/components/MNavigationBar.vue.d.ts +2 -0
- package/dist/components/MNavigationDrawer.vue.d.ts +11 -0
- package/dist/components/MNavigationRail.vue.d.ts +9 -6
- package/dist/components/MNavigationSuite.vue.d.ts +5 -3
- package/dist/components/MNumberField.vue.d.ts +17 -0
- package/dist/components/MOverlay.vue.d.ts +4 -1
- package/dist/components/MPageProgress.vue.d.ts +3 -0
- package/dist/components/MPagination.vue.d.ts +3 -0
- package/dist/components/MPasswordMeter.vue.d.ts +1 -0
- package/dist/components/MPinInput.vue.d.ts +11 -0
- package/dist/components/MProgressBar.vue.d.ts +6 -0
- package/dist/components/MPullToRefresh.vue.d.ts +8 -0
- package/dist/components/MQRCode.vue.d.ts +6 -0
- package/dist/components/MRadio.vue.d.ts +5 -0
- package/dist/components/MRadioGroup.vue.d.ts +6 -0
- package/dist/components/MRating.vue.d.ts +11 -0
- package/dist/components/MRelativeTime.vue.d.ts +1 -0
- package/dist/components/MResponsive.vue.d.ts +3 -0
- package/dist/components/MResult.vue.d.ts +6 -0
- package/dist/components/MRichTextEditor.vue.d.ts +8 -0
- package/dist/components/MScheduler.vue.d.ts +10 -0
- package/dist/components/MScrollField.vue.d.ts +40 -0
- package/dist/components/MScrollable.vue.d.ts +12 -0
- package/dist/components/MSearchBar.vue.d.ts +6 -0
- package/dist/components/MSection.vue.d.ts +5 -0
- package/dist/components/MSegmentedButton.vue.d.ts +5 -0
- package/dist/components/MSelect.vue.d.ts +17 -0
- package/dist/components/MShader.vue.d.ts +1 -0
- package/dist/components/MShortNavigationBar.vue.d.ts +8 -9
- package/dist/components/MSideSheet.vue.d.ts +3 -0
- package/dist/components/MSignaturePad.vue.d.ts +7 -0
- package/dist/components/MSimpleCarousel.vue.d.ts +10 -0
- package/dist/components/MSkeleton.vue.d.ts +8 -0
- package/dist/components/MSlider.vue.d.ts +14 -0
- package/dist/components/MSnackbar.vue.d.ts +1 -0
- package/dist/components/MSpinner.vue.d.ts +6 -0
- package/dist/components/MSplitButton.vue.d.ts +7 -0
- package/dist/components/MSplitter.vue.d.ts +6 -2
- package/dist/components/MSpotlightSearch.vue.d.ts +18 -0
- package/dist/components/MStack.vue.d.ts +7 -0
- package/dist/components/MStatCard.vue.d.ts +7 -0
- package/dist/components/MStepper.vue.d.ts +7 -0
- package/dist/components/MSticky.vue.d.ts +2 -0
- package/dist/components/MSubtitle.vue.d.ts +4 -0
- package/dist/components/MSwipeToDismiss.vue.d.ts +49 -0
- package/dist/components/MSwitch.vue.d.ts +5 -6
- package/dist/components/MTable.vue.d.ts +17 -4
- package/dist/components/MTabs.vue.d.ts +6 -0
- package/dist/components/MTagInput.vue.d.ts +17 -0
- package/dist/components/MTerminal.vue.d.ts +4 -0
- package/dist/components/MText.vue.d.ts +10 -0
- package/dist/components/MTextField.vue.d.ts +18 -0
- package/dist/components/MTimePicker.vue.d.ts +10 -0
- package/dist/components/MTimePickerModal.vue.d.ts +5 -0
- package/dist/components/MTimeline.vue.d.ts +3 -0
- package/dist/components/MTitle.vue.d.ts +4 -0
- package/dist/components/MToggleButton.vue.d.ts +4 -0
- package/dist/components/MToolbar.vue.d.ts +5 -0
- package/dist/components/MTooltip.vue.d.ts +7 -0
- package/dist/components/MTopAppBar.vue.d.ts +8 -0
- package/dist/components/MTour.vue.d.ts +5 -0
- package/dist/components/MTransferList.vue.d.ts +11 -0
- package/dist/components/MTransition.vue.d.ts +34 -0
- package/dist/components/MTree.vue.d.ts +11 -0
- package/dist/components/MTreeTable.vue.d.ts +7 -0
- package/dist/components/MVirtualTable.vue.d.ts +6 -0
- package/dist/components/MWindow.vue.d.ts +33 -1
- package/dist/components/_MColorPanel.vue.d.ts +18 -0
- package/dist/composables/_colorUtils.d.ts +34 -0
- package/dist/composables/_themeColor.d.ts +1 -0
- package/dist/composables/_useSpring.d.ts +15 -0
- package/dist/composables/dynamicColor.d.ts +18 -0
- package/dist/composables/useColorPalette.d.ts +27 -0
- package/dist/composables/useLocale.d.ts +12 -0
- package/dist/index.d.ts +9 -1
- package/dist/locales/index.js +70 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +6456 -5273
- package/dist/m3ui.js.map +1 -1
- package/dist/markdown.js +1 -1
- package/dist/markdown.js.map +1 -1
- package/dist/material-color-utilities-Cktu8DBU.js +3160 -0
- package/dist/material-color-utilities-Cktu8DBU.js.map +1 -0
- package/dist/plugin.d.ts +18 -0
- package/dist/qrcode.js.map +1 -1
- package/dist/rich-text-editor.js +3 -3
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles/palettes.css +546 -0
- package/dist/styles/theme.css +77 -0
- package/dist/styles.css +1 -1
- package/dist/terminal.js.map +1 -1
- package/dist/{useLocale-CmI675Ab.js → useLocale-CFW8cIzL.js} +23 -10
- package/dist/useLocale-CFW8cIzL.js.map +1 -0
- package/package.json +5 -2
- package/src/__tests__/MButtonGroup.test.ts +51 -0
- package/src/__tests__/MColorPicker.test.ts +141 -0
- package/src/__tests__/MDragHandle.test.ts +57 -0
- package/src/__tests__/MHotkeys.test.ts +57 -0
- package/src/__tests__/MListItemShape.test.ts +76 -0
- package/src/__tests__/MScrollField.test.ts +41 -0
- package/src/__tests__/MScrollable.test.ts +42 -0
- package/src/__tests__/MSwipeToDismiss.test.ts +104 -0
- package/src/__tests__/MTransition.test.ts +27 -0
- package/src/__tests__/dynamicColor.test.ts +191 -0
- package/src/__tests__/hostLocale.test.ts +57 -0
- package/src/components/MAbsolute.vue +18 -0
- package/src/components/MAlert.vue +12 -0
- package/src/components/MAppBar.vue +12 -0
- package/src/components/MAppLayout.vue +11 -0
- package/src/components/MAspectRatio.vue +6 -0
- package/src/components/MAutocomplete.vue +24 -0
- package/src/components/MAvatar.vue +12 -1
- package/src/components/MBadge.vue +11 -0
- package/src/components/MBar.vue +19 -0
- package/src/components/MBarcode.vue +14 -0
- package/src/components/MBottomSheet.vue +12 -0
- package/src/components/MBox.vue +15 -1
- package/src/components/MBreadcrumbs.vue +7 -0
- package/src/components/MButton.vue +22 -4
- package/src/components/MButtonGroup.vue +129 -35
- package/src/components/MCalendar.vue +14 -0
- package/src/components/MCard.vue +26 -0
- package/src/components/MCarousel.vue +17 -1
- package/src/components/MCenter.vue +6 -0
- package/src/components/MChart.vue +12 -0
- package/src/components/MChatBubble.vue +17 -0
- package/src/components/MCheckbox.vue +11 -0
- package/src/components/MChip.vue +17 -0
- package/src/components/MCircleProgressBar.vue +13 -0
- package/src/components/MCodeEditor.vue +15 -0
- package/src/components/MColorPicker.vue +124 -207
- package/src/components/MColorPickerModal.vue +58 -247
- package/src/components/MCommandPalette.vue +16 -0
- package/src/components/MConfirmDialog.vue +15 -0
- package/src/components/MContainer.vue +9 -0
- package/src/components/MContextMenu.vue +17 -6
- package/src/components/MCopyButton.vue +16 -0
- package/src/components/MDataTable.vue +58 -12
- package/src/components/MDatePicker.vue +21 -0
- package/src/components/MDatePickerModal.vue +16 -0
- package/src/components/MDateRangePicker.vue +23 -0
- package/src/components/MDateRangePickerModal.vue +16 -0
- package/src/components/MDialog.vue +27 -7
- package/src/components/MDivider.vue +6 -0
- package/src/components/MDragDropList.vue +18 -0
- package/src/components/MDragHandle.vue +54 -0
- package/src/components/MEmoji.vue +6 -0
- package/src/components/MEmojiButton.vue +11 -0
- package/src/components/MEmojiSelector.vue +7 -0
- package/src/components/MEmptyState.vue +9 -0
- package/src/components/MExpansionPanel.vue +17 -0
- package/src/components/MExportButton.vue +15 -0
- package/src/components/MFab.vue +17 -0
- package/src/components/MFabMenu.vue +20 -0
- package/src/components/MFileUpload.vue +19 -0
- package/src/components/MFixed.vue +16 -0
- package/src/components/MFlex.vue +11 -0
- package/src/components/MFooter.vue +11 -0
- package/src/components/MFullscreen.vue +8 -0
- package/src/components/MGrid.vue +12 -0
- package/src/components/MHotkeys.vue +20 -13
- package/src/components/MIcon.vue +10 -1
- package/src/components/MIconButton.vue +13 -0
- package/src/components/MInfiniteScroll.vue +16 -0
- package/src/components/MJsonEditor.vue +13 -0
- package/src/components/MJsonViewer.vue +7 -0
- package/src/components/MKanban.vue +18 -0
- package/src/components/MKbd.vue +6 -0
- package/src/components/MLightbox.vue +16 -0
- package/src/components/MList.vue +48 -3
- package/src/components/MListDetail.vue +11 -0
- package/src/components/MListItem.vue +112 -5
- package/src/components/MListSubheader.vue +6 -0
- package/src/components/MLoadingIndicator.vue +15 -0
- package/src/components/MLoadingOverlay.vue +12 -0
- package/src/components/MMarkdown.vue +7 -0
- package/src/components/MMaskField.vue +21 -0
- package/src/components/MMasonry.vue +11 -0
- package/src/components/MMenu.vue +16 -6
- package/src/components/MMenuDivider.vue +4 -0
- package/src/components/MMenuItem.vue +16 -0
- package/src/components/MMultiAutocomplete.vue +26 -0
- package/src/components/MMultiSelect.vue +27 -0
- package/src/components/MNavigationBar.vue +7 -0
- package/src/components/MNavigationDrawer.vue +25 -0
- package/src/components/MNavigationRail.vue +24 -6
- package/src/components/MNavigationSuite.vue +20 -3
- package/src/components/MNotificationHost.vue +3 -0
- package/src/components/MNumberField.vue +24 -0
- package/src/components/MOverlay.vue +10 -0
- package/src/components/MPageProgress.vue +7 -0
- package/src/components/MPagination.vue +15 -1
- package/src/components/MPasswordMeter.vue +7 -0
- package/src/components/MPinInput.vue +19 -0
- package/src/components/MProgressBar.vue +9 -0
- package/src/components/MPullToRefresh.vue +17 -0
- package/src/components/MQRCode.vue +12 -0
- package/src/components/MRadio.vue +11 -0
- package/src/components/MRadioGroup.vue +11 -0
- package/src/components/MRating.vue +19 -0
- package/src/components/MRelative.vue +8 -0
- package/src/components/MRelativeTime.vue +6 -0
- package/src/components/MResponsive.vue +9 -0
- package/src/components/MResult.vue +14 -0
- package/src/components/MRichTextEditor.vue +14 -0
- package/src/components/MScheduler.vue +21 -0
- package/src/components/MScrollField.vue +302 -0
- package/src/components/MScrollable.vue +167 -4
- package/src/components/MSearchBar.vue +17 -0
- package/src/components/MSection.vue +13 -0
- package/src/components/MSegmentedButton.vue +10 -0
- package/src/components/MSelect.vue +22 -0
- package/src/components/MShader.vue +13 -0
- package/src/components/MShape.vue +6 -0
- package/src/components/MShortNavigationBar.vue +23 -9
- package/src/components/MSideSheet.vue +13 -0
- package/src/components/MSignaturePad.vue +15 -0
- package/src/components/MSimpleCarousel.vue +18 -0
- package/src/components/MSkeleton.vue +8 -0
- package/src/components/MSlider.vue +21 -0
- package/src/components/MSnackbar.vue +5 -0
- package/src/components/MSpacer.vue +6 -0
- package/src/components/MSpinner.vue +10 -0
- package/src/components/MSplitButton.vue +14 -0
- package/src/components/MSplitter.vue +42 -9
- package/src/components/MSpotlightSearch.vue +27 -0
- package/src/components/MStack.vue +12 -0
- package/src/components/MStatCard.vue +13 -0
- package/src/components/MStepper.vue +12 -0
- package/src/components/MSticky.vue +7 -0
- package/src/components/MSubtitle.vue +9 -0
- package/src/components/MSupportingPane.vue +10 -0
- package/src/components/MSwipeToDismiss.vue +247 -0
- package/src/components/MSwitch.vue +14 -6
- package/src/components/MTable.vue +33 -4
- package/src/components/MTabs.vue +12 -0
- package/src/components/MTagInput.vue +23 -0
- package/src/components/MTerminal.vue +11 -0
- package/src/components/MText.vue +15 -0
- package/src/components/MTextField.vue +26 -0
- package/src/components/MTimePicker.vue +15 -0
- package/src/components/MTimePickerModal.vue +12 -0
- package/src/components/MTimeline.vue +7 -0
- package/src/components/MTitle.vue +9 -0
- package/src/components/MToggleButton.vue +12 -0
- package/src/components/MToolbar.vue +12 -0
- package/src/components/MTooltip.vue +15 -0
- package/src/components/MTopAppBar.vue +18 -0
- package/src/components/MTour.vue +13 -0
- package/src/components/MTransferList.vue +24 -0
- package/src/components/MTransition.vue +149 -0
- package/src/components/MTree.vue +11 -0
- package/src/components/MTreeTable.vue +15 -0
- package/src/components/MVirtualTable.vue +12 -0
- package/src/components/MWindow.vue +34 -0
- package/src/components/_MColorPanel.vue +478 -0
- package/src/composables/_colorUtils.ts +107 -0
- package/src/composables/_themeColor.ts +33 -0
- package/src/composables/_useSpring.ts +89 -0
- package/src/composables/dynamicColor.ts +85 -0
- package/src/composables/useColorPalette.ts +171 -25
- package/src/composables/useFieldBg.ts +6 -0
- package/src/composables/useLocale.ts +38 -3
- package/src/index.ts +9 -1
- package/src/locales/de.ts +10 -0
- package/src/locales/es.ts +10 -0
- package/src/locales/fr.ts +10 -0
- package/src/locales/ja.ts +10 -0
- package/src/locales/ko.ts +10 -0
- package/src/locales/pt.ts +10 -0
- package/src/locales/zh.ts +10 -0
- package/src/plugin.ts +30 -8
- package/src/styles/palettes.css +546 -0
- package/src/styles/theme.css +77 -0
- package/dist/MTextField-B0wGv1Mx.js.map +0 -1
- package/dist/useLocale-CmI675Ab.js.map +0 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach, beforeEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MColorPicker from '../components/MColorPicker.vue'
|
|
5
|
+
import MColorPickerModal from '../components/MColorPickerModal.vue'
|
|
6
|
+
import { recentColors } from '../composables/_colorUtils'
|
|
7
|
+
|
|
8
|
+
let wrapper: VueWrapper | undefined
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
localStorage.clear()
|
|
12
|
+
recentColors.value = []
|
|
13
|
+
})
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
wrapper?.unmount()
|
|
16
|
+
wrapper = undefined
|
|
17
|
+
document.body.innerHTML = ''
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const $ = <T extends Element = HTMLElement>(sel: string) => document.body.querySelector<T>(sel)
|
|
21
|
+
const $$ = <T extends Element = HTMLElement>(sel: string) => [...document.body.querySelectorAll<T>(sel)]
|
|
22
|
+
const slider = (label: string) => $(`[role="slider"][aria-label="${label}"]`)!
|
|
23
|
+
const lastEmit = (w: VueWrapper) => w.emitted<[string]>('update:modelValue')?.at(-1)?.[0]
|
|
24
|
+
|
|
25
|
+
function rect(el: Element, width: number, height: number) {
|
|
26
|
+
el.getBoundingClientRect = () =>
|
|
27
|
+
({ left: 0, top: 0, right: width, bottom: height, width, height, x: 0, y: 0, toJSON: () => ({}) }) as DOMRect
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function openPicker(props: Record<string, unknown>) {
|
|
31
|
+
wrapper = mount(MColorPicker, {
|
|
32
|
+
props: { 'onUpdate:modelValue': (v: string) => wrapper!.setProps({ modelValue: v }), ...props },
|
|
33
|
+
attachTo: document.body,
|
|
34
|
+
})
|
|
35
|
+
await wrapper.find('button').trigger('click')
|
|
36
|
+
await nextTick()
|
|
37
|
+
return wrapper
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('MColorPicker', () => {
|
|
41
|
+
it('keeps the hue when the color is dragged to black', async () => {
|
|
42
|
+
const w = await openPicker({ modelValue: '#00ff00' })
|
|
43
|
+
const area = slider('Saturation, Brightness')
|
|
44
|
+
rect(area, 200, 100)
|
|
45
|
+
area.dispatchEvent(new PointerEvent('pointerdown', { clientX: 200, clientY: 100, button: 0, bubbles: true }))
|
|
46
|
+
await nextTick()
|
|
47
|
+
expect(lastEmit(w)).toBe('#000000')
|
|
48
|
+
await nextTick()
|
|
49
|
+
expect(slider('Hue').getAttribute('aria-valuenow')).toBe('120')
|
|
50
|
+
expect(area.getAttribute('aria-valuenow')).toBe('100')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('updates live while dragging the hue', async () => {
|
|
54
|
+
const w = await openPicker({ modelValue: '#ff0000' })
|
|
55
|
+
const hue = slider('Hue')
|
|
56
|
+
rect(hue, 200, 24)
|
|
57
|
+
// 10px inset on each side: the middle of the track is 180°
|
|
58
|
+
hue.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 12, button: 0, bubbles: true }))
|
|
59
|
+
await nextTick()
|
|
60
|
+
expect(lastEmit(w)).toBe('#00ffff')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('marks the selected preset regardless of case, with a readable check', async () => {
|
|
64
|
+
await openPicker({ modelValue: '#FFEB3B' })
|
|
65
|
+
const swatch = $('button[aria-label="#ffeb3b"]')!
|
|
66
|
+
expect(swatch.getAttribute('aria-pressed')).toBe('true')
|
|
67
|
+
expect(swatch.querySelector<HTMLElement>('.material-symbols-outlined')!.style.color).toMatch(/#000000|rgb\(0, 0, 0\)/)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('accepts hex without # and in short form', async () => {
|
|
71
|
+
const w = await openPicker({ modelValue: '#000000' })
|
|
72
|
+
const input = $<HTMLInputElement>('input[aria-label="HEX"]')!
|
|
73
|
+
input.value = 'f80'
|
|
74
|
+
input.dispatchEvent(new Event('input'))
|
|
75
|
+
await nextTick()
|
|
76
|
+
expect(lastEmit(w)).toBe('#ff8800')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('edits RGB channels', async () => {
|
|
80
|
+
const w = await openPicker({ modelValue: '#000000' })
|
|
81
|
+
$('button[aria-label="Color format: HEX"]')!.click()
|
|
82
|
+
await nextTick()
|
|
83
|
+
const r = $<HTMLInputElement>('input[aria-label="R"]')!
|
|
84
|
+
r.value = '255'
|
|
85
|
+
r.dispatchEvent(new Event('input'))
|
|
86
|
+
await nextTick()
|
|
87
|
+
expect(lastEmit(w)).toBe('#ff0000')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('emits an 8-digit hex with the alpha slider', async () => {
|
|
91
|
+
const w = await openPicker({ modelValue: '#ff0000', alpha: true })
|
|
92
|
+
const alpha = slider('Opacity')
|
|
93
|
+
alpha.dispatchEvent(new KeyboardEvent('keydown', { key: 'Home', bubbles: true }))
|
|
94
|
+
await nextTick()
|
|
95
|
+
expect(lastEmit(w)).toBe('#ff000000')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('closes on Escape and remembers the picked color', async () => {
|
|
99
|
+
const w = await openPicker({ modelValue: '#ff0000' })
|
|
100
|
+
slider('Hue').dispatchEvent(new KeyboardEvent('keydown', { key: 'End', bubbles: true }))
|
|
101
|
+
slider('Hue').dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowLeft', shiftKey: true, bubbles: true }))
|
|
102
|
+
await nextTick()
|
|
103
|
+
$('[role="dialog"]')!.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
|
|
104
|
+
await nextTick()
|
|
105
|
+
expect($('[role="dialog"]')).toBeNull()
|
|
106
|
+
expect(recentColors.value).toEqual([lastEmit(w)])
|
|
107
|
+
expect(JSON.parse(localStorage.getItem('m3-color-recent')!)).toEqual(recentColors.value)
|
|
108
|
+
})
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
describe('MColorPickerModal', () => {
|
|
112
|
+
it('only emits on confirm, and records the color as recent', async () => {
|
|
113
|
+
wrapper = mount(MColorPickerModal, {
|
|
114
|
+
props: { modelValue: '#ff0000', show: true },
|
|
115
|
+
attachTo: document.body,
|
|
116
|
+
})
|
|
117
|
+
await nextTick()
|
|
118
|
+
expect(document.body.textContent).toContain('Select color')
|
|
119
|
+
$('button[aria-label="#2196f3"]')!.click()
|
|
120
|
+
await nextTick()
|
|
121
|
+
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
|
122
|
+
// The preview shows the original next to the new color
|
|
123
|
+
expect($('button[aria-label="Original color"]')).not.toBeNull()
|
|
124
|
+
$$('button').find((b) => b.textContent?.trim() === 'Confirm')!.click()
|
|
125
|
+
expect(lastEmit(wrapper)).toBe('#2196f3')
|
|
126
|
+
expect(wrapper.emitted('update:show')?.at(-1)).toEqual([false])
|
|
127
|
+
expect(recentColors.value).toEqual(['#2196f3'])
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('discards the draft on cancel', async () => {
|
|
131
|
+
wrapper = mount(MColorPickerModal, {
|
|
132
|
+
props: { modelValue: '#ff0000', show: true },
|
|
133
|
+
attachTo: document.body,
|
|
134
|
+
})
|
|
135
|
+
await nextTick()
|
|
136
|
+
$('button[aria-label="#2196f3"]')!.click()
|
|
137
|
+
$$('button').find((b) => b.textContent?.trim() === 'Cancel')!.click()
|
|
138
|
+
expect(wrapper.emitted('update:modelValue')).toBeUndefined()
|
|
139
|
+
expect(wrapper.emitted('update:show')?.at(-1)).toEqual([false])
|
|
140
|
+
})
|
|
141
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import MDragHandle from '../components/MDragHandle.vue'
|
|
4
|
+
import MSplitter from '../components/MSplitter.vue'
|
|
5
|
+
|
|
6
|
+
const settle = () => new Promise((r) => setTimeout(r, 600))
|
|
7
|
+
|
|
8
|
+
let wrapper: VueWrapper | undefined
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
wrapper?.unmount()
|
|
11
|
+
wrapper = undefined
|
|
12
|
+
document.body.innerHTML = ''
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
describe('MDragHandle', () => {
|
|
17
|
+
it('is a 4×48 outline capsule that becomes 12×52 on-surface when dragged', async () => {
|
|
18
|
+
wrapper = mount(MDragHandle)
|
|
19
|
+
const bar = wrapper.find('span > span').element as HTMLElement
|
|
20
|
+
expect([bar.style.width, bar.style.height]).toEqual(['4px', '48px'])
|
|
21
|
+
expect(bar.className).toContain('bg-outline')
|
|
22
|
+
await wrapper.setProps({ dragging: true })
|
|
23
|
+
await settle()
|
|
24
|
+
expect([bar.style.width, bar.style.height]).toEqual(['12px', '52px'])
|
|
25
|
+
expect(bar.className).toContain('bg-on-surface')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('lies down when horizontal', async () => {
|
|
29
|
+
wrapper = mount(MDragHandle, { props: { orientation: 'horizontal' } })
|
|
30
|
+
await settle()
|
|
31
|
+
const bar = wrapper.find('span > span').element as HTMLElement
|
|
32
|
+
expect([bar.style.width, bar.style.height]).toEqual(['48px', '4px'])
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
describe('MSplitter', () => {
|
|
37
|
+
it('draws the drag handle on its bar, dragged while the bar is', async () => {
|
|
38
|
+
wrapper = mount(MSplitter)
|
|
39
|
+
const sep = wrapper.find('[role="separator"]')
|
|
40
|
+
const bar = sep.find('span > span').element as HTMLElement
|
|
41
|
+
expect([bar.style.width, bar.style.height]).toEqual(['4px', '48px'])
|
|
42
|
+
await sep.trigger('pointerdown', { button: 0, pointerId: 1 })
|
|
43
|
+
await settle()
|
|
44
|
+
expect([bar.style.width, bar.style.height]).toEqual(['12px', '52px'])
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('moves the split with the arrow keys', async () => {
|
|
48
|
+
wrapper = mount(MSplitter, { props: { initialSplit: 50 } })
|
|
49
|
+
const sep = wrapper.find('[role="separator"]')
|
|
50
|
+
await sep.trigger('keydown', { key: 'ArrowRight' })
|
|
51
|
+
expect(sep.attributes('aria-valuenow')).toBe('51')
|
|
52
|
+
await sep.trigger('keydown', { key: 'ArrowLeft', shiftKey: true })
|
|
53
|
+
expect(sep.attributes('aria-valuenow')).toBe('41')
|
|
54
|
+
await sep.trigger('keydown', { key: 'End' })
|
|
55
|
+
expect(sep.attributes('aria-valuenow')).toBe('90')
|
|
56
|
+
})
|
|
57
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import MHotkeys from '../components/MHotkeys.vue'
|
|
4
|
+
|
|
5
|
+
let wrapper: VueWrapper | null = null
|
|
6
|
+
afterEach(() => { wrapper?.unmount(); wrapper = null })
|
|
7
|
+
|
|
8
|
+
function press(key: string, mods: Partial<KeyboardEventInit> = {}) {
|
|
9
|
+
document.dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true, ...mods }))
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe('MHotkeys', () => {
|
|
13
|
+
it('fires a mod binding with Ctrl (not on a Mac)', () => {
|
|
14
|
+
const handler = vi.fn()
|
|
15
|
+
wrapper = mount(MHotkeys, { props: { bindings: [{ keys: 'mod+z', label: 'Undo', handler }] } })
|
|
16
|
+
press('z', { ctrlKey: true })
|
|
17
|
+
expect(handler).toHaveBeenCalledTimes(1)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('fires mod+shift combos and not plain mod ones for them', () => {
|
|
21
|
+
const undo = vi.fn()
|
|
22
|
+
const redo = vi.fn()
|
|
23
|
+
wrapper = mount(MHotkeys, {
|
|
24
|
+
props: { bindings: [{ keys: 'mod+z', label: 'Undo', handler: undo }, { keys: 'mod+shift+z', label: 'Redo', handler: redo }] },
|
|
25
|
+
})
|
|
26
|
+
press('Z', { ctrlKey: true, shiftKey: true })
|
|
27
|
+
expect(redo).toHaveBeenCalledTimes(1)
|
|
28
|
+
expect(undo).not.toHaveBeenCalled()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('fires an explicit ctrl binding', () => {
|
|
32
|
+
const handler = vi.fn()
|
|
33
|
+
wrapper = mount(MHotkeys, { props: { bindings: [{ keys: 'ctrl+k', label: 'Search', handler }] } })
|
|
34
|
+
press('k', { ctrlKey: true })
|
|
35
|
+
expect(handler).toHaveBeenCalledTimes(1)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('does not fire when an extra modifier is held', () => {
|
|
39
|
+
const handler = vi.fn()
|
|
40
|
+
wrapper = mount(MHotkeys, { props: { bindings: [{ keys: 'mod+z', label: 'Undo', handler }] } })
|
|
41
|
+
press('z', { ctrlKey: true, altKey: true })
|
|
42
|
+
press('z')
|
|
43
|
+
expect(handler).not.toHaveBeenCalled()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('fires single keys, but not while typing', () => {
|
|
47
|
+
const handler = vi.fn()
|
|
48
|
+
wrapper = mount(MHotkeys, { props: { bindings: [{ keys: 'b', label: 'Brush', handler }] } })
|
|
49
|
+
press('b')
|
|
50
|
+
expect(handler).toHaveBeenCalledTimes(1)
|
|
51
|
+
const input = document.createElement('input')
|
|
52
|
+
document.body.appendChild(input)
|
|
53
|
+
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'b', bubbles: true }))
|
|
54
|
+
expect(handler).toHaveBeenCalledTimes(1)
|
|
55
|
+
input.remove()
|
|
56
|
+
})
|
|
57
|
+
})
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { h } from 'vue'
|
|
4
|
+
import MList from '../components/MList.vue'
|
|
5
|
+
import MListItem from '../components/MListItem.vue'
|
|
6
|
+
import MListSubheader from '../components/MListSubheader.vue'
|
|
7
|
+
|
|
8
|
+
let wrapper: VueWrapper | undefined
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
wrapper?.unmount()
|
|
11
|
+
wrapper = undefined
|
|
12
|
+
document.body.innerHTML = ''
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// Springs run on rAF; give them time to settle
|
|
16
|
+
const settle = () => new Promise((r) => setTimeout(r, 600))
|
|
17
|
+
const radius = (el: Element) => (el as HTMLElement).style.borderRadius
|
|
18
|
+
|
|
19
|
+
describe('MListItem shape morph', () => {
|
|
20
|
+
it('rests at 4px and grows on hover and press when clickable', async () => {
|
|
21
|
+
wrapper = mount(MListItem, { props: { title: 'A', clickable: true }, attachTo: document.body })
|
|
22
|
+
const row = wrapper.element
|
|
23
|
+
await settle()
|
|
24
|
+
expect(radius(row)).toBe('4px')
|
|
25
|
+
row.dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }))
|
|
26
|
+
await settle()
|
|
27
|
+
expect(radius(row)).toBe('8px')
|
|
28
|
+
row.dispatchEvent(new PointerEvent('pointerdown', { button: 0, pointerType: 'mouse' }))
|
|
29
|
+
await settle()
|
|
30
|
+
expect(radius(row)).toBe('16px')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('ignores hover when not interactive, but morphs when selected', async () => {
|
|
34
|
+
wrapper = mount(MListItem, { props: { title: 'A' }, attachTo: document.body })
|
|
35
|
+
wrapper.element.dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }))
|
|
36
|
+
await settle()
|
|
37
|
+
expect(radius(wrapper.element)).toBe('4px')
|
|
38
|
+
await wrapper.setProps({ active: true })
|
|
39
|
+
await settle()
|
|
40
|
+
expect(radius(wrapper.element)).toBe('16px')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('rounds the outer corners of each segmented run', async () => {
|
|
44
|
+
wrapper = mount(MList, {
|
|
45
|
+
props: { segmented: true },
|
|
46
|
+
slots: {
|
|
47
|
+
default: () => [
|
|
48
|
+
h(MListItem, { title: 'A' }),
|
|
49
|
+
h(MListItem, { title: 'B' }),
|
|
50
|
+
h(MListItem, { title: 'C' }),
|
|
51
|
+
h(MListSubheader, { title: 'More' }),
|
|
52
|
+
h(MListItem, { title: 'D' }),
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
attachTo: document.body,
|
|
56
|
+
})
|
|
57
|
+
await settle()
|
|
58
|
+
const rows = wrapper.findAll('[role="listitem"]').map((w) => w.element)
|
|
59
|
+
expect(rows.map(radius)).toEqual([
|
|
60
|
+
'16px 16px 4px 4px',
|
|
61
|
+
'4px',
|
|
62
|
+
'4px 4px 16px 16px',
|
|
63
|
+
'16px',
|
|
64
|
+
])
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('keeps the pill in nav lists', async () => {
|
|
68
|
+
wrapper = mount(MList, {
|
|
69
|
+
props: { nav: true },
|
|
70
|
+
slots: { default: () => h(MListItem, { title: 'A', clickable: true }) },
|
|
71
|
+
attachTo: document.body,
|
|
72
|
+
})
|
|
73
|
+
await settle()
|
|
74
|
+
expect(radius(wrapper.find('[role="listitem"]').element)).toBe('')
|
|
75
|
+
})
|
|
76
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import MScrollField from '../components/MScrollField.vue'
|
|
4
|
+
|
|
5
|
+
let wrapper: VueWrapper | undefined
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
wrapper?.unmount()
|
|
8
|
+
wrapper = undefined
|
|
9
|
+
document.body.innerHTML = ''
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const wait = (ms = 600) => new Promise((r) => setTimeout(r, ms))
|
|
13
|
+
|
|
14
|
+
describe('MScrollField', () => {
|
|
15
|
+
it('formats with two digits and moves with the arrow keys, wrapping around', async () => {
|
|
16
|
+
wrapper = mount(MScrollField, {
|
|
17
|
+
props: { modelValue: 0, count: 60, label: 'Minute', 'onUpdate:modelValue': (v: number) => wrapper!.setProps({ modelValue: v }) },
|
|
18
|
+
attachTo: document.body,
|
|
19
|
+
})
|
|
20
|
+
const field = wrapper.find('[role="slider"]')
|
|
21
|
+
expect(field.attributes('aria-valuetext')).toBe('00')
|
|
22
|
+
await field.trigger('keydown', { key: 'ArrowUp' })
|
|
23
|
+
await wait()
|
|
24
|
+
expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual([59])
|
|
25
|
+
expect(field.attributes('aria-valuetext')).toBe('59')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('follows an outside change the short way around', async () => {
|
|
29
|
+
wrapper = mount(MScrollField, { props: { modelValue: 58, count: 60 }, attachTo: document.body })
|
|
30
|
+
await wrapper.setProps({ modelValue: 1 })
|
|
31
|
+
await wait()
|
|
32
|
+
// 58 → 59 → 0 → 1, never back through 57…2
|
|
33
|
+
const seen = wrapper.emitted<[number]>('update:modelValue')!.map((e) => e[0])
|
|
34
|
+
expect(seen).toEqual([59, 0, 1])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('uses a custom format', () => {
|
|
38
|
+
wrapper = mount(MScrollField, { props: { modelValue: 1, count: 2, format: (i: number) => ['L', 'oz'][i]! } })
|
|
39
|
+
expect(wrapper.find('[role="slider"]').attributes('aria-valuetext')).toBe('oz')
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { h } from 'vue'
|
|
4
|
+
import MScrollable from '../components/MScrollable.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrapper?.unmount()
|
|
9
|
+
wrapper = undefined
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
describe('MScrollable indicator', () => {
|
|
15
|
+
it('hides the native scrollbar and sizes the thumb to the visible fraction', async () => {
|
|
16
|
+
wrapper = mount(MScrollable, {
|
|
17
|
+
props: { scrollbar: 'indicator', scrollbarFade: false },
|
|
18
|
+
slots: { default: () => h('div', 'Long content') },
|
|
19
|
+
attachTo: document.body,
|
|
20
|
+
})
|
|
21
|
+
const el = wrapper.element as HTMLElement
|
|
22
|
+
expect(el.className).toContain('m3-scrollable-hidden')
|
|
23
|
+
Object.defineProperty(el, 'clientHeight', { value: 200, configurable: true })
|
|
24
|
+
Object.defineProperty(el, 'scrollHeight', { value: 800, configurable: true })
|
|
25
|
+
el.scrollTop = 300
|
|
26
|
+
el.dispatchEvent(new Event('scroll'))
|
|
27
|
+
const thumb = wrapper.find('.m3-scrollable-thumb-v').element as HTMLElement
|
|
28
|
+
// Track 196px (2px inset at each end), thumb 196 × 200/800 = 49px, offset 2 + 300/600 × (196 − 49)
|
|
29
|
+
expect(thumb.style.height).toBe('49px')
|
|
30
|
+
expect(thumb.style.transform).toBe('translate(0px, 375.5px)')
|
|
31
|
+
expect(thumb.style.opacity).toBe('1')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('draws nothing when the content fits', async () => {
|
|
35
|
+
wrapper = mount(MScrollable, { props: { scrollbar: 'indicator' }, slots: { default: () => h('div', 'Short') } })
|
|
36
|
+
const el = wrapper.element as HTMLElement
|
|
37
|
+
Object.defineProperty(el, 'clientHeight', { value: 200, configurable: true })
|
|
38
|
+
Object.defineProperty(el, 'scrollHeight', { value: 200, configurable: true })
|
|
39
|
+
el.dispatchEvent(new Event('scroll'))
|
|
40
|
+
expect((wrapper.find('.m3-scrollable-thumb-v').element as HTMLElement).style.display).toBe('none')
|
|
41
|
+
})
|
|
42
|
+
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
4
|
+
import MSwipeToDismiss from '../components/MSwipeToDismiss.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrapper?.unmount()
|
|
9
|
+
wrapper = undefined
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const wait = (ms = 600) => new Promise((r) => setTimeout(r, ms))
|
|
14
|
+
|
|
15
|
+
describe('MSwipeToDismiss', () => {
|
|
16
|
+
function setup(props: Record<string, unknown> = {}) {
|
|
17
|
+
wrapper = mount(MSwipeToDismiss, {
|
|
18
|
+
props,
|
|
19
|
+
slots: { default: () => h('div', 'Row'), background: ({ target }: { target: string }) => h('span', { class: 'bg' }, target) },
|
|
20
|
+
attachTo: document.body,
|
|
21
|
+
})
|
|
22
|
+
Object.defineProperty(wrapper.element, 'offsetWidth', { value: 300, configurable: true })
|
|
23
|
+
return wrapper
|
|
24
|
+
}
|
|
25
|
+
function drag(el: Element, dx: number, durationMs: number) {
|
|
26
|
+
el.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 10, button: 0, pointerId: 1, bubbles: true }))
|
|
27
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 100 + dx / 2, clientY: 10, pointerId: 1, timeStamp: 0 } as PointerEventInit))
|
|
28
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 100 + dx, clientY: 10, pointerId: 1 }))
|
|
29
|
+
return new Promise<void>((r) => setTimeout(() => {
|
|
30
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 100 + dx, clientY: 10, pointerId: 1 }))
|
|
31
|
+
r()
|
|
32
|
+
}, durationMs))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Slowly (under the 125px/s fling velocity) and still moving when released, so the 56px threshold decides
|
|
36
|
+
async function slowDrag(el: Element, dx: number) {
|
|
37
|
+
el.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 10, button: 0, pointerId: 1, bubbles: true }))
|
|
38
|
+
const steps = 10
|
|
39
|
+
for (let i = 1; i <= steps; i++) {
|
|
40
|
+
await wait(60)
|
|
41
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 100 + (dx * i) / steps, clientY: 10, pointerId: 1 }))
|
|
42
|
+
}
|
|
43
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 100 + dx, clientY: 10, pointerId: 1 }))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
it('dismisses past the 56px threshold', async () => {
|
|
47
|
+
const w = setup()
|
|
48
|
+
await slowDrag(w.element, -80)
|
|
49
|
+
await nextTick()
|
|
50
|
+
expect(w.find('.bg').text()).toBe('end-to-start')
|
|
51
|
+
await wait(400)
|
|
52
|
+
expect(w.emitted('dismiss')?.[0]).toEqual(['end-to-start'])
|
|
53
|
+
expect(w.emitted('update:modelValue')?.[0]).toEqual(['end-to-start'])
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('springs back from a short swipe', async () => {
|
|
57
|
+
const w = setup()
|
|
58
|
+
await slowDrag(w.element, 30)
|
|
59
|
+
await wait(400)
|
|
60
|
+
expect(w.emitted('dismiss')).toBeUndefined()
|
|
61
|
+
expect((w.element.lastElementChild as HTMLElement).style.transform).toBe('')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('a quick flick dismisses even a short swipe', async () => {
|
|
65
|
+
const w = setup()
|
|
66
|
+
await drag(w.element, 30, 10)
|
|
67
|
+
await wait(400)
|
|
68
|
+
expect(w.emitted('dismiss')?.[0]).toEqual(['start-to-end'])
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('only swipes in the allowed directions', async () => {
|
|
72
|
+
const w = setup({ endToStart: false })
|
|
73
|
+
await drag(w.element, -120, 300)
|
|
74
|
+
await wait(400)
|
|
75
|
+
expect(w.emitted('dismiss')).toBeUndefined()
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('slides back when v-model is reset from inside @dismiss', async () => {
|
|
79
|
+
const state = ref<'settled' | 'start-to-end' | 'end-to-start'>('settled')
|
|
80
|
+
wrapper = mount(defineComponent({
|
|
81
|
+
setup: () => () => h(MSwipeToDismiss, {
|
|
82
|
+
modelValue: state.value,
|
|
83
|
+
'onUpdate:modelValue': (v: typeof state.value) => { state.value = v },
|
|
84
|
+
onDismiss: () => { state.value = 'settled' },
|
|
85
|
+
}, () => h('div', 'Row')),
|
|
86
|
+
}), { attachTo: document.body })
|
|
87
|
+
const root = wrapper.find('.touch-pan-y').element
|
|
88
|
+
Object.defineProperty(root, 'offsetWidth', { value: 300, configurable: true })
|
|
89
|
+
await drag(root, 30, 10)
|
|
90
|
+
await wait(800)
|
|
91
|
+
expect(state.value).toBe('settled')
|
|
92
|
+
expect((root.lastElementChild as HTMLElement).style.transform).toBe('')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('animates back when v-model is reset', async () => {
|
|
96
|
+
const w = setup()
|
|
97
|
+
await w.setProps({ modelValue: 'start-to-end' })
|
|
98
|
+
await wait(400)
|
|
99
|
+
expect((w.element.lastElementChild as HTMLElement).style.transform).toBe('translateX(300px)')
|
|
100
|
+
await w.setProps({ modelValue: 'settled' })
|
|
101
|
+
await wait(400)
|
|
102
|
+
expect((w.element.lastElementChild as HTMLElement).style.transform).toBe('')
|
|
103
|
+
})
|
|
104
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
4
|
+
import MTransition from '../components/MTransition.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrapper?.unmount()
|
|
9
|
+
wrapper = undefined
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const wait = (ms = 600) => new Promise((r) => setTimeout(r, ms))
|
|
14
|
+
|
|
15
|
+
describe('MTransition', () => {
|
|
16
|
+
it('overlaps both views while animating, then removes the old one', async () => {
|
|
17
|
+
const page = ref('a')
|
|
18
|
+
wrapper = mount(defineComponent({
|
|
19
|
+
setup: () => () => h(MTransition, { type: 'fade-through' }, () => h('div', { key: page.value, class: 'page' }, page.value)),
|
|
20
|
+
}), { attachTo: document.body, global: { stubs: { transition: false } } })
|
|
21
|
+
page.value = 'b'
|
|
22
|
+
await nextTick()
|
|
23
|
+
expect(wrapper.findAll('.page').map((p) => p.text())).toEqual(['a', 'b'])
|
|
24
|
+
await wait(800)
|
|
25
|
+
expect(wrapper.findAll('.page').map((p) => p.text())).toEqual(['b'])
|
|
26
|
+
})
|
|
27
|
+
})
|