import { mount } from '@vue/test-utils' import { describe, expect, it } from 'vitest' import BaseSelect from '../../components/BaseSelect.vue' describe('BaseSelect', () => { it('forwards native attributes to the select instead of the wrapper', () => { const wrapper = mount(BaseSelect, { props: { options: ['linear'], }, attrs: { id: 'curve-model', name: 'curve-model', 'aria-label': 'Curve model', 'data-testid': 'curve-model-select', class: 'curve-model-layout', style: 'width: 12rem;', }, }) const select = wrapper.get('select') expect({ select: { id: select.attributes('id'), name: select.attributes('name'), ariaLabel: select.attributes('aria-label'), testId: select.attributes('data-testid'), layoutClass: select.classes().includes('curve-model-layout'), }, wrapper: { id: wrapper.attributes('id'), name: wrapper.attributes('name'), ariaLabel: wrapper.attributes('aria-label'), testId: wrapper.attributes('data-testid'), layoutClass: wrapper.classes().includes('curve-model-layout'), style: wrapper.attributes('style'), }, }).toEqual({ select: { id: 'curve-model', name: 'curve-model', ariaLabel: 'Curve model', testId: 'curve-model-select', layoutClass: false, }, wrapper: { id: undefined, name: undefined, ariaLabel: undefined, testId: undefined, layoutClass: true, style: 'width: 12rem;', }, }) }) it('accepts string and number shorthand options', async () => { const wrapper = mount(BaseSelect, { props: { modelValue: 'linear', options: ['linear', 96, { value: 'log', label: 'Log scale' }], }, }) const options = wrapper.findAll('option') expect(options.map(option => option.text())).toEqual(['linear', '96', 'Log scale']) await wrapper.get('select').setValue('96') expect(wrapper.emitted('update:modelValue')?.[0]).toEqual([96]) }) })