@m3ui-vue/m3ui-vue 1.3.8 → 1.4.1
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 +1102 -20
- package/dist/{MButton-D5eJiDza.js → MButton-DQMTIlaV.js} +2 -2
- package/dist/{MButton-D5eJiDza.js.map → MButton-DQMTIlaV.js.map} +1 -1
- package/dist/{MDialog-WqB0jewp.js → MDialog-cdgapGfZ.js} +2 -2
- package/dist/{MDialog-WqB0jewp.js.map → MDialog-cdgapGfZ.js.map} +1 -1
- package/dist/{MListItem-Cf-C2Ru-.js → MListItem-ZkSGIIrb.js} +2 -2
- package/dist/{MListItem-Cf-C2Ru-.js.map → MListItem-ZkSGIIrb.js.map} +1 -1
- package/dist/{MLoadingIndicator-D4GzEZoH.js → MLoadingIndicator-U6_oGx8z.js} +2 -2
- package/dist/{MLoadingIndicator-D4GzEZoH.js.map → MLoadingIndicator-U6_oGx8z.js.map} +1 -1
- package/dist/{MSeekBar-B19xoWE3.js → MSeekBar-DTZVizZg.js} +2 -2
- package/dist/{MSeekBar-B19xoWE3.js.map → MSeekBar-DTZVizZg.js.map} +1 -1
- package/dist/{MSlider-9RoiuebS.js → MSlider-CqJkEYRZ.js} +2 -2
- package/dist/{MSlider-9RoiuebS.js.map → MSlider-CqJkEYRZ.js.map} +1 -1
- package/dist/{MSpinner-BNF8MN-L.js → MSpinner-Btgc-0nb.js} +2 -2
- package/dist/{MSpinner-BNF8MN-L.js.map → MSpinner-Btgc-0nb.js.map} +1 -1
- package/dist/{MTextField-CuG0T3qh.js → MTextField-B6M0gJEO.js} +2 -2
- package/dist/{MTextField-CuG0T3qh.js.map → MTextField-B6M0gJEO.js.map} +1 -1
- package/dist/{MTooltip-Bv7yxngk.js → MTooltip-Dspji4XG.js} +4 -4
- package/dist/{MTooltip-Bv7yxngk.js.map → MTooltip-Dspji4XG.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAudioPlayer.vue.d.ts +2 -2
- package/dist/components/MAvailabilityCalendar.vue.d.ts +83 -0
- package/dist/components/MBeforeAfter.vue.d.ts +61 -0
- package/dist/components/MBodyMap.vue.d.ts +70 -0
- package/dist/components/MCandlestickChart.vue.d.ts +82 -0
- package/dist/components/MCertificate.vue.d.ts +76 -0
- package/dist/components/MCountdown.vue.d.ts +80 -0
- package/dist/components/MCreditCardInput.vue.d.ts +75 -0
- package/dist/components/MMortgageCalculator.vue.d.ts +83 -0
- package/dist/components/MOdontogram.vue.d.ts +86 -0
- package/dist/components/MOrderBook.vue.d.ts +89 -0
- package/dist/components/MOrderTicket.vue.d.ts +91 -0
- package/dist/components/MPosKeypad.vue.d.ts +84 -0
- package/dist/components/MProductConfigurator.vue.d.ts +136 -0
- package/dist/components/MQuiz.vue.d.ts +102 -0
- package/dist/components/MReceipt.vue.d.ts +93 -0
- package/dist/components/MSeatMap.vue.d.ts +131 -0
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MTicket.vue.d.ts +83 -0
- package/dist/components/MVideoPlayer.vue.d.ts +1 -1
- package/dist/components/MVitalsChart.vue.d.ts +73 -0
- package/dist/composables/_printElement.d.ts +9 -0
- package/dist/composables/cardBrand.d.ts +25 -0
- package/dist/composables/mortgage.d.ts +37 -0
- package/dist/composables/useLocale.d.ts +131 -0
- package/dist/draw.js +2 -2
- package/dist/flow.js +1 -1
- package/dist/gantt.js +1 -1
- package/dist/index.d.ts +37 -0
- package/dist/locales/index.js +924 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +10125 -5263
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +5 -5
- package/dist/media.js +4 -4
- package/dist/pdf.js +4 -4
- package/dist/rich-text-editor.js +4 -4
- package/dist/styles.css +1 -1
- package/dist/{useLocale-D2ucaY-l.js → useLocale-DLKJIRFi.js} +133 -2
- package/dist/useLocale-DLKJIRFi.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MAvailabilityCalendar.test.ts +85 -0
- package/src/__tests__/MBeforeAfter.test.ts +79 -0
- package/src/__tests__/MBodyMap.test.ts +60 -0
- package/src/__tests__/MCandlestickChart.test.ts +66 -0
- package/src/__tests__/MCertificate.test.ts +32 -0
- package/src/__tests__/MCountdown.test.ts +75 -0
- package/src/__tests__/MCreditCardInput.test.ts +122 -0
- package/src/__tests__/MMortgageCalculator.test.ts +49 -0
- package/src/__tests__/MOdontogram.test.ts +93 -0
- package/src/__tests__/MOrderBook.test.ts +66 -0
- package/src/__tests__/MOrderTicket.test.ts +68 -0
- package/src/__tests__/MPosKeypad.test.ts +116 -0
- package/src/__tests__/MProductConfigurator.test.ts +73 -0
- package/src/__tests__/MQuiz.test.ts +104 -0
- package/src/__tests__/MReceipt.test.ts +52 -0
- package/src/__tests__/MSeatMap.test.ts +76 -0
- package/src/__tests__/MTicket.test.ts +38 -0
- package/src/__tests__/MVitalsChart.test.ts +49 -0
- package/src/__tests__/clearToNull.test.ts +30 -0
- package/src/__tests__/mortgage.test.ts +25 -0
- package/src/__tests__/ssr.test.ts +11 -0
- package/src/components/MAutocomplete.vue +2 -2
- package/src/components/MAvailabilityCalendar.vue +460 -0
- package/src/components/MBeforeAfter.vue +248 -0
- package/src/components/MBodyMap.vue +266 -0
- package/src/components/MCandlestickChart.vue +479 -0
- package/src/components/MCertificate.vue +351 -0
- package/src/components/MCountdown.vue +200 -0
- package/src/components/MCreditCardInput.vue +351 -0
- package/src/components/MMortgageCalculator.vue +258 -0
- package/src/components/MOdontogram.vue +462 -0
- package/src/components/MOrderBook.vue +287 -0
- package/src/components/MOrderTicket.vue +217 -0
- package/src/components/MPosKeypad.vue +406 -0
- package/src/components/MProductConfigurator.vue +412 -0
- package/src/components/MQuiz.vue +531 -0
- package/src/components/MReceipt.vue +249 -0
- package/src/components/MSeatMap.vue +431 -0
- package/src/components/MSelect.vue +2 -2
- package/src/components/MTicket.vue +209 -0
- package/src/components/MVitalsChart.vue +303 -0
- package/src/composables/_printElement.ts +36 -0
- package/src/composables/cardBrand.ts +104 -0
- package/src/composables/mortgage.ts +70 -0
- package/src/composables/useLocale.ts +277 -0
- package/src/index.ts +37 -0
- package/src/locales/de.ts +131 -0
- package/src/locales/es.ts +131 -0
- package/src/locales/fr.ts +131 -0
- package/src/locales/ja.ts +131 -0
- package/src/locales/ko.ts +131 -0
- package/src/locales/pt.ts +131 -0
- package/src/locales/zh.ts +131 -0
- package/dist/useLocale-D2ucaY-l.js.map +0 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MOdontogram from '../components/MOdontogram.vue'
|
|
4
|
+
import type { OdontogramValue } from '../components/MOdontogram.vue'
|
|
5
|
+
|
|
6
|
+
function setup(extra: Record<string, unknown> = {}) {
|
|
7
|
+
const w = mount(MOdontogram, {
|
|
8
|
+
props: {
|
|
9
|
+
modelValue: {} as OdontogramValue,
|
|
10
|
+
'onUpdate:modelValue': (v: OdontogramValue) => w.setProps({ modelValue: v }),
|
|
11
|
+
'onUpdate:tool': (t: string) => w.setProps({ tool: t }),
|
|
12
|
+
...extra,
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
return w
|
|
16
|
+
}
|
|
17
|
+
const teeth = (w: ReturnType<typeof setup>) => w.findAll('[data-tooth]').map((t) => t.attributes('data-tooth'))
|
|
18
|
+
const surface = (w: ReturnType<typeof setup>, tooth: string, s: string) => w.find(`[data-tooth="${tooth}"] [data-surface="${s}"]`)
|
|
19
|
+
|
|
20
|
+
describe('MOdontogram', () => {
|
|
21
|
+
it('lays out FDI teeth from the patient’s upper right', () => {
|
|
22
|
+
const w = setup()
|
|
23
|
+
const t = teeth(w)
|
|
24
|
+
expect(t).toHaveLength(32)
|
|
25
|
+
expect(t.slice(0, 3)).toEqual(['18', '17', '16'])
|
|
26
|
+
expect(t.slice(7, 9)).toEqual(['11', '21'])
|
|
27
|
+
expect(t.slice(16, 18)).toEqual(['48', '47'])
|
|
28
|
+
expect(t.at(-1)).toBe('38')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('numbers Universal and primary teeth', async () => {
|
|
32
|
+
const w = setup({ numbering: 'universal' })
|
|
33
|
+
expect(teeth(w).slice(0, 2)).toEqual(['1', '2'])
|
|
34
|
+
expect(teeth(w)[16]).toBe('32')
|
|
35
|
+
expect(teeth(w).at(-1)).toBe('17')
|
|
36
|
+
await w.setProps({ dentition: 'primary' })
|
|
37
|
+
expect(teeth(w)).toHaveLength(20)
|
|
38
|
+
expect(teeth(w).slice(0, 2)).toEqual(['A', 'B'])
|
|
39
|
+
await w.setProps({ numbering: 'fdi' })
|
|
40
|
+
expect(teeth(w).slice(0, 5)).toEqual(['55', '54', '53', '52', '51'])
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('points mesial at the midline and buccal outward', () => {
|
|
44
|
+
const w = setup()
|
|
45
|
+
// Tooth 16 sits left of the midline: its mesial side is the box's right side
|
|
46
|
+
expect(surface(w, '16', 'mesial').attributes('points')).toBe('40,0 28,12 28,28 40,40')
|
|
47
|
+
expect(surface(w, '26', 'mesial').attributes('points')).toBe('0,0 12,12 12,28 0,40')
|
|
48
|
+
expect(surface(w, '16', 'buccal').attributes('points')).toBe('0,0 40,0 28,12 12,12')
|
|
49
|
+
expect(surface(w, '46', 'buccal').attributes('points')).toBe('0,40 40,40 28,28 12,28')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('charts a surface with the picked condition and clears it on a second tap', async () => {
|
|
53
|
+
const w = setup()
|
|
54
|
+
await surface(w, '36', 'occlusal').trigger('click')
|
|
55
|
+
expect(w.props('modelValue')).toEqual({ 36: { surfaces: { occlusal: 'caries' } } })
|
|
56
|
+
expect(w.emitted('change')![0]![0]).toEqual({ tooth: '36', surface: 'occlusal', condition: 'caries' })
|
|
57
|
+
await w.find('[data-tool="filling"]').trigger('click')
|
|
58
|
+
await surface(w, '36', 'occlusal').trigger('click')
|
|
59
|
+
expect(w.props('modelValue')).toEqual({ 36: { surfaces: { occlusal: 'filling' } } })
|
|
60
|
+
await surface(w, '36', 'occlusal').trigger('click')
|
|
61
|
+
expect(w.props('modelValue')).toEqual({})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('charts whole-tooth conditions from the number', async () => {
|
|
65
|
+
const w = setup({ tool: 'missing' })
|
|
66
|
+
await w.find('[data-tooth="18"] [data-number]').trigger('click')
|
|
67
|
+
expect(w.props('modelValue')).toEqual({ 18: { conditions: ['missing'] } })
|
|
68
|
+
expect(w.find('[data-tooth="18"] [data-mark="missing"]').exists()).toBe(true)
|
|
69
|
+
await w.setProps({ tool: 'rootCanal' })
|
|
70
|
+
await w.find('[data-tooth="11"] [data-surface="buccal"]').trigger('click')
|
|
71
|
+
expect(w.props('modelValue')['11']).toEqual({ conditions: ['rootCanal'] })
|
|
72
|
+
await w.setProps({ tool: 'eraser' })
|
|
73
|
+
await w.find('[data-tooth="18"] [data-number]').trigger('click')
|
|
74
|
+
expect(w.props('modelValue')['18']).toBeUndefined()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('charts surfaces from the keyboard', async () => {
|
|
78
|
+
const w = setup()
|
|
79
|
+
const first = w.find('[data-tooth="18"]')
|
|
80
|
+
await first.trigger('keydown', { key: 'o' })
|
|
81
|
+
await first.trigger('keydown', { key: 'M' })
|
|
82
|
+
expect(w.props('modelValue')['18']).toEqual({ surfaces: { occlusal: 'caries', mesial: 'caries' } })
|
|
83
|
+
expect(first.attributes('aria-label')).toBe('Tooth 18, Occlusal: Caries, Mesial: Caries')
|
|
84
|
+
await first.trigger('keydown', { key: 'Delete' })
|
|
85
|
+
expect(w.props('modelValue')).toEqual({})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('does nothing when readonly', async () => {
|
|
89
|
+
const w = setup({ readonly: true })
|
|
90
|
+
await surface(w, '36', 'occlusal').trigger('click')
|
|
91
|
+
expect(w.emitted('update:modelValue')).toBeUndefined()
|
|
92
|
+
})
|
|
93
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MOrderBook from '../components/MOrderBook.vue'
|
|
4
|
+
import type { OrderBookLevel } from '../components/MOrderBook.vue'
|
|
5
|
+
|
|
6
|
+
const bids: OrderBookLevel[] = [[99.5, 2], [100, 1], [99.75, 3]]
|
|
7
|
+
const asks: OrderBookLevel[] = [[100.5, 1], [100.25, 4], [101, 2]]
|
|
8
|
+
|
|
9
|
+
afterEach(() => vi.useRealTimers())
|
|
10
|
+
|
|
11
|
+
const prices = (w: ReturnType<typeof mount>, side: string) =>
|
|
12
|
+
w.findAll(`[data-side="${side}"]`).map((r) => r.findAll('span.relative')[0]!.text())
|
|
13
|
+
|
|
14
|
+
describe('MOrderBook', () => {
|
|
15
|
+
it('sorts asks above bids with the best of each by the middle', () => {
|
|
16
|
+
const w = mount(MOrderBook, { props: { bids, asks } })
|
|
17
|
+
expect(prices(w, 'ask')).toEqual(['101.00', '100.50', '100.25'])
|
|
18
|
+
expect(prices(w, 'bid')).toEqual(['100.00', '99.75', '99.50'])
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('accumulates totals and shows the spread', () => {
|
|
22
|
+
const w = mount(MOrderBook, { props: { bids, asks } })
|
|
23
|
+
const bidTotals = w.findAll('[data-side="bid"]').map((r) => r.findAll('span.relative')[2]!.text())
|
|
24
|
+
expect(bidTotals).toEqual(['1.0000', '4.0000', '6.0000'])
|
|
25
|
+
expect(w.find('[data-spread]').text()).toContain('0.25')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('groups levels into price steps', () => {
|
|
29
|
+
const w = mount(MOrderBook, { props: { bids, asks, step: 1 } })
|
|
30
|
+
expect(prices(w, 'bid')).toEqual(['100', '99'])
|
|
31
|
+
expect(prices(w, 'ask')).toEqual(['101'])
|
|
32
|
+
const sizes = w.findAll('[data-side="bid"]').map((r) => r.findAll('span.relative')[1]!.text())
|
|
33
|
+
expect(sizes).toEqual(['1.0000', '5.0000'])
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('caps the levels per side', () => {
|
|
37
|
+
const w = mount(MOrderBook, { props: { bids, asks, levels: 2 } })
|
|
38
|
+
expect(prices(w, 'bid')).toEqual(['100.00', '99.75'])
|
|
39
|
+
expect(prices(w, 'ask')).toEqual(['100.50', '100.25'])
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('flashes a level whose size changed', async () => {
|
|
43
|
+
vi.useFakeTimers()
|
|
44
|
+
const w = mount(MOrderBook, { props: { bids, asks } })
|
|
45
|
+
expect(w.find('.m3-ob-flash').exists()).toBe(false)
|
|
46
|
+
await w.setProps({ bids: [[99.5, 2], [100, 1.5], [99.75, 3]] })
|
|
47
|
+
expect(w.findAll('.m3-ob-flash')).toHaveLength(1)
|
|
48
|
+
vi.advanceTimersByTime(800)
|
|
49
|
+
await w.vm.$nextTick()
|
|
50
|
+
expect(w.find('.m3-ob-flash').exists()).toBe(false)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('points the last price arrow the way it moved', async () => {
|
|
54
|
+
const w = mount(MOrderBook, { props: { bids, asks, lastPrice: 100.1 } })
|
|
55
|
+
await w.setProps({ lastPrice: 100.2 })
|
|
56
|
+
expect(w.find('[data-middle]').text()).toContain('arrow_upward')
|
|
57
|
+
await w.setProps({ lastPrice: 100 })
|
|
58
|
+
expect(w.find('[data-middle]').text()).toContain('arrow_downward')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('emits the clicked level', async () => {
|
|
62
|
+
const w = mount(MOrderBook, { props: { bids, asks, layout: 'split' } })
|
|
63
|
+
await w.find('[data-side="ask"]').trigger('click')
|
|
64
|
+
expect(w.emitted('select')![0]![0]).toEqual({ price: 100.25, size: 4, side: 'ask' })
|
|
65
|
+
})
|
|
66
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest'
|
|
2
|
+
import { mount, enableAutoUnmount } from '@vue/test-utils'
|
|
3
|
+
import MOrderTicket from '../components/MOrderTicket.vue'
|
|
4
|
+
|
|
5
|
+
const items = [
|
|
6
|
+
{ id: 1, name: 'Margherita', quantity: 2, modifiers: [{ label: 'onion', kind: 'remove' as const }, { label: 'extra cheese', kind: 'add' as const }] },
|
|
7
|
+
{ id: 2, name: 'Fries', note: 'well done' },
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
enableAutoUnmount(afterEach)
|
|
11
|
+
afterEach(() => vi.useRealTimers())
|
|
12
|
+
|
|
13
|
+
describe('MOrderTicket', () => {
|
|
14
|
+
it('renders lines with quantities, modifiers and notes', () => {
|
|
15
|
+
const w = mount(MOrderTicket, { props: { number: 42, title: 'Table 7', createdAt: Date.now(), items } })
|
|
16
|
+
expect(w.text()).toContain('#42')
|
|
17
|
+
expect(w.text()).toContain('2×')
|
|
18
|
+
expect(w.text()).toContain('− onion')
|
|
19
|
+
expect(w.text()).toContain('+ extra cheese')
|
|
20
|
+
expect(w.text()).toContain('well done')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('ticks the timer and changes color as the order ages', async () => {
|
|
24
|
+
vi.useFakeTimers()
|
|
25
|
+
vi.setSystemTime(new Date(2026, 0, 1, 12, 0, 0))
|
|
26
|
+
const w = mount(MOrderTicket, { props: { number: 1, createdAt: new Date(2026, 0, 1, 11, 51, 0), items } })
|
|
27
|
+
expect(w.find('[role="timer"]').text()).toBe('schedule 9:00')
|
|
28
|
+
expect(w.find('[data-level]').attributes('data-level')).toBe('normal')
|
|
29
|
+
vi.advanceTimersByTime(60_000)
|
|
30
|
+
await w.vm.$nextTick()
|
|
31
|
+
expect(w.find('[role="timer"]').text()).toBe('schedule 10:00')
|
|
32
|
+
expect(w.find('[data-level]').attributes('data-level')).toBe('warn')
|
|
33
|
+
await w.setProps({ lateAfter: 10 })
|
|
34
|
+
expect(w.find('[data-level]').attributes('data-level')).toBe('late')
|
|
35
|
+
w.unmount()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('freezes the timer at finishedAt', () => {
|
|
39
|
+
const w = mount(MOrderTicket, { props: { number: 1, createdAt: 0, finishedAt: 125_000, items } })
|
|
40
|
+
expect(w.find('[role="timer"]').text()).toBe('check_circle 2:05')
|
|
41
|
+
expect(w.find('[data-level]').attributes('data-level')).toBe('normal')
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('ticks lines done and emits complete on the last one', async () => {
|
|
45
|
+
const w = mount(MOrderTicket, { props: { number: 1, createdAt: Date.now(), items, done: [1] } })
|
|
46
|
+
const lines = w.findAll('li button')
|
|
47
|
+
expect(lines[0]!.attributes('aria-pressed')).toBe('true')
|
|
48
|
+
await lines[1]!.trigger('click')
|
|
49
|
+
expect(w.emitted('update:done')?.[0]).toEqual([[1, 2]])
|
|
50
|
+
expect(w.emitted('complete')).toHaveLength(1)
|
|
51
|
+
await lines[0]!.trigger('click')
|
|
52
|
+
expect(w.emitted('update:done')?.[1]).toEqual([[]])
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('ignores taps when readonly', async () => {
|
|
56
|
+
const w = mount(MOrderTicket, { props: { number: 1, createdAt: Date.now(), items, readonly: true } })
|
|
57
|
+
await w.findAll('li button')[0]!.trigger('click')
|
|
58
|
+
expect(w.emitted('update:done')).toBeUndefined()
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('passes allDone to the actions slot', () => {
|
|
62
|
+
const w = mount(MOrderTicket, {
|
|
63
|
+
props: { number: 1, createdAt: Date.now(), items, done: [1, 2] },
|
|
64
|
+
slots: { actions: `<template #actions="{ allDone }"><span>{{ allDone ? 'ready' : 'cooking' }}</span></template>` },
|
|
65
|
+
})
|
|
66
|
+
expect(w.text()).toContain('ready')
|
|
67
|
+
})
|
|
68
|
+
})
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MPosKeypad from '../components/MPosKeypad.vue'
|
|
4
|
+
|
|
5
|
+
type Props = InstanceType<typeof MPosKeypad>['$props']
|
|
6
|
+
|
|
7
|
+
// Mounts with a working v-model so each key sees the previous value
|
|
8
|
+
function mountKeypad(props: Partial<Props> = {}) {
|
|
9
|
+
const w = mount(MPosKeypad, {
|
|
10
|
+
props: {
|
|
11
|
+
modelValue: '',
|
|
12
|
+
...props,
|
|
13
|
+
'onUpdate:modelValue': (v: string) => w.setProps({ modelValue: v }),
|
|
14
|
+
} as any,
|
|
15
|
+
})
|
|
16
|
+
return w
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function type(w: ReturnType<typeof mount>, keys: string[]) {
|
|
20
|
+
for (const k of keys) await w.find(`[data-key="${k}"]`).trigger('click')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('MPosKeypad', () => {
|
|
24
|
+
it('types a free amount with a decimal point', async () => {
|
|
25
|
+
const w = mountKeypad()
|
|
26
|
+
await type(w, ['0', '1', '2', '.', '5', '0', '9'])
|
|
27
|
+
expect(w.props('modelValue')).toBe('12.50')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('enters cash-register style in shift mode', async () => {
|
|
31
|
+
const w = mountKeypad({ entry: 'shift' })
|
|
32
|
+
await type(w, ['1', '2', '5'])
|
|
33
|
+
expect(w.props('modelValue')).toBe('1.25')
|
|
34
|
+
await type(w, ['00'])
|
|
35
|
+
expect(w.props('modelValue')).toBe('125.00')
|
|
36
|
+
await type(w, ['backspace'])
|
|
37
|
+
expect(w.props('modelValue')).toBe('12.50')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('formats with a currency', async () => {
|
|
41
|
+
const w = mountKeypad({ currency: 'USD', modelValue: '1234.5' })
|
|
42
|
+
expect(w.text()).toContain('$1,234.5')
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('respects max and maxLength', async () => {
|
|
46
|
+
const w = mountKeypad({ max: 100 })
|
|
47
|
+
await type(w, ['9', '9', '9'])
|
|
48
|
+
expect(w.props('modelValue')).toBe('99')
|
|
49
|
+
const p = mountKeypad({ mode: 'pin', maxLength: 4 })
|
|
50
|
+
await type(p, ['0', '0', '1', '2', '3'])
|
|
51
|
+
expect(p.props('modelValue')).toBe('0012')
|
|
52
|
+
expect(p.emitted('submit')).toEqual([['0012']])
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('shows remaining and change against the amount due', async () => {
|
|
56
|
+
const w = mountKeypad({ due: 20, modelValue: '15' })
|
|
57
|
+
expect(w.text()).toContain('Remaining: 5.00')
|
|
58
|
+
await w.setProps({ modelValue: '50' })
|
|
59
|
+
expect(w.text()).toContain('Change: 30.00')
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('disables the action until the amount covers what is due', async () => {
|
|
63
|
+
const w = mountKeypad({ due: 20, modelValue: '15', actionLabel: 'Charge' })
|
|
64
|
+
const btn = () => w.findAll('button').find((b) => b.text() === 'Charge')!
|
|
65
|
+
expect(btn().attributes('disabled')).toBeDefined()
|
|
66
|
+
await w.setProps({ modelValue: '20' })
|
|
67
|
+
expect(btn().attributes('disabled')).toBeUndefined()
|
|
68
|
+
await btn().trigger('click')
|
|
69
|
+
expect(w.emitted('submit')).toEqual([['20']])
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('sets or adds quick amounts', async () => {
|
|
73
|
+
const w = mountKeypad({ quickAmounts: [10, 20], modelValue: '5' })
|
|
74
|
+
await w.findAll('button').find((b) => b.text().includes('20'))!.trigger('click')
|
|
75
|
+
expect(w.props('modelValue')).toBe('20')
|
|
76
|
+
const a = mountKeypad({ quickAmounts: [10], quickMode: 'add', modelValue: '5' })
|
|
77
|
+
await a.findAll('button').find((b) => b.text().includes('+10'))!.trigger('click')
|
|
78
|
+
expect(a.props('modelValue')).toBe('15')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('clears on a long press of delete', async () => {
|
|
82
|
+
vi.useFakeTimers()
|
|
83
|
+
const w = mountKeypad({ modelValue: '123' })
|
|
84
|
+
const del = w.find('[data-key="backspace"]')
|
|
85
|
+
await del.trigger('pointerdown', { button: 0 })
|
|
86
|
+
vi.advanceTimersByTime(600)
|
|
87
|
+
await del.trigger('pointerup')
|
|
88
|
+
await del.trigger('click')
|
|
89
|
+
expect(w.props('modelValue')).toBe('')
|
|
90
|
+
vi.useRealTimers()
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('takes the physical keyboard while focused', async () => {
|
|
94
|
+
const w = mountKeypad()
|
|
95
|
+
for (const key of ['4', ',', '5', 'Backspace', '7']) await w.trigger('keydown', { key })
|
|
96
|
+
expect(w.props('modelValue')).toBe('4.7')
|
|
97
|
+
await w.trigger('keydown', { key: 'Enter' })
|
|
98
|
+
expect(w.emitted('submit')).toEqual([['4.7']])
|
|
99
|
+
await w.trigger('keydown', { key: 'Escape' })
|
|
100
|
+
expect(w.props('modelValue')).toBe('')
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
it('listens globally only with keyboard="global", never stealing from fields', async () => {
|
|
104
|
+
const w = mountKeypad({ keyboard: 'global' })
|
|
105
|
+
window.dispatchEvent(new KeyboardEvent('keydown', { key: '8' }))
|
|
106
|
+
await w.vm.$nextTick()
|
|
107
|
+
expect(w.props('modelValue')).toBe('8')
|
|
108
|
+
const input = document.createElement('input')
|
|
109
|
+
document.body.appendChild(input)
|
|
110
|
+
input.dispatchEvent(new KeyboardEvent('keydown', { key: '9', bubbles: true }))
|
|
111
|
+
await w.vm.$nextTick()
|
|
112
|
+
expect(w.props('modelValue')).toBe('8')
|
|
113
|
+
input.remove()
|
|
114
|
+
w.unmount()
|
|
115
|
+
})
|
|
116
|
+
})
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MProductConfigurator from '../components/MProductConfigurator.vue'
|
|
4
|
+
import type { ProductOptionGroup, ProductSelection } from '../components/MProductConfigurator.vue'
|
|
5
|
+
|
|
6
|
+
const groups: ProductOptionGroup[] = [
|
|
7
|
+
{ key: 'size', label: 'Size', required: true, display: 'chips', options: [
|
|
8
|
+
{ value: 's', label: 'S' }, { value: 'm', label: 'M' }, { value: 'l', label: 'L', price: 2 },
|
|
9
|
+
] },
|
|
10
|
+
{ key: 'extras', label: 'Extras', type: 'multiple', max: 2, options: [
|
|
11
|
+
{ value: 'bacon', label: 'Bacon', price: 1.5 }, { value: 'egg', label: 'Egg', price: 1 }, { value: 'cheese', label: 'Cheese', price: 0.5 },
|
|
12
|
+
] },
|
|
13
|
+
{ key: 'dips', label: 'Dips', type: 'quantity', max: 3, options: [{ value: 'bbq', label: 'BBQ', price: 0.25 }, { value: 'mayo', label: 'Mayo' }] },
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
describe('MProductConfigurator', () => {
|
|
18
|
+
it('keeps the action disabled until required groups are chosen', async () => {
|
|
19
|
+
const w = mount(MProductConfigurator, { props: { groups, basePrice: 10, actionLabel: 'Add' } })
|
|
20
|
+
expect(w.find('[data-action]').attributes('disabled')).toBeDefined()
|
|
21
|
+
await w.setProps({ modelValue: { size: 'm' } })
|
|
22
|
+
expect(w.find('[data-action]').attributes('disabled')).toBeUndefined()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('picks a single option and prices it', async () => {
|
|
26
|
+
const w = mount(MProductConfigurator, { props: { groups, basePrice: 10, actionLabel: 'Add' } })
|
|
27
|
+
await w.find('[data-group="size"] [data-option="l"]').trigger('click')
|
|
28
|
+
const v = w.emitted('update:modelValue')!.at(-1)![0] as ProductSelection
|
|
29
|
+
expect(v.size).toBe('l')
|
|
30
|
+
await w.setProps({ modelValue: v, quantity: 2 })
|
|
31
|
+
expect((w.vm as any).unitPrice).toBe(12)
|
|
32
|
+
expect((w.vm as any).total).toBe(24)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('caps a multiple group at max', async () => {
|
|
36
|
+
const w = mount(MProductConfigurator, { props: { groups, modelValue: { size: 's', extras: ['bacon', 'egg'] }, basePrice: 10 } })
|
|
37
|
+
const cheese = w.find('[data-group="extras"] [data-option="cheese"] input')
|
|
38
|
+
expect(cheese.attributes('disabled')).toBeDefined()
|
|
39
|
+
expect((w.vm as any).unitPrice).toBe(12.5)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('counts quantities up to the group max', async () => {
|
|
43
|
+
const w = mount(MProductConfigurator, { props: { groups, modelValue: { size: 's', dips: { bbq: 2, mayo: 1 } }, basePrice: 10 } })
|
|
44
|
+
expect((w.vm as any).unitPrice).toBe(10.5)
|
|
45
|
+
const addMayo = w.findAll('[data-group="dips"] [data-option="mayo"] button').at(-1)!
|
|
46
|
+
expect(addMayo.attributes('disabled')).toBeDefined()
|
|
47
|
+
await w.findAll('[data-group="dips"] [data-option="bbq"] button')[0]!.trigger('click')
|
|
48
|
+
expect(w.emitted('update:modelValue')!.at(-1)![0]).toEqual({ size: 's', dips: { bbq: 1, mayo: 1 } })
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('crosses out combinations isAvailable rejects', () => {
|
|
52
|
+
const w = mount(MProductConfigurator, {
|
|
53
|
+
props: {
|
|
54
|
+
groups,
|
|
55
|
+
modelValue: { extras: ['egg'] },
|
|
56
|
+
isAvailable: (g, o, s) => !(g.key === 'size' && o.value === 'l' && (s.extras as string[] | undefined)?.includes('egg')),
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
expect(w.find('[data-group="size"] [data-option="l"]').attributes('disabled')).toBeDefined()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('emits add with the selection and totals', async () => {
|
|
63
|
+
const w = mount(MProductConfigurator, { props: { groups, modelValue: { size: 'm' }, basePrice: 10, quantity: 3, actionLabel: 'Add' } })
|
|
64
|
+
await w.find('[data-action]').trigger('click')
|
|
65
|
+
expect(w.emitted('add')![0]![0]).toEqual({ selection: { size: 'm' }, quantity: 3, unitPrice: 10, total: 30 })
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('shows the rule of each group', () => {
|
|
69
|
+
const w = mount(MProductConfigurator, { props: { groups: [...groups, { key: 'x', label: 'X', type: 'multiple', min: 2, max: 2, options: [] }] } })
|
|
70
|
+
const rules = w.findAll('[data-rule]').map((r) => r.text())
|
|
71
|
+
expect(rules).toEqual(['Required', 'Choose up to 2', 'Choose up to 3', 'Choose 2'])
|
|
72
|
+
})
|
|
73
|
+
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MQuiz from '../components/MQuiz.vue'
|
|
4
|
+
import type { QuizQuestion, QuizResult } from '../components/MQuiz.vue'
|
|
5
|
+
|
|
6
|
+
afterEach(() => vi.useRealTimers())
|
|
7
|
+
|
|
8
|
+
const questions: QuizQuestion[] = [
|
|
9
|
+
{ id: 'q1', prompt: 'Capital of France?', options: ['Lyon', 'Paris', 'Nice'], answer: 1, explanation: 'Paris since 508.' },
|
|
10
|
+
{ id: 'q2', type: 'multiple', prompt: 'Prime numbers?', options: ['2', '4', '5'], answer: [0, 2], points: 2 },
|
|
11
|
+
{ id: 'q3', type: 'truefalse', prompt: 'Water boils at 100 °C at sea level.', answer: true },
|
|
12
|
+
{ id: 'q4', type: 'text', prompt: 'Largest ocean?', answer: ['Pacific', 'Pacific Ocean'] },
|
|
13
|
+
{ id: 'q5', type: 'order', prompt: 'Smallest to largest', options: ['one', 'two', 'three'] },
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
type W = ReturnType<typeof mount>
|
|
17
|
+
const click = (w: W, sel: string) => w.find(sel).trigger('click')
|
|
18
|
+
|
|
19
|
+
async function solveOrder(w: W) {
|
|
20
|
+
// bubble-sort with the up buttons until solved
|
|
21
|
+
for (let pass = 0; pass < 3; pass++) {
|
|
22
|
+
const items = w.findAll('[data-order-item]').map((e) => Number(e.attributes('data-order-item')))
|
|
23
|
+
for (let p = 1; p < items.length; p++) {
|
|
24
|
+
const now = w.findAll('[data-order-item]').map((e) => Number(e.attributes('data-order-item')))
|
|
25
|
+
if (now[p]! < now[p - 1]!) await w.findAll('[data-order-item]')[p]!.find('[data-move="up"] , button').trigger('click')
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('MQuiz', () => {
|
|
31
|
+
it('checks each answer right away with its explanation', async () => {
|
|
32
|
+
const w = mount(MQuiz, { props: { questions } })
|
|
33
|
+
expect(w.find('[data-progress-text]').text()).toBe('Question 1 of 5')
|
|
34
|
+
expect(w.find('[data-action="check"]').attributes('disabled')).toBeDefined()
|
|
35
|
+
await click(w, '[data-option="0"]')
|
|
36
|
+
await click(w, '[data-action="check"]')
|
|
37
|
+
expect(w.find('[data-feedback]').text()).toContain('Not quite')
|
|
38
|
+
expect(w.find('[data-feedback]').text()).toContain('Paris since 508.')
|
|
39
|
+
expect(w.find('[data-option="1"]').attributes('data-state')).toBe('correct')
|
|
40
|
+
expect(w.find('[data-option="0"]').attributes('data-state')).toBe('wrong')
|
|
41
|
+
expect(w.emitted('answer')![0]![0]).toEqual({ id: 'q1', value: 0, correct: false })
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('scores a full run with every question type', async () => {
|
|
45
|
+
const w = mount(MQuiz, { props: { questions, passScore: 70 } })
|
|
46
|
+
// q1 right
|
|
47
|
+
await click(w, '[data-option="1"]'); await click(w, '[data-action="check"]'); await click(w, '[data-action="next"]')
|
|
48
|
+
// q2 right (2 points)
|
|
49
|
+
await click(w, '[data-option="0"]'); await click(w, '[data-option="2"]'); await click(w, '[data-action="check"]')
|
|
50
|
+
expect(w.find('[data-feedback]').text()).toContain('Correct!')
|
|
51
|
+
await click(w, '[data-action="next"]')
|
|
52
|
+
// q3 wrong
|
|
53
|
+
await click(w, '[data-option="false"]'); await click(w, '[data-action="check"]'); await click(w, '[data-action="next"]')
|
|
54
|
+
// q4 right, ignoring case and accents
|
|
55
|
+
await w.find('[data-text-answer]').setValue(' pacífic ocean ')
|
|
56
|
+
await click(w, '[data-action="check"]')
|
|
57
|
+
expect(w.find('[data-feedback]').text()).toContain('Correct!')
|
|
58
|
+
await click(w, '[data-action="next"]')
|
|
59
|
+
// q5: put in order
|
|
60
|
+
await solveOrder(w)
|
|
61
|
+
expect(w.findAll('[data-order-item]').map((e) => e.attributes('data-order-item'))).toEqual(['0', '1', '2'])
|
|
62
|
+
await click(w, '[data-action="check"]')
|
|
63
|
+
await click(w, '[data-action="next"]')
|
|
64
|
+
|
|
65
|
+
const r = w.emitted('finish')![0]![0] as QuizResult
|
|
66
|
+
expect(r.score).toBe(5)
|
|
67
|
+
expect(r.total).toBe(6)
|
|
68
|
+
expect(r.percent).toBe(83)
|
|
69
|
+
expect(r.passed).toBe(true)
|
|
70
|
+
expect(w.find('[data-passed]').text()).toBe('Passed')
|
|
71
|
+
expect(w.find('[data-score]').text()).toBe('5 of 6 points')
|
|
72
|
+
expect(w.find('[data-review="q3"]').text()).toContain('Correct answer: True')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('reveals answers only at the end with feedback="end"', async () => {
|
|
76
|
+
const w = mount(MQuiz, { props: { questions: questions.slice(0, 1), feedback: 'end' } })
|
|
77
|
+
await click(w, '[data-option="0"]')
|
|
78
|
+
expect(w.find('[data-action="check"]').exists()).toBe(false)
|
|
79
|
+
await click(w, '[data-action="next"]')
|
|
80
|
+
expect(w.find('[data-feedback]').exists()).toBe(false)
|
|
81
|
+
expect((w.emitted('finish')![0]![0] as QuizResult).score).toBe(0)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('never starts an order question solved and retries from scratch', async () => {
|
|
85
|
+
const w = mount(MQuiz, { props: { questions: [questions[4]!] } })
|
|
86
|
+
const order = w.findAll('[data-order-item]').map((e) => e.attributes('data-order-item'))
|
|
87
|
+
expect(order).not.toEqual(['0', '1', '2'])
|
|
88
|
+
await click(w, '[data-action="check"]')
|
|
89
|
+
await click(w, '[data-action="next"]')
|
|
90
|
+
await click(w, '[data-action="retry"]')
|
|
91
|
+
expect(w.find('[data-prompt]').exists()).toBe(true)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('ends when the time runs out', async () => {
|
|
95
|
+
vi.useFakeTimers()
|
|
96
|
+
const w = mount(MQuiz, { props: { questions, timeLimit: 3 } })
|
|
97
|
+
expect(w.find('[data-timer]').text()).toContain('0:03')
|
|
98
|
+
vi.advanceTimersByTime(3000)
|
|
99
|
+
await w.vm.$nextTick()
|
|
100
|
+
expect(w.emitted('finish')).toHaveLength(1)
|
|
101
|
+
expect(w.find('[data-result]').exists()).toBe(true)
|
|
102
|
+
w.unmount()
|
|
103
|
+
})
|
|
104
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MReceipt from '../components/MReceipt.vue'
|
|
4
|
+
|
|
5
|
+
const items = [
|
|
6
|
+
{ name: 'Coffee', quantity: 3, price: 0.1 },
|
|
7
|
+
{ name: 'Croissant', price: 2.35, note: 'Warm' },
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
describe('MReceipt', () => {
|
|
11
|
+
it('adds lines in cents, without float drift', () => {
|
|
12
|
+
const w = mount(MReceipt, { props: { items } })
|
|
13
|
+
// 3 × 0.1 = 0.30000000000000004 in floats
|
|
14
|
+
expect(w.text()).toContain('0.30')
|
|
15
|
+
expect(w.text()).toContain('3 × 0.10')
|
|
16
|
+
expect(w.find('[data-receipt="total"]').text()).toContain('2.65')
|
|
17
|
+
expect((w.vm as any).totals.total).toBe(2.65)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('applies discounts, percentages and included taxes', () => {
|
|
21
|
+
const w = mount(MReceipt, {
|
|
22
|
+
props: {
|
|
23
|
+
items: [{ name: 'A', price: 100 }],
|
|
24
|
+
adjustments: [
|
|
25
|
+
{ label: 'Promo', percent: -10 },
|
|
26
|
+
{ label: 'VAT', percent: 21, included: true },
|
|
27
|
+
{ label: 'Tip', amount: 5 },
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
expect(w.find('[data-receipt="subtotal"]').text()).toContain('100.00')
|
|
32
|
+
expect(w.text()).toContain('Promo (10%)')
|
|
33
|
+
expect(w.text()).toContain('-10.00')
|
|
34
|
+
// VAT inside the discounted 90: 90 − 90 / 1.21
|
|
35
|
+
expect(w.text()).toContain('15.62')
|
|
36
|
+
expect((w.vm as any).totals.total).toBe(95)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('shows the change when paid in excess', () => {
|
|
40
|
+
const w = mount(MReceipt, {
|
|
41
|
+
props: { items: [{ name: 'A', price: 37.4 }], payments: [{ method: 'Cash', amount: 50 }], currency: 'USD' },
|
|
42
|
+
})
|
|
43
|
+
expect(w.find('[data-receipt="change"]').text()).toContain('$12.60')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('renders header and footer', () => {
|
|
47
|
+
const w = mount(MReceipt, { props: { items, number: 'A-0042', footer: 'Thanks!' }, slots: { header: '<b>Café Sol</b>' } })
|
|
48
|
+
expect(w.text()).toContain('Café Sol')
|
|
49
|
+
expect(w.text()).toContain('#A-0042')
|
|
50
|
+
expect(w.text()).toContain('Thanks!')
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MSeatMap from '../components/MSeatMap.vue'
|
|
4
|
+
|
|
5
|
+
const hall = ['ss_ss', '', 'pp_pp']
|
|
6
|
+
|
|
7
|
+
function ids(w: ReturnType<typeof mount>) {
|
|
8
|
+
return w.findAll('[data-seat]').map((b) => b.attributes('data-seat'))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('MSeatMap', () => {
|
|
12
|
+
it('names seats theater style, skipping gaps and blank rows', () => {
|
|
13
|
+
const w = mount(MSeatMap, { props: { layout: hall } })
|
|
14
|
+
expect(ids(w)).toEqual(['A1', 'A2', 'A3', 'A4', 'B1', 'B2', 'B3', 'B4'])
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
it('names seats plane style and numbers right to left', () => {
|
|
18
|
+
const plane = mount(MSeatMap, { props: { layout: ['sss_sss', 'sss_sss'], naming: 'plane' } })
|
|
19
|
+
expect(ids(plane).slice(0, 6)).toEqual(['1A', '1B', '1C', '1D', '1E', '1F'])
|
|
20
|
+
const rtl = mount(MSeatMap, { props: { layout: ['sss'], numbering: 'rtl' } })
|
|
21
|
+
expect(ids(rtl)).toEqual(['A3', 'A2', 'A1'])
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('selects and releases seats', async () => {
|
|
25
|
+
const w = mount(MSeatMap, { props: { layout: hall, modelValue: ['A1'] } })
|
|
26
|
+
await w.find('[data-seat="A2"]').trigger('click')
|
|
27
|
+
expect(w.emitted('update:modelValue')?.[0]).toEqual([['A1', 'A2']])
|
|
28
|
+
await w.find('[data-seat="A1"]').trigger('click')
|
|
29
|
+
expect(w.emitted('update:modelValue')?.[1]).toEqual([[]])
|
|
30
|
+
expect(w.emitted('select')?.[1]?.[1]).toBe(false)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('does not pick occupied or blocked seats', async () => {
|
|
34
|
+
const w = mount(MSeatMap, { props: { layout: hall, occupied: ['A1'], blocked: ['A2'] } })
|
|
35
|
+
expect(w.find('[data-seat="A1"]').attributes('disabled')).toBeDefined()
|
|
36
|
+
expect(w.find('[data-seat="A2"]').classes()).toContain('is-blocked')
|
|
37
|
+
await w.find('[data-seat="A1"]').trigger('click')
|
|
38
|
+
expect(w.emitted('update:modelValue')).toBeUndefined()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('stops at max, or moves the selection when max is 1', async () => {
|
|
42
|
+
const w = mount(MSeatMap, { props: { layout: hall, modelValue: ['A1', 'A2'], max: 2 } })
|
|
43
|
+
await w.find('[data-seat="A3"]').trigger('click')
|
|
44
|
+
expect(w.emitted('update:modelValue')).toBeUndefined()
|
|
45
|
+
expect(w.emitted('limit')).toHaveLength(1)
|
|
46
|
+
const one = mount(MSeatMap, { props: { layout: hall, modelValue: ['A1'], max: 1 } })
|
|
47
|
+
await one.find('[data-seat="B2"]').trigger('click')
|
|
48
|
+
expect(one.emitted('update:modelValue')?.[0]).toEqual([['B2']])
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('labels seats with category and price', () => {
|
|
52
|
+
const w = mount(MSeatMap, {
|
|
53
|
+
props: { layout: hall, categories: [{ key: 'p', label: 'Premium', price: 12, color: 'tertiary' }], currency: 'USD' },
|
|
54
|
+
})
|
|
55
|
+
expect(w.find('[data-seat="B1"]').attributes('aria-label')).toBe('Seat B1, Premium, $12.00')
|
|
56
|
+
expect(w.text()).toContain('Premium · $12.00')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('moves focus with arrows over gaps and blank rows, skipping occupied seats', async () => {
|
|
60
|
+
const w = mount(MSeatMap, { props: { layout: hall, occupied: ['A3'] }, attachTo: document.body })
|
|
61
|
+
const a2 = w.find('[data-seat="A2"]')
|
|
62
|
+
expect(w.find('[data-seat="A1"]').attributes('tabindex')).toBe('0')
|
|
63
|
+
await a2.trigger('keydown', { key: 'ArrowRight' })
|
|
64
|
+
await w.vm.$nextTick()
|
|
65
|
+
expect(document.activeElement?.getAttribute('data-seat')).toBe('A4')
|
|
66
|
+
await w.find('[data-seat="A4"]').trigger('keydown', { key: 'ArrowDown' })
|
|
67
|
+
await w.vm.$nextTick()
|
|
68
|
+
expect(document.activeElement?.getAttribute('data-seat')).toBe('B4')
|
|
69
|
+
w.unmount()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('hides the stage with stage=false', () => {
|
|
73
|
+
expect(mount(MSeatMap, { props: { layout: hall } }).text()).toContain('Screen')
|
|
74
|
+
expect(mount(MSeatMap, { props: { layout: hall, stage: false } }).text()).not.toContain('Screen')
|
|
75
|
+
})
|
|
76
|
+
})
|