-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Specify error_id in combo box component. Add combo box component unit…
… test.
- Loading branch information
Showing
2 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
training-front-end/src/components/__tests__/USWDSComboBox.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { mount } from '@vue/test-utils'; | ||
import USWDSComboBox from "../form-components/USWDSComboBox.vue"; | ||
|
||
describe('USWDSComboBox', () => { | ||
it('renders properly', () => { | ||
const wrapper = mount(USWDSComboBox, { | ||
props: { | ||
modelValue: '', | ||
validator: { | ||
$error: false, | ||
$errors: [] | ||
}, | ||
name: 'testAgency', | ||
label: 'Test Agency', | ||
items: [ | ||
{ id: 1, name: 'Option 1' }, | ||
{ id: 2, name: 'Option 2' }, | ||
{ id: 3, name: 'Option 3' } | ||
], | ||
required: true | ||
} | ||
}) | ||
|
||
expect(wrapper.find('.usa-form-group').exists()).toBe(true) | ||
expect(wrapper.find('.usa-label').text()).toBe('Test Agency (*Required)') | ||
expect(wrapper.findAll('option').length).toBe(3) | ||
}) | ||
|
||
it('displays errors when validator has errors', async () => { | ||
const wrapper = mount(USWDSComboBox, { | ||
props: { | ||
modelValue: '', | ||
validator: { | ||
$error: true, | ||
$errors: [{ $property: 'agency', $message: 'Agency is required' }] | ||
}, | ||
name: 'testAgency', | ||
label: 'Test Agency', | ||
items: [ | ||
{ id: 1, name: 'Option 1' }, | ||
{ id: 2, name: 'Option 2' }, | ||
{ id: 3, name: 'Option 3' } | ||
] | ||
} | ||
}) | ||
|
||
expect(wrapper.find('.usa-form-group--error').exists()).toBe(true) | ||
expect(wrapper.find('.usa-error-message').text()).toBe('Agency is required') | ||
}) | ||
|
||
it('emits update:modelValue event on select', async () => { | ||
const wrapper = mount(USWDSComboBox, { | ||
props: { | ||
modelValue: '', | ||
validator: { | ||
$error: false, | ||
$errors: [] | ||
}, | ||
name: 'testAgency', | ||
label: 'Test Agency', | ||
items: [ | ||
{ id: 1, name: 'Option 1' }, | ||
{ id: 2, name: 'Option 2' }, | ||
{ id: 3, name: 'Option 3' } | ||
] | ||
} | ||
}) | ||
|
||
const select = wrapper.find('select') | ||
await select.setValue('1') | ||
|
||
expect(wrapper.emitted('update:modelValue')).toBeTruthy() | ||
expect(wrapper.emitted('update:modelValue')[0]).toEqual(['1']) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters