2020-07-25 13:27:58 +00:00
|
|
|
import * as Vue from 'vue';
|
2019-01-12 03:33:27 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import SelectionBox from '../SelectionBox';
|
2018-06-01 13:25:16 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const getDefaultStore = selectedRowKeys => {
|
2021-02-27 14:50:21 +00:00
|
|
|
return Vue.reactive({
|
2018-06-01 13:25:16 +00:00
|
|
|
selectedRowKeys: selectedRowKeys || [],
|
|
|
|
selectionDirty: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
};
|
2018-06-01 13:25:16 +00:00
|
|
|
|
|
|
|
describe('SelectionBox', () => {
|
|
|
|
it('unchecked by selectedRowKeys ', () => {
|
|
|
|
const wrapper = mount(SelectionBox, {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2018-06-01 13:25:16 +00:00
|
|
|
store: getDefaultStore(),
|
|
|
|
rowIndex: '1',
|
|
|
|
disabled: false,
|
|
|
|
onChange: () => {},
|
|
|
|
defaultSelection: [],
|
|
|
|
},
|
|
|
|
listeners: {
|
|
|
|
change: () => {},
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-01 13:25:16 +00:00
|
|
|
|
2021-02-27 14:50:21 +00:00
|
|
|
expect(wrapper.vm.checked).toEqual(false);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-01 13:25:16 +00:00
|
|
|
|
|
|
|
it('checked by selectedRowKeys ', () => {
|
|
|
|
const wrapper = mount(SelectionBox, {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2018-06-01 13:25:16 +00:00
|
|
|
store: getDefaultStore(['1']),
|
|
|
|
rowIndex: '1',
|
|
|
|
disabled: false,
|
|
|
|
onChange: () => {},
|
|
|
|
defaultSelection: [],
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-01 13:25:16 +00:00
|
|
|
|
2021-02-27 14:50:21 +00:00
|
|
|
expect(wrapper.vm.checked).toEqual(true);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-01 13:25:16 +00:00
|
|
|
|
|
|
|
it('checked by defaultSelection', () => {
|
|
|
|
const wrapper = mount(SelectionBox, {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2018-06-01 13:25:16 +00:00
|
|
|
store: getDefaultStore(),
|
|
|
|
rowIndex: '1',
|
|
|
|
disabled: false,
|
|
|
|
onChange: () => {},
|
|
|
|
defaultSelection: ['1'],
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2021-02-27 14:50:21 +00:00
|
|
|
expect(wrapper.vm.checked).toEqual(true);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-01 13:25:16 +00:00
|
|
|
|
|
|
|
it('checked when store change', () => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const store = getDefaultStore();
|
2018-06-01 13:25:16 +00:00
|
|
|
const wrapper = mount(SelectionBox, {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2020-03-18 06:52:02 +00:00
|
|
|
store,
|
2018-06-01 13:25:16 +00:00
|
|
|
rowIndex: '1',
|
|
|
|
disabled: false,
|
2020-08-12 08:30:13 +00:00
|
|
|
onChange: () => {},
|
2018-06-01 13:25:16 +00:00
|
|
|
defaultSelection: [],
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-01 13:25:16 +00:00
|
|
|
|
2021-02-27 14:50:21 +00:00
|
|
|
store.selectedRowKeys = ['1'];
|
|
|
|
store.selectionDirty = true;
|
2018-06-01 13:25:16 +00:00
|
|
|
|
2021-02-27 14:50:21 +00:00
|
|
|
expect(wrapper.vm.checked).toEqual(true);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-01 13:25:16 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
it('passes props to Checkbox', done => {
|
2018-06-01 13:25:16 +00:00
|
|
|
const checkboxProps = {
|
|
|
|
name: 'testName',
|
|
|
|
id: 'testId',
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-06-01 13:25:16 +00:00
|
|
|
const wrapper = mount(SelectionBox, {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2018-06-01 13:25:16 +00:00
|
|
|
store: getDefaultStore(),
|
|
|
|
rowIndex: '1',
|
|
|
|
disabled: false,
|
2020-08-12 08:30:13 +00:00
|
|
|
onChange: () => {},
|
2018-06-01 13:25:16 +00:00
|
|
|
defaultSelection: ['1'],
|
|
|
|
...checkboxProps,
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-01 13:25:16 +00:00
|
|
|
Vue.nextTick(() => {
|
2020-08-12 08:30:13 +00:00
|
|
|
wrapper.findAllComponents({ name: 'ACheckbox' }).forEach(box => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(box.props().name).toEqual(checkboxProps.name);
|
|
|
|
expect(box.props().id).toEqual(checkboxProps.id);
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-06-01 13:25:16 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
it('passes props to Radios', done => {
|
2018-06-01 13:25:16 +00:00
|
|
|
const radioProps = {
|
|
|
|
name: 'testName',
|
|
|
|
id: 'testId',
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-06-01 13:25:16 +00:00
|
|
|
const wrapper = mount(SelectionBox, {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: {
|
2018-06-01 13:25:16 +00:00
|
|
|
store: getDefaultStore(),
|
|
|
|
rowIndex: '1',
|
|
|
|
disabled: false,
|
2020-08-12 08:30:13 +00:00
|
|
|
onChange: () => {},
|
2018-06-01 13:25:16 +00:00
|
|
|
defaultSelection: ['1'],
|
|
|
|
type: 'radio',
|
|
|
|
...radioProps,
|
|
|
|
},
|
|
|
|
sync: false,
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-01 13:25:16 +00:00
|
|
|
Vue.nextTick(() => {
|
2020-08-12 08:30:13 +00:00
|
|
|
wrapper.findAllComponents({ name: 'ARadio' }).forEach(radio => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(radio.props().name).toEqual(radioProps.name);
|
|
|
|
expect(radio.props().id).toEqual(radioProps.id);
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|