diff --git a/src/App.js b/src/App.js index 446eed9..e14fcb9 100644 --- a/src/App.js +++ b/src/App.js @@ -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 diff --git a/src/Graph/__tests__/Download.test.tsx b/src/Graph/__tests__/Download.test.tsx index d9c4e3c..a5ee899 100644 --- a/src/Graph/__tests__/Download.test.tsx +++ b/src/Graph/__tests__/Download.test.tsx @@ -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( )); setTimeout(() => { }, delay) @@ -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); }); }); diff --git a/src/Graph/__tests__/Trends.test.tsx b/src/Graph/__tests__/Trends.test.tsx new file mode 100644 index 0000000..e2a50a1 --- /dev/null +++ b/src/Graph/__tests__/Trends.test.tsx @@ -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( + + )); + setTimeout(() => { }, delay) + }); + + expect(queryAllByText('Tracking Trends', {selector: 'text'}).length).toBe(1); + expect(queryAllByText('Monthly Trends', {selector: 'text'}).length).toBe(2); + }); +}); diff --git a/vitest-setup.ts b/vitest-setup.ts index e0a27fe..a5ee275 100644 --- a/vitest-setup.ts +++ b/vitest-setup.ts @@ -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');