UNPKG

@websolutespa/payload-plugin-bowl

Version:

Bowl PayloadCms plugin of the BOM Repository

175 lines (174 loc) 6.92 kB
import { beforeAll, describe, expect, it } from 'vitest'; import { getPagination } from './pagination.service'; describe('pagination.service', ()=>{ let entities; beforeAll(async ()=>{ entities = [ { id: 'foo' }, { id: 'bar' } ]; }); describe('getPagination(entities, 1, 1): one item per page, first page', ()=>{ let result; beforeAll(async ()=>{ result = await getPagination(entities, 1, 1); }); it('should return the first doc', async ()=>{ expect(result.docs[0].id).toEqual('foo'); }); it('should have a totalDocs property of 2', async ()=>{ expect(result.totalDocs).toEqual(2); }); it('should have a totalPages property of 2', async ()=>{ expect(result.totalPages).toEqual(2); }); it('should have a page property of 1', async ()=>{ expect(result.page).toEqual(1); }); it('should have a limit property of 1', async ()=>{ expect(result.limit).toEqual(1); }); it('should have a hasNextPage property of true', async ()=>{ expect(result.hasNextPage).toEqual(true); }); it('should have a hasPrevPage property of false', async ()=>{ expect(result.hasPrevPage).toEqual(false); }); it('should have a nextPage property of 2', async ()=>{ expect(result.nextPage).toEqual(2); }); it('should have a prevPage property of null', async ()=>{ expect(result.prevPage).toEqual(null); }); it('should have a pagingCounter property of 1', async ()=>{ expect(result.pagingCounter).toEqual(1); }); it('should have a docs property of length 1', async ()=>{ expect(result.docs.length).toEqual(1); }); }); describe('getPagination(entities, 2, 1): one item per page, second page', ()=>{ let result; beforeAll(async ()=>{ result = await getPagination(entities, 2, 1); }); it('should return the second doc', async ()=>{ expect(result.docs[0].id).toEqual('bar'); }); it('should have a totalDocs property of 2', async ()=>{ expect(result.totalDocs).toEqual(2); }); it('should have a totalPages property of 2', async ()=>{ expect(result.totalPages).toEqual(2); }); it('should have a page property of 2', async ()=>{ expect(result.page).toEqual(2); }); it('should have a limit property of 1', async ()=>{ expect(result.limit).toEqual(1); }); it('should have a hasNextPage property of false', async ()=>{ expect(result.hasNextPage).toEqual(false); }); it('should have a hasPrevPage property of true', async ()=>{ expect(result.hasPrevPage).toEqual(true); }); it('should have a nextPage property of null', async ()=>{ expect(result.nextPage).toEqual(null); }); it('should have a prevPage property of 1', async ()=>{ expect(result.prevPage).toEqual(1); }); it('should have a pagingCounter property of 2', async ()=>{ expect(result.pagingCounter).toEqual(2); }); it('should have a docs property of length 1', async ()=>{ expect(result.docs.length).toEqual(1); }); }); describe('getPagination(entities, 1, 2): two items per page, first page', ()=>{ let result; beforeAll(async ()=>{ result = await getPagination(entities, 1, 2); }); it('should return the first 2 docs', async ()=>{ expect(result.docs.length).toEqual(2); expect(result.docs[0].id).toEqual('foo'); expect(result.docs[1].id).toEqual('bar'); }); it('should have a totalDocs property of 2', async ()=>{ expect(result.totalDocs).toEqual(2); }); it('should have a totalPages property of 1', async ()=>{ expect(result.totalPages).toEqual(1); }); it('should have a page property of 1', async ()=>{ expect(result.page).toEqual(1); }); it('should have a limit property of 2', async ()=>{ expect(result.limit).toEqual(2); }); it('should have a hasNextPage property of false', async ()=>{ expect(result.hasNextPage).toEqual(false); }); it('should have a hasPrevPage property of false', async ()=>{ expect(result.hasPrevPage).toEqual(false); }); it('should have a nextPage property of null', async ()=>{ expect(result.nextPage).toEqual(null); }); it('should have a prevPage property of null', async ()=>{ expect(result.prevPage).toEqual(null); }); it('should have a pagingCounter property of 1', async ()=>{ expect(result.pagingCounter).toEqual(1); }); it('should have a docs property of length 2', async ()=>{ expect(result.docs.length).toEqual(2); }); }); describe('getPagination(entities, 2, 2): two items per page, second page', ()=>{ let result; beforeAll(async ()=>{ result = await getPagination(entities, 2, 2); }); it('should return the second 2 docs', async ()=>{ expect(result.docs.length).toEqual(0); }); it('should have a totalDocs property of 2', async ()=>{ expect(result.totalDocs).toEqual(2); }); it('should have a totalPages property of 1', async ()=>{ expect(result.totalPages).toEqual(1); }); it('should have a page property of 2', async ()=>{ expect(result.page).toEqual(2); }); it('should have a limit property of 2', async ()=>{ expect(result.limit).toEqual(2); }); it('should have a hasNextPage property of false', async ()=>{ expect(result.hasNextPage).toEqual(false); }); it('should have a hasPrevPage property of true', async ()=>{ expect(result.hasPrevPage).toEqual(true); }); it('should have a nextPage property of null', async ()=>{ expect(result.nextPage).toEqual(null); }); it('should have a prevPage property of 1', async ()=>{ expect(result.prevPage).toEqual(1); }); it('should have a pagingCounter property of 3', async ()=>{ expect(result.pagingCounter).toEqual(3); }); it('should have a docs property of length 0', async ()=>{ expect(result.docs.length).toEqual(0); }); }); }); //# sourceMappingURL=pagination.service.test.js.map