|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { mount } from '@vue/test-utils'; |
| 3 | +import { DpCalendarGridHeadRow } from '@packages/components/Calendar'; |
| 4 | +import { DpRootKey } from '@packages/components/DpRoot'; |
| 5 | + |
| 6 | +const props = { locale: 'en-US', weekStart: 1 }; |
| 7 | + |
| 8 | +const getMockContext = (overrideProps?: Partial<typeof props>) => { |
| 9 | + return { |
| 10 | + provide: { |
| 11 | + [DpRootKey]: { |
| 12 | + props: { ...props, ...(overrideProps ?? {}) }, |
| 13 | + }, |
| 14 | + }, |
| 15 | + }; |
| 16 | +}; |
| 17 | + |
| 18 | +const getRowElements = (overrideProps?: Partial<typeof props>, renderKey = 'day.name') => { |
| 19 | + const wrapper = mount(DpCalendarGridHeadRow, { |
| 20 | + global: getMockContext(overrideProps), |
| 21 | + slots: { |
| 22 | + default: ` |
| 23 | + <template #default="{ days }"> |
| 24 | + <td v-for="day in days" :key="day.name">{{${renderKey}}}</td> |
| 25 | + </template> |
| 26 | + `, |
| 27 | + }, |
| 28 | + }); |
| 29 | + |
| 30 | + return wrapper.findAll('td'); |
| 31 | +}; |
| 32 | + |
| 33 | +describe('DpCalendarGridHeadRow', () => { |
| 34 | + it('Should render properly', () => { |
| 35 | + const wrapper = mount(DpCalendarGridHeadRow, { global: getMockContext() }); |
| 36 | + expect(wrapper.html()).toContain('<tr>'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('Should fail to mount without context', () => { |
| 40 | + expect(() => mount(DpCalendarGridHeadRow)).toThrowError(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('Should render as custom HTML tag', () => { |
| 44 | + const wrapper = mount(DpCalendarGridHeadRow, { |
| 45 | + props: { as: 'div' }, |
| 46 | + global: getMockContext(), |
| 47 | + }); |
| 48 | + expect(wrapper.html()).toContain('<div>'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('Should expose week days with Monday first', () => { |
| 52 | + const cells = getRowElements(); |
| 53 | + |
| 54 | + expect(cells).toHaveLength(7); |
| 55 | + expect(cells[0].text()).toEqual('Monday'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('Should expose week days with Sunday first', () => { |
| 59 | + const cells = getRowElements({ weekStart: 0 }); |
| 60 | + |
| 61 | + expect(cells).toHaveLength(7); |
| 62 | + expect(cells[0].text()).toEqual('Sunday'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('Should localize week days', () => { |
| 66 | + const cells = getRowElements({ locale: 'ja-JP' }); |
| 67 | + expect(cells).toHaveLength(7); |
| 68 | + expect(cells[0].text()).toEqual('月曜日'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('Should display proper short name for Arabic locale', () => { |
| 72 | + const cells = getRowElements({ locale: 'ar' }, 'day.label'); |
| 73 | + expect(cells[0].text()).toEqual('اثن'); |
| 74 | + }); |
| 75 | +}); |
0 commit comments