Add tests for RepoRow expansion
This commit is contained in:
@@ -91,7 +91,7 @@ export const RepoRow = ({
|
||||
return;
|
||||
}
|
||||
|
||||
if (resultsLoaded) {
|
||||
if (resultsLoaded || status !== VariantAnalysisRepoStatus.Succeeded) {
|
||||
setExpanded(oldIsExpanded => !oldIsExpanded);
|
||||
return;
|
||||
}
|
||||
@@ -102,15 +102,17 @@ export const RepoRow = ({
|
||||
});
|
||||
|
||||
setResultsLoading(true);
|
||||
}, [resultsLoading, resultsLoaded, repository.fullName]);
|
||||
}, [resultsLoading, resultsLoaded, repository.fullName, status]);
|
||||
|
||||
useEffect(() => {
|
||||
if (resultsLoaded) {
|
||||
if (resultsLoaded && resultsLoading) {
|
||||
setResultsLoading(false);
|
||||
setExpanded(true);
|
||||
}
|
||||
}, [resultsLoaded]);
|
||||
}, [resultsLoaded, resultsLoading]);
|
||||
|
||||
const disabled = !status || !isCompletedAnalysisRepoStatus(status);
|
||||
const expandableContentLoaded = status && (status !== VariantAnalysisRepoStatus.Succeeded || resultsLoaded);
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -130,7 +132,7 @@ export const RepoRow = ({
|
||||
</span>
|
||||
{downloadStatus === VariantAnalysisScannedRepositoryDownloadStatus.InProgress && <LoadingIcon label="Downloading" />}
|
||||
</TitleContainer>
|
||||
{isExpanded && resultsLoaded && status &&
|
||||
{isExpanded && expandableContentLoaded &&
|
||||
<AnalyzedRepoItemContent status={status} interpretedResults={interpretedResults} rawResults={rawResults} />}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -164,6 +164,56 @@ describe(RepoRow.name, () => {
|
||||
screen.getByText('Error: Timed out');
|
||||
});
|
||||
|
||||
it('can expand the repo item when succeeded and loaded', async () => {
|
||||
render({
|
||||
status: VariantAnalysisRepoStatus.Succeeded,
|
||||
interpretedResults: [],
|
||||
});
|
||||
|
||||
await userEvent.click(screen.getByRole('button', {
|
||||
expanded: false
|
||||
}));
|
||||
|
||||
expect(screen.getByRole('button', {
|
||||
expanded: true,
|
||||
})).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('can expand the repo item when succeeded and not loaded', async () => {
|
||||
const { rerender } = render({
|
||||
status: VariantAnalysisRepoStatus.Succeeded,
|
||||
});
|
||||
|
||||
await userEvent.click(screen.getByRole('button', {
|
||||
expanded: false
|
||||
}));
|
||||
|
||||
expect((window as any).vsCodeApi.postMessage).toHaveBeenCalledWith({
|
||||
t: 'requestRepositoryResults',
|
||||
repositoryFullName: 'octodemo/hello-world-1',
|
||||
});
|
||||
|
||||
expect(screen.getByRole('button', {
|
||||
expanded: false,
|
||||
})).toBeInTheDocument();
|
||||
|
||||
rerender(
|
||||
<RepoRow
|
||||
repository={{
|
||||
id: 1,
|
||||
fullName: 'octodemo/hello-world-1',
|
||||
private: false,
|
||||
}}
|
||||
status={VariantAnalysisRepoStatus.Succeeded}
|
||||
interpretedResults={[]}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByRole('button', {
|
||||
expanded: true,
|
||||
})).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not allow expanding the repo item when status is undefined', async () => {
|
||||
render({
|
||||
status: undefined,
|
||||
|
||||
@@ -14,3 +14,11 @@ Object.defineProperty(window, 'matchMedia', {
|
||||
dispatchEvent: jest.fn(),
|
||||
})),
|
||||
});
|
||||
|
||||
// Store this on the window so we can mock it
|
||||
(window as any).vsCodeApi = {
|
||||
postMessage: jest.fn(),
|
||||
setState: jest.fn(),
|
||||
};
|
||||
|
||||
(window as any).acquireVsCodeApi = () => (window as any).vsCodeApi;
|
||||
|
||||
Reference in New Issue
Block a user