Skip to content

Commit

Permalink
all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitvinnakota-codecov committed Mar 20, 2024
1 parent ca4ff0f commit f6ae134
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ const mockNoHeadReport = {
branch: {
head: {
pathContents: {
__typename: 'PathContents',
__typename: 'MissingHeadReport',
results: [],
},
__typename: 'MissingHeadReport',
},
},
},
Expand All @@ -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<React.PropsWithChildren> =>
({ children }) => {
return (
<QueryClientProvider client={queryClient}>
<MemoryRouter initialEntries={[initialEntries]}>
<Route path="/:provider/:owner/:repo/tree/:branch/:path+">
<Route path="/:provider/:owner/:repo/tree/:branch/:path*">
{children}
</Route>
</MemoryRouter>
Expand All @@ -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(
Expand Down Expand Up @@ -196,47 +189,47 @@ describe('FileListTable', () => {
describe('rendering table', () => {
describe('displaying the table head', () => {
it('has a files column', async () => {
setup()
setup({})
render(<FileListTable />, { wrapper: wrapper() })

const files = await screen.findByText('Files')
expect(files).toBeInTheDocument()
})

it('has a tracked lines column', async () => {
setup()
setup({})
render(<FileListTable />, { wrapper: wrapper() })

const trackedLines = await screen.findByText('Tracked lines')
expect(trackedLines).toBeInTheDocument()
})

it('has a covered column', async () => {
setup()
setup({})
render(<FileListTable />, { wrapper: wrapper() })

const covered = await screen.findByText('Covered')
expect(covered).toBeInTheDocument()
})

it('has a partial column', async () => {
setup()
setup({})
render(<FileListTable />, { wrapper: wrapper() })

const partial = await screen.findByText('Partial')
expect(partial).toBeInTheDocument()
})

it('has a missed column', async () => {
setup()
setup({})
render(<FileListTable />, { wrapper: wrapper() })

const missed = await screen.findByText('Missed')
expect(missed).toBeInTheDocument()
})

it('has a coverage column', async () => {
setup()
setup({})
render(<FileListTable />, { wrapper: wrapper() })

const coverage = await screen.findByText('Coverage %')
Expand All @@ -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(<FileListTable />, {
wrapper: wrapper(
`/gh/codecov/cool-repo/tree/main/a/b/c${qs.stringify(
Expand All @@ -270,7 +263,7 @@ describe('FileListTable', () => {

describe('displaying a file', () => {
it('has the correct url', async () => {
setup()
setup({})
render(<FileListTable />, {
wrapper: wrapper(
`/gh/codecov/cool-repo/tree/main/a/b/c${qs.stringify(
Expand All @@ -294,7 +287,9 @@ describe('FileListTable', () => {
describe('there is no results found', () => {
it('displays error fetching data message', async () => {
setup({ noFiles: true })
render(<FileListTable />, { wrapper: wrapper() })
render(<FileListTable />, {
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.'
Expand All @@ -306,7 +301,9 @@ describe('FileListTable', () => {
describe('when head commit has no reports', () => {
it('renders no report uploaded message', async () => {
setup({ noHeadReport: true })
render(<FileListTable />, { wrapper: wrapper() })
render(<FileListTable />, {
wrapper: wrapper('/gh/codecov/cool-repo/tree/main'),
})

const message = await screen.findByText(
'No coverage report uploaded for this branch head commit'
Expand Down Expand Up @@ -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(<FileListTable />, { wrapper: wrapper() })

let files = await screen.findByText('Files')
await user.click(files)
await user.click(files)

expect(requestFilters).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -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(<FileListTable />, { wrapper: wrapper() })

let files = await screen.findByText('Files')
Expand All @@ -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(<FileListTable />, { wrapper: wrapper() })

let trackedLines = await screen.findByText('Tracked lines')
Expand All @@ -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(<FileListTable />, { wrapper: wrapper() })

let trackedLines = await screen.findByText('Tracked lines')
Expand All @@ -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(<FileListTable />, { wrapper: wrapper() })

const covered = await screen.findByText('Covered')
Expand All @@ -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(<FileListTable />, { wrapper: wrapper() })

let covered = await screen.findByText('Covered')
Expand All @@ -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(<FileListTable />, { wrapper: wrapper() })

let partial = await screen.findByText('Partial')
Expand All @@ -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(<FileListTable />, { wrapper: wrapper() })

let partial = await screen.findByText('Partial')
Expand All @@ -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(<FileListTable />, { wrapper: wrapper() })

let missed = await screen.findByText('Missed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const getBaseColumns = () => {
}),
columnHelper.accessor('lines', {
id: 'lines',
header: () => 'Lines',
header: () => 'Tracked lines',
cell: ({ renderValue }) => renderValue(),
}),
columnHelper.accessor('hits', {
Expand All @@ -73,7 +73,7 @@ export const getBaseColumns = () => {
cell: ({ renderValue }) => renderValue(),
}),
columnHelper.accessor('partials', {
id: 'change',
id: 'partials',
header: () => 'Partial',
cell: ({ renderValue }) => renderValue(),
}),
Expand Down Expand Up @@ -104,7 +104,6 @@ function FileListTable() {
hasComponentsSelected,
pathContentsType,
} = useRepoBranchContentsTable(ordering)

const table = useReactTable({
columns: getBaseColumns(),
getCoreRowModel: getCoreRowModel(),
Expand Down

0 comments on commit f6ae134

Please sign in to comment.