Browse Source

SONAR-20295 Fix flaky test in ComponentMeasures-it

tags/10.2.0.77647
David Cho-Lerat 9 months ago
parent
commit
40a1e666a1

+ 14
- 9
server/sonar-web/src/main/js/apps/component-measures/__tests__/ComponentMeasures-it.tsx View File

import { MetricKey } from '../../../types/metrics'; import { MetricKey } from '../../../types/metrics';
import routes from '../routes'; import routes from '../routes';


jest.mock('lodash', () => ({
...jest.requireActual('lodash'),
throttle: (fn: (...args: unknown[]) => unknown) => fn,
}));

jest.mock('../../../api/metrics', () => { jest.mock('../../../api/metrics', () => {
const { DEFAULT_METRICS } = jest.requireActual('../../../helpers/mocks/metrics'); const { DEFAULT_METRICS } = jest.requireActual('../../../helpers/mocks/metrics');
const metrics = Object.values(MetricKey).map( const metrics = Object.values(MetricKey).map(
await user.click(ui.maintainabilityDomainBtn.get()); await user.click(ui.maintainabilityDomainBtn.get());
await user.click(ui.measureBtn('Code Smells 8').get()); await user.click(ui.measureBtn('Code Smells 8').get());


// Select "folderA".
await ui.arrowDown();
await ui.arrowDown(); // Select the 1st element ("folderA")
await act(async () => { await act(async () => {
await ui.arrowRight();
await ui.arrowRight(); // Open "folderA"
}); });


expect( expect(


// Move back to project. // Move back to project.
await act(async () => { await act(async () => {
await ui.arrowLeft();
await ui.arrowLeft(); // Close "folderA"
}); });


expect( expect(
within(ui.measuresRow('folderA').get()).getByRole('cell', { name: '3' }) within(ui.measuresRow('folderA').get()).getByRole('cell', { name: '3' })
).toBeInTheDocument(); ).toBeInTheDocument();


// Go to "folderA/out.tsx".
await act(async () => { await act(async () => {
await ui.arrowRight();
await ui.arrowRight(); // Open "folderA"
}); });
await ui.arrowDown();
await ui.arrowDown();

await ui.arrowDown(); // Select the 1st element ("out.tsx")

await act(async () => { await act(async () => {
await ui.arrowRight();
await ui.arrowRight(); // Open "out.tsx"
}); });


expect((await ui.sourceCode.findAll()).length).toBeGreaterThan(0); expect((await ui.sourceCode.findAll()).length).toBeGreaterThan(0);

Loading…
Cancel
Save