Skip to content

Commit 0d0367c

Browse files
committed
Add tests for variant analysis stats component
1 parent ba0a30d commit 0d0367c

3 files changed

Lines changed: 84 additions & 8 deletions

File tree

extensions/ql-vscode/src/view/variant-analysis/VariantAnalysisRepositoriesStats.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ type Props = {
1010
completedRepositoryCount?: number | undefined;
1111

1212
queryResult?: 'warning' | 'stopped';
13-
14-
completedAt?: Date | undefined;
1513
};
1614

1715
const Icon = styled.span`
@@ -36,22 +34,21 @@ export const VariantAnalysisRepositoriesStats = ({
3634
totalRepositoryCount,
3735
completedRepositoryCount = 0,
3836
queryResult,
39-
completedAt,
4037
}: Props) => {
4138
if (variantAnalysisStatus === VariantAnalysisStatus.Failed) {
4239
return (
4340
<>
44-
0<ErrorIcon className="codicon codicon-error" />
41+
0<ErrorIcon role="img" aria-label="Error" className="codicon codicon-error" />
4542
</>
4643
);
4744
}
4845

4946
return (
5047
<>
5148
{formatDecimal(completedRepositoryCount)}/{formatDecimal(totalRepositoryCount)}
52-
{queryResult && <WarningIcon className="codicon codicon-warning" />}
53-
{completedAt && !queryResult && variantAnalysisStatus === VariantAnalysisStatus.Succeeded &&
54-
<SuccessIcon className="codicon codicon-pass" />}
49+
{queryResult && <WarningIcon role="img" aria-label="Warning" className="codicon codicon-warning" />}
50+
{!queryResult && variantAnalysisStatus === VariantAnalysisStatus.Succeeded &&
51+
<SuccessIcon role="img" aria-label="Completed" className="codicon codicon-pass" />}
5552
</>
5653
);
5754
};

extensions/ql-vscode/src/view/variant-analysis/VariantAnalysisStats.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export const VariantAnalysisStats = ({
7070
totalRepositoryCount={totalRepositoryCount}
7171
completedRepositoryCount={completedRepositoryCount}
7272
queryResult={queryResult}
73-
completedAt={completedAt}
7473
/>
7574
</StatItem>
7675
<StatItem title="Duration">
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import * as React from 'react';
2+
import { render as reactRender, screen } from '@testing-library/react';
3+
import { VariantAnalysisStatus } from '../../../remote-queries/shared/variant-analysis';
4+
import { VariantAnalysisStats, VariantAnalysisStatsProps } from '../VariantAnalysisStats';
5+
import { userEvent } from '@storybook/testing-library';
6+
7+
describe(VariantAnalysisStats.name, () => {
8+
const onViewLogsClick = jest.fn();
9+
10+
afterEach(() => {
11+
onViewLogsClick.mockReset();
12+
});
13+
14+
const render = (props: Partial<VariantAnalysisStatsProps> = {}) =>
15+
reactRender(
16+
<VariantAnalysisStats
17+
variantAnalysisStatus={VariantAnalysisStatus.InProgress}
18+
totalRepositoryCount={10}
19+
onViewLogsClick={onViewLogsClick}
20+
{...props}
21+
/>
22+
);
23+
24+
it('renders correctly', () => {
25+
render();
26+
27+
expect(screen.getByText('Results')).toBeInTheDocument();
28+
});
29+
30+
it('renders the number of results as a formatted number', () => {
31+
render({ resultCount: 123456 });
32+
33+
expect(screen.getByText('123,456')).toBeInTheDocument();
34+
});
35+
36+
it('renders the number of repositories as a formatted number', () => {
37+
render({ totalRepositoryCount: 123456, completedRepositoryCount: 654321 });
38+
39+
expect(screen.getByText('654,321/123,456')).toBeInTheDocument();
40+
});
41+
42+
it('renders a warning icon when the query result is a warning', () => {
43+
render({ queryResult: 'warning' });
44+
45+
expect(screen.getByRole('img', {
46+
name: 'Warning',
47+
})).toBeInTheDocument();
48+
});
49+
50+
it('renders a warning icon when the query result is stopped', () => {
51+
render({ queryResult: 'stopped' });
52+
53+
expect(screen.getByRole('img', {
54+
name: 'Warning',
55+
})).toBeInTheDocument();
56+
});
57+
58+
it('renders an error icon when the variant analysis status is failed', () => {
59+
render({ variantAnalysisStatus: VariantAnalysisStatus.Failed });
60+
61+
expect(screen.getByRole('img', {
62+
name: 'Error',
63+
})).toBeInTheDocument();
64+
});
65+
66+
it('renders a completed icon when the variant analysis status is succeeded', () => {
67+
render({ variantAnalysisStatus: VariantAnalysisStatus.Succeeded });
68+
69+
expect(screen.getByRole('img', {
70+
name: 'Completed',
71+
})).toBeInTheDocument();
72+
});
73+
74+
it('renders a view logs link when the variant analysis status is succeeded', () => {
75+
render({ variantAnalysisStatus: VariantAnalysisStatus.Succeeded, completedAt: new Date() });
76+
77+
userEvent.click(screen.getByText('View logs'));
78+
expect(onViewLogsClick).toHaveBeenCalledTimes(1);
79+
});
80+
});

0 commit comments

Comments
 (0)