Skip to content

Commit

Permalink
Fix a pb with snapshots due to rendering animation (Highcharts) (adop…
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierfacq authored Sep 22, 2023
1 parent c8eb2a1 commit 969c74f
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions src/Graph/__tests__/BarChart.test.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
import React from 'react';
import { act, render } from '@testing-library/react';
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
import { afterAll, beforeAll, describe, expect, test } from 'vitest'
import BarChart from '../BarChart'
import Highcharts from 'highcharts'

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

const delay = 2000;

const mock_data = {
"jdk8u302-b08": 3238608,
"jdk8u302-b08.1": 513472,
"jdk8u312-b07": 5815865,
"jdk8u322-b06": 4010319,
"jdk8u332-b09": 6751030,
"jdk8u342-b07": 629406,
"jdk8u342-b07.1": 61770,
"jdk8u345-b01": 3035189,
"jdk8u352-b08": 2791698,
"jdk8u362-b09": 3866298,
"jdk8u372-b07": 3210329,
"jdk8u382-b05": 1929984
"jdk8u302-b08": 3238608,
"jdk8u302-b08.1": 513472,
"jdk8u312-b07": 5815865,
"jdk8u322-b06": 4010319,
"jdk8u332-b09": 6751030,
"jdk8u342-b07": 629406,
"jdk8u342-b07.1": 61770,
"jdk8u345-b01": 3035189,
"jdk8u352-b08": 2791698,
"jdk8u362-b09": 3866298,
"jdk8u372-b07": 3210329,
"jdk8u382-b05": 1929984
}

beforeAll(async () => {
Highcharts.useSerialIds(true);
Highcharts.useSerialIds(true);
})

afterAll(async () => {
Highcharts.useSerialIds(false);
Highcharts.useSerialIds(false);
})

describe('BarChart component', () => {
test('renders correctly', async() => {
let container;
await act(async () => {
({ container } = render(
<BarChart
data={mock_data}
name={'Downloads'}
/>
));
});

expect(container).toMatchSnapshot();
});
test('renders correctly', async () => {
let container;

await act(async () => {
({ container } = render(
<BarChart
data={mock_data}
name={'Downloads'}
/>
));
setTimeout(() => { }, delay)
});

expect(container).toMatchSnapshot();
});
});

0 comments on commit 969c74f

Please sign in to comment.