From c0e94978cd14cbc3bc62b66053f044761bcbaa73 Mon Sep 17 00:00:00 2001 From: Joseph Ojoko Date: Fri, 26 Jan 2024 21:49:24 +0100 Subject: [PATCH] chore: test table un/selection --- src/components/tables/DataTable.spec.ts | 47 +++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/components/tables/DataTable.spec.ts b/src/components/tables/DataTable.spec.ts index d49269d6..51da650b 100644 --- a/src/components/tables/DataTable.spec.ts +++ b/src/components/tables/DataTable.spec.ts @@ -207,6 +207,53 @@ describe('dataTable', () => { ).toBeTruthy(); }); + it('selection toggles correctly', async () => { + const wrapper = createWrapper({ + props: { + 'cols': columns, + 'modelValue': [], + 'onUpdate:modelValue': (e: any) => wrapper.setProps({ modelValue: e }), + 'rowAttr': 'id', + 'rows': data, + }, + }); + + expect(wrapper.props().modelValue).toHaveLength(0); + + expect( + wrapper + .find('thead tr [data-cy=table-toggle-check-all] input') + .exists(), + ).toBeTruthy(); + + await wrapper + .find('thead tr [data-cy=table-toggle-check-all] input') + .setValue(true); + + expect(wrapper.props().modelValue).toHaveLength(10); + + expect( + wrapper + .find('tr [data-cy*=table-toggle-check-] span[class*=checkbox][class*=checked]') + .exists(), + ).toBeTruthy(); + + expect( + wrapper + .findAll('tr [data-cy*=table-toggle-check-] span[class*=checkbox][class*=checked]'), + ).toHaveLength(11); + + await wrapper + .find('thead tr [data-cy=table-toggle-check-all] input') + .setValue(false); + + expect(wrapper.props().modelValue).toHaveLength(0); + + await wrapper.find('tr [data-cy=table-toggle-check-0] input').setValue(true); + + expect(wrapper.props().modelValue).toHaveLength(1); + }); + it('single expand toggles correctly', async () => { const wrapper = createWrapper({ props: {