All Downloads are FREE. Search and download functionalities are using the official Maven repository.

generator.client.pagination.secondary.RestPage.spec.ts.mustache Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
import { describe, expect, it } from 'vitest';
import { RestPage, toPage } from '@/shared/pagination/infrastructure/secondary/RestPage';
import { Page } from '@/shared/pagination/domain/Page';

describe('RestPage', () => {
  it('should map empty page', () => {
    expect(
      toPage(mapValue)({
        data: emptyRestPage(),
      }),
    ).toEqual(emptyPage());
  });

  it('should map to page', () => {
    expect(toPage(mapValue)({ data: restPage() })).toEqual(page());
  });
});

const mapValue = (value: string): string => value + value;

const emptyRestPage = () => ({
  currentPage: 0,
  pagesCount: 0,
  pageSize: 1,
  hasPrevious: false,
  hasNext: false,
  totalElementsCount: 0,
  content: [],
});

const emptyPage = () => ({
  currentPage: 1,
  pagesCount: 0,
  hasPrevious: false,
  hasNext: false,
  totalElementsCount: 0,
  displayed: { start: 0, end: 0 },
  content: [],
});

const restPage = (): RestPage => ({
  currentPage: 1,
  pagesCount: 5,
  pageSize: 1,
  hasPrevious: true,
  hasNext: true,
  totalElementsCount: 5,
  content: ['test'],
});

const page = (): Page => ({
  currentPage: 2,
  pagesCount: 5,
  hasPrevious: true,
  hasNext: true,
  totalElementsCount: 5,
  displayed: {
    start: 2,
    end: 2,
  },
  content: ['testtest'],
});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy