2023-04-28 13:58:46 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2022-09-06 12:03:37 +00:00
|
|
|
import TriStateCheckbox from './TriStateCheckbox.vue';
|
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
let wrapper;
|
|
|
|
const modelValues = [true, false, null];
|
|
|
|
const emittedResults = [false, null, true];
|
2022-09-06 12:03:37 +00:00
|
|
|
|
2022-09-14 11:26:01 +00:00
|
|
|
describe('TriStateCheckbox.vue', () => {
|
2022-09-06 12:03:37 +00:00
|
|
|
beforeEach(() => {
|
2022-09-14 11:26:01 +00:00
|
|
|
wrapper = mount(TriStateCheckbox);
|
2022-12-09 09:18:21 +00:00
|
|
|
});
|
2022-09-14 11:26:01 +00:00
|
|
|
|
|
|
|
it('When onBlur is triggered focused property should be false', async () => {
|
|
|
|
wrapper.vm.onBlur();
|
|
|
|
|
|
|
|
expect(wrapper.vm.focused).toBeFalsy();
|
|
|
|
expect(wrapper.emitted().blur).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2022-12-09 09:18:21 +00:00
|
|
|
|
|
|
|
describe('UpdateModel method tests', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = mount(TriStateCheckbox);
|
|
|
|
});
|
|
|
|
|
2024-01-18 08:14:47 +00:00
|
|
|
it('When disable props true change emit should not triggered', async () => {
|
2022-12-09 09:18:21 +00:00
|
|
|
await wrapper.setProps({
|
|
|
|
disabled: true,
|
|
|
|
modelValue: null
|
|
|
|
});
|
|
|
|
|
2024-01-18 08:14:47 +00:00
|
|
|
await wrapper.trigger('change');
|
2022-12-09 09:18:21 +00:00
|
|
|
|
2024-01-18 08:14:47 +00:00
|
|
|
expect(wrapper.emitted()['change']).toBeFalsy();
|
2022-12-09 09:18:21 +00:00
|
|
|
});
|
|
|
|
|
2022-12-09 09:20:24 +00:00
|
|
|
it('When disable props false updateModal should triggered emit', () => {
|
2022-12-09 09:18:21 +00:00
|
|
|
wrapper.vm.updateModel();
|
|
|
|
|
|
|
|
expect(wrapper.emitted()['update:modelValue']).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
modelValues.forEach((modelValue, index) => {
|
|
|
|
it('When modelValue changed update model emitted value should be change', async () => {
|
|
|
|
await wrapper.setProps({
|
|
|
|
modelValue
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.updateModel();
|
|
|
|
|
|
|
|
expect(wrapper.emitted()['update:modelValue']).toEqual([[emittedResults[index]]]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|