UNPKG

3.85 kBJavaScriptView Raw
1import React from 'react';
2import {shallow, mount, render} from 'enzyme';
3import {expect} from 'chai';
4import Pagination from '../src/index'
5import App from '../demo/PaginationDemo.js'
6
7
8describe('Pagination test', function() {
9
10 it('Pagination should be exist', function() {
11
12
13 let pagination = mount(<Pagination />);
14
15 expect(pagination.find('ul').hasClass('u-pagination')).to.equal(true);
16
17 })
18
19 it('Pagination length should be right', function() {
20
21
22 let pagination = mount(<Pagination items={10}/>);
23
24
25 expect(pagination.find('ul').find('li').length).to.equal(10);
26
27 })
28
29 it('no border page button should be exist', function() {
30
31
32 let pagination = mount(<Pagination items={10} activePage={2} noBorder/>);
33
34 expect(pagination.find('ul').hasClass('u-pagination-no-border')).to.equal(true);
35
36 })
37
38 it('gap page button should be exist', function() {
39
40
41 let pagination = mount(<Pagination items={10} activePage={2} gap/>);
42
43 expect(pagination.find('ul').hasClass('u-pagination-gap')).to.equal(true);
44
45 })
46
47 it('lg size should be right', function() {
48
49
50 let pagination = mount(<Pagination items={10} activePage={2} size="lg"/>);
51
52 expect(pagination.find('ul').hasClass('u-pagination-lg')).to.equal(true);
53
54 })
55
56 it('sm size should be right', function() {
57
58
59 let pagination = mount(<Pagination items={10} activePage={2} size="sm"/>);
60
61 expect(pagination.find('ul').hasClass('u-pagination-sm')).to.equal(true);
62
63 })
64
65 it('active page should be right', function() {
66
67
68 let pagination = mount(<Pagination items={10} activePage={2}/>);
69
70 expect(pagination.find('ul').find('li').at(1).hasClass('active')).to.equal(true);
71
72 })
73
74 it('previous button should be exist', function() {
75
76
77 let pagination = mount(<Pagination prev items={10} activePage={2}/>);
78
79 expect(pagination.find('ul').find('li').at(0).find('span').prop('aria-label')).to.equal('Previous');
80
81 })
82 it('next button should be exist', function() {
83
84
85 let pagination = mount(<Pagination prev next items={10} activePage={2}/>);
86
87 expect(pagination.find('ul').find('li').last().find('span').prop('aria-label')).to.equal('Next');
88
89 })
90 it('first button should be exist', function() {
91
92
93 let pagination = mount(<Pagination first prev next items={10} activePage={2}/>);
94
95 expect(pagination.find('ul').find('li').at(0).find('span').prop('aria-label')).to.equal('First');
96
97 })
98 it('last button should be exist', function() {
99
100
101 let pagination = mount(<Pagination first prev next last items={10} activePage={2}/>);
102
103 expect(pagination.find('ul').find('li').last().find('span').prop('aria-label')).to.equal('Last');
104
105 })
106 it('more button should be exist', function() {
107
108
109 let pagination = mount(<Pagination items={10} activePage={2} maxButtons={5}/>);
110
111 expect(pagination.find('ul').find('li').at(5).find('span').prop('aria-label')).to.equal('More');
112
113 })
114 it('last boundary text should be 10', function() {
115
116
117 let pagination = mount(<Pagination boundaryLinks items={10} activePage={2} maxButtons={5}/>);
118
119 expect(pagination.find('ul').find('li').last().text()).to.equal('10');
120
121 })
122 it('fist boundary text should be 10', function() {
123
124
125 let pagination = mount(<Pagination boundaryLinks items={10} activePage={2} maxButtons={5}/>);
126
127 expect(pagination.find('ul').find('li').at(0).text()).to.equal('1');
128
129 })
130
131})
132
133describe('App test', function() {
134
135 it('before more button should be show when click the maxButtons', function() {
136
137
138 let app = mount(<App />);
139
140 app.setState({activePage:5});
141
142 expect(app.find('li').at(3).find('span').prop('aria-label')).to.equal('More');
143
144 })
145 it('after more button should be show when click the maxButtons', function() {
146
147
148 let app = mount(<App />);
149
150 app.setState({activePage:5});
151
152 expect(app.find('li').at(9).find('span').prop('aria-label')).to.equal('More');
153
154 })
155})
\No newline at end of file