|
1 |
| -/* global expect: false, it: false, describe: false */ |
2 | 1 | "use strict";
|
3 |
| -describe("Angular Pagination", function(){ |
| 2 | +describe("Angular Pagination",function(){ |
4 | 3 | var pg
|
5 | 4 | // load the app
|
6 | 5 | beforeEach(module("pagination"))
|
7 |
| - // get service |
| 6 | + // get service |
8 | 7 | beforeEach(inject(function(Pagination){
|
9 | 8 | pg = new Pagination()
|
10 | 9 | }))
|
11 |
| - it("should have page values that match defaults", function(){ |
| 10 | + it("should have proper defaults",function(){ |
12 | 11 | expect(pg.pages).toBe(0)
|
13 | 12 | expect(pg.page).toBe(1)
|
14 | 13 | expect(pg.start).toBe(0)
|
15 | 14 | expect(pg.limit).toBe(10)
|
16 | 15 | })
|
17 |
| - it("should have correct values after setting new params",function(){ |
18 |
| - pg.set({start: 40, limit: 20, total: 120}) |
19 |
| - expect(pg.pages).toBe(6) |
20 |
| - expect(pg.page).toBe(3) |
21 |
| - expect(pg.start).toBe(40) |
22 |
| - expect(pg.limit).toBe(20) |
23 |
| - }) |
24 |
| - it("should have correct values for previous",function(){ |
25 |
| - pg.set({start: 40, limit: 20, total: 120}) |
26 |
| - pg.set({start: pg.previous()}) |
27 |
| - expect(pg.page).toBe(2) |
28 |
| - expect(pg.start).toBe(20) |
29 |
| - }) |
30 |
| - it("should have correct values for next",function(){ |
31 |
| - pg.set({start: 40, limit: 20, total: 120}) |
32 |
| - pg.set({start: pg.next()}) |
33 |
| - expect(pg.page).toBe(4) |
34 |
| - expect(pg.start).toBe(60) |
35 |
| - }) |
36 |
| - it("should have correct values for first",function(){ |
37 |
| - pg.set({start: 40, limit: 20, total: 120}) |
38 |
| - pg.set({start: pg.first()}) |
39 |
| - expect(pg.page).toBe(1) |
40 |
| - expect(pg.start).toBe(0) |
41 |
| - }) |
42 |
| - it("should have correct values for last",function(){ |
43 |
| - pg.set({start: 40, limit: 20, total: 120}) |
44 |
| - pg.set({start: pg.last()}) |
45 |
| - expect(pg.page).toBe(6) |
46 |
| - expect(pg.start).toBe(100) |
47 |
| - }) |
48 |
| - it("should have correct values setting forPage",function(){ |
49 |
| - pg.set({start: 40, limit: 20, total: 120}) |
50 |
| - pg.set({start: pg.forPage(2)}) |
51 |
| - expect(pg.page).toBe(2) |
52 |
| - expect(pg.start).toBe(20) |
53 |
| - }) |
54 |
| - it("should not be able to page above max", function(){ |
55 |
| - pg.set({start: 40, limit: 20, total: 120}) |
56 |
| - pg.set({start: pg.forPage(20)}) |
57 |
| - expect(pg.page).toBe(6) |
58 |
| - expect(pg.start).toBe(100) |
59 |
| - }) |
60 |
| - it("should not be able to page below min",function(){ |
61 |
| - pg.set({start: 40, limit: 20, total: 120}) |
62 |
| - pg.set({start: pg.forPage(-50)}) |
63 |
| - expect(pg.page).toBe(1) |
64 |
| - expect(pg.start).toBe(0) |
65 |
| - }) |
66 |
| - it("should not be able to previous below min",function(){ |
67 |
| - pg.set({start: 40, limit: 20, total: 120}) |
68 |
| - pg.set({start: pg.first()}) |
69 |
| - pg.set({start: pg.previous()}) |
70 |
| - expect(pg.page).toBe(1) |
71 |
| - expect(pg.start).toBe(0) |
72 |
| - }) |
73 |
| - it("should not be able to next above max",function(){ |
74 |
| - pg.set({start: 40, limit: 20, total: 120}) |
75 |
| - pg.set({start: pg.last()}) |
76 |
| - pg.set({start: pg.next()}) |
77 |
| - expect(pg.page).toBe(6) |
78 |
| - expect(pg.start).toBe(100) |
79 |
| - }) |
80 |
| - it("should have correct range values",function(){ |
81 |
| - pg.set({start: 40, limit: 20, total: 120}) |
82 |
| - expect(pg.range.start).toBe(41) |
83 |
| - expect(pg.range.end).toBe(60) |
84 |
| - expect(pg.range.total).toBe(120) |
85 |
| - }) |
86 |
| - it("should generate 5 buttons with 4 on the right at the beginning",function(){ |
87 |
| - pg.set({start: 40, limit: 20, total: 120}) |
88 |
| - pg.set({start: pg.first()}) |
89 |
| - var buttons = pg.buttons() |
90 |
| - expect(buttons.length).toBe(pg.buttons_max) |
91 |
| - expect(buttons.shift()).toBe(1) |
92 |
| - expect(buttons.pop()).toBe(5) |
93 |
| - }) |
94 |
| - it("should generate 5 buttons with 2 on each side",function(){ |
95 |
| - pg.set({start: 40, limit: 20, total: 120}) |
96 |
| - pg.set({start: pg.forPage(3)}) |
97 |
| - var buttons = pg.buttons() |
98 |
| - expect(buttons.length).toBe(pg.buttons_max) |
99 |
| - expect(buttons.shift()).toBe(1) |
100 |
| - expect(buttons.pop()).toBe(5) |
101 |
| - }) |
102 |
| - it("should generate 5 buttons with 4 on the left at the end",function(){ |
103 |
| - pg.set({start: 40, limit: 20, total: 120}) |
104 |
| - pg.set({start: pg.last()}) |
105 |
| - var buttons = pg.buttons() |
106 |
| - expect(buttons.length).toBe(pg.buttons_max) |
107 |
| - expect(buttons.shift()).toBe(2) |
108 |
| - expect(buttons.pop()).toBe(6) |
109 |
| - }) |
110 |
| - it("should generate 5 buttons with 3 on the left and 1 on the right close to the end",function(){ |
111 |
| - pg.set({start: 40, limit: 20, total: 120}) |
112 |
| - pg.set({start: pg.forPage(pg.pages - 1)}) |
113 |
| - var buttons = pg.buttons() |
114 |
| - expect(buttons.length).toBe(pg.buttons_max) |
115 |
| - expect(buttons.shift()).toBe(2) |
116 |
| - expect(buttons.pop()).toBe(6) |
117 |
| - }) |
118 |
| - it("should generate 5 buttons with 3 on the right and 1 on the right close to the beginning",function(){ |
119 |
| - pg.set({start: 40, limit: 20, total: 120}) |
120 |
| - pg.set({start: pg.forPage(2)}) |
121 |
| - var buttons = pg.buttons() |
122 |
| - expect(buttons.length).toBe(pg.buttons_max) |
123 |
| - expect(buttons.shift()).toBe(1) |
124 |
| - expect(buttons.pop()).toBe(5) |
125 |
| - }) |
126 |
| - it("should generate 3 buttons with 1 on each side",function(){ |
127 |
| - pg.set({start: 0, limit: 10, total: 30}) |
128 |
| - pg.set({start: pg.forPage(2)}) |
129 |
| - var buttons = pg.buttons() |
130 |
| - expect(buttons.length).toBe(3) |
131 |
| - expect(buttons.shift()).toBe(1) |
132 |
| - expect(buttons.pop()).toBe(3) |
133 |
| - }) |
134 |
| - it("should generate 3 buttons with 2 on the right at the beginning",function(){ |
135 |
| - pg.set({start: 0, limit: 10, total: 30}) |
136 |
| - pg.set({start: pg.first()}) |
137 |
| - var buttons = pg.buttons() |
138 |
| - expect(buttons.length).toBe(3) |
139 |
| - expect(buttons.shift()).toBe(1) |
140 |
| - expect(buttons.pop()).toBe(3) |
141 |
| - }) |
142 |
| - it("should generate 3 buttons with 2 on the left at the end",function(){ |
143 |
| - pg.set({start: 0, limit: 10, total: 30}) |
144 |
| - pg.set({start: pg.last()}) |
145 |
| - var buttons = pg.buttons() |
146 |
| - expect(buttons.length).toBe(3) |
147 |
| - expect(buttons.shift()).toBe(1) |
148 |
| - expect(buttons.pop()).toBe(3) |
| 16 | + describe("Value Checks",function(){ |
| 17 | + beforeEach(function(){ |
| 18 | + pg.set({start: 40,limit: 20,total: 120}) |
| 19 | + }) |
| 20 | + it("should have correct values after set()",function(){ |
| 21 | + expect(pg.pages).toBe(6) |
| 22 | + expect(pg.page).toBe(3) |
| 23 | + expect(pg.start).toBe(40) |
| 24 | + expect(pg.limit).toBe(20) |
| 25 | + expect(pg.range.start).toBe(41) |
| 26 | + expect(pg.range.end).toBe(60) |
| 27 | + expect(pg.range.total).toBe(120) |
| 28 | + }) |
| 29 | + it("should have correct values from previous()",function(){ |
| 30 | + pg.set({start: pg.previous()}) |
| 31 | + expect(pg.page).toBe(2) |
| 32 | + expect(pg.start).toBe(20) |
| 33 | + }) |
| 34 | + it("should have correct values from next()",function(){ |
| 35 | + pg.set({start: pg.next()}) |
| 36 | + expect(pg.page).toBe(4) |
| 37 | + expect(pg.start).toBe(60) |
| 38 | + }) |
| 39 | + it("should have correct values from first()",function(){ |
| 40 | + pg.set({start: pg.first()}) |
| 41 | + expect(pg.page).toBe(1) |
| 42 | + expect(pg.start).toBe(0) |
| 43 | + }) |
| 44 | + it("should have correct values from last()",function(){ |
| 45 | + pg.set({start: pg.last()}) |
| 46 | + expect(pg.page).toBe(6) |
| 47 | + expect(pg.start).toBe(100) |
| 48 | + }) |
| 49 | + it("should have correct values from forPage(page)",function(){ |
| 50 | + pg.set({start: pg.forPage(2)}) |
| 51 | + expect(pg.page).toBe(2) |
| 52 | + expect(pg.start).toBe(20) |
| 53 | + }) |
| 54 | + }) |
| 55 | + describe("Action Checks",function(){ |
| 56 | + beforeEach(function(){ |
| 57 | + pg.set({start: 40,limit: 20,total: 120}) |
| 58 | + }) |
| 59 | + it("should be unable to forPage() above max",function(){ |
| 60 | + pg.set({start: pg.forPage(20)}) |
| 61 | + expect(pg.page).toBe(6) |
| 62 | + expect(pg.start).toBe(100) |
| 63 | + }) |
| 64 | + it("should be unable to forPage() below min",function(){ |
| 65 | + pg.set({start: pg.forPage(-50)}) |
| 66 | + expect(pg.page).toBe(1) |
| 67 | + expect(pg.start).toBe(0) |
| 68 | + }) |
| 69 | + it("should be unable to previous() below min",function(){ |
| 70 | + pg.set({start: pg.first()}) |
| 71 | + pg.set({start: pg.previous()}) |
| 72 | + expect(pg.page).toBe(1) |
| 73 | + expect(pg.start).toBe(0) |
| 74 | + }) |
| 75 | + it("should be unable to next() above max",function(){ |
| 76 | + pg.set({start: pg.last()}) |
| 77 | + pg.set({start: pg.next()}) |
| 78 | + expect(pg.page).toBe(6) |
| 79 | + expect(pg.start).toBe(100) |
| 80 | + }) |
| 81 | + }) |
| 82 | + describe("Button Generator Checks",function(){ |
| 83 | + describe("Many-page Datasets",function(){ |
| 84 | + beforeEach(function(){ |
| 85 | + pg.set({start: 40,limit: 20,total: 120}) |
| 86 | + }) |
| 87 | + it("should have 5 buttons with 4 on the right, on first() page",function(){ |
| 88 | + pg.set({start: pg.first()}) |
| 89 | + var buttons = pg.buttons() |
| 90 | + expect(buttons.length).toBe(pg.buttons_max) |
| 91 | + expect(buttons.shift()).toBe(1) |
| 92 | + expect(buttons.pop()).toBe(5) |
| 93 | + }) |
| 94 | + it("should have 5 buttons with 3 on the right and 1 on the right, one page after first()",function(){ |
| 95 | + pg.set({start: pg.forPage(2)}) |
| 96 | + var buttons = pg.buttons() |
| 97 | + expect(buttons.length).toBe(pg.buttons_max) |
| 98 | + expect(buttons.shift()).toBe(1) |
| 99 | + expect(buttons.pop()).toBe(5) |
| 100 | + }) |
| 101 | + it("should have 5 buttons with 2 on each side, on midrange page of larger sets",function(){ |
| 102 | + pg.set({start: pg.forPage(3)}) |
| 103 | + var buttons = pg.buttons() |
| 104 | + expect(buttons.length).toBe(pg.buttons_max) |
| 105 | + expect(buttons.shift()).toBe(1) |
| 106 | + expect(buttons.pop()).toBe(5) |
| 107 | + }) |
| 108 | + it("should have 5 buttons with 3 on the left and 1 on the right, one page before last()",function(){ |
| 109 | + pg.set({start: pg.forPage(pg.pages - 1)}) |
| 110 | + var buttons = pg.buttons() |
| 111 | + expect(buttons.length).toBe(pg.buttons_max) |
| 112 | + expect(buttons.shift()).toBe(2) |
| 113 | + expect(buttons.pop()).toBe(6) |
| 114 | + }) |
| 115 | + it("should have 5 buttons with 4 on the left, on last() page",function(){ |
| 116 | + pg.set({start: pg.last()}) |
| 117 | + var buttons = pg.buttons() |
| 118 | + expect(buttons.length).toBe(pg.buttons_max) |
| 119 | + expect(buttons.shift()).toBe(2) |
| 120 | + expect(buttons.pop()).toBe(6) |
| 121 | + }) |
| 122 | + }) |
| 123 | + describe("Three-page Datasets",function(){ |
| 124 | + beforeEach(function(){ |
| 125 | + pg.set({start: 0,limit: 10,total: 30}) |
| 126 | + }) |
| 127 | + it("should have 3 buttons with 2 on the right, on first() page",function(){ |
| 128 | + pg.set({start: pg.first()}) |
| 129 | + var buttons = pg.buttons() |
| 130 | + expect(buttons.length).toBe(3) |
| 131 | + expect(buttons.shift()).toBe(1) |
| 132 | + expect(buttons.pop()).toBe(3) |
| 133 | + }) |
| 134 | + it("should have 3 buttons with 1 on each side, on middle page",function(){ |
| 135 | + pg.set({start: pg.forPage(2)}) |
| 136 | + var buttons = pg.buttons() |
| 137 | + expect(buttons.length).toBe(3) |
| 138 | + expect(buttons.shift()).toBe(1) |
| 139 | + expect(buttons.pop()).toBe(3) |
| 140 | + }) |
| 141 | + it("should generate 3 buttons with 2 on the left, on last() page",function(){ |
| 142 | + pg.set({start: pg.last()}) |
| 143 | + var buttons = pg.buttons() |
| 144 | + expect(buttons.length).toBe(3) |
| 145 | + expect(buttons.shift()).toBe(1) |
| 146 | + expect(buttons.pop()).toBe(3) |
| 147 | + }) |
| 148 | + }) |
149 | 149 | })
|
150 | 150 | })
|
0 commit comments