This repository has been archived by the owner on Jun 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 360
/
Pagination.spec.js
61 lines (47 loc) · 1.81 KB
/
Pagination.spec.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
import {createMockComponentContext} from 'fluxible/utils';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react/lib/ReactTestUtils';
import Pagination from 'components/Pagination';
import Immutable from 'immutable';
import { RouteStore } from 'fluxible-router';
import provideContext from 'fluxible-addons-react/provideContext';
var component, node, makeComponent;
describe('Pagination', function() {
beforeEach(function() {
makeComponent = function(page) {
var currentRoute = Immutable.Map({
path: 'http:localhost:8000',
query: Immutable.Map({q: 'light', p: page || 1})
});
var context = createMockComponentContext({
stores: [RouteStore]
});
context.dispatcherContext.dispatcher.stores.RouteStore.prototype.getCurrentRoute = function() {
return currentRoute;
}
var PaginationClass = provideContext(Pagination);
component = ReactTestUtils.renderIntoDocument(
<PaginationClass totalHits={100} hitsPerPage={20} context={context}/>
);
node = ReactDOM.findDOMNode(component);
}
});
it('should render', function() {
makeComponent();
expect(node).to.exist;
expect(node.querySelectorAll('.pagination li').length).to.equal(7);
});
it('should disable first link when on first page', function() {
makeComponent();
expect(node.querySelector('.pagination li a').className).to.contain('disabled')
makeComponent(4);
expect(node.querySelector('.pagination li a').className).not.to.contain('disabled')
});
it('should point to next page', function() {
makeComponent();
expect(node.querySelectorAll('.pagination li a')[6].href).to.contain('p=2')
makeComponent(4);
expect(node.querySelectorAll('.pagination li a')[6].href).to.contain('p=5')
});
});