Skip to content

Commit 24add15

Browse files
committed
chore: container and grid tests
1 parent ed9d6e3 commit 24add15

File tree

2 files changed

+29
-47
lines changed

2 files changed

+29
-47
lines changed

tests/jest/grid.test.ts

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
11
import Grid from '../../src/grid';
2+
import * as Actions from '../../src/view/actions';
23
import MemoryStorage from '../../src/storage/memory';
34
import { mount } from 'enzyme';
45
import { flushPromises } from './testUtil';
56

67
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+
736
it('should raise an exception with empty config', () => {
837
expect(() => {
938
new Grid({}).render(document.createElement('div'));
@@ -49,49 +78,4 @@ describe('Grid class', () => {
4978
expect(grid.config.data).toStrictEqual(config1.data);
5079
expect(grid.config.width).toStrictEqual(config2.width);
5180
});
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-
});
9781
});

tests/jest/view/container.test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { mount } from 'enzyme';
33
import { axe, toHaveNoViolations } from 'jest-axe';
44
import { Config, ConfigContext } from '../../../src/config';
55
import { Container } from '../../../src/view/container';
6-
//import StorageUtils from '../../../src/storage/storageUtils';
76
import {
87
PipelineProcessor,
98
ProcessorType,
109
} from '../../../src/pipeline/processor';
1110
import { flushPromises } from '../testUtil';
12-
//import PipelineUtils from '../../../src/pipeline/pipelineUtils';
1311
import { EventEmitter } from '../../../src/util/eventEmitter';
1412
import { GridEvents } from '../../../src/events';
1513
import { PluginManager } from '../../../src/plugin';

0 commit comments

Comments
 (0)