Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from "react";
  2.  
  3. import Pagination from "./Pagination.js";
  4.  
  5. import PreviousPages from "../PreviousPages/PreviousPages.js";
  6. import NextPages from "../NextPages/NextPages.js";
  7. import Page from "../Page/Page.js";
  8.  
  9. const exampleLinkFactory = () => (
  10.   <a href={`#`} />
  11. );
  12.  
  13. describe("Pagination/Pagination", () => {
  14.   const defaultProps = {
  15.     linkFactory: exampleLinkFactory
  16.   };
  17.  
  18.   rendersComponent(Pagination, defaultProps);
  19.  
  20.   const wrapper = mount(
  21.     <Pagination { ...defaultProps } />
  22.   );
  23.  
  24.   it("renders a Page component for the current page", () => {
  25.     expect(wrapper.find(Page).exists()).toEqual(true);
  26.     expect(wrapper.find("div.-current").exists()).toEqual(true);
  27.   });
  28.  
  29.   it("renders a PreviousPages component", () => {
  30.     expect(wrapper.find(PreviousPages).exists()).toEqual(true);
  31.   });
  32.  
  33.   it("renders a NextPages component", () => {
  34.     expect(wrapper.find(NextPages).exists()).toEqual(true);
  35.   });
  36.  
  37.   describe("when page and totalPages are zero", () => {
  38.     const customProps = Object.assign({}, defaultProps, {
  39.       page: 0,
  40.       totalPages: 0
  41.     });
  42.  
  43.     rendersComponent(Pagination, customProps);
  44.  
  45.     const wrapper = mount(
  46.       <Pagination { ...customProps } />
  47.     );
  48.  
  49.     it("renders no Page components", () => {
  50.       expect(wrapper.find(Page).exists()).toEqual(false);
  51.     });
  52.  
  53.     it("renders no PreviousPages component", () => {
  54.       expect(wrapper.find(PreviousPages).exists()).toEqual(false);
  55.     });
  56.  
  57.     it("renders no NextPages component", () => {
  58.       expect(wrapper.find(NextPages).exists()).toEqual(false);
  59.     });
  60.   });
  61.  
  62.   describe("when current page is the first page", () => {
  63.     const customProps = Object.assign({}, defaultProps, {
  64.       page: 1,
  65.       totalPages: 20
  66.     });
  67.  
  68.     rendersComponent(Pagination, customProps);
  69.  
  70.     const wrapper = mount(
  71.       <Pagination { ...customProps } />
  72.     );
  73.  
  74.     it("renders five Page components: one for the current, two for the following pages and two for the NextPages component", () => {
  75.       expect(wrapper.find(Page).length).toEqual(5);
  76.     });
  77.   });
  78.  
  79.   describe("when the current page is the last page", () => {
  80.     const customProps = Object.assign({}, defaultProps, {
  81.       page: 20,
  82.       totalPages: 20
  83.     });
  84.  
  85.     rendersComponent(Pagination, customProps);
  86.  
  87.     const newWrapper = mount(
  88.       <Pagination { ...customProps } />
  89.     );
  90.  
  91.     it("renders five Page components: one for the current, two for the following pages and two for the Previous component", () => {
  92.       expect(newWrapper.find(Page).length).toEqual(5);
  93.     });
  94.   });
  95.  
  96.   describe("when the current page is 10 while there are 20 pages", () => {
  97.     const customProps = Object.assign({}, defaultProps, {
  98.       page: 10,
  99.       totalPages: 20
  100.     });
  101.  
  102.     rendersComponent(Pagination, customProps);
  103.  
  104.     const wrapper = mount(
  105.       <Pagination { ...customProps } />
  106.     );
  107.  
  108.     it("renders a PreviousPages component", () => {
  109.       expect(wrapper.find(PreviousPages).exists()).toEqual(true);
  110.     });
  111.  
  112.     it("renders a NextPages component", () => {
  113.       expect(wrapper.find(NextPages).exists()).toEqual(true);
  114.     });
  115.  
  116.     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", () => {
  117.       expect(wrapper.find(Page).length).toEqual(9);
  118.     });
  119.   });
  120.  
  121.   describe("when the current page is 2 while there are 20 pages", () => {
  122.     const customProps = Object.assign({}, defaultProps, {
  123.       page: 2,
  124.       totalPages: 20
  125.     });
  126.  
  127.     rendersComponent(Pagination, customProps);
  128.  
  129.     const wrapper = mount(
  130.       <Pagination { ...customProps } />
  131.     );
  132.  
  133.     it("renders a PreviousPages component", () => {
  134.       expect(wrapper.find(PreviousPages).exists()).toEqual(true);
  135.     });
  136.  
  137.     it("renders a NextPages component", () => {
  138.       expect(wrapper.find(NextPages).exists()).toEqual(true);
  139.     });
  140.  
  141.     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", () => {
  142.       expect(wrapper.find(Page).length).toEqual(8);
  143.     });
  144.   });
  145.  
  146.   describe("when the current page is 19 while there are 20 pages", () => {
  147.     const customProps = Object.assign({}, defaultProps, {
  148.       page: 19,
  149.       totalPages: 20
  150.     });
  151.  
  152.     rendersComponent(Pagination, customProps);
  153.  
  154.     const wrapper = mount(
  155.       <Pagination { ...customProps } />
  156.     );
  157.  
  158.     it("renders a PreviousPages component", () => {
  159.       expect(wrapper.find(PreviousPages).exists()).toEqual(true);
  160.     });
  161.  
  162.     it("renders a NextPages component", () => {
  163.       expect(wrapper.find(NextPages).exists()).toEqual(true);
  164.     });
  165.  
  166.     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", () => {
  167.       expect(wrapper.find(Page).length).toEqual(8);
  168.     });
  169.   });
  170. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement