Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from "react";
- import Pagination from "./Pagination.js";
- import PreviousPages from "../PreviousPages/PreviousPages.js";
- import NextPages from "../NextPages/NextPages.js";
- import Page from "../Page/Page.js";
- const exampleLinkFactory = () => (
- <a href={`#`} />
- );
- describe("Pagination/Pagination", () => {
- const defaultProps = {
- linkFactory: exampleLinkFactory
- };
- rendersComponent(Pagination, defaultProps);
- const wrapper = mount(
- <Pagination { ...defaultProps } />
- );
- it("renders a Page component for the current page", () => {
- expect(wrapper.find(Page).exists()).toEqual(true);
- expect(wrapper.find("div.-current").exists()).toEqual(true);
- });
- it("renders a PreviousPages component", () => {
- expect(wrapper.find(PreviousPages).exists()).toEqual(true);
- });
- it("renders a NextPages component", () => {
- expect(wrapper.find(NextPages).exists()).toEqual(true);
- });
- describe("when page and totalPages are zero", () => {
- const customProps = Object.assign({}, defaultProps, {
- page: 0,
- totalPages: 0
- });
- rendersComponent(Pagination, customProps);
- const wrapper = mount(
- <Pagination { ...customProps } />
- );
- it("renders no Page components", () => {
- expect(wrapper.find(Page).exists()).toEqual(false);
- });
- it("renders no PreviousPages component", () => {
- expect(wrapper.find(PreviousPages).exists()).toEqual(false);
- });
- it("renders no NextPages component", () => {
- expect(wrapper.find(NextPages).exists()).toEqual(false);
- });
- });
- describe("when current page is the first page", () => {
- const customProps = Object.assign({}, defaultProps, {
- page: 1,
- totalPages: 20
- });
- rendersComponent(Pagination, customProps);
- const wrapper = mount(
- <Pagination { ...customProps } />
- );
- it("renders five Page components: one for the current, two for the following pages and two for the NextPages component", () => {
- expect(wrapper.find(Page).length).toEqual(5);
- });
- });
- describe("when the current page is the last page", () => {
- const customProps = Object.assign({}, defaultProps, {
- page: 20,
- totalPages: 20
- });
- rendersComponent(Pagination, customProps);
- const newWrapper = mount(
- <Pagination { ...customProps } />
- );
- it("renders five Page components: one for the current, two for the following pages and two for the Previous component", () => {
- expect(newWrapper.find(Page).length).toEqual(5);
- });
- });
- describe("when the current page is 10 while there are 20 pages", () => {
- const customProps = Object.assign({}, defaultProps, {
- page: 10,
- totalPages: 20
- });
- rendersComponent(Pagination, customProps);
- const wrapper = mount(
- <Pagination { ...customProps } />
- );
- it("renders a PreviousPages component", () => {
- expect(wrapper.find(PreviousPages).exists()).toEqual(true);
- });
- it("renders a NextPages component", () => {
- expect(wrapper.find(NextPages).exists()).toEqual(true);
- });
- it("renders nine Page components: one for the current page, two for the following pages, two for the previous pages, two for the PreviousPages component and two for the NextPages component", () => {
- expect(wrapper.find(Page).length).toEqual(9);
- });
- });
- describe("when the current page is 2 while there are 20 pages", () => {
- const customProps = Object.assign({}, defaultProps, {
- page: 2,
- totalPages: 20
- });
- rendersComponent(Pagination, customProps);
- const wrapper = mount(
- <Pagination { ...customProps } />
- );
- it("renders a PreviousPages component", () => {
- expect(wrapper.find(PreviousPages).exists()).toEqual(true);
- });
- it("renders a NextPages component", () => {
- expect(wrapper.find(NextPages).exists()).toEqual(true);
- });
- it("renders eight Page components: one for the current page, two for the following pages, one for the previous page, two for the PreviousPages component and two for the NextPages component", () => {
- expect(wrapper.find(Page).length).toEqual(8);
- });
- });
- describe("when the current page is 19 while there are 20 pages", () => {
- const customProps = Object.assign({}, defaultProps, {
- page: 19,
- totalPages: 20
- });
- rendersComponent(Pagination, customProps);
- const wrapper = mount(
- <Pagination { ...customProps } />
- );
- it("renders a PreviousPages component", () => {
- expect(wrapper.find(PreviousPages).exists()).toEqual(true);
- });
- it("renders a NextPages component", () => {
- expect(wrapper.find(NextPages).exists()).toEqual(true);
- });
- it("renders eight Page components: one for the current page, one for the following page, two for the previous pages, two for the PreviousPages component and two for the NextPages component", () => {
- expect(wrapper.find(Page).length).toEqual(8);
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement