-
Notifications
You must be signed in to change notification settings - Fork 539
/
Copy pathpages.js
83 lines (56 loc) · 1.95 KB
/
pages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
var algoliasearchHelper = require('../../../index');
var fakeClient = {};
test('setChange should change the current page', function () {
var helper = algoliasearchHelper(fakeClient, null, null);
expect(helper.getPage()).toBeUndefined();
helper.setPage(3);
expect(helper.getPage()).toBe(3);
});
test('nextPage should increment the page by one', function () {
var helper = algoliasearchHelper(fakeClient, null, null);
expect(helper.getPage()).toBeUndefined();
helper.nextPage();
helper.nextPage();
helper.nextPage();
expect(helper.getPage()).toBe(3);
});
test('previousPage should decrement the current page by one', function () {
var helper = algoliasearchHelper(fakeClient, null, null);
expect(helper.getPage()).toBeUndefined();
helper.setPage(3);
expect(helper.getPage()).toBe(3);
helper.previousPage();
expect(helper.getPage()).toBe(2);
});
test('previousPage should throw an error without a current page', function () {
var helper = algoliasearchHelper(fakeClient, null, null);
expect(function () {
helper.previousPage();
}).toThrow('Page requested below 0.');
});
test('pages should be reset if the mutation might change the number of pages', function () {
var helper = algoliasearchHelper(fakeClient, '', {
facets: ['facet1', 'f2'],
disjunctiveFacets: ['f1'],
});
[
['clearRefinements'],
['setQuery', 'query'],
['addNumericRefinement', 'facet', '>', '2'],
['removeNumericRefinement', 'facet', '>'],
['addExclude', 'facet1', 'val2'],
['removeExclude', 'facet1', 'val2'],
['addRefine', 'f2', 'val'],
['removeRefine', 'f2', 'val'],
['addDisjunctiveRefine', 'f1', 'val'],
['removeDisjunctiveRefine', 'f1', 'val'],
['toggleRefine', 'f1', 'v1'],
['toggleExclude', 'facet1', '55'],
].forEach(function ([fn, ...args]) {
helper.setPage(10);
expect(helper.getPage()).toBe(10);
helper[fn](...args);
expect(helper.getPage()).toBe(0);
});
});