|
| 1 | +import moment from 'moment'; |
| 2 | +import { createPinia, setActivePinia } from 'pinia'; |
| 3 | +import { shallowMount } from '@vue/test-utils'; |
| 4 | +import QueryOptions from '~/components/QueryOptions.vue'; |
| 5 | +import Search from '~/views/Search.vue'; |
| 6 | + |
| 7 | +const mockEnsureLoaded = jest.fn().mockResolvedValue(undefined); |
| 8 | + |
| 9 | +jest.mock('~/stores/buckets', () => ({ |
| 10 | + useBucketsStore: () => ({ |
| 11 | + ensureLoaded: mockEnsureLoaded, |
| 12 | + hosts: ['laptop'], |
| 13 | + }), |
| 14 | +})); |
| 15 | + |
| 16 | +describe('QueryOptions', () => { |
| 17 | + beforeEach(() => { |
| 18 | + setActivePinia(createPinia()); |
| 19 | + mockEnsureLoaded.mockClear(); |
| 20 | + }); |
| 21 | + |
| 22 | + test('renders date range values in native date inputs', async () => { |
| 23 | + const wrapper = shallowMount(QueryOptions, { |
| 24 | + propsData: { |
| 25 | + queryOptions: { |
| 26 | + start: '2026-08-15', |
| 27 | + stop: '2026-08-16', |
| 28 | + }, |
| 29 | + }, |
| 30 | + stubs: { |
| 31 | + 'b-form-group': { template: '<div><slot /></div>' }, |
| 32 | + 'b-form-select': true, |
| 33 | + 'b-form-checkbox': true, |
| 34 | + }, |
| 35 | + }); |
| 36 | + |
| 37 | + await wrapper.vm.$nextTick(); |
| 38 | + await wrapper.vm.$nextTick(); |
| 39 | + |
| 40 | + const dateInputs = wrapper.findAll('input[type="date"]'); |
| 41 | + expect(dateInputs).toHaveLength(2); |
| 42 | + expect(dateInputs.at(0).element.value).toBe('2026-08-15'); |
| 43 | + expect(dateInputs.at(1).element.value).toBe('2026-08-16'); |
| 44 | + }); |
| 45 | + |
| 46 | + test.each([Search])('initializes date ranges as YYYY-MM-DD strings', view => { |
| 47 | + const data = view.data(); |
| 48 | + |
| 49 | + expect(data.queryOptions.start).toMatch(/^\d{4}-\d{2}-\d{2}$/); |
| 50 | + expect(data.queryOptions.stop).toMatch(/^\d{4}-\d{2}-\d{2}$/); |
| 51 | + }); |
| 52 | + |
| 53 | + test.each([Search])('keeps extended ranges compatible with date inputs', view => { |
| 54 | + const vm = { |
| 55 | + queryOptions: { start: moment('2026-08-15') }, |
| 56 | + search: jest.fn(), |
| 57 | + generate: jest.fn(), |
| 58 | + }; |
| 59 | + |
| 60 | + view.methods.extendByWeek.call(vm); |
| 61 | + |
| 62 | + expect(vm.queryOptions.start).toBe('2026-08-08'); |
| 63 | + }); |
| 64 | +}); |
0 commit comments