forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFlameGraphTopTableContainer.test.tsx
76 lines (60 loc) · 2.94 KB
/
FlameGraphTopTableContainer.test.tsx
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
import { render, screen } from '@testing-library/react';
import userEvents from '@testing-library/user-event';
import { createDataFrame } from '@grafana/data';
import { FlameGraphDataContainer } from '../FlameGraph/dataTransform';
import { data } from '../FlameGraph/testData/dataNestedSet';
import { ColorScheme } from '../types';
import FlameGraphTopTableContainer from './FlameGraphTopTableContainer';
describe('FlameGraphTopTableContainer', () => {
const setup = () => {
const flameGraphData = createDataFrame(data);
const container = new FlameGraphDataContainer(flameGraphData, { collapsing: true });
const onSearch = jest.fn();
const onSandwich = jest.fn();
const renderResult = render(
<FlameGraphTopTableContainer
data={container}
onSymbolClick={jest.fn()}
onSearch={onSearch}
onSandwich={onSandwich}
colorScheme={ColorScheme.ValueBased}
/>
);
return { renderResult, mocks: { onSearch, onSandwich } };
};
it('should render correctly', async () => {
// Needed for AutoSizer to work in test
Object.defineProperty(HTMLElement.prototype, 'offsetHeight', { configurable: true, value: 500 });
Object.defineProperty(HTMLElement.prototype, 'offsetWidth', { configurable: true, value: 500 });
setup();
const rows = screen.getAllByRole('row');
expect(rows).toHaveLength(16);
const columnHeaders = screen.getAllByRole('columnheader');
expect(columnHeaders).toHaveLength(4);
expect(columnHeaders[1].textContent).toEqual('Symbol');
expect(columnHeaders[2].textContent).toEqual('Self');
expect(columnHeaders[3].textContent).toEqual('Total');
const cells = screen.getAllByRole('cell');
expect(cells).toHaveLength(60); // 16 rows
expect(cells[1].textContent).toEqual('net/http.HandlerFunc.ServeHTTP');
expect(cells[2].textContent).toEqual('31.7 K');
expect(cells[3].textContent).toEqual('31.7 Bil');
expect(cells[25].textContent).toEqual('net/http.(*conn).serve');
expect(cells[26].textContent).toEqual('5.63 K');
expect(cells[27].textContent).toEqual('5.63 Bil');
});
it('should render search and sandwich buttons', async () => {
// Needed for AutoSizer to work in test
Object.defineProperty(HTMLElement.prototype, 'offsetHeight', { configurable: true, value: 500 });
Object.defineProperty(HTMLElement.prototype, 'offsetWidth', { configurable: true, value: 500 });
const { mocks } = setup();
const searchButtons = screen.getAllByLabelText(/Search for symbol/);
expect(searchButtons.length > 0).toBeTruthy();
await userEvents.click(searchButtons[0]);
expect(mocks.onSearch).toHaveBeenCalledWith('net/http.HandlerFunc.ServeHTTP');
const sandwichButtons = screen.getAllByLabelText(/Show in sandwich view/);
expect(sandwichButtons.length > 0).toBeTruthy();
await userEvents.click(sandwichButtons[0]);
expect(mocks.onSandwich).toHaveBeenCalledWith('net/http.HandlerFunc.ServeHTTP');
});
});