From f6ae1348c151ce01e40d4a4985250f3de48c7c07 Mon Sep 17 00:00:00 2001 From: Rohit Date: Wed, 20 Mar 2024 13:32:34 -0700 Subject: [PATCH] all tests --- ...tTable.spec.jsx => FileListTable.spec.tsx} | 76 +++++----- .../FileListTable/FileListTable.tsx | 5 +- ...js => useRepoBranchContentsTable.spec.tsx} | 130 +++++------------- ...spec.js => useRepoBranchContents.spec.tsx} | 25 ++-- .../branch/dir/useRepoBranchContents.tsx | 8 +- .../BranchEntries/BranchDirEntry.spec.jsx | 48 ++++--- .../BranchEntries/BranchFileEntry.spec.jsx | 61 ++++---- 7 files changed, 158 insertions(+), 195 deletions(-) rename src/pages/RepoPage/CoverageTab/subroute/FileExplorer/FileListTable/{FileListTable.spec.jsx => FileListTable.spec.tsx} (92%) rename src/pages/RepoPage/CoverageTab/subroute/FileExplorer/hooks/{useRepoBranchContentsTable.spec.js => useRepoBranchContentsTable.spec.tsx} (69%) rename src/services/pathContents/branch/dir/{useRepoBranchContents.spec.js => useRepoBranchContents.spec.tsx} (91%) diff --git a/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/FileListTable/FileListTable.spec.jsx b/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/FileListTable/FileListTable.spec.tsx similarity index 92% rename from src/pages/RepoPage/CoverageTab/subroute/FileExplorer/FileListTable/FileListTable.spec.jsx rename to src/pages/RepoPage/CoverageTab/subroute/FileExplorer/FileListTable/FileListTable.spec.tsx index de93598378..f871969e3c 100644 --- a/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/FileListTable/FileListTable.spec.jsx +++ b/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/FileListTable/FileListTable.spec.tsx @@ -90,10 +90,9 @@ const mockNoHeadReport = { branch: { head: { pathContents: { - __typename: 'PathContents', + __typename: 'MissingHeadReport', results: [], }, - __typename: 'MissingHeadReport', }, }, }, @@ -114,12 +113,14 @@ const mockOverview = { } const wrapper = - (initialEntries = '/gh/codecov/cool-repo/tree/main/a/b/c') => + ( + initialEntries = '/gh/codecov/cool-repo/tree/main/a/b/c' + ): React.FC => ({ children }) => { return ( - + {children} @@ -139,22 +140,14 @@ afterAll(() => { }) describe('FileListTable', () => { - function setup( - { - noFiles = false, - noHeadReport = false, - noFlagCoverage = false, - missingCoverage = false, - unknownPath = false, - } = { - noFiles: false, - noHeadReport: false, - noFlagCoverage: false, - missingCoverage: false, - unknownPath: false, - } - ) { - const user = userEvent.setup() + function setup({ + noFiles = false, + noHeadReport = false, + noFlagCoverage = false, + missingCoverage = false, + unknownPath = false, + }) { + const user = userEvent.setup({}) const requestFilters = jest.fn() server.use( @@ -196,7 +189,7 @@ describe('FileListTable', () => { describe('rendering table', () => { describe('displaying the table head', () => { it('has a files column', async () => { - setup() + setup({}) render(, { wrapper: wrapper() }) const files = await screen.findByText('Files') @@ -204,7 +197,7 @@ describe('FileListTable', () => { }) it('has a tracked lines column', async () => { - setup() + setup({}) render(, { wrapper: wrapper() }) const trackedLines = await screen.findByText('Tracked lines') @@ -212,7 +205,7 @@ describe('FileListTable', () => { }) it('has a covered column', async () => { - setup() + setup({}) render(, { wrapper: wrapper() }) const covered = await screen.findByText('Covered') @@ -220,7 +213,7 @@ describe('FileListTable', () => { }) it('has a partial column', async () => { - setup() + setup({}) render(, { wrapper: wrapper() }) const partial = await screen.findByText('Partial') @@ -228,7 +221,7 @@ describe('FileListTable', () => { }) it('has a missed column', async () => { - setup() + setup({}) render(, { wrapper: wrapper() }) const missed = await screen.findByText('Missed') @@ -236,7 +229,7 @@ describe('FileListTable', () => { }) it('has a coverage column', async () => { - setup() + setup({}) render(, { wrapper: wrapper() }) const coverage = await screen.findByText('Coverage %') @@ -247,7 +240,7 @@ describe('FileListTable', () => { describe('table is displaying file list', () => { describe('display type is set', () => { it('set to list', async () => { - const { requestFilters } = setup() + const { requestFilters } = setup({}) render(, { wrapper: wrapper( `/gh/codecov/cool-repo/tree/main/a/b/c${qs.stringify( @@ -270,7 +263,7 @@ describe('FileListTable', () => { describe('displaying a file', () => { it('has the correct url', async () => { - setup() + setup({}) render(, { wrapper: wrapper( `/gh/codecov/cool-repo/tree/main/a/b/c${qs.stringify( @@ -294,7 +287,9 @@ describe('FileListTable', () => { describe('there is no results found', () => { it('displays error fetching data message', async () => { setup({ noFiles: true }) - render(, { wrapper: wrapper() }) + render(, { + wrapper: wrapper('/gh/codecov/cool-repo/tree/main/'), + }) const message = await screen.findByText( 'There is no coverage on the default branch for this repository. Use the Branch Context selector above to choose a different branch.' @@ -306,7 +301,9 @@ describe('FileListTable', () => { describe('when head commit has no reports', () => { it('renders no report uploaded message', async () => { setup({ noHeadReport: true }) - render(, { wrapper: wrapper() }) + render(, { + wrapper: wrapper('/gh/codecov/cool-repo/tree/main'), + }) const message = await screen.findByText( 'No coverage report uploaded for this branch head commit' @@ -375,12 +372,13 @@ describe('FileListTable', () => { describe('sorting on head column', () => { describe('sorting in asc order', () => { it('sets the correct api variables', async () => { - const { requestFilters, user } = setup() + const { requestFilters, user } = setup({}) render(, { wrapper: wrapper() }) let files = await screen.findByText('Files') await user.click(files) + await user.click(files) expect(requestFilters).toHaveBeenCalledWith( expect.objectContaining({ @@ -392,7 +390,7 @@ describe('FileListTable', () => { describe('sorting in desc order', () => { it('sets the correct api variables', async () => { - const { requestFilters, user } = setup() + const { requestFilters, user } = setup({}) render(, { wrapper: wrapper() }) let files = await screen.findByText('Files') @@ -414,7 +412,7 @@ describe('FileListTable', () => { describe('sorting on tracked lines column', () => { describe('sorting in asc order', () => { it('sets the correct api variables', async () => { - const { requestFilters, user } = setup() + const { requestFilters, user } = setup({}) render(, { wrapper: wrapper() }) let trackedLines = await screen.findByText('Tracked lines') @@ -433,7 +431,7 @@ describe('FileListTable', () => { describe('sorting in desc order', () => { it('sets the correct api variables', async () => { - const { requestFilters, user } = setup() + const { requestFilters, user } = setup({}) render(, { wrapper: wrapper() }) let trackedLines = await screen.findByText('Tracked lines') @@ -456,7 +454,7 @@ describe('FileListTable', () => { describe('sorting on the covered column', () => { describe('sorting in asc order', () => { it('sets the correct api variables', async () => { - const { requestFilters, user } = setup() + const { requestFilters, user } = setup({}) render(, { wrapper: wrapper() }) const covered = await screen.findByText('Covered') @@ -474,7 +472,7 @@ describe('FileListTable', () => { describe('sorting in desc order', () => { it('sets the correct api variables', async () => { - const { requestFilters, user } = setup() + const { requestFilters, user } = setup({}) render(, { wrapper: wrapper() }) let covered = await screen.findByText('Covered') @@ -497,7 +495,7 @@ describe('FileListTable', () => { describe('sorting on the partial column', () => { describe('sorting in asc order', () => { it('sets the correct api variables', async () => { - const { requestFilters, user } = setup() + const { requestFilters, user } = setup({}) render(, { wrapper: wrapper() }) let partial = await screen.findByText('Partial') @@ -516,7 +514,7 @@ describe('FileListTable', () => { describe('sorting in desc order', () => { it('sets the correct api variables', async () => { - const { requestFilters, user } = setup() + const { requestFilters, user } = setup({}) render(, { wrapper: wrapper() }) let partial = await screen.findByText('Partial') @@ -539,7 +537,7 @@ describe('FileListTable', () => { describe('sorting on the coverage line', () => { describe('sorting in desc order', () => { it('sets the correct api variables', async () => { - const { requestFilters, user } = setup() + const { requestFilters, user } = setup({}) render(, { wrapper: wrapper() }) let missed = await screen.findByText('Missed') diff --git a/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/FileListTable/FileListTable.tsx b/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/FileListTable/FileListTable.tsx index 9173483c1b..e8078abb54 100644 --- a/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/FileListTable/FileListTable.tsx +++ b/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/FileListTable/FileListTable.tsx @@ -64,7 +64,7 @@ export const getBaseColumns = () => { }), columnHelper.accessor('lines', { id: 'lines', - header: () => 'Lines', + header: () => 'Tracked lines', cell: ({ renderValue }) => renderValue(), }), columnHelper.accessor('hits', { @@ -73,7 +73,7 @@ export const getBaseColumns = () => { cell: ({ renderValue }) => renderValue(), }), columnHelper.accessor('partials', { - id: 'change', + id: 'partials', header: () => 'Partial', cell: ({ renderValue }) => renderValue(), }), @@ -104,7 +104,6 @@ function FileListTable() { hasComponentsSelected, pathContentsType, } = useRepoBranchContentsTable(ordering) - const table = useReactTable({ columns: getBaseColumns(), getCoreRowModel: getCoreRowModel(), diff --git a/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/hooks/useRepoBranchContentsTable.spec.js b/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/hooks/useRepoBranchContentsTable.spec.tsx similarity index 69% rename from src/pages/RepoPage/CoverageTab/subroute/FileExplorer/hooks/useRepoBranchContentsTable.spec.js rename to src/pages/RepoPage/CoverageTab/subroute/FileExplorer/hooks/useRepoBranchContentsTable.spec.tsx index 03740ea4e9..410a3d0058 100644 --- a/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/hooks/useRepoBranchContentsTable.spec.js +++ b/src/pages/RepoPage/CoverageTab/subroute/FileExplorer/hooks/useRepoBranchContentsTable.spec.tsx @@ -3,12 +3,12 @@ import { renderHook, waitFor } from '@testing-library/react' import { graphql } from 'msw' import { setupServer } from 'msw/node' import qs from 'qs' +import React from 'react' import { MemoryRouter, Route } from 'react-router-dom' -import { act } from 'react-test-renderer' import { useRepoBranchContentsTable } from './useRepoBranchContentsTable' -const mockCommitContentData = { +const mockBranchContentData = { owner: { repository: { repositoryConfig: { @@ -23,17 +23,23 @@ const mockCommitContentData = { __typename: 'PathContents', results: [ { + hits: 9, + misses: 0, + partials: 0, + lines: 10, name: 'src', - filePath: null, - percentCovered: 50.0, - type: 'dir', + path: 'src', + percentCovered: 100.0, __typename: 'PathContentDir', }, { + hits: 9, + misses: 0, + partials: 0, + lines: 10, name: 'file.ts', - filePath: null, - percentCovered: 50.0, - type: 'file', + path: 'src/file.ts', + percentCovered: 100.0, __typename: 'PathContentFile', }, ], @@ -71,7 +77,9 @@ const queryClient = new QueryClient({ const server = setupServer() const wrapper = - (initialEntries = '/gh/test-org/test-repo/tree/main') => + ( + initialEntries = '/gh/test-org/test-repo/tree/main' + ): React.FC => ({ children }) => ( @@ -113,24 +121,24 @@ const mockOverview = { describe('useRepoBranchContentsTable', () => { function setup({ noData } = { noData: false }) { - const calledCommitContents = jest.fn() + const calledBranchContents = jest.fn() server.use( graphql.query('BranchContents', (req, res, ctx) => { - calledCommitContents(req?.variables) + calledBranchContents(req?.variables) if (noData) { return res(ctx.status(200), ctx.data(mockCommitNoContentData)) } - return res(ctx.status(200), ctx.data(mockCommitContentData)) + return res(ctx.status(200), ctx.data(mockBranchContentData)) }), graphql.query('GetRepoOverview', (req, res, ctx) => { return res(ctx.status(200), ctx.data(mockOverview)) }) ) - return { calledCommitContents } + return { calledBranchContents } } describe('calling the hook', () => { @@ -166,18 +174,6 @@ describe('useRepoBranchContentsTable', () => { await waitFor(() => expect(result.current.data.length).toBe(3)) }) }) - - it('sets the correct headers', async () => { - setup() - const { result } = renderHook(() => useRepoBranchContentsTable(), { - wrapper: wrapper(), - }) - - await waitFor(() => expect(queryClient.isFetching()).toBeGreaterThan(0)) - await waitFor(() => expect(queryClient.isFetching()).toBe(0)) - - expect(result.current.headers.length).toBe(6) - }) }) describe('when there is no data', () => { @@ -197,7 +193,7 @@ describe('useRepoBranchContentsTable', () => { describe('when there is a search param', () => { it('makes a gql request with the search value', async () => { - const { calledCommitContents } = setup() + const { calledBranchContents } = setup() renderHook(() => useRepoBranchContentsTable(), { wrapper: wrapper( `/gh/test-org/test-repo/tree/main${qs.stringify( @@ -210,17 +206,12 @@ describe('useRepoBranchContentsTable', () => { await waitFor(() => expect(queryClient.isFetching()).toBeGreaterThan(0)) await waitFor(() => expect(queryClient.isFetching()).toBe(0)) - expect(calledCommitContents).toHaveBeenCalled() - expect(calledCommitContents).toHaveBeenCalledWith({ + expect(calledBranchContents).toHaveBeenCalled() + expect(calledBranchContents).toHaveBeenCalledWith({ branch: 'main', filters: { searchValue: 'file.js', - flags: [], - components: [], - ordering: { - direction: 'ASC', - parameter: 'NAME', - }, + displayType: 'LIST', }, name: 'test-org', repo: 'test-repo', @@ -231,7 +222,7 @@ describe('useRepoBranchContentsTable', () => { describe('when called with the list param', () => { it('makes a gql request with the list param', async () => { - const { calledCommitContents } = setup() + const { calledBranchContents } = setup() renderHook(() => useRepoBranchContentsTable(), { wrapper: wrapper( `/gh/test-org/test-repo/tree/main${qs.stringify( @@ -244,17 +235,11 @@ describe('useRepoBranchContentsTable', () => { await waitFor(() => expect(queryClient.isFetching()).toBeGreaterThan(0)) await waitFor(() => expect(queryClient.isFetching()).toBe(0)) - expect(calledCommitContents).toHaveBeenCalled() - expect(calledCommitContents).toHaveBeenCalledWith({ + expect(calledBranchContents).toHaveBeenCalled() + expect(calledBranchContents).toHaveBeenCalledWith({ branch: 'main', filters: { displayType: 'LIST', - flags: [], - components: [], - ordering: { - direction: 'DESC', - parameter: 'MISSES', - }, }, name: 'test-org', repo: 'test-repo', @@ -265,7 +250,7 @@ describe('useRepoBranchContentsTable', () => { describe('when there is a flags param', () => { it('makes a gql request with the flags param', async () => { - const { calledCommitContents } = setup() + const { calledBranchContents } = setup() renderHook(() => useRepoBranchContentsTable(), { wrapper: wrapper( `/gh/test-org/test-repo/tree/main${qs.stringify( @@ -278,16 +263,12 @@ describe('useRepoBranchContentsTable', () => { await waitFor(() => expect(queryClient.isFetching()).toBeGreaterThan(0)) await waitFor(() => expect(queryClient.isFetching()).toBe(0)) - expect(calledCommitContents).toHaveBeenCalled() - expect(calledCommitContents).toHaveBeenCalledWith({ + expect(calledBranchContents).toHaveBeenCalled() + expect(calledBranchContents).toHaveBeenCalledWith({ branch: 'main', filters: { flags: ['flag-1'], - components: [], - ordering: { - direction: 'ASC', - parameter: 'NAME', - }, + displayType: 'TREE', }, name: 'test-org', repo: 'test-repo', @@ -298,7 +279,7 @@ describe('useRepoBranchContentsTable', () => { describe('when there is a components param', () => { it('makes a gql request with the components param', async () => { - const { calledCommitContents } = setup() + const { calledBranchContents } = setup() renderHook(() => useRepoBranchContentsTable(), { wrapper: wrapper( `/gh/test-org/test-repo/tree/main${qs.stringify( @@ -311,51 +292,12 @@ describe('useRepoBranchContentsTable', () => { await waitFor(() => expect(queryClient.isFetching()).toBeGreaterThan(0)) await waitFor(() => expect(queryClient.isFetching()).toBe(0)) - expect(calledCommitContents).toHaveBeenCalled() - expect(calledCommitContents).toHaveBeenCalledWith({ + expect(calledBranchContents).toHaveBeenCalled() + expect(calledBranchContents).toHaveBeenCalledWith({ branch: 'main', filters: { components: ['component-1'], - flags: [], - ordering: { - direction: 'ASC', - parameter: 'NAME', - }, - }, - name: 'test-org', - repo: 'test-repo', - path: '', - }) - }) - }) - - describe('when handleSort is triggered', () => { - it('makes a gql request with the updated params', async () => { - const { calledCommitContents } = setup() - const { result } = renderHook(() => useRepoBranchContentsTable(), { - wrapper: wrapper(), - }) - - await waitFor(() => expect(queryClient.isFetching()).toBeGreaterThan(0)) - await waitFor(() => expect(queryClient.isFetching()).toBe(0)) - - act(() => { - result.current.handleSort([{ desc: true, id: 'name' }]) - }) - - await waitFor(() => expect(queryClient.isFetching()).toBeGreaterThan(0)) - await waitFor(() => expect(queryClient.isFetching()).toBe(0)) - - expect(calledCommitContents).toHaveBeenCalledTimes(2) - expect(calledCommitContents).toHaveBeenNthCalledWith(2, { - branch: 'main', - filters: { - flags: [], - components: [], - ordering: { - direction: 'DESC', - parameter: 'NAME', - }, + displayType: 'TREE', }, name: 'test-org', repo: 'test-repo', diff --git a/src/services/pathContents/branch/dir/useRepoBranchContents.spec.js b/src/services/pathContents/branch/dir/useRepoBranchContents.spec.tsx similarity index 91% rename from src/services/pathContents/branch/dir/useRepoBranchContents.spec.js rename to src/services/pathContents/branch/dir/useRepoBranchContents.spec.tsx index f160d295bd..abdeb0aaf8 100644 --- a/src/services/pathContents/branch/dir/useRepoBranchContents.spec.js +++ b/src/services/pathContents/branch/dir/useRepoBranchContents.spec.tsx @@ -10,7 +10,7 @@ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } }, }) -const wrapper = ({ children }) => ( +const wrapper: React.FC = ({ children }) => ( {children} @@ -42,10 +42,14 @@ const dataReturned = { pathContents: { results: [ { - name: 'flag1', - filePath: null, + __typename: 'PathContentDir', + hits: 9, + misses: 0, + partials: 0, + lines: 10, + name: 'src', + path: 'src', percentCovered: 100.0, - type: 'dir', }, ], __typename: 'PathContents', @@ -157,15 +161,18 @@ describe('useRepoBranchContents', () => { await waitFor(() => result.current.isLoading) await waitFor(() => !result.current.isLoading) await waitFor(() => result.current.isSuccess) - - expect(queryClient.getQueryState().data).toEqual( + expect(result.current.data).toEqual( expect.objectContaining({ results: [ { - name: 'flag1', - filePath: null, + __typename: 'PathContentDir', + hits: 9, + misses: 0, + partials: 0, + lines: 10, + name: 'src', + path: 'src', percentCovered: 100.0, - type: 'dir', }, ], indicationRange: { diff --git a/src/services/pathContents/branch/dir/useRepoBranchContents.tsx b/src/services/pathContents/branch/dir/useRepoBranchContents.tsx index e9d7290850..69bd4f30a7 100644 --- a/src/services/pathContents/branch/dir/useRepoBranchContents.tsx +++ b/src/services/pathContents/branch/dir/useRepoBranchContents.tsx @@ -74,11 +74,11 @@ const BranchContentsSchema = z.object({ owner: z .object({ repository: z.object({ - repoConfig: RepoConfig, + repositoryConfig: RepoConfig, branch: z.object({ head: z .object({ - pathContents: PathContentsUnionSchema, + pathContents: PathContentsUnionSchema.nullish(), }) .nullable(), }), @@ -111,6 +111,7 @@ function fetchRepoContents({ const parsedData = BranchContentsSchema.safeParse(res?.data) if (!parsedData.success) { + console.log('FAIL', parsedData.error) return null } @@ -122,11 +123,12 @@ function fetchRepoContents({ results = parsedData?.data?.owner?.repository?.branch?.head?.pathContents?.results } + return { results: results ?? null, pathContentsType, indicationRange: - parsedData?.data?.owner?.repository?.repoConfig?.indicationRange, + parsedData?.data?.owner?.repository?.repositoryConfig?.indicationRange, __typename: res?.data?.owner?.repository?.branch?.head?.__typename, } }) diff --git a/src/shared/ContentsTable/TableEntries/BranchEntries/BranchDirEntry.spec.jsx b/src/shared/ContentsTable/TableEntries/BranchEntries/BranchDirEntry.spec.jsx index 081937a9be..c4fd2071f9 100644 --- a/src/shared/ContentsTable/TableEntries/BranchEntries/BranchDirEntry.spec.jsx +++ b/src/shared/ContentsTable/TableEntries/BranchEntries/BranchDirEntry.spec.jsx @@ -45,15 +45,18 @@ const queryClient = new QueryClient({ }) const server = setupServer() -const wrapper = ({ children }) => ( - - - - {children} - - - -) +const wrapper = + (initialEntries = ['/gh/codecov/test-repo/tree/main/src/']) => + ({ children }) => + ( + + + + {children} + + + + ) beforeAll(() => server.listen()) afterEach(() => { @@ -79,7 +82,7 @@ describe('BranchDirEntry', () => { setup() render( , - { wrapper } + { wrapper: wrapper() } ) const dir = await screen.findByText('dir') @@ -90,7 +93,7 @@ describe('BranchDirEntry', () => { setup() render( , - { wrapper } + { wrapper: wrapper() } ) const a = await screen.findByRole('link') @@ -100,7 +103,7 @@ describe('BranchDirEntry', () => { ) }) - describe('flags filters is passed', () => { + describe('flags filter is set', () => { it('sets the correct href', async () => { setup() render( @@ -113,18 +116,21 @@ describe('BranchDirEntry', () => { components: [], }} />, - { wrapper } + { + wrapper: wrapper([ + '/gh/codecov/test-repo/tree/main/src?flags=flag-1', + ]), + } ) - const a = await screen.findByRole('link') expect(a).toHaveAttribute( 'href', - '/gh/codecov/test-repo/tree/branch/path%2Fto%2Fdirectory%2Fdir?flags%5B0%5D=flag-1' + '/gh/codecov/test-repo/tree/branch/path%2Fto%2Fdirectory%2Fdir?flags=flag-1' ) }) }) - describe('components and flags filters is passed', () => { + describe('components and flags filters is set', () => { it('sets the correct href', async () => { setup() render( @@ -137,13 +143,17 @@ describe('BranchDirEntry', () => { components: ['component-1'], }} />, - { wrapper } + { + wrapper: wrapper([ + '/gh/codecov/test-repo/tree/main/src?flags=flag-1&components=component-1', + ]), + } ) const a = await screen.findByRole('link') expect(a).toHaveAttribute( 'href', - '/gh/codecov/test-repo/tree/branch/path%2Fto%2Fdirectory%2Fdir?flags%5B0%5D=flag-1&components%5B0%5D=component-1' + '/gh/codecov/test-repo/tree/branch/path%2Fto%2Fdirectory%2Fdir?flags=flag-1&components=component-1' ) }) }) @@ -153,7 +163,7 @@ describe('BranchDirEntry', () => { render( , - { wrapper } + { wrapper: wrapper() } ) await user.hover(screen.getByText('dir')) diff --git a/src/shared/ContentsTable/TableEntries/BranchEntries/BranchFileEntry.spec.jsx b/src/shared/ContentsTable/TableEntries/BranchEntries/BranchFileEntry.spec.jsx index 3cb3c9a4c2..dcfab65bd7 100644 --- a/src/shared/ContentsTable/TableEntries/BranchEntries/BranchFileEntry.spec.jsx +++ b/src/shared/ContentsTable/TableEntries/BranchEntries/BranchFileEntry.spec.jsx @@ -57,14 +57,16 @@ const queryClient = new QueryClient({ }) const server = setupServer() -const wrapper = ({ children }) => ( - - - {children} - - -) - +const wrapper = + (initialEntries = ['/gh/codecov/test-repo/']) => + ({ children }) => + ( + + + {children} + + + ) beforeAll(() => { server.listen() }) @@ -107,7 +109,7 @@ describe('BranchFileEntry', () => { isCriticalFile={false} displayType={displayTypeParameter.list} />, - { wrapper } + { wrapper: wrapper() } ) const file = await screen.findByText('dir/file.js') @@ -128,7 +130,7 @@ describe('BranchFileEntry', () => { isCriticalFile={false} displayType={displayTypeParameter.tree} />, - { wrapper } + { wrapper: wrapper() } ) const file = await screen.findByText('file.js') @@ -147,7 +149,7 @@ describe('BranchFileEntry', () => { isCriticalFile={false} displayType={displayTypeParameter.tree} />, - { wrapper } + { wrapper: wrapper() } ) await waitFor(() => queryClient.isFetching) @@ -171,7 +173,7 @@ describe('BranchFileEntry', () => { isCriticalFile={true} displayType={displayTypeParameter.list} />, - { wrapper } + { wrapper: wrapper() } ) const file = await screen.findByText('Critical File') @@ -192,7 +194,7 @@ describe('BranchFileEntry', () => { isCriticalFile={false} displayType={displayTypeParameter.list} />, - { wrapper } + { wrapper: wrapper() } ) const file = await screen.findByText('dir/file.js') @@ -200,7 +202,7 @@ describe('BranchFileEntry', () => { }) }) - describe('flags filters is passed', () => { + describe('flags filters is set', () => { it('sets the correct href', async () => { setup() render( @@ -211,12 +213,12 @@ describe('BranchFileEntry', () => { urlPath="dir" isCriticalFile={false} displayType={displayTypeParameter.tree} - filters={{ - flags: ['flag-1'], - components: [], - }} />, - { wrapper } + { + wrapper: wrapper([ + '/gh/codecov/test-repo/blob/main/dir%2Ffile.js?flags%5B0%5D=flag-1', + ]), + } ) const a = await screen.findByRole('link') @@ -238,12 +240,12 @@ describe('BranchFileEntry', () => { urlPath="dir" isCriticalFile={false} displayType={displayTypeParameter.tree} - filters={{ - flags: ['flag-1'], - components: ['component-3.1415924'], - }} />, - { wrapper } + { + wrapper: wrapper([ + '/gh/codecov/test-repo/blob/main/dir%2Ffile.js?flags%5B0%5D=flag-1&components%5B0%5D=component-3.1415924', + ]), + } ) const a = await screen.findByRole('link') @@ -267,7 +269,7 @@ describe('BranchFileEntry', () => { isCriticalFile={false} displayType={displayTypeParameter.tree} />, - { wrapper } + { wrapper: wrapper() } ) const file = await screen.findByText('file.js') @@ -318,9 +320,12 @@ describe('BranchFileEntry', () => { urlPath="dir" isCriticalFile={false} displayType={displayTypeParameter.tree} - filters={{ flags: ['flag-1'] }} />, - { wrapper } + { + wrapper: wrapper([ + '/gh/codecov/test-repo/blob/main/dir%2Ffile.js?flags%5B0%5D=flag-1&components%5B0%5D=component-3.1415924', + ]), + } ) const file = await screen.findByText('file.js') @@ -352,7 +357,7 @@ describe('BranchFileEntry', () => { displayType={displayTypeParameter.tree} filters={{ flags: [] }} />, - { wrapper } + { wrapper: wrapper() } ) const file = await screen.findByText('file.js')