Skip to content

Commit

Permalink
tip from good guy KCD cleans things up quite a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Jan 3, 2022
1 parent 96f5349 commit 2aba869
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
8 changes: 3 additions & 5 deletions app/pages/__tests__/InstanceCreatePage.spec.tsx
Expand Up @@ -93,17 +93,15 @@ describe('InstanceCreatePage', () => {

it('navigates to project instances page on success', async () => {
const mock = fetchMock.post(instancesUrl, { status: 201, body: instance })
const { history } = renderPage()
renderPage()

const instancesPage = `/orgs/${org.name}/projects/${project.name}/instances`
expect(history.location.pathname).not.toEqual(instancesPage)
expect(window.location.pathname).not.toEqual(instancesPage)

fireEvent.click(submitButton())

await waitFor(() => expect(mock.called(instancesUrl)).toBeTruthy())
await waitFor(() => expect(mock.done()).toBeTruthy())
await waitFor(() =>
expect(history.location.pathname).toEqual(instancesPage)
)
await waitFor(() => expect(window.location.pathname).toEqual(instancesPage))
})
})
6 changes: 3 additions & 3 deletions app/pages/__tests__/ProjectCreatePage.spec.tsx
Expand Up @@ -116,12 +116,12 @@ describe('ProjectCreatePage', () => {
// instances fetch after success
fetchMock.get(instancesUrl, { status: 200, body: { items: [] } })

const { history } = renderPage()
renderPage()
const projectPath = `/orgs/${org.name}/projects/${project.name}/instances`
expect(history.location.pathname).not.toEqual(projectPath)
expect(window.location.pathname).not.toEqual(projectPath)

fireEvent.click(submitButton())

await waitFor(() => expect(history.location.pathname).toEqual(projectPath))
await waitFor(() => expect(window.location.pathname).toEqual(projectPath))
})
})
15 changes: 3 additions & 12 deletions app/test-utils.tsx
@@ -1,9 +1,5 @@
import React from 'react'
import {
BrowserRouter,
unstable_HistoryRouter as HistoryRouter,
} from 'react-router-dom'
import { createMemoryHistory } from 'history'
import { BrowserRouter } from 'react-router-dom'
import { render } from '@testing-library/react'
import { QueryClient, QueryClientProvider } from 'react-query'
import type { FetchMockStatic } from 'fetch-mock'
Expand Down Expand Up @@ -36,13 +32,8 @@ export const renderWithRouter = (ui: React.ReactElement) =>
})

export function renderAppAt(location: string) {
const history = createMemoryHistory({ initialEntries: [location] })
const rendered = render(
<HistoryRouter history={history}>
<QueryClientProvider client={queryClient}>{routes}</QueryClientProvider>
</HistoryRouter>
)
return { history, rendered }
window.history.pushState({}, 'Test page', location)
return renderWithRouter(routes)
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down

0 comments on commit 2aba869

Please sign in to comment.