Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9c5e679
Trigger Build
bencegadanyi1-nhs Sep 11, 2025
664a016
Merge branch 'main' into AEA-5328-go-back-button-functionality
bencegadanyi1-nhs Sep 16, 2025
27573e2
Merge branch 'main' into AEA-5328-go-back-button-functionality
bencegadanyi1-nhs Sep 19, 2025
aeb3763
Merge branch 'main' into AEA-5328-go-back-button-functionality
bencegadanyi1-nhs Sep 24, 2025
c4a371d
Merge branch 'main' into AEA-5328-go-back-button-functionality
bencegadanyi1-nhs Sep 24, 2025
cd0e4fa
Merge branch 'main' into AEA-5328-go-back-button-functionality
bencegadanyi1-nhs Sep 26, 2025
c1e278f
Merge branch 'main' into AEA-5328-go-back-button-functionality
bencegadanyi1-nhs Oct 1, 2025
99d9fd3
Merge branch 'main' into AEA-5328-go-back-button-functionality
bencegadanyi1-nhs Oct 3, 2025
07f3677
chore: changes wording
bencegadanyi1-nhs Oct 3, 2025
e3af9de
feat: adds navigation provider and search type context
bencegadanyi1-nhs Oct 3, 2025
0db68e2
feat: integrates EpsBackLink on pages
bencegadanyi1-nhs Oct 3, 2025
fb16a00
feat: integrate serach and navigation context to searches
bencegadanyi1-nhs Oct 3, 2025
7b5605f
test: fixes broken tests
bencegadanyi1-nhs Oct 3, 2025
bb1f1d9
Merge branch 'main' into AEA-5328-go-back-button-functionality
bencegadanyi1-nhs Oct 3, 2025
5799032
test: adds missing NavigationProvider tests
bencegadanyi1-nhs Oct 3, 2025
5f96509
Merge remote-tracking branch 'origin/main' into AEA-5328-go-back-butt…
jonathanwelch1-nhs Oct 7, 2025
06e2c16
trigger build
jonathanwelch1-nhs Oct 7, 2025
c403754
Merge remote-tracking branch 'origin/AEA-5328-go-back-button-function…
jonathanwelch1-nhs Oct 7, 2025
063d90f
trigger build
jonathanwelch1-nhs Oct 7, 2025
1c51b97
fixed broken test
jonathanwelch1-nhs Oct 7, 2025
3c9ec1b
fixed broken test
jonathanwelch1-nhs Oct 7, 2025
c3fdc73
fixed typing error
jonathanwelch1-nhs Oct 7, 2025
d930240
fixed type error
jonathanwelch1-nhs Oct 7, 2025
06da3e2
fixed type error
jonathanwelch1-nhs Oct 7, 2025
c11ec7d
Merge branch 'main' into AEA-5328-go-back-button-functionality
MatthewPopat-NHS Oct 13, 2025
1189628
fixed merge conflicts
jonathanwelch1-nhs Oct 16, 2025
196bb57
fixed merge conflicts
jonathanwelch1-nhs Oct 16, 2025
2b9023e
Merge branch 'main' into AEA-5328-go-back-button-functionality
jonathanwelch1-nhs Oct 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions packages/cpt-ui/__tests__/BasicDetailsSearch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {STRINGS} from "@/constants/ui-strings/BasicDetailsSearchStrings"
import {FRONTEND_PATHS} from "@/constants/environment"
import {AuthContext, AuthContextType} from "@/context/AuthProvider"
import {SearchContext, SearchProviderContextType} from "@/context/SearchProvider"
import {NavigationProvider} from "@/context/NavigationProvider"

