Files
sensor-web-v2/tests/components/TimeWindows.test.ts

32 lines
982 B
TypeScript

import { expect, test, describe } from 'vitest'
import { shallowMount } from '@vue/test-utils'
import TimeWindows from '@/components/TimeWindows.vue'
import type { Window } from '@/utils/types'
import { windows } from '@/utils/helpers'
const getWrapper = () => {
return shallowMount(TimeWindows, {
props: {
activeWindow: windows[1],
windows
}
})
}
describe('TimeWindows', () => {
test('renders time windows correctly', () => {
const wrapper = getWrapper()
const listItems = wrapper.findAll('li')
expect(listItems.at(0)?.text()).toContain(windows[0].label)
expect(listItems.at(1)?.classes('is-active')).toBe(true)
})
test('emits an event when a time window is clicked', async () => {
const wrapper = getWrapper()
const listItems = wrapper.findAll('li')
await listItems.at(0)?.trigger('click')
const event = (wrapper.emitted('set-window') || [])[0][0] as Window
expect(event.label).toEqual('afgelopen uur')
})
})