salix-front/test/vitest/__tests__/components/VnTable.spec.js

48 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-10-28 14:40:36 +00:00
import { describe, expect, it, beforeAll, beforeEach } from 'vitest';
import { createWrapper } from 'app/test/vitest/helper';
import VnTable from 'src/components/VnTable/VnTable.vue';
describe('VnTable', () => {
let wrapper;
let vm;
beforeAll(() => {
wrapper = createWrapper(VnTable, {
propsData: {
columns: [],
},
});
vm = wrapper.vm;
});
beforeEach(() => (vm.selected = []));
describe('handleSelection()', () => {
const rows = [{ $index: 0 }, { $index: 1 }, { $index: 2 }];
const selectedRows = [{ $index: 1 }];
2024-11-05 09:37:35 +00:00
it('should add rows to selected when shift key is pressed and rows are added except last one', () => {
2024-10-28 14:40:36 +00:00
vm.handleSelection(
{ evt: { shiftKey: true }, added: true, rows: selectedRows },
rows
);
2024-11-05 09:37:35 +00:00
expect(vm.selected).toEqual([{ $index: 0 }]);
2024-10-28 14:40:36 +00:00
});
it('should not add rows to selected when shift key is not pressed', () => {
vm.handleSelection(
{ evt: { shiftKey: false }, added: true, rows: selectedRows },
rows
);
expect(vm.selected).toEqual([]);
});
it('should not add rows to selected when rows are not added', () => {
vm.handleSelection(
{ evt: { shiftKey: true }, added: false, rows: selectedRows },
rows
);
expect(vm.selected).toEqual([]);
});
});
});