Skip to content

Commit

Permalink
Add tests for fragmentarium 404 routes
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Feb 28, 2024
1 parent cefe006 commit 80392d6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.
30 changes: 30 additions & 0 deletions src/router/notFoundRoutes.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import { Router, Switch } from 'react-router-dom'
import FragmentariumRoutes from './fragmentariumRoutes'
import { getServices } from 'test-support/AppDriver'
import { createMemoryHistory } from 'history'

describe('NotFoundPage rendering in FragmentariumRoutes', () => {
const nonExistentRoutes = [
'/fragmentarium/search/non-existent',
'/fragmentarium/Fragment.12345/match/non-existent',
'/fragmentarium/Fragment.12345/annotate/non-existent',
'/fragmentarium/Fragment.12345/non-existent',
]
nonExistentRoutes.forEach((path) => {
const history = createMemoryHistory({ initialEntries: [path] })
test(`renders NotFoundPage for "${path}"`, () => {
render(
<Router history={history}>
<Switch>
{[...FragmentariumRoutes({ ...getServices(), sitemap: false })]}
</Switch>
</Router>
)
expect(
screen.getByText(/The page you are looking for does not exist./i)
).toBeInTheDocument()
})
})
})
48 changes: 32 additions & 16 deletions src/test-support/AppDriver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,22 @@ import AfoRegisterRepository from 'afo-register/infrastructure/AfoRegisterReposi
import AfoRegisterService from 'afo-register/application/AfoRegisterService'
import { FindspotService } from 'fragmentarium/application/FindspotService'
import { ApiFindspotRepository } from 'fragmentarium/infrastructure/FindspotRepository'

function createApp(api): JSX.Element {
import FakeApi from 'test-support/FakeApi'

export function getServices(
api: any = FakeApi
): {
signService: SignService
wordService: WordService
fragmentService: FragmentService
fragmentSearchService: FragmentSearchService
bibliographyService: BibliographyService
textService: TextService
markupService: MarkupService
cachedMarkupService: CachedMarkupService
afoRegisterService: AfoRegisterService
findspotService: FindspotService
} {
const wordRepository = new WordRepository(api)
const fragmentRepository = new FragmentRepository(api)
const imageRepository = new ApiImageRepository(api)
Expand Down Expand Up @@ -64,20 +78,22 @@ function createApp(api): JSX.Element {
const cachedMarkupService = new CachedMarkupService(api, bibliographyService)
const afoRegisterService = new AfoRegisterService(afoRegisterRepository)
const findspotService = new FindspotService(findspotRepository)
return (
<App
signService={signService}
wordService={wordService}
fragmentService={fragmentService}
fragmentSearchService={fragmentSearchService}
bibliographyService={bibliographyService}
textService={textService}
markupService={markupService}
cachedMarkupService={cachedMarkupService}
afoRegisterService={afoRegisterService}
findspotService={findspotService}
/>
)
return {
signService,
wordService,
fragmentService,
fragmentSearchService,
bibliographyService,
textService,
markupService,
cachedMarkupService,
afoRegisterService,
findspotService,
}
}

function createApp(api): JSX.Element {
return <App {...getServices(api)} />
}

const breadcrumbs = {
Expand Down

0 comments on commit 80392d6

Please sign in to comment.