diff --git a/src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsPage.spec.tsx b/src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsPage.spec.tsx new file mode 100644 index 0000000000..3833b292bd --- /dev/null +++ b/src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsPage.spec.tsx @@ -0,0 +1,80 @@ +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import { render, screen } from '@testing-library/react' +import { graphql } from 'msw' +import { setupServer } from 'msw/node' +import { PropsWithChildren, Suspense } from 'react' +import { MemoryRouter, Route } from 'react-router-dom' + +import FailedTestsPage from './FailedTestsPage' + +jest.mock('./SelectorSection/SelectorSection', () => () => 'Selector Section') +jest.mock('./MetricsSection/MetricsSection', () => () => 'Metrics Section') +jest.mock( + './FailedTestsTable/FailedTestsTable', + () => () => 'Failed Tests Table' +) + +const server = setupServer() +const queryClient = new QueryClient({ + defaultOptions: { + queries: { + retry: false, + suspense: false, + }, + }, +}) + +const wrapper: (initialEntries?: string) => React.FC = + (initialEntries = '/gh/codecov/cool-repo/tests') => + ({ children }) => ( + + + + {children} + + + + ) + +beforeAll(() => { + server.listen() +}) + +afterEach(() => { + queryClient.clear() + server.resetHandlers() +}) + +afterAll(() => { + server.close() +}) + +describe('FailedTestsPage', () => { + function setup() { + server.use( + graphql.query('GetRepoOverview', (req, res, ctx) => { + return res(ctx.status(200), ctx.data({})) + }) + ) + } + + it('renders sub-components', () => { + setup() + render(, { wrapper: wrapper() }) + + const selectorSection = screen.getByText(/Selector Section/) + const metricSection = screen.getByText(/Metrics Section/) + const table = screen.getByText(/Failed Tests Table/) + expect(selectorSection).toBeInTheDocument() + expect(metricSection).toBeInTheDocument() + expect(table).toBeInTheDocument() + }) +}) diff --git a/src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsPage.tsx b/src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsPage.tsx index c83b3f1b2e..678be1c9c9 100644 --- a/src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsPage.tsx +++ b/src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsPage.tsx @@ -1,128 +1,12 @@ -import { useParams } from 'react-router-dom' - -import { - TIME_OPTION_VALUES, - TimeOption, - TimeOptions, -} from 'pages/RepoPage/shared/constants' -import { useLocationParams } from 'services/navigation' -import { useRepoOverview } from 'services/repo' -import A from 'ui/A' -import MultiSelect from 'ui/MultiSelect' -import Select from 'ui/Select' - -import BranchSelector from './BranchSelector' import FailedTestsTable from './FailedTestsTable' import { MetricsSection } from './MetricsSection' - -interface URLParams { - provider: string - owner: string - repo: string - branch?: string -} - -const getDecodedBranch = (branch?: string) => - !!branch ? decodeURIComponent(branch) : undefined +import { SelectorSection } from './SelectorSection' function FailedTestsPage() { - const { params, updateParams } = useLocationParams({ - search: '', - historicalTrend: '', - }) - const { provider, owner, repo, branch } = useParams() - - const { data: overview } = useRepoOverview({ - provider, - owner, - repo, - }) - - const decodedBranch = getDecodedBranch(branch) - const selectedBranch = decodedBranch ?? overview?.defaultBranch ?? '' - - const value = TimeOptions.find( - // @ts-expect-error need to type out useLocationParams - (item) => item.value === params.historicalTrend - ) - - const defaultValue = TimeOptions.find( - (option) => option.value === TIME_OPTION_VALUES.LAST_3_MONTHS - ) - return (
-
- - {selectedBranch === overview?.defaultBranch ? ( - <> -
-

- Historical trend -

-
- + updateParams({ historicalTrend: historicalTrend.value }) + } + renderItem={({ label }: { label: string }) => label} + renderSelected={({ label }: { label: string }) => label} + /> +
+ + 30 day retention + +
+
+

+ Test suites +

+
+ item} + resourceName="Test Suites" + onChange={() => {}} + /> +
+
+
+

+ Flags +

+
+ item} + resourceName="Flags" + onChange={() => {}} + /> +
+
+ + ) : null} +
+ ) +} + +export default SelectorSection diff --git a/src/pages/RepoPage/FailedTestsTab/FailedTestsPage/SelectorSection/index.ts b/src/pages/RepoPage/FailedTestsTab/FailedTestsPage/SelectorSection/index.ts new file mode 100644 index 0000000000..b820c3d889 --- /dev/null +++ b/src/pages/RepoPage/FailedTestsTab/FailedTestsPage/SelectorSection/index.ts @@ -0,0 +1 @@ +export { default as SelectorSection } from './SelectorSection'