jest.mock("react-router-dom", () => {
const actual = jest.requireActual("react-router-dom")
Expand Down Expand Up @@ -68,10 +69,12 @@ const mockSetLastName = jest.fn()
const mockSetDobDay = jest.fn()
const mockSetDobMonth = jest.fn()
const mockSetDobYear = jest.fn()
const mockSetPostcode =jest.fn()
const mockSetPostcode = jest.fn()
const mockSetNhsNumber = jest.fn()
const mockGetAllSearchParameters = jest.fn()
const mockSetAllSearchParameters = jest.fn()
const mockSetSearchType = jest.fn()

const defaultSearchState: SearchProviderContextType = {
prescriptionId: undefined,
issueNumber: undefined,
Expand All @@ -82,6 +85,7 @@ const defaultSearchState: SearchProviderContextType = {
dobYear: undefined,
postcode: undefined,
nhsNumber: undefined,
searchType: undefined,
clearSearchParameters: mockClearSearchParameters,
setPrescriptionId: mockSetPrescriptionId,
setIssueNumber: mockSetIssueNumber,
Expand All @@ -93,7 +97,8 @@ const defaultSearchState: SearchProviderContextType = {
setPostcode: mockSetPostcode,
setNhsNumber: mockSetNhsNumber,
getAllSearchParameters: mockGetAllSearchParameters,
setAllSearchParameters: mockSetAllSearchParameters
setAllSearchParameters: mockSetAllSearchParameters,
setSearchType: mockSetSearchType
}

const LocationDisplay = () => {
Expand All @@ -106,10 +111,12 @@ const renderWithRouter = (ui: React.ReactElement, searchState: SearchProviderCon
<AuthContext.Provider value={signedInAuthState}>
<SearchContext.Provider value={searchState}>
<MemoryRouter initialEntries={["/search"]}>
<Routes>
<Route path="/search" element={ui} />
<Route path="*" element={<LocationDisplay />} />
</Routes>
<NavigationProvider>
<Routes>
<Route path="/search" element={ui} />
<Route path="*" element={<LocationDisplay />} />
</Routes>
</NavigationProvider>
</MemoryRouter>
</SearchContext.Provider>
</AuthContext.Provider>
Expand Down
148 changes: 124 additions & 24 deletions packages/cpt-ui/__tests__/BasicDetailsSearchResultsPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,37 @@ import {SearchResultsPageStrings} from "@/constants/ui-strings/BasicDetailsSearc
import http from "@/helpers/axios"
import {AuthContext, type AuthContextType} from "@/context/AuthProvider"
import {SearchContext, SearchProviderContextType} from "@/context/SearchProvider"
import {NavigationProvider} from "@/context/NavigationProvider"
import {AxiosError, AxiosHeaders} from "axios"

// Mock the axios module
jest.mock("@/helpers/axios")
const mockAxiosGet = http.get as jest.MockedFunction<typeof http.get>

const mockGetRelevantSearchParameters = jest.fn()
const mockGetBackPath = jest.fn()
const mockGoBack = jest.fn()
const mockNavigationContext = {
pushNavigation: jest.fn(),
goBack: mockGoBack,
getBackPath: mockGetBackPath,
clearNavigation: jest.fn(),
getCurrentEntry: jest.fn(),
getNavigationStack: jest.fn(),
canGoBack: jest.fn(),
setOriginalSearchPage: jest.fn(),
getOriginalSearchPage: jest.fn(),
captureOriginalSearchParameters: jest.fn(),
getOriginalSearchParameters: jest.fn(),
getRelevantSearchParameters: mockGetRelevantSearchParameters,
startNewNavigationSession: jest.fn()
}

jest.mock("@/context/NavigationProvider", () => ({
...jest.requireActual("@/context/NavigationProvider"),
useNavigationContext: () => mockNavigationContext
}))

const mockAuthContext: AuthContextType = {
error: null,
user: null,
Expand Down Expand Up @@ -49,7 +74,7 @@ const mockSetLastName = jest.fn()
const mockSetDobDay = jest.fn()
const mockSetDobMonth = jest.fn()
const mockSetDobYear = jest.fn()
const mockSetPostcode =jest.fn()
const mockSetPostcode = jest.fn()
const mockSetNhsNumber = jest.fn()
const mockGetAllSearchParameters = jest.fn()
const mockSetAllSearchParameters = jest.fn()
Expand All @@ -63,6 +88,7 @@ const defaultSearchState: SearchProviderContextType = {
dobYear: undefined,
postcode: undefined,
nhsNumber: undefined,
searchType: undefined,
clearSearchParameters: mockClearSearchParameters,
setPrescriptionId: mockSetPrescriptionId,
setIssueNumber: mockSetIssueNumber,
Expand All @@ -73,6 +99,7 @@ const defaultSearchState: SearchProviderContextType = {
setDobYear: mockSetDobYear,
setPostcode: mockSetPostcode,
setNhsNumber: mockSetNhsNumber,
setSearchType: jest.fn(),
getAllSearchParameters: mockGetAllSearchParameters,
setAllSearchParameters: mockSetAllSearchParameters
}
Expand All @@ -96,17 +123,20 @@ const mockPatients = [
}
]

function renderWithRouter() {
function renderWithRouter(initialEntries = ["/patient-search-results"]) {
return render(
<AuthContext.Provider value={mockAuthContext}>
<SearchContext.Provider value={defaultSearchState}>
<MemoryRouter initialEntries={["/patient-search-results"]}>
<Routes>
<Route path="/patient-search-results" element={<BasicDetailsSearchResultsPage />} />
<Route path="/login" element={<div data-testid="login-page-shown" />} />
<Route path="/prescription-list-current" element={<div data-testid="prescription-list-shown" />} />
<Route path="/search-by-basic-details" element={<div data-testid="search-page-shown" />} />
</Routes>
<MemoryRouter initialEntries={initialEntries}>
<NavigationProvider>
<Routes>
<Route path="/patient-search-results" element={<BasicDetailsSearchResultsPage />} />
<Route path="/login" element={<div data-testid="login-page-shown" />} />
<Route path="/prescription-list-current" element={<div data-testid="prescription-list-shown" />} />
<Route path="/search-by-basic-details" element={<div data-testid="search-page-shown" />} />
<Route path="/search-by-prescription-id" element={<div data-testid="search-page-shown" />} />
</Routes>
</NavigationProvider>
</MemoryRouter>
</SearchContext.Provider>
</AuthContext.Provider>
Expand All @@ -115,11 +145,24 @@ function renderWithRouter() {

describe("BasicDetailsSearchResultsPage", () => {
beforeEach(() => {
jest.clearAllMocks()

// Mock successful API response
mockAxiosGet.mockResolvedValue({
status: 200,
data: mockPatients
})

mockGetRelevantSearchParameters.mockReturnValue({
firstName: "John",
lastName: "Doe",
dobDay: "01",
dobMonth: "01",
dobYear: "1990",
postcode: "SW1A 1AA"
})

mockGetBackPath.mockReturnValue("/search-by-basic-details")
})

it("shows loading state initially", () => {
Expand Down Expand Up @@ -201,20 +244,42 @@ describe("BasicDetailsSearchResultsPage", () => {

await waitFor(() => {
expect(screen.getByTestId("prescription-list-shown")).toBeInTheDocument()
expect(mockClearSearchParameters).toHaveBeenCalled()
expect(mockSetNhsNumber).toHaveBeenCalledWith("9726919207")
expect(mockGetRelevantSearchParameters).toHaveBeenCalledWith(
"basicDetails"
)
expect(mockSetAllSearchParameters).toHaveBeenCalledWith({
firstName: "John",
lastName: "Doe",
dobDay: "01",
dobMonth: "01",
dobYear: "1990",
postcode: "SW1A 1AA",
nhsNumber: "9726919207"
})
})
})

it("navigates to prescription list when clicking a patient row", async () => {
renderWithRouter()
await waitFor(() => {
const firstPatientRow = screen.getByText("Issac Wolderton-Rodriguez").closest("tr")
const firstPatientRow = screen
.getByText("Issac Wolderton-Rodriguez")
.closest("tr")
fireEvent.click(firstPatientRow!)

expect(screen.getByTestId("prescription-list-shown")).toBeInTheDocument()
expect(mockClearSearchParameters).toHaveBeenCalled()
expect(mockSetNhsNumber).toHaveBeenCalledWith("9726919207")
expect(mockGetRelevantSearchParameters).toHaveBeenCalledWith(
"basicDetails"
)
expect(mockSetAllSearchParameters).toHaveBeenCalledWith({
firstName: "John",
lastName: "Doe",
dobDay: "01",
dobMonth: "01",
dobYear: "1990",
postcode: "SW1A 1AA",
nhsNumber: "9726919207"
})
})
})

Expand All @@ -226,20 +291,35 @@ describe("BasicDetailsSearchResultsPage", () => {
fireEvent.click(patientNameLink)

expect(screen.getByTestId("prescription-list-shown")).toBeInTheDocument()
expect(mockClearSearchParameters).toHaveBeenCalled()
expect(mockSetNhsNumber).toHaveBeenCalledWith("9726919207")
expect(mockGetRelevantSearchParameters).toHaveBeenCalledWith(
"basicDetails"
)
expect(mockSetAllSearchParameters).toHaveBeenCalledWith({
firstName: "John",
lastName: "Doe",
dobDay: "01",
dobMonth: "01",
dobYear: "1990",
postcode: "SW1A 1AA",
nhsNumber: "9726919207"
})
})
})

it("navigates back when clicking the back link", async () => {
renderWithRouter()

await waitFor(() => {
const backLink = screen.getByText(SearchResultsPageStrings.GO_BACK)
fireEvent.click(backLink)

expect(screen.getByTestId("search-page-shown")).toBeInTheDocument()
expect(
screen.getByText(SearchResultsPageStrings.GO_BACK)
).toBeInTheDocument()
})

const backLink = screen.getByText(SearchResultsPageStrings.GO_BACK)
fireEvent.click(backLink)

expect(mockGoBack).toHaveBeenCalled()
expect(mockGetBackPath).toHaveBeenCalled()
})

it("handles enter key navigation for patient rows", async () => {
Expand All @@ -250,8 +330,18 @@ describe("BasicDetailsSearchResultsPage", () => {
fireEvent.keyDown(firstPatientRow!, {key: "Enter"})

expect(screen.getByTestId("prescription-list-shown")).toBeInTheDocument()
expect(mockClearSearchParameters).toHaveBeenCalled()
expect(mockSetNhsNumber).toHaveBeenCalledWith("9726919207")
expect(mockGetRelevantSearchParameters).toHaveBeenCalledWith(
"basicDetails"
)
expect(mockSetAllSearchParameters).toHaveBeenCalledWith({
firstName: "John",
lastName: "Doe",
dobDay: "01",
dobMonth: "01",
dobYear: "1990",
postcode: "SW1A 1AA",
nhsNumber: "9726919207"
})
})
})

Expand All @@ -263,8 +353,18 @@ describe("BasicDetailsSearchResultsPage", () => {
fireEvent.keyDown(firstPatientRow!, {key: " "})

expect(screen.getByTestId("prescription-list-shown")).toBeInTheDocument()
expect(mockClearSearchParameters).toHaveBeenCalled()
expect(mockSetNhsNumber).toHaveBeenCalledWith("9726919207")
expect(mockGetRelevantSearchParameters).toHaveBeenCalledWith(
"basicDetails"
)
expect(mockSetAllSearchParameters).toHaveBeenCalledWith({
firstName: "John",
lastName: "Doe",
dobDay: "01",
dobMonth: "01",
dobYear: "1990",
postcode: "SW1A 1AA",
nhsNumber: "9726919207"
})
})
})

Expand Down
Loading