From 1c1060581d203379b671727e29861fae1e16c1ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Fri, 18 Mar 2022 16:11:09 +0300 Subject: [PATCH] Create Paginator.spec.js --- src/components/paginator/Paginator.spec.js | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/components/paginator/Paginator.spec.js diff --git a/src/components/paginator/Paginator.spec.js b/src/components/paginator/Paginator.spec.js new file mode 100644 index 000000000..1894fc4ab --- /dev/null +++ b/src/components/paginator/Paginator.spec.js @@ -0,0 +1,50 @@ +import { mount } from '@vue/test-utils'; +import Paginator from './Paginator.vue'; + +describe('Paginator.vue', () => { + let wrapper; + + beforeEach(() => { + wrapper = mount(Paginator, { + props: { + rows: 10, + totalRecords: 120, + rowsPerPageOptions: [10,20,30] + } + }); + }); + + it('should exist', () => { + expect(wrapper.find('.p-paginator.p-component').exists()).toBe(true); + expect(wrapper.find('.p-paginator-icon.pi-angle-double-left').exists()).toBe(true); + expect(wrapper.find('.p-paginator-icon.pi-angle-right').exists()).toBe(true); + expect(wrapper.findAll('.p-paginator-page.p-paginator-element').length).toBe(5); + expect(wrapper.find('.p-dropdown.p-component').exists()).toBe(true); + expect(wrapper.find('.p-dropdown-label').text()).toBe('10'); + expect(wrapper.find('.p-paginator-first').classes()).toContain('p-disabled'); + expect(wrapper.find('.p-paginator-prev').classes()).toContain('p-disabled'); + expect(wrapper.vm.pageCount).toBe(12); + }); + + it('show jump to the end', async () => { + await wrapper.vm.changePageToLast({ preventDefault: () => {} }); + + expect(wrapper.findAll('.p-paginator-page.p-paginator-element')[4].classes()).toContain('p-highlight'); + expect(wrapper.findAll('.p-paginator-page.p-paginator-element')[4].text()).toBe('12'); + expect(wrapper.find('.p-paginator-next').classes()).toContain('p-disabled'); + expect(wrapper.find('.p-paginator-last').classes()).toContain('p-disabled'); + }); + + it('should change row count', async () => { + await wrapper.vm.onRowChange(20); + + expect(wrapper.vm.d_rows).toBe(20); + expect(wrapper.emitted()['update:rows'][0]).toEqual([20]); + expect(wrapper.vm.pageCount).toBe(6); + + await wrapper.setProps({ rows: 20 }); + + console.log(wrapper.html()) + expect(wrapper.find('.p-dropdown-label').text()).toBe('20'); + }); +}); \ No newline at end of file