import { flushPromises, mount } from '@vue/test-utils'; import AnnotationDataTable from '@/components/navigation/annotation/AnnotationDataTable.vue'; import { VBtn, VDataTableVirtual, VTextField } from 'vuetify/components'; describe('AnnotationDataTable tests', () => { it('should mount', async () => { const wrapper = mount(AnnotationDataTable, { drawer: true }); await flushPromises(); expect(wrapper).toBeTruthy(); }); it('should update search', async () => { const wrapper = mount(AnnotationDataTable, { drawer: true }); await wrapper.findComponent(VTextField).setValue('123'); await flushPromises(); expect(wrapper.vm.search).toBe('123'); }); it('should clear search', async () => { const wrapper = mount(AnnotationDataTable, { drawer: true }); await wrapper.findComponent(VTextField).setValue('123'); await flushPromises(); expect(wrapper.vm.search).toBe('123'); await wrapper.findComponent(VBtn).trigger('click'); expect(wrapper.vm.search).toBe(''); }); it('should update expanded', async () => { const wrapper = mount(AnnotationDataTable, { drawer: true }); await wrapper .findComponent(VDataTableVirtual) .setValue(['123'], 'expanded'); await flushPromises(); expect(wrapper.vm.expanded).toStrictEqual(['123']); }); it('should check header props', async () => { const wrapper = mount(AnnotationDataTable, { drawer: true }); const table = wrapper.findComponent(VDataTableVirtual); for (const header of table.props().headers!!) { if (header.cellProps) { expect( (header.cellProps as any)({ item: { Id: '123' } } as any), ).not.toContain('bg-minsk_100'); } if (header.sortRaw) { expect(header.sortRaw!!({ Title: '123' }, { Title: '234' })).toBe(-1); } } }); it('should filter', async () => { const wrapper = mount(AnnotationDataTable, { drawer: true }); expect( wrapper.vm.filter('123', 'title-to-find', { raw: { Title: 'title-to-find', }, }), ).toBe(true); }); it('should filter', async () => { const wrapper = mount(AnnotationDataTable, { drawer: true }); expect( wrapper.vm.filter('123', 'title-not-to-find', { raw: { Title: 'title-to-find', }, }), ).toBe(false); }); });