Skip to content

Commit

Permalink
dev: Clean up some unneccesary mocks to speed up gazebo tests (#3604)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-sentry authored Dec 20, 2024
1 parent fdd77d4 commit 6a6fd2c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 46 deletions.
10 changes: 3 additions & 7 deletions src/pages/DefaultOrgSelector/DefaultOrgSelector.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const wrapper =
)

beforeAll(() => {
console.error = () => {}
server.listen({
onUnhandledRequest: 'warn',
})
Expand All @@ -169,6 +170,7 @@ afterEach(() => {
})
afterAll(() => {
server.close()
vi.resetAllMocks()
})

describe('DefaultOrgSelector', () => {
Expand Down Expand Up @@ -1296,7 +1298,7 @@ describe('DefaultOrgSelector', () => {

describe('on fetch next page', () => {
it('renders next page', async () => {
const { user, fetchNextPage } = setup({
const { fetchNextPage } = setup({
useUserData: mockUserData,
myOrganizationsData: {
me: {
Expand All @@ -1318,12 +1320,6 @@ describe('DefaultOrgSelector', () => {
render(<DefaultOrgSelector />, { wrapper: wrapper() })
mocks.useIntersection.mockReturnValue({ isIntersecting: true })

const selectOrg = await screen.findByRole('button', {
name: 'Select an organization',
})

await user.click(selectOrg)

await waitFor(() => expect(fetchNextPage).toHaveBeenCalled())
await waitFor(() => expect(fetchNextPage).toHaveBeenCalledWith('MTI='))
})
Expand Down
18 changes: 4 additions & 14 deletions src/pages/RepoPage/CommitsTab/CommitsTab.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,6 @@ describe('CommitsTab', () => {
})

describe('when select onLoadMore is triggered', () => {
beforeEach(() => {
mocks.useIntersection.mockReturnValue({
isIntersecting: true,
})
})

afterEach(() => {
vi.clearAllMocks()
})

describe('when there is not a next page', () => {
it('does not call fetchNextPage', async () => {
const { user, fetchNextPage } = setup({ hasNextPage: false })
Expand All @@ -359,12 +349,12 @@ describe('CommitsTab', () => {

describe('when there is a next page', () => {
it('calls fetchNextPage', async () => {
const { fetchNextPage, user } = setup({ hasNextPage: true })
const { fetchNextPage } = setup({ hasNextPage: true })
mocks.useIntersection.mockReturnValue({
isIntersecting: true,
})
render(<CommitsTab />, { wrapper })

const select = await screen.findByText('Select branch')
await user.click(select)

await waitFor(() =>
expect(fetchNextPage).toHaveBeenCalledWith('some cursor')
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ describe('Summary', () => {
describe('there is a next page', () => {
it('calls fetchNextPage', async () => {
const mockSetNewPath = vi.fn()
const { fetchNextPage, user } = setup({
const { fetchNextPage } = setup({
hasNextPage: true,
coverageRedirectData: {
redirectState: {
Expand All @@ -378,11 +378,6 @@ describe('Summary', () => {
})
render(<Summary />, { wrapper: wrapper() })

const select = await screen.findByRole('button', {
name: 'select branch',
})
await user.click(select)

await waitFor(() => expect(fetchNextPage).toHaveBeenCalled())
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ describe('Summary', () => {
describe('there is a next page', () => {
it('calls fetchNextPage', async () => {
const mockSetNewPath = vi.fn()
const { fetchNextPage, user } = setup({
const { fetchNextPage } = setup({
isIntersecting: true,
hasNextPage: true,
coverageRedirectData: {
Expand All @@ -361,11 +361,6 @@ describe('Summary', () => {
})
render(<SummaryTeamPlan />, { wrapper: wrapper() })

const select = await screen.findByRole('button', {
name: 'select branch',
})
await user.click(select)

await waitFor(() => expect(fetchNextPage).toHaveBeenCalled())
})
})
Expand Down
13 changes: 0 additions & 13 deletions src/ui/FileViewer/ToggleHeader/ToggleHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ import { MemoryRouter, Route } from 'react-router-dom'

import ToggleHeader from './ToggleHeader'

const mocks = vi.hoisted(() => ({
useIntersection: vi.fn(),
}))

vi.mock('react-use', async () => {
const original = await vi.importActual('react-use')

return {
...original,
useIntersection: mocks.useIntersection,
}
})

const mockFlagResponse = {
owner: {
repository: {
Expand Down

0 comments on commit 6a6fd2c

Please sign in to comment.