Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Indirect changes table refactor #2552

Merged
merged 11 commits into from
Feb 6, 2024

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import userEvent from '@testing-library/user-event'
import { graphql } from 'msw'
import { setupServer } from 'msw/node'
import qs from 'qs'
import { Suspense } from 'react'
import { MemoryRouter, Route } from 'react-router-dom'

import IndirectChangesTable from '.'
import IndirectChangesTable from './IndirectChangesTable'

jest.mock('./CommitFileDiff', () => () => 'CommitFileDiff')

Expand All @@ -27,9 +26,9 @@ afterAll(() => {

const wrapper =
(
queryClient,
queryClient: QueryClient,
initialEntries = '/gh/codecov/cool-repo/commit/123/indirect-changes'
) =>
): React.FC<React.PropsWithChildren> =>
({ children }) =>
(
<QueryClientProvider client={queryClient}>
Expand All @@ -40,20 +39,19 @@ const wrapper =
'/:provider/:owner/:repo/commit/:commit/blob/:path+',
]}
>
<Suspense fallback="Loading...">{children}</Suspense>
{children}
</Route>
</MemoryRouter>
</QueryClientProvider>
)

describe('IndirectChangesTable', () => {
function setup(data = [], state = 'processed') {
function setup(data = {}, state = 'processed') {
const user = userEvent.setup()
const mockVars = jest.fn()
const queryClient = new QueryClient({
defaultOptions: {
queries: {
suspense: true,
retry: false,
},
},
Expand Down Expand Up @@ -179,36 +177,6 @@ describe('IndirectChangesTable', () => {
})
})

describe('when all data is missing', () => {
const mockData = {
__typename: 'ImpactedFiles',
results: [
{
headName: '',
baseCoverage: null,
headCoverage: null,
patchCoverage: null,
},
],
}

it('does not render coverage', () => {
const { queryClient } = setup(mockData)
render(<IndirectChangesTable />, { wrapper: wrapper(queryClient) })

const coverage = screen.queryByText(/0.00%/)
expect(coverage).not.toBeInTheDocument()
})

it('renders no available data copy', async () => {
const { queryClient } = setup(mockData)
render(<IndirectChangesTable />, { wrapper: wrapper(queryClient) })

const copy = await screen.findByText('No data')
expect(copy).toBeInTheDocument()
})
})

describe('when some data is missing', () => {
const mockData = {
__typename: 'ImpactedFiles',
Expand Down Expand Up @@ -271,6 +239,9 @@ describe('IndirectChangesTable', () => {
)
render(<IndirectChangesTable />, { wrapper: wrapper(queryClient) })

await waitFor(() => expect(queryClient.isFetching()).toBeGreaterThan(0))
await waitFor(() => expect(queryClient.isFetching()).toBe(0))

const spinner = await screen.findByTestId('spinner')
expect(spinner).toBeInTheDocument()
})
Expand Down Expand Up @@ -305,6 +276,29 @@ describe('IndirectChangesTable', () => {
const commitFileDiff = await screen.findByText('CommitFileDiff')
expect(commitFileDiff).toBeInTheDocument()
})

it('renders commit file diff', async () => {
const { queryClient, user } = setup(mockData)
render(<IndirectChangesTable />, { wrapper: wrapper(queryClient) })

const expander = await screen.findByTestId('file-diff-expand')
expect(expander).toBeInTheDocument()
await user.click(expander)

const commitFileDiff = await screen.findByText('CommitFileDiff')
expect(commitFileDiff).toBeInTheDocument()
})

it('when click on file name', async () => {
const { queryClient, user } = setup(mockData)
render(<IndirectChangesTable />, { wrapper: wrapper(queryClient) })

const fileName = await screen.findByText('src/index2.py')
await user.click(fileName)

const commitFileDiff = await screen.findByText('CommitFileDiff')
expect(commitFileDiff).toBeInTheDocument()
})
})

describe('flags and components param in url is set', () => {
Expand Down Expand Up @@ -342,4 +336,17 @@ describe('IndirectChangesTable', () => {
expect(coverage).toBeInTheDocument()
})
})

describe('when is loading', () => {
it('renders loader', () => {
const { queryClient } = setup({
__typename: 'ImpactedFiles',
results: [],
})
render(<IndirectChangesTable />, { wrapper: wrapper(queryClient) })

const loader = screen.getByTestId('spinner')
expect(loader).toBeInTheDocument()
})
})
})
Loading
Loading