From 78e371d6084b1f84a5ada99a8cbe252a376ab085 Mon Sep 17 00:00:00 2001 From: Gilbert Pellegrom Date: Wed, 15 Nov 2023 12:06:30 +0000 Subject: [PATCH] Add test for parsing laravel-data pagination --- tests/unit/RenderlessPagination.spec.mjs | 63 ++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/unit/RenderlessPagination.spec.mjs b/tests/unit/RenderlessPagination.spec.mjs index 85dfc75..ceb33a6 100644 --- a/tests/unit/RenderlessPagination.spec.mjs +++ b/tests/unit/RenderlessPagination.spec.mjs @@ -164,3 +164,66 @@ test('parses paginate data', function () { expect(wrapper.vm.total).toEqual(resourcePaginateData.meta.total); expect(wrapper.vm.pageRange).toEqual(10); }); + +const dataPaginateData = { + data: [...Array(10).keys()], + links: [ + { + url: null, + label: '\u00ab Previous', + active: false, + }, + { + url: 'https://example.com/pagination?page=1', + label: '1', + active: true, + }, + { + url: 'https://example.com/pagination?page=2', + label: '2', + active: false, + }, + { + url: 'https://example.com/pagination?page=3', + label: 'Next \u00bb', + active: false, + }, + ], + meta: { + current_page: 1, + first_page_url: 'https://example.com/pagination?page=1', + from: 1, + last_page: 10, + last_page_url: 'https://example.com/pagination?page=10', + next_page_url: 'https://example.com/pagination?page=2', + path: 'https://example.com/pagination', + per_page: 10, + prev_page_url: null, + to: 10, + total: 100, + }, +}; + +test('parses paginate data', function () { + const wrapper = mount(RenderlessPagination, { + slots: { + default: '
', + }, + propsData: { + data: dataPaginateData, + }, + }); + + expect(wrapper.vm.isApiResource).toEqual(true); + expect(wrapper.vm.currentPage).toEqual(dataPaginateData.meta.current_page); + expect(wrapper.vm.firstPageUrl).toEqual(dataPaginateData.links.first); + expect(wrapper.vm.from).toEqual(dataPaginateData.meta.from); + expect(wrapper.vm.lastPage).toEqual(dataPaginateData.meta.last_page); + expect(wrapper.vm.lastPageUrl).toEqual(dataPaginateData.links.last); + expect(wrapper.vm.nextPageUrl).toEqual(dataPaginateData.links.next); + expect(wrapper.vm.perPage).toEqual(dataPaginateData.meta.per_page); + expect(wrapper.vm.prevPageUrl).toEqual(dataPaginateData.links.prev); + expect(wrapper.vm.to).toEqual(dataPaginateData.meta.to); + expect(wrapper.vm.total).toEqual(dataPaginateData.meta.total); + expect(wrapper.vm.pageRange).toEqual(10); +});