|
| 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