Skip to content

Commit ed9d6e3

Browse files
committed
chore: pagination tests
1 parent 5f717e7 commit ed9d6e3

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Pagination plugin should render the pagination with no records 1`] = `"<div class=\\"gridjs-pagination\\"><div class=\\"gridjs-pages\\"><button tabindex=\\"0\\" role=\\"button\\" disabled=\\"\\" title=\\"Previous\\" aria-label=\\"Previous\\" class=\\"\\">Previous</button><button tabindex=\\"0\\" role=\\"button\\" disabled=\\"\\" title=\\"Next\\" aria-label=\\"Next\\" class=\\"\\">Next</button></div></div>"`;
3+
exports[`Pagination plugin should render the pagination with no records 1`] = `"<div class="gridjs-pagination"><div class="gridjs-pages"><button tabindex="0" role="button" disabled="" title="Previous" aria-label="Previous" class="">Previous</button><button tabindex="0" role="button" disabled="" title="Next" aria-label="Next" class="">Next</button></div></div>"`;
44

5-
exports[`Pagination plugin should render the pagination with one page 1`] = `"<div class=\\"gridjs-pagination\\"><div role=\\"status\\" aria-live=\\"polite\\" class=\\"gridjs-summary\\" title=\\"Page 1 of 1\\">Showing <b>1</b> to <b>3</b> of <b>3</b> results</div><div class=\\"gridjs-pages\\"><button tabindex=\\"0\\" role=\\"button\\" disabled=\\"\\" title=\\"Previous\\" aria-label=\\"Previous\\" class=\\"\\">Previous</button><button tabindex=\\"0\\" role=\\"button\\" class=\\"gridjs-currentPage\\" title=\\"Page 1\\" aria-label=\\"Page 1\\">1</button><button tabindex=\\"0\\" role=\\"button\\" disabled=\\"\\" title=\\"Next\\" aria-label=\\"Next\\" class=\\"\\">Next</button></div></div>"`;
5+
exports[`Pagination plugin should render the pagination with one page 1`] = `"<div class="gridjs-pagination"><div role="status" aria-live="polite" class="gridjs-summary" title="Page 1 of 1">Showing <b>1</b> to <b>3</b> of <b>3</b> results</div><div class="gridjs-pages"><button tabindex="0" role="button" disabled="" title="Previous" aria-label="Previous" class="">Previous</button><button tabindex="0" role="button" class="gridjs-currentPage" title="Page 1" aria-label="Page 1">1</button><button tabindex="0" role="button" disabled="" title="Next" aria-label="Next" class="">Next</button></div></div>"`;
66

7-
exports[`Pagination plugin should render the pagination with three page 1`] = `"<div class=\\"gridjs-pagination\\"><div role=\\"status\\" aria-live=\\"polite\\" class=\\"gridjs-summary\\" title=\\"Page 1 of 3\\">Showing <b>1</b> to <b>1</b> of <b>3</b> results</div><div class=\\"gridjs-pages\\"><button tabindex=\\"0\\" role=\\"button\\" disabled=\\"\\" title=\\"Previous\\" aria-label=\\"Previous\\" class=\\"\\">Previous</button><button tabindex=\\"0\\" role=\\"button\\" class=\\"gridjs-currentPage\\" title=\\"Page 1\\" aria-label=\\"Page 1\\">1</button><button tabindex=\\"0\\" role=\\"button\\" class=\\"\\" title=\\"Page 2\\" aria-label=\\"Page 2\\">2</button><button tabindex=\\"0\\" role=\\"button\\" class=\\"\\" title=\\"Page 3\\" aria-label=\\"Page 3\\">3</button><button tabindex=\\"0\\" role=\\"button\\" title=\\"Next\\" aria-label=\\"Next\\" class=\\"\\">Next</button></div></div>"`;
7+
exports[`Pagination plugin should render the pagination with three page 1`] = `"<div class="gridjs-pagination"><div role="status" aria-live="polite" class="gridjs-summary" title="Page 1 of 3">Showing <b>1</b> to <b>1</b> of <b>3</b> results</div><div class="gridjs-pages"><button tabindex="0" role="button" disabled="" title="Previous" aria-label="Previous" class="">Previous</button><button tabindex="0" role="button" class="gridjs-currentPage" title="Page 1" aria-label="Page 1">1</button><button tabindex="0" role="button" class="" title="Page 2" aria-label="Page 2">2</button><button tabindex="0" role="button" class="" title="Page 3" aria-label="Page 3">3</button><button tabindex="0" role="button" title="Next" aria-label="Next" class="">Next</button></div></div>"`;

tests/jest/view/plugin/pagination.test.tsx

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
import { mount } from 'enzyme';
2-
import { createContext } from 'preact';
3-
import { Config } from '../../../../src/config';
4-
import { Plugin, PluginPosition } from '../../../../src/plugin';
2+
import { h } from 'preact';
3+
import { Config, ConfigContext } from '../../../../src/config';
54
import { Pagination } from '../../../../src/view/plugin/pagination';
6-
import Header from '../../../../src/header';
75

86
describe('Pagination plugin', () => {
97
let config: Config;
10-
const configContext = createContext(null);
11-
const plugin: Plugin<any> = {
12-
id: 'mypagination',
13-
position: PluginPosition.Footer,
14-
component: {},
15-
};
168

179
beforeEach(() => {
18-
config = Config.fromUserConfig({
19-
header: Header.fromColumns(['a', 'b', 'c']),
10+
config = new Config().update({
11+
columns: ['a', 'b', 'c'],
2012
data: [
2113
[1, 2, 3],
2214
[4, 5, 6],
@@ -30,67 +22,76 @@ describe('Pagination plugin', () => {
3022
});
3123

3224
it('should render the pagination with no records', async () => {
33-
config = Config.fromUserConfig({
34-
header: Header.fromColumns(['a', 'b', 'c']),
25+
config.update({
3526
data: [],
27+
pagination: true,
3628
});
3729

3830
const pagination = mount(
39-
<configContext.Provider
40-
value={{
41-
...config,
42-
data: [],
43-
}}
44-
>
45-
<Pagination plugin={plugin} enabled={true} />
46-
</configContext.Provider>,
31+
<ConfigContext.Provider value={config}>
32+
<Pagination />
33+
</ConfigContext.Provider>,
4734
);
4835

4936
await config.pipeline.process();
5037
expect(pagination.html()).toMatchSnapshot();
5138
});
5239

5340
it('should render the pagination with one page', async () => {
41+
config.update({
42+
pagination: {
43+
limit: 3,
44+
},
45+
});
46+
5447
const pagination = mount(
55-
<configContext.Provider value={config}>
56-
<Pagination plugin={plugin} enabled={true} limit={3} />
57-
</configContext.Provider>,
48+
<ConfigContext.Provider value={config}>
49+
<Pagination />
50+
</ConfigContext.Provider>,
5851
);
59-
6052
await config.pipeline.process();
53+
6154
expect(pagination.html()).toMatchSnapshot();
6255
});
6356

6457
it('should render the pagination with three page', async () => {
58+
config.update({
59+
pagination: {
60+
limit: 1,
61+
},
62+
});
63+
6564
const pagination = mount(
66-
<configContext.Provider value={config}>
67-
<Pagination plugin={plugin} enabled={true} limit={1} />
68-
</configContext.Provider>,
65+
<ConfigContext.Provider value={config}>
66+
<Pagination />
67+
</ConfigContext.Provider>,
6968
);
7069

71-
await config.pipeline.process();
7270
pagination.update();
71+
await config.pipeline.process();
7372

7473
expect(pagination.html()).toMatchSnapshot();
7574
});
7675

7776
it('should add config.className.pagination', async () => {
77+
config.update({
78+
pagination: {
79+
limit: 1,
80+
},
81+
className: {
82+
pagination: 'my-pagination-class',
83+
paginationButton: 'my-button',
84+
paginationButtonNext: 'my-next-button',
85+
paginationButtonPrev: 'my-prev-button',
86+
paginationSummary: 'my-page-summary',
87+
paginationButtonCurrent: 'my-current-button',
88+
},
89+
});
90+
7891
const pagination = mount(
79-
<configContext.Provider
80-
value={{
81-
...config,
82-
className: {
83-
pagination: 'my-pagination-class',
84-
paginationButton: 'my-button',
85-
paginationButtonNext: 'my-next-button',
86-
paginationButtonPrev: 'my-prev-button',
87-
paginationSummary: 'my-page-summary',
88-
paginationButtonCurrent: 'my-current-button',
89-
},
90-
}}
91-
>
92-
<Pagination plugin={plugin} enabled={true} limit={1} />
93-
</configContext.Provider>,
92+
<ConfigContext.Provider value={config}>
93+
<Pagination />
94+
</ConfigContext.Provider>,
9495
);
9596

9697
await config.pipeline.process();

0 commit comments

Comments
 (0)