Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ const BookingAndLabelsPage = async (props: { params: Promise<ShipmentParams> })
<List spacing='3em'>
<ListItem>
<Heading size='lg'>Tracking labels</Heading>
<Text my='1em'>
<Text mt='1em'>
Print tracking labels and affix them to the outside of the dewar and dewar case. If
you are sending multiple dewars, ensure the code on the label matches the code on the
dewar.
</Text>
<Text my='1em'>
If a dewar doesn&#39;t have a barcode (such as the ones on the last page) already, cut
out the barcode on the last page and affix it to the dewar. If you&#39;re sending
multiple dewars, ensure the dewar matches the barcode you&#39;ve selected for it
previously.
</Text>
<Button
as={NextLink}
href={`${process.env.NEXT_PUBLIC_API_URL}/shipments/${params.shipmentId}/tracking-labels`}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defaultData } from "@/mocks/handlers";
import { server } from "@/mocks/server";
import { baseShipmentParams, renderWithProviders } from "@/utils/test-utils";
import { baseShipmentParams, dewar, renderWithProviders } from "@/utils/test-utils";
import { screen } from "@testing-library/react";
import { HttpResponse, http } from "msw";
import ShipmentHome from "./page";
Expand Down Expand Up @@ -47,7 +47,7 @@ describe("Sample Collection Submission Overview", () => {
server.use(
http.get(
"http://localhost/api/shipments/:shipmentId",
() => HttpResponse.json({ ...defaultData, data: { status: "Booked" } }),
() => HttpResponse.json({ ...defaultData, data: { shipmentRequest: 1 } }),
{ once: true },
),
);
Expand All @@ -56,6 +56,19 @@ describe("Sample Collection Submission Overview", () => {
expect(screen.getAllByRole("group")[0]).toHaveAttribute("aria-disabled", "true");
});

it("should not enable 'edit pre-session information' button if session is locked", async () => {
server.use(
http.get(
"http://localhost/api/shipments/:shipmentId/preSession",
() => HttpResponse.json({ details: {}, isLocked: true }),
{ once: true },
),
);
renderWithProviders(await ShipmentHome(baseShipmentParams));

expect(screen.getAllByRole("group")[1]).toHaveAttribute("aria-disabled", "true");
});

it("should not enable 'print pre-session' button if no pre-session data is available", async () => {
server.use(
http.get(
Expand Down Expand Up @@ -97,4 +110,19 @@ describe("Sample Collection Submission Overview", () => {

expect(screen.getByTestId("booking-label")).toHaveAttribute("aria-disabled", "true");
});

it("should disable booking and labels link if shipment hasn't been pushed to ISPyB", async () => {
let noDewarData = structuredClone(defaultData);
noDewarData = { ...defaultData, children: [dewar] };

noDewarData.children = [];
server.use(
http.get("http://localhost/api/shipments/:shipmentId", () => HttpResponse.json(noDewarData), {
once: true,
}),
);
renderWithProviders(await ShipmentHome(baseShipmentParams));

expect(screen.getByTestId("booking-label")).toHaveAttribute("aria-disabled", "true");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const ShipmentHome = async (props: { params: Promise<ShipmentParams> }) => {
Pre-Session Information
</Heading>
<Divider borderColor='gray.800' />
{shipmentData.preSessionInfo ? (
{shipmentData.preSessionInfo?.details ? (
<DynamicFormView
formType='preSession'
data={shipmentData.preSessionInfo.details}
Expand All @@ -148,15 +148,18 @@ const ShipmentHome = async (props: { params: Promise<ShipmentParams> }) => {
title='Edit Sample Collection'
as={NextLink}
href={`${params.shipmentId}/edit`}
isDisabled={shipmentData.dispatch.status === "Booked"}
isDisabled={!!shipmentData.dispatch.shipmentRequest}
>
Edit sample collection contents, or add new items
</TwoLineLink>
<TwoLineLink
title={`${shipmentData.preSessionInfo ? "Edit" : "Set"} Pre-Session Information`}
as={NextLink}
href={`${params.shipmentId}/pre-session`}
isDisabled={shipmentData.dispatch.status === "Booked"}
isDisabled={
!shipmentData.preSessionInfo ||
!!shipmentData.preSessionInfo.isLocked
}
>
Set imaging conditions, grid/data acquisition parameters
</TwoLineLink>
Expand Down Expand Up @@ -189,7 +192,7 @@ const ShipmentHome = async (props: { params: Promise<ShipmentParams> }) => {
title='Booking & Labels'
as={NextLink}
href={`${params.shipmentId}/booking-and-labels`}
isDisabled={!shipmentData.counts.Dewar}
isDisabled={!shipmentData.counts.Dewar || !shipmentData.dispatch.externalId}
data-testid='booking-label'
>
Book pickup with courier or print tracking labels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ describe("Sample Collection Submission Overview", () => {
server.use(
http.get(
"http://localhost/api/shipments/:shipmentId",
() =>
HttpResponse.json({ ...defaultData, data: { shipmentRequest: 123 } }),
() => HttpResponse.json({ ...defaultData, data: { shipmentRequest: 123 } }),
{ once: true },
),
);
Expand All @@ -58,8 +57,7 @@ describe("Sample Collection Submission Overview", () => {
server.use(
http.get(
"http://localhost/api/shipments/:shipmentId",
() =>
HttpResponse.json({ }, { status: 404 }),
() => HttpResponse.json({}, { status: 404 }),
{ once: true },
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ const SubmissionOverview = async (props: { params: Promise<ShipmentParams> }) =>
const shipmentData = await getShipment(params.shipmentId);

if (shipmentData === null) {
return <VStack w='100%' mt='3em'>
<Heading variant='notFound'>Sample Collection Unavailable</Heading>
<Text>This sample collection does not exist or you do not have permission to view it.</Text>
<Link as={NextLink} href='..'>
Return to session page
</Link>
</VStack>;
return (
<VStack w='100%' mt='3em'>
<Heading variant='notFound'>Sample Collection Unavailable</Heading>
<Text>This sample collection does not exist or you do not have permission to view it.</Text>
<Link as={NextLink} href='..'>
Return to session page
</Link>
</VStack>
);
}

return (
Expand Down
5 changes: 3 additions & 2 deletions src/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { pluralToSingular } from "@/mappings/pages";
import { BaseShipmentItem, pluralToSingular } from "@/mappings/pages";
import { http, HttpResponse } from "msw";

export const defaultData = {
export const defaultData: BaseShipmentItem = {
id: 1,
name: "Shipment",
type: "shipment",
data: { proposalNumber: "123", proposalCode: "cm", visitNumber: 1 },
children: [
{
Expand Down
5 changes: 5 additions & 0 deletions src/types/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,11 @@ export interface components {
PreSessionOut: {
/** Details */
details?: Record<string, never> | null;
/**
* Islocked
* @default false
*/
isLocked: boolean;
};
/** SampleIn */
SampleIn: {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export const puck: TreeData<BaseShipmentItem> = {
data: { type: "puck", registeredContainer: "DLS-0001" },
};

export const dewar: TreeData<BaseShipmentItem> = {
id: 15,
name: "dewar",
data: { type: "dewar", code: "DLS-0001" },
};

export const cane: TreeData<BaseShipmentItem> = {
id: 10,
name: "cane",
Expand Down