Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test avoid warnings #365

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ErrorBoundary from './ErrorBoundary'
import { MenuFoldOutlined, MenuUnfoldOutlined } from '@ant-design/icons'

AccessibilityModule(Highcharts)
Highcharts.AST.allowedAttributes.push('rel')

const { Header, Content, Sider } = Layout

Expand Down
11 changes: 6 additions & 5 deletions src/Graph/__tests__/Download.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ api.downloads = vi.fn().mockImplementation(() => {
describe('Download component', () => {
test('renders correctly', async () => {
let getByText;
let queryAllByLabelText;
let queryAllByText;

await act(async () => {
({ getByText, queryAllByLabelText } = render(
({ getByText, queryAllByText } = render(
<Download />
));
setTimeout(() => { }, delay)
Expand All @@ -51,16 +51,17 @@ describe('Download component', () => {
expect(getByText('Adoptium Download Stats')).toBeInTheDocument();
expect(getByText('233 144 070')).toBeInTheDocument();

expect(queryAllByLabelText('Total Downloads').length).toBe(2);
expect(queryAllByText('Total Downloads', {selector: 'text'}).length).toBe(3);
expect(getByText('72 333 402')).toBeInTheDocument();
expect(getByText('160 810 668')).toBeInTheDocument();
expect(getByText('233 144 070')).toBeInTheDocument();

expect(queryAllByLabelText('Github Downloads').length).toBe(1);

expect(queryAllByText('Github Downloads', {selector: 'text'}).length).toBe(3);
expect(getByText('39 821 217')).toBeInTheDocument();
expect(getByText('48 300 842')).toBeInTheDocument();
expect(getByText('45 342 098')).toBeInTheDocument();
expect(getByText('594 778')).toBeInTheDocument();

expect(queryAllByText('JDK Versions', {selector: 'text'}).length).toBe(1);
});
});
91 changes: 91 additions & 0 deletions src/Graph/__tests__/Trends.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from 'react';
import '@testing-library/jest-dom';
import { act, render } from '@testing-library/react';
import { describe, expect, test, vi } from 'vitest'
import Trends from '../Trends'
import { api } from '../../api'

// NOTE: Use a delay to avoid diff with rendering animation
// https://github.com/highcharts/highcharts/issues/14328

const delay = 2000;

const mock_tracking_data =
[
{
"daily": 391783,
"date": "2023-09-23T22:31:18Z",
"total": 232137708
},
{
"daily": 357992,
"date": "2023-09-24T23:29:09Z",
"total": 232509871
},
{
"daily": 622526,
"date": "2023-09-25T23:56:17Z",
"total": 233144070
},
{
"daily": 604188,
"date": "2023-09-27T00:50:24Z",
"total": 233770916
}
];

const mock_monthly_data = [
{
"month": "2023-03",
"monthly": 12979542,
"total": 141309172
},
{
"month": "2023-04",
"monthly": 13901768,
"total": 155210940
},
{
"month": "2023-05",
"monthly": 14989924,
"total": 170200864
},
{
"month": "2023-06",
"monthly": 13907241,
"total": 184108105
},
{
"month": "2023-07",
"monthly": 18093361,
"total": 202201466
},
{
"month": "2023-08",
"monthly": 16954788,
"total": 219156254
}
]

api.tracking = vi.fn().mockImplementation(() => {
return mock_tracking_data;
});
api.monthly = vi.fn().mockImplementation(() => {
return mock_monthly_data;
});

describe('Trends component', () => {
test('renders correctly', async () => {
let queryAllByText;

await act(async () => {
({ queryAllByText } = render(
<Trends />
));
setTimeout(() => { }, delay)
});

expect(queryAllByText('Tracking Trends', {selector: 'text'}).length).toBe(1);
expect(queryAllByText('Monthly Trends', {selector: 'text'}).length).toBe(2);
});
});
4 changes: 4 additions & 0 deletions vitest-setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { vi } from 'vitest'
import Highcharts from 'highcharts'
import AccessibilityModule from 'highcharts/modules/accessibility'

AccessibilityModule(Highcharts)

Highcharts.useSerialIds(true);
Highcharts.AST.allowedAttributes.push('rel');

// mock router for 'useParams'
vi.mock('react-router-dom');
Expand Down