Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/_common
Submodule _common updated 176 files
113 changes: 113 additions & 0 deletions src/tree/__tests__/disabled-checking.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import {
describe, it, expect, afterEach, vi,
} from 'vitest';
import { mount as mountVue } from '@vue/test-utils';
import AfterTree from '@/src/tree/index.ts';

const modes = ['all', 'parentFirst', 'onlyLeaf'];
const data = [
{
value: 'P',
label: 'Parent',
children: [
{ value: 'A', label: 'A' },
{ value: 'B', label: 'B' },
{ value: 'D', label: 'Disabled', disabled: true },
],
},
];
const cleanup = [];
afterEach(() => {
cleanup.splice(0).forEach((fn) => fn());
});
async function mount(Component, mode, initial = []) {
const onChange = vi.fn();
const wrapper = mountVue(
{
data: () => ({ value: initial }),
render(h) {
return h(Component, {
props: {
data,
checkable: true,
expandAll: true,
transition: false,
valueMode: mode,
value: this.value,
onChange: (next, context) => {
onChange(next, context);
this.value = next;
},
},
});
},
},
{ attachTo: document.body },
);
cleanup.push(() => wrapper.destroy());
const host = wrapper.element;
const input = (id) => host.querySelector(`[data-value="${id}"] input[type="checkbox"]`);
await vi.waitFor(() => expect(input('D')).toBeTruthy());
return {
host,
value: {
get value() {
return wrapper.vm.value;
},
},
onChange,
input,
click: async (id) => {
input(id).click();
await wrapper.vm.$nextTick();
},
};
}
const expected = (mode) => {
if (mode === 'all') return ['P', 'A', 'B'];
if (mode === 'parentFirst') return ['P'];
return ['A', 'B'];
};
const half = (host, id) => host.querySelector(`[data-value="${id}"] .t-checkbox`).classList.contains('t-is-indeterminate');
describe('Tree disabled children controlled checking', () => {
it.each(modes)('fixed parent checking and cancellation round-trip in %s', async (mode) => {
const {
host, input, value, click,
} = await mount(AfterTree, mode);
await click('P');
await vi.waitFor(() => expect(input('P').checked).toBe(true));
expect(value.value).toEqual(expected(mode));
expect(half(host, 'P')).toBe(false);
expect(input('D').disabled).toBe(true);
expect(input('D').checked).toBe(false);
await click('P');
await vi.waitFor(() => expect(value.value).toEqual([]));
expect(input('P').checked).toBe(false);
expect(half(host, 'P')).toBe(false);
});
it.each(modes)('enabled children derive partial and full selection in %s', async (mode) => {
const {
host, input, value, click,
} = await mount(AfterTree, mode);
await click('A');
await vi.waitFor(() => expect(half(host, 'P')).toBe(true));
await click('B');
await vi.waitFor(() => expect(input('P').checked).toBe(true));
expect(half(host, 'P')).toBe(false);
expect(value.value).toEqual(expected(mode));
await click('A');
await vi.waitFor(() => expect(half(host, 'P')).toBe(true));
expect(value.value).toEqual(['B']);
});
it.each(['all', 'parentFirst'])('retains a selected disabled child in %s', async (mode) => {
const { input, value, click } = await mount(AfterTree, mode, ['D']);
await click('P');
await vi.waitFor(() => expect(input('P').checked).toBe(true));
expect(value.value).toEqual(mode === 'all' ? ['P', 'A', 'B', 'D'] : ['P', 'D']);
expect(input('D').checked).toBe(true);
await click('P');
await vi.waitFor(() => expect(value.value).toEqual(['D']));
expect(input('P').checked).toBe(false);
expect(input('D').checked).toBe(true);
});
});
12 changes: 6 additions & 6 deletions src/tree/__tests__/disabled.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ describe('Tree:disabled', () => {
expect(wrapper.find('[data-value="t1.1"] .t-checkbox').classes('t-is-checked')).toBe(false);
await wrapper.find('[data-value="t1"] input[type="checkbox"]').setChecked();
await delay(1);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-checked')).toBe(false);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-indeterminate')).toBe(true);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-checked')).toBe(true);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-indeterminate')).toBe(false);
expect(wrapper.find('[data-value="t1.1"] .t-checkbox').classes('t-is-checked')).toBe(false);
expect(wrapper.find('[data-value="t1.2"] .t-checkbox').classes('t-is-checked')).toBe(true);
await wrapper.find('[data-value="t1"] input[type="checkbox"]').setChecked(false);
Expand Down Expand Up @@ -328,7 +328,7 @@ describe('Tree:disabled', () => {
await wrapper.find('[data-value="t1"] input[type="checkbox"]').setChecked(false);
await delay(1);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-checked')).toBe(false);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-indeterminate')).toBe(true);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-indeterminate')).toBe(false);
expect(wrapper.find('[data-value="t1.1"] .t-checkbox').classes('t-is-checked')).toBe(true);
expect(wrapper.find('[data-value="t1.2"] .t-checkbox').classes('t-is-checked')).toBe(false);
});
Expand Down Expand Up @@ -375,15 +375,15 @@ describe('Tree:disabled', () => {
expect(wrapper.find('[data-value="t1.2"] .t-checkbox').classes('t-is-checked')).toBe(false);
await wrapper.find('[data-value="t1"] input[type="checkbox"]').setChecked();
await delay(1);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-checked')).toBe(false);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-indeterminate')).toBe(true);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-checked')).toBe(true);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-indeterminate')).toBe(false);
expect(wrapper.find('[data-value="t1.1"] .t-checkbox').classes('t-is-checked')).toBe(true);
expect(wrapper.find('[data-value="t1.2"] .t-checkbox').classes('t-is-checked')).toBe(false);
expect(wrapper.find('[data-value="t1.3"] .t-checkbox').classes('t-is-checked')).toBe(true);
await wrapper.find('[data-value="t1"] input[type="checkbox"]').setChecked(false);
await delay(1);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-checked')).toBe(false);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-indeterminate')).toBe(true);
expect(wrapper.find('[data-value="t1"] .t-checkbox').classes('t-is-indeterminate')).toBe(false);
expect(wrapper.find('[data-value="t1.1"] .t-checkbox').classes('t-is-checked')).toBe(true);
expect(wrapper.find('[data-value="t1.2"] .t-checkbox').classes('t-is-checked')).toBe(false);
expect(wrapper.find('[data-value="t1.3"] .t-checkbox').classes('t-is-checked')).toBe(false);
Expand Down
Loading