-
Notifications
You must be signed in to change notification settings - Fork 24
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: refactor page components into separate sections #3231
Merged
ajay-sentry
merged 2 commits into
tests-analytics-v2
from
Ajay/test-analytics-component-refactors
Sep 24, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsPage.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<PropsWithChildren> = | ||
(initialEntries = '/gh/codecov/cool-repo/tests') => | ||
({ children }) => ( | ||
<QueryClientProvider client={queryClient}> | ||
<MemoryRouter initialEntries={[initialEntries]}> | ||
<Route | ||
path={[ | ||
'/:provider/:owner/:repo/tests', | ||
'/:provider/:owner/:repo/tests/new', | ||
'/:provider/:owner/:repo/tests/new/codecov-cli', | ||
'/:provider/:owner/:repo/tests/:branch', | ||
]} | ||
exact | ||
> | ||
<Suspense fallback={null}>{children}</Suspense> | ||
</Route> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
) | ||
|
||
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(<FailedTestsPage />, { 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() | ||
}) | ||
}) |
122 changes: 3 additions & 119 deletions
122
src/pages/RepoPage/FailedTestsTab/FailedTestsPage/FailedTestsPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to break these down into separate it blocks to improve debugging, but it's not a blocker since this file will be worked on later anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer this pattern, though I have seen us do the multiple renders and verbose testing that way.
My reasoning is that we have less renders overall, and if something fails on a certain line we know the exact column that fails anyway.
The perk with the verbose method though is if multiple columns fail you see them all at once