-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2838 from andrewbaldwin44/feature/chart-tests
Add Tests for Web UI Line Chart
- Loading branch information
Showing
6 changed files
with
364 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
locust/webui/src/components/LineChart/tests/LineChart.mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ICharts } from 'types/ui.types'; | ||
import { formatLocaleTime } from 'utils/date'; | ||
|
||
export type MockChartType = Pick<ICharts, 'currentRps' | 'currentFailPerSec' | 'time'>; | ||
|
||
export const mockChartLines = [ | ||
{ name: 'RPS', key: 'currentRps' as keyof MockChartType }, | ||
{ name: 'Failures/s', key: 'currentFailPerSec' as keyof MockChartType }, | ||
]; | ||
|
||
export const mockCharts = { | ||
currentRps: [3, 3.1, 3.27, 3.62, 4.19], | ||
currentFailPerSec: [0, 0, 0, 0, 0], | ||
time: [ | ||
'Tue, 06 Aug 2024 11:33:02 GMT', | ||
'Tue, 06 Aug 2024 11:33:08 GMT', | ||
'Tue, 06 Aug 2024 11:33:10 GMT', | ||
'Tue, 06 Aug 2024 11:33:12 GMT', | ||
'Tue, 06 Aug 2024 11:33:14 GMT', | ||
], | ||
}; | ||
|
||
export const mockFormattedTimeAxis = mockCharts.time.map(formatLocaleTime); | ||
|
||
export const mockSeriesData = [ | ||
{ type: 'line', name: 'RPS', data: mockCharts.currentRps }, | ||
{ type: 'line', name: 'Failures/s', data: mockCharts.currentFailPerSec }, | ||
]; | ||
|
||
export const mockTooltipParams = [ | ||
{ | ||
axisValue: 'Tue, 06 Aug 2024 11:33:02 GMT', | ||
color: '#ff0', | ||
seriesName: 'RPS', | ||
value: 1, | ||
}, | ||
{ | ||
axisValue: 'Tue, 06 Aug 2024 11:33:08 GMT', | ||
color: '#0ff', | ||
seriesName: 'User', | ||
value: 10, | ||
}, | ||
]; |
28 changes: 28 additions & 0 deletions
28
locust/webui/src/components/LineChart/tests/LineChart.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { describe, test, expect } from 'vitest'; | ||
|
||
import LineChart from 'components/LineChart/LineChart'; | ||
import { mockChartLines } from 'components/LineChart/tests/LineChart.mocks'; | ||
import { statsResponseTransformed } from 'test/mocks/statsRequest.mock'; | ||
import { renderWithProvider } from 'test/testUtils'; | ||
import { ICharts } from 'types/ui.types'; | ||
|
||
const mockChart = { | ||
title: 'Total Requests per Second', | ||
lines: mockChartLines, | ||
colors: ['#00ca5a', '#ff6d6d'], | ||
}; | ||
|
||
describe('LineChart', () => { | ||
test('renders LineChart with charts and lines', () => { | ||
const { container } = renderWithProvider( | ||
<LineChart<ICharts> | ||
charts={statsResponseTransformed.charts} | ||
colors={mockChart.colors} | ||
lines={mockChart.lines} | ||
title={mockChart.title} | ||
/>, | ||
); | ||
|
||
expect(container.querySelector('canvas')).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.