|
1 | 1 | import Grid from '../../src/grid';
|
| 2 | +import * as Actions from '../../src/view/actions'; |
2 | 3 | import MemoryStorage from '../../src/storage/memory';
|
3 | 4 | import { mount } from 'enzyme';
|
4 | 5 | import { flushPromises } from './testUtil';
|
5 | 6 |
|
6 | 7 | describe('Grid class', () => {
|
| 8 | + afterEach(() => { |
| 9 | + jest.restoreAllMocks(); |
| 10 | + jest.clearAllMocks(); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should trigger the events in the correct order', async () => { |
| 14 | + const grid = new Grid({ |
| 15 | + columns: ['a', 'b', 'c'], |
| 16 | + data: [[1, 2, 3]], |
| 17 | + }); |
| 18 | + |
| 19 | + const setLoadingDataMock = jest.spyOn(Actions, 'SetLoadingData'); |
| 20 | + const setDataMock = jest.spyOn(Actions, 'SetData'); |
| 21 | + const setStatusToRenderedMock = jest.spyOn(Actions, 'SetStatusToRendered'); |
| 22 | + |
| 23 | + mount(grid.createElement()); |
| 24 | + |
| 25 | + await flushPromises(); |
| 26 | + await flushPromises(); |
| 27 | + |
| 28 | + expect(setLoadingDataMock).toHaveBeenCalledBefore(setDataMock); |
| 29 | + expect(setDataMock).toHaveBeenCalledBefore(setStatusToRenderedMock); |
| 30 | + |
| 31 | + expect(setLoadingDataMock).toBeCalledTimes(1); |
| 32 | + expect(setDataMock).toBeCalledTimes(1); |
| 33 | + expect(setStatusToRenderedMock).toBeCalledTimes(1); |
| 34 | + }); |
| 35 | + |
7 | 36 | it('should raise an exception with empty config', () => {
|
8 | 37 | expect(() => {
|
9 | 38 | new Grid({}).render(document.createElement('div'));
|
@@ -49,49 +78,4 @@ describe('Grid class', () => {
|
49 | 78 | expect(grid.config.data).toStrictEqual(config1.data);
|
50 | 79 | expect(grid.config.width).toStrictEqual(config2.width);
|
51 | 80 | });
|
52 |
| - |
53 |
| - it('should trigger the load and beforeLoad events', async () => { |
54 |
| - const grid = new Grid({ |
55 |
| - data: [[1, 2, 3]], |
56 |
| - }); |
57 |
| - |
58 |
| - const loadMock = jest.fn(); |
59 |
| - const beforeLoadMock = jest.fn(); |
60 |
| - grid.on('load', loadMock); |
61 |
| - grid.on('beforeLoad', beforeLoadMock); |
62 |
| - |
63 |
| - const container = mount(grid.createElement()); |
64 |
| - |
65 |
| - await container.instance().componentDidMount(); |
66 |
| - expect(loadMock).toBeCalled(); |
67 |
| - expect(beforeLoadMock).toBeCalled(); |
68 |
| - }); |
69 |
| - |
70 |
| - it('should trigger the events in the correct order', async () => { |
71 |
| - const grid = new Grid({ |
72 |
| - columns: ['a', 'b', 'c'], |
73 |
| - data: [[1, 2, 3]], |
74 |
| - }); |
75 |
| - |
76 |
| - const loadMock = jest.fn(); |
77 |
| - const beforeLoadMock = jest.fn(); |
78 |
| - const readyMock = jest.fn(); |
79 |
| - |
80 |
| - grid.on('load', loadMock); |
81 |
| - grid.on('beforeLoad', beforeLoadMock); |
82 |
| - grid.on('ready', readyMock); |
83 |
| - |
84 |
| - const container = mount(grid.createElement()); |
85 |
| - |
86 |
| - return flushPromises().then(async () => { |
87 |
| - await container.instance().componentDidMount(); |
88 |
| - |
89 |
| - expect(beforeLoadMock).toHaveBeenCalledBefore(loadMock); |
90 |
| - expect(loadMock).toHaveBeenCalledBefore(readyMock); |
91 |
| - |
92 |
| - expect(beforeLoadMock).toBeCalledTimes(2); |
93 |
| - expect(loadMock).toBeCalledTimes(2); |
94 |
| - expect(readyMock).toBeCalledTimes(2); |
95 |
| - }); |
96 |
| - }); |
97 | 81 | });
|
0 commit comments