@m3ui-vue/m3ui-vue 1.2.2 → 1.3.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/dist/API.md +2776 -351
- package/dist/MButton-CuNzpoxm.js +172 -0
- package/dist/MButton-CuNzpoxm.js.map +1 -0
- package/dist/MDialog-HxEL-m58.js +173 -0
- package/dist/MDialog-HxEL-m58.js.map +1 -0
- package/dist/MIconButton-DoNotQ9v.js +282 -0
- package/dist/MIconButton-DoNotQ9v.js.map +1 -0
- package/dist/MListItem-DnPtv-hY.js +824 -0
- package/dist/MListItem-DnPtv-hY.js.map +1 -0
- package/dist/MLoadingIndicator-BQMNX6Dx.js +115 -0
- package/dist/MLoadingIndicator-BQMNX6Dx.js.map +1 -0
- package/dist/MMenuItem-Bih0h4-n.js +604 -0
- package/dist/MMenuItem-Bih0h4-n.js.map +1 -0
- package/dist/MProgressBar-BCoruxA-.js +184 -0
- package/dist/MProgressBar-BCoruxA-.js.map +1 -0
- package/dist/MSeekBar-LURE1Ah7.js +435 -0
- package/dist/MSeekBar-LURE1Ah7.js.map +1 -0
- package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
- package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
- package/dist/MSlider-_J4IS2_z.js +691 -0
- package/dist/MSlider-_J4IS2_z.js.map +1 -0
- package/dist/MSpinner-BhkMYKOM.js +65 -0
- package/dist/MSpinner-BhkMYKOM.js.map +1 -0
- package/dist/MTextField-CkzwNBWS.js +296 -0
- package/dist/MTextField-CkzwNBWS.js.map +1 -0
- package/dist/MTooltip-B67ZDSGp.js +756 -0
- package/dist/MTooltip-B67ZDSGp.js.map +1 -0
- package/dist/_storageKeys-CYXsUBwK.js +18 -0
- package/dist/_storageKeys-CYXsUBwK.js.map +1 -0
- package/dist/_useEscapeStack-CjndQhqg.js +19 -0
- package/dist/_useEscapeStack-CjndQhqg.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAudioPlayer.vue.d.ts +115 -0
- package/dist/components/MBadge.vue.d.ts +1 -1
- package/dist/components/MBottomSheetScaffold.vue.d.ts +1 -1
- package/dist/components/MBox.vue.d.ts +1 -1
- package/dist/components/MButton.vue.d.ts +1 -1
- package/dist/components/MConfirmDialog.vue.d.ts +1 -1
- package/dist/components/MCopyButton.vue.d.ts +2 -2
- package/dist/components/MDataTable.vue.d.ts +2 -2
- package/dist/components/MDialog.vue.d.ts +2 -2
- package/dist/components/MDivider.vue.d.ts +1 -1
- package/dist/components/MDragHandle.vue.d.ts +1 -1
- package/dist/components/MDrawCanvas.vue.d.ts +148 -0
- package/dist/components/MDrawLayers.vue.d.ts +3 -0
- package/dist/components/MDrawToolbar.vue.d.ts +34 -0
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +2 -2
- package/dist/components/MFixed.vue.d.ts +1 -1
- package/dist/components/MFlex.vue.d.ts +2 -2
- package/dist/components/MFloorPlan.vue.d.ts +160 -0
- package/dist/components/MFlow.vue.d.ts +305 -0
- package/dist/components/MFlowControls.vue.d.ts +33 -0
- package/dist/components/MFlowHandle.vue.d.ts +16 -0
- package/dist/components/MFlowMinimap.vue.d.ts +22 -0
- package/dist/components/MFlowNode.vue.d.ts +35 -0
- package/dist/components/MGantt.vue.d.ts +141 -0
- package/dist/components/MGanttControls.vue.d.ts +32 -0
- package/dist/components/MIconButton.vue.d.ts +3 -1
- package/dist/components/MImageCropper.vue.d.ts +110 -0
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MLightbox.vue.d.ts +2 -2
- package/dist/components/MList.vue.d.ts +1 -1
- package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
- package/dist/components/MMapControl.vue.d.ts +1 -1
- package/dist/components/MMapSearch.vue.d.ts +1 -1
- package/dist/components/MMaskField.vue.d.ts +12 -1
- package/dist/components/MMenu.vue.d.ts +1 -1
- package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
- package/dist/components/MNumberField.vue.d.ts +11 -2
- package/dist/components/MPdfViewer.vue.d.ts +174 -0
- package/dist/components/MPullToRefresh.vue.d.ts +1 -1
- package/dist/components/MResourceTimeline.vue.d.ts +149 -0
- package/dist/components/MScheduler.vue.d.ts +3 -3
- package/dist/components/MScheme.vue.d.ts +1 -1
- package/dist/components/MSearchField.vue.d.ts +1 -1
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
- package/dist/components/MSkeleton.vue.d.ts +1 -1
- package/dist/components/MSlider.vue.d.ts +2 -2
- package/dist/components/MSparkline.vue.d.ts +1 -1
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTagInput.vue.d.ts +12 -1
- package/dist/components/MTextField.vue.d.ts +13 -2
- package/dist/components/MToolbar.vue.d.ts +1 -1
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/MVideoPlayer.vue.d.ts +253 -0
- package/dist/components/MVirtualTable.vue.d.ts +1 -1
- package/dist/components/MWindow.vue.d.ts +3 -3
- package/dist/components/_MFlowEdge.vue.d.ts +9 -0
- package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
- package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
- package/dist/components/_MPdfPage.vue.d.ts +76 -0
- package/dist/components/_MTimeBackground.vue.d.ts +14 -0
- package/dist/components/_MTimeHeader.vue.d.ts +20 -0
- package/dist/composables/_flowPanel.d.ts +2 -0
- package/dist/composables/_flowSlot.d.ts +5 -0
- package/dist/composables/_ganttTime.d.ts +41 -0
- package/dist/composables/_useTimeAxis.d.ts +90 -0
- package/dist/composables/drawGeometry.d.ts +119 -0
- package/dist/composables/flowFormats.d.ts +79 -0
- package/dist/composables/flowLayout.d.ts +45 -0
- package/dist/composables/flowPaths.d.ts +53 -0
- package/dist/composables/ganttFormats.d.ts +52 -0
- package/dist/composables/ganttSchedule.d.ts +99 -0
- package/dist/composables/useDrawing.d.ts +44 -0
- package/dist/composables/useFlow.d.ts +266 -0
- package/dist/composables/useGantt.d.ts +87 -0
- package/dist/composables/useLocale.d.ts +163 -0
- package/dist/composables/useMediaPlayer.d.ts +101 -0
- package/dist/composables/usePdf.d.ts +119 -0
- package/dist/composables/useResourceTimeline.d.ts +70 -0
- package/dist/draw.d.ts +7 -0
- package/dist/draw.js +1700 -0
- package/dist/draw.js.map +1 -0
- package/dist/flow.d.ts +14 -0
- package/dist/flow.js +3542 -0
- package/dist/flow.js.map +1 -0
- package/dist/flowPaths-CUc6X373.js +161 -0
- package/dist/flowPaths-CUc6X373.js.map +1 -0
- package/dist/gantt.d.ts +12 -0
- package/dist/gantt.js +3575 -0
- package/dist/gantt.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/locales/index.js +1148 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7286 -7654
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +113 -108
- package/dist/map.js.map +1 -1
- package/dist/media.d.ts +5 -0
- package/dist/media.js +1311 -0
- package/dist/media.js.map +1 -0
- package/dist/pdf.d.ts +4 -0
- package/dist/pdf.js +1871 -0
- package/dist/pdf.js.map +1 -0
- package/dist/rich-text-editor.js +28 -26
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/{useLocale-JYxDDeXC.js → useLocale-BpGxplLV.js} +165 -2
- package/dist/useLocale-BpGxplLV.js.map +1 -0
- package/dist/{useThemeTokens-y0HZpyhL.js → useThemeTokens-DQQcaWbE.js} +40 -54
- package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
- package/package.json +29 -5
- package/src/__tests__/MAudioPlayer.test.ts +75 -0
- package/src/__tests__/MDrawCanvas.test.ts +110 -0
- package/src/__tests__/MFloorPlan.test.ts +97 -0
- package/src/__tests__/MFlow.test.ts +575 -0
- package/src/__tests__/MGantt.test.ts +130 -0
- package/src/__tests__/MImageCropper.test.ts +89 -0
- package/src/__tests__/MPdfViewer.test.ts +235 -0
- package/src/__tests__/MResourceTimeline.test.ts +102 -0
- package/src/__tests__/MVideoPlayer.test.ts +201 -0
- package/src/__tests__/drawGeometry.test.ts +58 -0
- package/src/__tests__/fieldExpose.test.ts +30 -0
- package/src/__tests__/flowFormats.test.ts +185 -0
- package/src/__tests__/flowLayout.test.ts +113 -0
- package/src/__tests__/ganttFormats.test.ts +76 -0
- package/src/__tests__/ganttSchedule.test.ts +136 -0
- package/src/__tests__/pdfMock.ts +83 -0
- package/src/__tests__/useMediaPlayer.test.ts +182 -0
- package/src/__tests__/usePdf.test.ts +102 -0
- package/src/components/MAudioPlayer.vue +319 -0
- package/src/components/MDrawCanvas.vue +813 -0
- package/src/components/MDrawLayers.vue +114 -0
- package/src/components/MDrawToolbar.vue +171 -0
- package/src/components/MFloorPlan.vue +581 -0
- package/src/components/MFlow.vue +2049 -0
- package/src/components/MFlowControls.vue +110 -0
- package/src/components/MFlowHandle.vue +60 -0
- package/src/components/MFlowMinimap.vue +134 -0
- package/src/components/MFlowNode.vue +98 -0
- package/src/components/MGantt.vue +1609 -0
- package/src/components/MGanttControls.vue +77 -0
- package/src/components/MIconButton.vue +3 -1
- package/src/components/MImageCropper.vue +507 -0
- package/src/components/MMaskField.vue +13 -0
- package/src/components/MNumberField.vue +13 -0
- package/src/components/MPdfViewer.vue +1269 -0
- package/src/components/MResourceTimeline.vue +1020 -0
- package/src/components/MTagInput.vue +13 -0
- package/src/components/MTextField.vue +16 -0
- package/src/components/MVideoPlayer.vue +839 -0
- package/src/components/_MFlowEdge.vue +100 -0
- package/src/components/_MFlowEdgeLabel.vue +56 -0
- package/src/components/_MFlowNodeShell.vue +111 -0
- package/src/components/_MPdfPage.vue +456 -0
- package/src/components/_MTimeBackground.vue +16 -0
- package/src/components/_MTimeHeader.vue +31 -0
- package/src/composables/_flowPanel.ts +13 -0
- package/src/composables/_flowSlot.ts +6 -0
- package/src/composables/_ganttTime.ts +200 -0
- package/src/composables/_useTimeAxis.ts +224 -0
- package/src/composables/drawGeometry.ts +405 -0
- package/src/composables/flowFormats.ts +916 -0
- package/src/composables/flowLayout.ts +297 -0
- package/src/composables/flowPaths.ts +239 -0
- package/src/composables/ganttFormats.ts +366 -0
- package/src/composables/ganttSchedule.ts +403 -0
- package/src/composables/useDrawing.ts +53 -0
- package/src/composables/useFlow.ts +250 -0
- package/src/composables/useGantt.ts +92 -0
- package/src/composables/useLocale.ts +328 -0
- package/src/composables/useMediaPlayer.ts +406 -0
- package/src/composables/usePdf.ts +456 -0
- package/src/composables/useResourceTimeline.ts +76 -0
- package/src/draw.ts +25 -0
- package/src/flow.ts +26 -0
- package/src/gantt.ts +12 -0
- package/src/index.ts +4 -0
- package/src/locales/de.ts +163 -0
- package/src/locales/es.ts +163 -0
- package/src/locales/fr.ts +163 -0
- package/src/locales/ja.ts +163 -0
- package/src/locales/ko.ts +163 -0
- package/src/locales/pt.ts +163 -0
- package/src/locales/zh.ts +163 -0
- package/src/media.ts +5 -0
- package/src/pdf.ts +15 -0
- package/dist/MMenuItem-D4Gx_l3F.js +0 -929
- package/dist/MMenuItem-D4Gx_l3F.js.map +0 -1
- package/dist/MSlider-Dx_S3vJ9.js +0 -1506
- package/dist/MSlider-Dx_S3vJ9.js.map +0 -1
- package/dist/MTextField-Bz8JIsnl.js +0 -633
- package/dist/MTextField-Bz8JIsnl.js.map +0 -1
- package/dist/useLocale-JYxDDeXC.js.map +0 -1
- package/dist/useThemeTokens-y0HZpyhL.js.map +0 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
import { mount, flushPromises } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MGantt from '../components/MGantt.vue'
|
|
5
|
+
import type { GanttTask } from '../composables/ganttSchedule'
|
|
6
|
+
|
|
7
|
+
// A 1200 × 600 chart at 40 px per day, the list 320 wide
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(1200)
|
|
10
|
+
vi.spyOn(HTMLElement.prototype, 'clientHeight', 'get').mockReturnValue(600)
|
|
11
|
+
vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(() => ({ left: 0, top: 0, right: 1200, bottom: 600, width: 1200, height: 600, x: 0, y: 0, toJSON() {} }) as DOMRect)
|
|
12
|
+
})
|
|
13
|
+
afterEach(() => vi.restoreAllMocks())
|
|
14
|
+
|
|
15
|
+
const tasks = (): GanttTask[] => [
|
|
16
|
+
{ id: 'p', name: 'Phase', start: '2026-03-02', end: '2026-03-06' },
|
|
17
|
+
{ id: 'a', name: 'Design', start: '2026-03-02', end: '2026-03-04', parentId: 'p', progress: 50 },
|
|
18
|
+
{ id: 'b', name: 'Build', start: '2026-03-05', end: '2026-03-06', parentId: 'p', dependencies: ['a'] },
|
|
19
|
+
{ id: 'm', name: 'Ship', start: '2026-03-09', type: 'milestone', dependencies: ['b'] },
|
|
20
|
+
]
|
|
21
|
+
async function gantt(props: Record<string, unknown> = {}) {
|
|
22
|
+
const w = mount(MGantt, { props: { tasks: tasks(), today: null, ...props }, attachTo: document.body })
|
|
23
|
+
await flushPromises()
|
|
24
|
+
await nextTick()
|
|
25
|
+
return w
|
|
26
|
+
}
|
|
27
|
+
function pointer(el: EventTarget, type: string, x: number, y = 100, extra: Record<string, unknown> = {}) {
|
|
28
|
+
el.dispatchEvent(new PointerEvent(type, { bubbles: true, cancelable: true, clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', button: 0, buttons: 1, ...extra }))
|
|
29
|
+
}
|
|
30
|
+
const last = (w: ReturnType<typeof mount>) => {
|
|
31
|
+
const e = w.emitted('update:tasks')
|
|
32
|
+
return Object.fromEntries((e!.at(-1)![0] as GanttTask[]).map((t) => [t.id, t]))
|
|
33
|
+
}
|
|
34
|
+
const bar = (w: ReturnType<typeof mount>, id: string) => w.find(`[data-gantt-task="${id}"]`).element
|
|
35
|
+
|
|
36
|
+
describe('MGantt', () => {
|
|
37
|
+
it('lists tasks as a tree, rolls summaries up and draws bars, a milestone and dependencies', async () => {
|
|
38
|
+
const w = await gantt()
|
|
39
|
+
const rows = w.findAll('[role="row"][data-gantt-row]')
|
|
40
|
+
expect(rows.map((r) => r.attributes('data-gantt-row'))).toEqual(['p', 'a', 'b', 'm'])
|
|
41
|
+
expect(rows[1]!.attributes('aria-level')).toBe('2')
|
|
42
|
+
expect(w.findAll('[data-gantt-task]')).toHaveLength(4)
|
|
43
|
+
expect(w.find('.m3-gantt-summary').exists()).toBe(true)
|
|
44
|
+
expect(w.findAll('.m3-gantt-link')).toHaveLength(2)
|
|
45
|
+
// The summary's dates come from its tasks
|
|
46
|
+
expect(rows[0]!.text()).toContain('5 d')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('drags a bar by whole days, its summary following', async () => {
|
|
50
|
+
const w = await gantt()
|
|
51
|
+
pointer(bar(w, 'a'), 'pointerdown', 500)
|
|
52
|
+
pointer(window, 'pointermove', 520)
|
|
53
|
+
pointer(window, 'pointermove', 585)
|
|
54
|
+
pointer(window, 'pointerup', 585)
|
|
55
|
+
const t = last(w)
|
|
56
|
+
expect(t.a).toMatchObject({ start: '2026-03-04', end: '2026-03-06' })
|
|
57
|
+
expect(t.p).toMatchObject({ start: '2026-03-04', end: '2026-03-06' })
|
|
58
|
+
expect(w.emitted('change')!.at(-1)![0]).toMatchObject({ kind: 'move' })
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('resizes from an end, sets progress, and with schedule="auto" pushes the tasks that depend on it', async () => {
|
|
62
|
+
const w = await gantt({ schedule: 'auto' })
|
|
63
|
+
const handle = bar(w, 'a').parentElement!.querySelector('[data-gantt-resize="end"]')!
|
|
64
|
+
pointer(handle, 'pointerdown', 500)
|
|
65
|
+
pointer(window, 'pointermove', 510)
|
|
66
|
+
pointer(window, 'pointermove', 580)
|
|
67
|
+
pointer(window, 'pointerup', 580)
|
|
68
|
+
const t = last(w)
|
|
69
|
+
expect(t.a).toMatchObject({ start: '2026-03-02', end: '2026-03-06' })
|
|
70
|
+
// b waited on a: it moves past a's new end, and the milestone after it
|
|
71
|
+
expect(t.b).toMatchObject({ start: '2026-03-07', end: '2026-03-08' })
|
|
72
|
+
expect(t.m!.start).toBe('2026-03-09')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('draws a dependency from one bar end to another', async () => {
|
|
76
|
+
const w = await gantt({ tasks: [{ id: 'x', name: 'X', start: '2026-03-02', end: '2026-03-03' }, { id: 'y', name: 'Y', start: '2026-03-05', end: '2026-03-06' }] })
|
|
77
|
+
const dot = w.find('.cursor-crosshair:last-of-type').element
|
|
78
|
+
document.elementFromPoint = () => bar(w, 'y')
|
|
79
|
+
pointer(dot, 'pointerdown', 400)
|
|
80
|
+
pointer(window, 'pointermove', 450)
|
|
81
|
+
pointer(window, 'pointermove', 600)
|
|
82
|
+
pointer(window, 'pointerup', 600)
|
|
83
|
+
expect(w.emitted('link')![0]![0]).toMatchObject({ from: 'x', to: 'y' })
|
|
84
|
+
expect(last(w).y!.dependencies).toHaveLength(1)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('reorders rows and indents with the keyboard; undo and redo', async () => {
|
|
88
|
+
const w = await gantt()
|
|
89
|
+
const row = w.find('[data-gantt-row="b"]')
|
|
90
|
+
await row.trigger('keydown', { key: 'ArrowUp', altKey: true })
|
|
91
|
+
expect(Object.keys(last(w))).toEqual(['p', 'b', 'a', 'm'])
|
|
92
|
+
await w.setProps({ tasks: w.emitted('update:tasks')!.at(-1)![0] })
|
|
93
|
+
await w.find('[data-gantt-row="m"]').trigger('keydown', { key: ']', ctrlKey: true })
|
|
94
|
+
expect(last(w).m!.parentId).toBe('p')
|
|
95
|
+
await w.find('[data-gantt-row="a"]').trigger('keydown', { key: 'ArrowRight', altKey: true })
|
|
96
|
+
expect(last(w).a).toMatchObject({ start: '2026-03-03', end: '2026-03-05' })
|
|
97
|
+
const before = w.emitted('update:tasks')!.length
|
|
98
|
+
await w.find('[data-gantt-row="a"]').trigger('keydown', { key: 'z', ctrlKey: true })
|
|
99
|
+
expect(w.emitted('update:tasks')!.length).toBe(before + 1)
|
|
100
|
+
expect(last(w).a!.start).toBe('2026-03-02')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('folds a summary, keeping its links drawn from it', async () => {
|
|
104
|
+
const w = await gantt({ tasks: [...tasks(), { id: 'z', name: 'After', start: '2026-03-10', end: '2026-03-11', dependencies: ['a'] }] })
|
|
105
|
+
await w.find('[aria-label="Collapse"]').trigger('click')
|
|
106
|
+
expect(w.emitted('update:collapsed')![0]![0]).toEqual(['p'])
|
|
107
|
+
expect(w.findAll('[data-gantt-row]').map((r) => r.attributes('data-gantt-row'))).toEqual(['p', 'm', 'z'])
|
|
108
|
+
// a → z now runs from the folded phase
|
|
109
|
+
expect(w.findAll('.m3-gantt-link').length).toBeGreaterThan(0)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('marks the critical path', async () => {
|
|
113
|
+
const w = await gantt({ criticalPath: true, tasks: [
|
|
114
|
+
{ id: 'a', name: 'A', start: '2026-03-02', end: '2026-03-03' },
|
|
115
|
+
{ id: 'b', name: 'B', start: '2026-03-04', end: '2026-03-09', dependencies: ['a'] },
|
|
116
|
+
{ id: 'c', name: 'C', start: '2026-03-04', end: '2026-03-04', dependencies: ['a'] },
|
|
117
|
+
] })
|
|
118
|
+
expect(bar(w, 'b').className).toContain('bg-error-container')
|
|
119
|
+
expect(bar(w, 'c').className).not.toContain('bg-error-container')
|
|
120
|
+
expect(w.findAll('.m3-gantt-link.text-error')).toHaveLength(1)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('readonly: no drag', async () => {
|
|
124
|
+
const w = await gantt({ readonly: true })
|
|
125
|
+
pointer(bar(w, 'a'), 'pointerdown', 500)
|
|
126
|
+
pointer(window, 'pointermove', 600)
|
|
127
|
+
pointer(window, 'pointerup', 600)
|
|
128
|
+
expect(w.emitted('update:tasks')).toBeUndefined()
|
|
129
|
+
})
|
|
130
|
+
})
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
import { mount, flushPromises } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MImageCropper from '../components/MImageCropper.vue'
|
|
5
|
+
import type { CropRect } from '../components/MImageCropper.vue'
|
|
6
|
+
|
|
7
|
+
// A 448 × 348 stage (400 × 300 inside the padding) and an 800 × 600 picture: half scale
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(448)
|
|
10
|
+
vi.spyOn(HTMLElement.prototype, 'clientHeight', 'get').mockReturnValue(348)
|
|
11
|
+
})
|
|
12
|
+
afterEach(() => vi.restoreAllMocks())
|
|
13
|
+
|
|
14
|
+
async function cropper(props: Record<string, unknown> = {}) {
|
|
15
|
+
const w = mount(MImageCropper, { props: { src: 'photo.jpg', ...props }, attachTo: document.body })
|
|
16
|
+
await nextTick()
|
|
17
|
+
const img = w.find('img').element as HTMLImageElement
|
|
18
|
+
Object.defineProperty(img, 'naturalWidth', { value: 800 })
|
|
19
|
+
Object.defineProperty(img, 'naturalHeight', { value: 600 })
|
|
20
|
+
await w.find('img').trigger('load')
|
|
21
|
+
await flushPromises()
|
|
22
|
+
return w
|
|
23
|
+
}
|
|
24
|
+
const last = (w: ReturnType<typeof mount>) => w.emitted('update:crop')!.at(-1)![0] as CropRect
|
|
25
|
+
function pointer(el: Element, type: string, x: number, y: number) {
|
|
26
|
+
el.dispatchEvent(new PointerEvent(type, { bubbles: true, cancelable: true, clientX: x, clientY: y, pointerId: 1, button: 0 }))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('MImageCropper', () => {
|
|
30
|
+
it('starts with the whole picture, or the largest frame of the aspect, centered', async () => {
|
|
31
|
+
expect(last(await cropper())).toEqual({ x: 0, y: 0, width: 800, height: 600 })
|
|
32
|
+
expect(last(await cropper({ aspect: 1 }))).toEqual({ x: 100, y: 0, width: 600, height: 600 })
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('moves the frame, kept inside the picture', async () => {
|
|
36
|
+
const w = await cropper({ aspect: 1 })
|
|
37
|
+
const frame = w.find('[role="slider"]').element
|
|
38
|
+
pointer(frame, 'pointerdown', 200, 150)
|
|
39
|
+
// 100 px on screen = 200 px of picture, but only 100 are left to the right
|
|
40
|
+
pointer(frame, 'pointermove', 300, 150)
|
|
41
|
+
pointer(frame, 'pointerup', 300, 150)
|
|
42
|
+
expect(last(w)).toEqual({ x: 200, y: 0, width: 600, height: 600 })
|
|
43
|
+
expect(w.emitted('change')!.at(-1)![0]).toEqual({ x: 200, y: 0, width: 600, height: 600 })
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('resizes from a corner keeping the aspect, the opposite corner fixed', async () => {
|
|
47
|
+
const w = await cropper({ aspect: 1 })
|
|
48
|
+
const se = w.findAll('[role="slider"] > div').find((d) => d.classes().includes('cursor-nwse-resize') && d.classes().includes('top-full'))!.element
|
|
49
|
+
pointer(se, 'pointerdown', 0, 0)
|
|
50
|
+
pointer(se, 'pointermove', -100, -40)
|
|
51
|
+
pointer(se, 'pointerup', -100, -40)
|
|
52
|
+
// The bigger pull (width, -200) decides: 400 × 400 from the top left corner
|
|
53
|
+
expect(last(w)).toEqual({ x: 100, y: 0, width: 400, height: 400 })
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('free frames resize each side on its own; arrows move, Shift + arrows resize', async () => {
|
|
57
|
+
const w = await cropper()
|
|
58
|
+
const frame = w.find('[role="slider"]')
|
|
59
|
+
const e = w.findAll('[role="slider"] > div').find((d) => d.classes().includes('cursor-ew-resize') && d.classes().includes('left-full'))!.element
|
|
60
|
+
pointer(e, 'pointerdown', 0, 0)
|
|
61
|
+
pointer(e, 'pointermove', -50, 30)
|
|
62
|
+
pointer(e, 'pointerup', -50, 30)
|
|
63
|
+
expect(last(w)).toEqual({ x: 0, y: 0, width: 700, height: 600 })
|
|
64
|
+
await frame.trigger('keydown', { key: 'ArrowRight', altKey: true })
|
|
65
|
+
expect(last(w)).toEqual({ x: 20, y: 0, width: 700, height: 600 })
|
|
66
|
+
await frame.trigger('keydown', { key: 'ArrowDown', shiftKey: true, altKey: true })
|
|
67
|
+
// Already full height
|
|
68
|
+
expect(last(w).height).toBe(600)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('turns and mirrors the frame with the picture', async () => {
|
|
72
|
+
const w = await cropper({ crop: { x: 100, y: 50, width: 200, height: 100 } })
|
|
73
|
+
const vm = w.vm as unknown as { rotate(d: 1 | -1): void; flip(): void; setAspect(a: number | null): void; reset(): void }
|
|
74
|
+
vm.rotate(1)
|
|
75
|
+
// 600 × 800 now: the top left corner goes top right
|
|
76
|
+
expect(w.emitted('update:rotation')!.at(-1)![0]).toBe(90)
|
|
77
|
+
expect(last(w)).toEqual({ x: 450, y: 100, width: 100, height: 200 })
|
|
78
|
+
vm.flip()
|
|
79
|
+
// Mirrored as seen: the turn's direction flips with it
|
|
80
|
+
expect(w.emitted('update:flipped')!.at(-1)![0]).toBe(true)
|
|
81
|
+
expect(w.emitted('update:rotation')!.at(-1)![0]).toBe(270)
|
|
82
|
+
expect(last(w)).toEqual({ x: 50, y: 100, width: 100, height: 200 })
|
|
83
|
+
vm.setAspect(1)
|
|
84
|
+
expect(last(w)).toEqual({ x: 0, y: 100, width: 200, height: 200 })
|
|
85
|
+
// Back to no turn and no mirror; the aspect chosen stays
|
|
86
|
+
vm.reset()
|
|
87
|
+
expect(last(w)).toEqual({ x: 100, y: 0, width: 600, height: 600 })
|
|
88
|
+
})
|
|
89
|
+
})
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
import { mount, flushPromises } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import type { PdfAnnotation } from '../components/MPdfViewer.vue'
|
|
5
|
+
|
|
6
|
+
vi.mock('pdfjs-dist', () => import('./pdfMock'))
|
|
7
|
+
const { fakeDoc } = await import('./pdfMock')
|
|
8
|
+
const { default: MPdfViewer, eraseFrom } = await import('../components/MPdfViewer.vue')
|
|
9
|
+
|
|
10
|
+
// happy-dom has no layout: the scroller is 640×480
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(640)
|
|
13
|
+
vi.spyOn(HTMLElement.prototype, 'clientHeight', 'get').mockReturnValue(480)
|
|
14
|
+
fakeDoc.password = ''
|
|
15
|
+
fakeDoc.outline = []
|
|
16
|
+
fakeDoc.pages = Array.from({ length: 4 }, (_, i) => ({ width: 612, height: 792, text: [{ str: `Page ${i + 1} talks about basil` }] }))
|
|
17
|
+
})
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
vi.restoreAllMocks()
|
|
20
|
+
document.body.innerHTML = ''
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
async function settle() {
|
|
24
|
+
for (let i = 0; i < 8; i++) await flushPromises()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function viewer(props: Record<string, unknown> = {}) {
|
|
28
|
+
const w = mount(MPdfViewer, { props: { src: '/doc.pdf', ...props }, attachTo: document.body })
|
|
29
|
+
await settle()
|
|
30
|
+
return w
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const pages = (w: ReturnType<typeof mount>) => w.findAll('.m3-pdf-page')
|
|
34
|
+
const pageBox = (w: ReturnType<typeof mount>, n: number) => pages(w)[n - 1]!.element.parentElement as HTMLElement
|
|
35
|
+
|
|
36
|
+
describe('MPdfViewer', () => {
|
|
37
|
+
it('lays every page out at fit-width, with the title and page count', async () => {
|
|
38
|
+
const w = await viewer()
|
|
39
|
+
expect(pages(w)).toHaveLength(4)
|
|
40
|
+
// (640 - 2 × 16 padding) / 612pt
|
|
41
|
+
const box = pageBox(w, 1)
|
|
42
|
+
expect(box.style.width).toBe('608px')
|
|
43
|
+
expect(box.style.height).toBe(`${Math.floor(792 * (608 / 612))}px`)
|
|
44
|
+
expect(w.text()).toContain('Fake document')
|
|
45
|
+
expect(w.text()).toContain('/ 4')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('a numeric zoom is relative to 100% (96/72 px per point), and the buttons step through it', async () => {
|
|
49
|
+
const w = await viewer({ zoom: 1 })
|
|
50
|
+
expect(pageBox(w, 1).style.width).toBe(`${Math.floor(612 * (96 / 72))}px`)
|
|
51
|
+
expect(w.text()).toContain('100%')
|
|
52
|
+
await w.find('[aria-label="Zoom in"]').trigger('click')
|
|
53
|
+
expect(w.emitted('update:zoom')!.at(-1)).toEqual([1.25])
|
|
54
|
+
await w.find('[aria-label="Zoom out"]').trigger('click')
|
|
55
|
+
expect(w.emitted('update:zoom')!.at(-1)).toEqual([1])
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('v-model:page scrolls to that page', async () => {
|
|
59
|
+
const w = await viewer()
|
|
60
|
+
const scroller = w.find('.m3-pdf-scroller').element as HTMLElement
|
|
61
|
+
const scrollTo = vi.fn()
|
|
62
|
+
scroller.scrollTo = scrollTo as never
|
|
63
|
+
await w.setProps({ page: 3 })
|
|
64
|
+
const top = Number(pageBox(w, 3).style.top.replace('px', ''))
|
|
65
|
+
expect(scrollTo).toHaveBeenCalledWith({ top: top - 16, behavior: 'auto' })
|
|
66
|
+
expect(w.emitted('update:page')!.at(-1)).toEqual([3])
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('search marks the hits in the text layer and counts them', async () => {
|
|
70
|
+
vi.useFakeTimers()
|
|
71
|
+
const w = await viewer()
|
|
72
|
+
await w.find('[aria-label="Find in document"]').trigger('click')
|
|
73
|
+
await w.find('.m3-pdf-search input').setValue('basil')
|
|
74
|
+
vi.advanceTimersByTime(300)
|
|
75
|
+
vi.useRealTimers()
|
|
76
|
+
await settle()
|
|
77
|
+
expect(w.text()).toContain('1 of 4')
|
|
78
|
+
const hits = w.findAll('.m3-pdf-hit')
|
|
79
|
+
expect(hits.length).toBeGreaterThan(0)
|
|
80
|
+
expect(hits[0]!.text()).toBe('basil')
|
|
81
|
+
expect(w.findAll('.m3-pdf-hit-current')).toHaveLength(1)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('the note tool places a note where clicked, in PDF points; undo takes it back', async () => {
|
|
85
|
+
const annotations: PdfAnnotation[] = []
|
|
86
|
+
const w = await viewer({ annotate: true, annotations, author: 'Mara' })
|
|
87
|
+
await w.find('[aria-label="Annotate"]').trigger('click')
|
|
88
|
+
await w.find('[aria-label="Note"]').trigger('click')
|
|
89
|
+
const page = pages(w)[0]!.element as HTMLElement
|
|
90
|
+
page.getBoundingClientRect = () => ({ left: 0, top: 0, width: 608, height: 787, right: 608, bottom: 787, x: 0, y: 0, toJSON: () => ({}) })
|
|
91
|
+
page.dispatchEvent(new MouseEvent('click', { clientX: 304, clientY: 100, bubbles: true }))
|
|
92
|
+
const next = w.emitted('update:annotations')!.at(-1)![0] as PdfAnnotation[]
|
|
93
|
+
expect(next).toHaveLength(1)
|
|
94
|
+
expect(next[0]).toMatchObject({ type: 'note', page: 1, author: 'Mara' })
|
|
95
|
+
// Half the page's width, 100px from the top: y counts up from the bottom
|
|
96
|
+
expect(next[0]!.at![0]).toBeCloseTo(306, 0)
|
|
97
|
+
expect(next[0]!.at![1]).toBeGreaterThan(600)
|
|
98
|
+
await w.setProps({ annotations: next })
|
|
99
|
+
await w.find('[aria-label="Undo"]').trigger('click')
|
|
100
|
+
expect(w.emitted('update:annotations')!.at(-1)![0]).toEqual([])
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('a tap on a highlight, under the text layer, opens it to delete; the pen offers its widths', async () => {
|
|
104
|
+
const annotations: PdfAnnotation[] = [{ id: 'h', type: 'highlight', page: 1, color: '#ff0', rects: [[72, 700, 200, 712]], createdAt: '' }]
|
|
105
|
+
const w = await viewer({ annotate: true, annotations, zoom: 1 })
|
|
106
|
+
const page = pages(w)[0]!
|
|
107
|
+
// The page on screen at its viewport's size: client px = viewBox units
|
|
108
|
+
const [, , vw, vh] = page.find('svg').attributes('viewBox')!.split(' ').map(Number)
|
|
109
|
+
const box = { left: 0, top: 0, width: vw!, height: vh!, right: vw!, bottom: vh!, x: 0, y: 0, toJSON: () => ({}) }
|
|
110
|
+
for (const el of [page.element, ...page.element.querySelectorAll('*')]) (el as HTMLElement).getBoundingClientRect = () => box as DOMRect
|
|
111
|
+
const rect = w.find('.m3-pdf-highlight rect')
|
|
112
|
+
const x = Number(rect.attributes('x')) + 4
|
|
113
|
+
const y = Number(rect.attributes('y')) + 4
|
|
114
|
+
// The text layer's host, over the highlights
|
|
115
|
+
const text = page.find('.overflow-hidden.absolute.inset-0').element
|
|
116
|
+
text.dispatchEvent(new PointerEvent('pointerup', { bubbles: true, clientX: x, clientY: y }))
|
|
117
|
+
await new Promise((r) => setTimeout(r))
|
|
118
|
+
await nextTick()
|
|
119
|
+
await w.find('[aria-label="Delete"]').trigger('click')
|
|
120
|
+
expect(w.emitted('update:annotations')!.at(-1)![0]).toEqual([])
|
|
121
|
+
// The pen: its widths show with it, and the one picked goes into the strokes
|
|
122
|
+
await w.find('[aria-label="Annotate"]').trigger('click')
|
|
123
|
+
await w.find('[aria-label="Draw"]').trigger('click')
|
|
124
|
+
expect(w.findAll('[aria-label^="Line width"]')).toHaveLength(4)
|
|
125
|
+
await w.find('[aria-label="Line width 8 pt"]').trigger('click')
|
|
126
|
+
expect(w.find('[aria-label="Line width 8 pt"]').attributes('aria-pressed')).toBe('true')
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('draws annotations from the model, and the eraser removes them', async () => {
|
|
130
|
+
const annotations: PdfAnnotation[] = [
|
|
131
|
+
{ id: 'h', type: 'highlight', page: 1, color: '#ff0', rects: [[72, 700, 200, 712]], createdAt: '' },
|
|
132
|
+
{ id: 'n', type: 'note', page: 2, color: '#0f0', at: [100, 100], text: 'Hi', createdAt: '' },
|
|
133
|
+
]
|
|
134
|
+
const w = await viewer({ annotate: true, annotations })
|
|
135
|
+
expect(w.findAll('.m3-pdf-highlight rect')).toHaveLength(1)
|
|
136
|
+
expect(w.findAll('.m3-pdf-note')).toHaveLength(1)
|
|
137
|
+
await w.find('[aria-label="Annotate"]').trigger('click')
|
|
138
|
+
await w.find('[aria-label="Eraser"]').trigger('click')
|
|
139
|
+
await w.find('.m3-pdf-note').trigger('click')
|
|
140
|
+
expect((w.emitted('update:annotations')!.at(-1)![0] as PdfAnnotation[]).map((a) => a.id)).toEqual(['h'])
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('eraseFrom cuts a stroke where the eraser passes, and takes highlights and notes it touches', () => {
|
|
144
|
+
const line: PdfAnnotation = { id: 'i', type: 'ink', page: 1, color: '#000', width: 2, paths: [[[0, 0], [10, 0], [20, 0], [30, 0], [40, 0], [50, 0]]], createdAt: '' }
|
|
145
|
+
// The middle goes: two strokes are left
|
|
146
|
+
const cut = eraseFrom(line, { x: 25, y: 0, r: 3 })!
|
|
147
|
+
expect(cut.paths).toEqual([[[0, 0], [10, 0], [20, 0]], [[30, 0], [40, 0], [50, 0]]])
|
|
148
|
+
// A fast drag across a long segment, between its points, still cuts it
|
|
149
|
+
const across = eraseFrom({ ...line, paths: [[[0, 0], [100, 0]]] }, { x: 50, y: 1, r: 3 })
|
|
150
|
+
expect(across).toBe(null)
|
|
151
|
+
// Out of reach: untouched, the same object
|
|
152
|
+
expect(eraseFrom(line, { x: 25, y: 30, r: 3 })).toBe(line)
|
|
153
|
+
// Erasing the end of a stroke leaves the rest
|
|
154
|
+
expect(eraseFrom(line, { x: 50, y: 0, r: 3 })!.paths).toEqual([[[0, 0], [10, 0], [20, 0], [30, 0], [40, 0]]])
|
|
155
|
+
const hl: PdfAnnotation = { id: 'h', type: 'highlight', page: 1, color: '#ff0', rects: [[10, 10, 90, 22]], createdAt: '' }
|
|
156
|
+
expect(eraseFrom(hl, { x: 50, y: 16, r: 2 })).toBe(null)
|
|
157
|
+
expect(eraseFrom(hl, { x: 50, y: 60, r: 2 })).toBe(hl)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('dragging the eraser over a drawing cuts it, as one undo step', async () => {
|
|
161
|
+
const annotations: PdfAnnotation[] = [
|
|
162
|
+
{ id: 'i', type: 'ink', page: 1, color: '#000', width: 2, paths: [Array.from({ length: 21 }, (_, k) => [100 + k * 10, 500] as [number, number])], createdAt: '' },
|
|
163
|
+
]
|
|
164
|
+
const w = await viewer({ annotate: true, annotations, zoom: 1 })
|
|
165
|
+
await w.find('[aria-label="Annotate"]').trigger('click')
|
|
166
|
+
await w.find('[aria-label="Eraser"]').trigger('click')
|
|
167
|
+
const page = pages(w)[0]!.element as HTMLElement
|
|
168
|
+
const scale = 96 / 72
|
|
169
|
+
const width = Math.floor(612 * scale)
|
|
170
|
+
const height = Math.floor(792 * scale)
|
|
171
|
+
page.getBoundingClientRect = () => ({ left: 0, top: 0, width, height, right: width, bottom: height, x: 0, y: 0, toJSON: () => ({}) })
|
|
172
|
+
const svg = page.querySelector('svg')!
|
|
173
|
+
// Across the stroke's middle, top to bottom (y = 500pt from the bottom)
|
|
174
|
+
const yPx = (792 - 500) * scale
|
|
175
|
+
const ev = (type: string, y: number) => svg.dispatchEvent(new PointerEvent(type, { clientX: 200 * scale, clientY: y, pointerId: 3, button: 0, pointerType: 'pen', bubbles: true }))
|
|
176
|
+
ev('pointerdown', yPx - 30)
|
|
177
|
+
for (let d = -20; d <= 30; d += 5) ev('pointermove', yPx + d)
|
|
178
|
+
ev('pointerup', yPx + 30)
|
|
179
|
+
const next = w.emitted('update:annotations')!.at(-1)![0] as PdfAnnotation[]
|
|
180
|
+
expect(next).toHaveLength(1)
|
|
181
|
+
expect(next[0]!.paths!.length).toBe(2)
|
|
182
|
+
await w.setProps({ annotations: next })
|
|
183
|
+
await w.find('[aria-label="Undo"]').trigger('click')
|
|
184
|
+
expect(w.emitted('update:annotations')!.at(-1)![0]).toEqual(annotations)
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
it('asks for the password of an encrypted file', async () => {
|
|
188
|
+
fakeDoc.password = 'm3ui'
|
|
189
|
+
const w = await viewer()
|
|
190
|
+
expect(w.text()).toContain('password protected')
|
|
191
|
+
await w.find('input[type="password"]').setValue('m3ui')
|
|
192
|
+
await w.find('form').trigger('submit')
|
|
193
|
+
await settle()
|
|
194
|
+
expect(pages(w)).toHaveLength(4)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it('shows #empty without a src, and forwards attrs to its root', async () => {
|
|
198
|
+
const w = mount(MPdfViewer, { props: { src: null }, slots: { empty: 'Pick a file' }, attrs: { class: 'h-96', 'data-x': '1' } })
|
|
199
|
+
await settle()
|
|
200
|
+
expect(w.text()).toContain('Pick a file')
|
|
201
|
+
expect(w.classes()).toContain('h-96')
|
|
202
|
+
// Its position/display defaults live in @layer base (.m3-pdf), so a consumer's `absolute inset-0` wins:
|
|
203
|
+
// a `relative` utility on the root beat it and the viewer collapsed when its side panel closed
|
|
204
|
+
expect(w.classes()).not.toContain('relative')
|
|
205
|
+
expect(w.classes()).not.toContain('flex')
|
|
206
|
+
expect(w.attributes('data-x')).toBe('1')
|
|
207
|
+
})
|
|
208
|
+
it('keeps the reading point when the width changes a fit mode (the side panel opening)', async () => {
|
|
209
|
+
const callbacks: (() => void)[] = []
|
|
210
|
+
vi.stubGlobal('ResizeObserver', class {
|
|
211
|
+
constructor(cb: () => void) { callbacks.push(cb) }
|
|
212
|
+
observe() {}
|
|
213
|
+
disconnect() {}
|
|
214
|
+
})
|
|
215
|
+
const width = vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(640)
|
|
216
|
+
const w = await viewer()
|
|
217
|
+
const scroller = w.find('.m3-pdf-scroller').element as HTMLElement
|
|
218
|
+
// A third of the way into page 3, under the reading point (a third of the 480px view)
|
|
219
|
+
const before = pageBox(w, 3)
|
|
220
|
+
const top3 = parseFloat(before.style.top)
|
|
221
|
+
const h3 = parseFloat(before.style.height)
|
|
222
|
+
scroller.scrollTop = top3 + h3 / 3 - 160
|
|
223
|
+
scroller.dispatchEvent(new Event('scroll'))
|
|
224
|
+
width.mockReturnValue(400)
|
|
225
|
+
callbacks.forEach((cb) => cb())
|
|
226
|
+
await nextTick()
|
|
227
|
+
await nextTick()
|
|
228
|
+
const after = pageBox(w, 3)
|
|
229
|
+
const point = scroller.scrollTop + 160
|
|
230
|
+
expect(parseFloat(after.style.height)).toBeLessThan(h3)
|
|
231
|
+
expect((point - parseFloat(after.style.top)) / parseFloat(after.style.height)).toBeCloseTo(1 / 3, 1)
|
|
232
|
+
expect(w.emitted('update:page')?.at(-1)).toEqual([3])
|
|
233
|
+
vi.unstubAllGlobals()
|
|
234
|
+
})
|
|
235
|
+
})
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
|
+
import { mount, flushPromises } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MResourceTimeline from '../components/MResourceTimeline.vue'
|
|
5
|
+
import type { TimelineEvent, TimelineResource } from '../composables/useResourceTimeline'
|
|
6
|
+
|
|
7
|
+
// 1200 × 600, the list 220 wide, 240 px a day = 10 px an hour; rows 56 high under a 56 px header
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(1200)
|
|
10
|
+
vi.spyOn(HTMLElement.prototype, 'clientHeight', 'get').mockReturnValue(600)
|
|
11
|
+
vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(() => ({ left: 0, top: 0, right: 1200, bottom: 600, width: 1200, height: 600, x: 0, y: 0, toJSON() {} }) as DOMRect)
|
|
12
|
+
})
|
|
13
|
+
afterEach(() => vi.restoreAllMocks())
|
|
14
|
+
|
|
15
|
+
const resources: TimelineResource[] = [
|
|
16
|
+
{ id: 'ana', name: 'Ana Ruiz', group: 'Kitchen' },
|
|
17
|
+
{ id: 'leo', name: 'Leo Paz', group: 'Kitchen' },
|
|
18
|
+
{ id: 'mia', name: 'Mia Sol', group: 'Floor', capacity: 2 },
|
|
19
|
+
]
|
|
20
|
+
const events = (): TimelineEvent[] => [
|
|
21
|
+
{ id: 's1', resourceId: 'ana', start: '2026-03-02T09:00', end: '2026-03-02T17:00', title: 'Morning' },
|
|
22
|
+
{ id: 's2', resourceId: 'ana', start: '2026-03-02T16:00', end: '2026-03-02T22:00', title: 'Evening' },
|
|
23
|
+
{ id: 's3', resourceId: 'mia', start: '2026-03-02T10:00', end: '2026-03-02T14:00', title: 'Lunch' },
|
|
24
|
+
{ id: 's4', resourceId: 'mia', start: '2026-03-02T11:00', end: '2026-03-02T15:00', title: 'Lunch 2' },
|
|
25
|
+
]
|
|
26
|
+
async function timeline(props: Record<string, unknown> = {}) {
|
|
27
|
+
const w = mount(MResourceTimeline, { props: { resources, events: events(), now: null, start: '2026-03-02T00:00', ...props }, attachTo: document.body })
|
|
28
|
+
await flushPromises()
|
|
29
|
+
await nextTick()
|
|
30
|
+
return w
|
|
31
|
+
}
|
|
32
|
+
function pointer(el: EventTarget, type: string, x: number, y: number, extra: Record<string, unknown> = {}) {
|
|
33
|
+
el.dispatchEvent(new PointerEvent(type, { bubbles: true, cancelable: true, clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', button: 0, buttons: 1, ...extra }))
|
|
34
|
+
}
|
|
35
|
+
const block = (w: ReturnType<typeof mount>, title: string) => w.findAll('[data-timeline-event]').find((b) => b.text().includes(title))!
|
|
36
|
+
const last = (w: ReturnType<typeof mount>) => Object.fromEntries((w.emitted('update:events')!.at(-1)![0] as TimelineEvent[]).map((e) => [e.id, e]))
|
|
37
|
+
|
|
38
|
+
describe('MResourceTimeline', () => {
|
|
39
|
+
it('groups resources, stacks overlaps in lanes and marks conflicts past capacity', async () => {
|
|
40
|
+
const w = await timeline()
|
|
41
|
+
expect(w.findAll('button[aria-expanded]').map((b) => b.text().replace('expand_more', ''))).toEqual(['Kitchen2', 'Floor1'])
|
|
42
|
+
expect(w.findAll('[data-timeline-event]')).toHaveLength(4)
|
|
43
|
+
// Ana holds one at a time: her two overlap; Mia holds two
|
|
44
|
+
expect(block(w, 'Morning').classes()).toContain('outline-error')
|
|
45
|
+
expect(block(w, 'Lunch 2').classes()).not.toContain('outline-error')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('moves a booking in time by snapped steps and to another resource', async () => {
|
|
49
|
+
const w = await timeline()
|
|
50
|
+
const y = 56 + 40 + 20
|
|
51
|
+
pointer(block(w, 'Lunch').element, 'pointerdown', 500, y)
|
|
52
|
+
pointer(window, 'pointermove', 510, y)
|
|
53
|
+
// 1 hour right (10 px) plus a bit, and down into Leo's row (Kitchen header 40, Ana's row is two lanes high)
|
|
54
|
+
pointer(window, 'pointermove', 512, 56 + 40 + 88 + 20)
|
|
55
|
+
pointer(window, 'pointerup', 512, 56 + 40 + 88 + 20)
|
|
56
|
+
const e = last(w)
|
|
57
|
+
expect(e.s3).toMatchObject({ resourceId: 'leo', start: '2026-03-02T11:15', end: '2026-03-02T15:15' })
|
|
58
|
+
expect(w.emitted('change')![0]![0]).toMatchObject({ kind: 'move' })
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it("overlap='prevent' refuses a drop that conflicts", async () => {
|
|
62
|
+
const w = await timeline({ overlap: 'prevent', events: events().filter((e) => e.id !== 's2') })
|
|
63
|
+
// Lunch onto Ana, who's busy 9 to 5
|
|
64
|
+
pointer(block(w, 'Lunch').element, 'pointerdown', 500, 300)
|
|
65
|
+
pointer(window, 'pointermove', 510, 300)
|
|
66
|
+
pointer(window, 'pointermove', 500, 56 + 40 + 20)
|
|
67
|
+
pointer(window, 'pointerup', 500, 56 + 40 + 20)
|
|
68
|
+
expect(w.emitted('update:events')).toBeUndefined()
|
|
69
|
+
expect(w.emitted('conflict')![0]![0]).toMatchObject({ event: { id: 's3', resourceId: 'ana' } })
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('with creatable, dragging across empty time asks for a booking', async () => {
|
|
73
|
+
const w = await timeline({ creatable: true })
|
|
74
|
+
const pane = w.findAll('.relative.shrink-0').at(-1)!.element
|
|
75
|
+
const y = 56 + 40 + 88 + 20
|
|
76
|
+
// From 02:00 to 05:00 on Leo (the view starts 48 px before `start`)
|
|
77
|
+
pointer(pane, 'pointerdown', 220 + 48 + 20, y)
|
|
78
|
+
pointer(window, 'pointermove', 220 + 48 + 30, y)
|
|
79
|
+
pointer(window, 'pointermove', 220 + 48 + 50, y)
|
|
80
|
+
pointer(window, 'pointerup', 220 + 48 + 50, y)
|
|
81
|
+
expect(w.emitted('create')![0]![0]).toEqual({ resourceId: 'leo', start: '2026-03-02T02:00', end: '2026-03-02T05:00' })
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('keyboard: arrows move and resize, up/down change resource, undo', async () => {
|
|
85
|
+
const w = await timeline()
|
|
86
|
+
await block(w, 'Lunch').trigger('keydown', { key: 'ArrowRight' })
|
|
87
|
+
expect(last(w).s3!.start).toBe('2026-03-02T10:15')
|
|
88
|
+
await block(w, 'Lunch').trigger('keydown', { key: 'ArrowRight', shiftKey: true })
|
|
89
|
+
expect(last(w).s3!.end).toBe('2026-03-02T14:30')
|
|
90
|
+
await block(w, 'Lunch').trigger('keydown', { key: 'ArrowUp' })
|
|
91
|
+
expect(last(w).s3!.resourceId).toBe('leo')
|
|
92
|
+
await block(w, 'Lunch').trigger('keydown', { key: 'z', ctrlKey: true })
|
|
93
|
+
expect(last(w).s3!.resourceId).toBe('mia')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('folds a group', async () => {
|
|
97
|
+
const w = await timeline()
|
|
98
|
+
await w.findAll('button[aria-expanded]')[0]!.trigger('click')
|
|
99
|
+
expect(w.emitted('update:collapsed')![0]![0]).toEqual(['Kitchen'])
|
|
100
|
+
expect(w.findAll('[data-timeline-event]')).toHaveLength(2)
|
|
101
|
+
})
|
|
102
|
+
})
|