Skip to content

Commit dd7f289

Browse files
Refactor Cypress tests to update selectors for date fields and transportation details
- Updated selectors for arrival and export date fields to use consolidated IDs instead of separate day, month, and year fields across multiple test files. - Changed references from "#truck" to "#vehicle" in tests related to transportation methods. - Adjusted assertions and interactions in tests for storage facility details and catch certificate functionalities to reflect the new structure. - Ensured consistency in test cases by verifying the presence and values of updated elements.
1 parent ebaa017 commit dd7f289

36 files changed

Lines changed: 248 additions & 224 deletions

File tree

app/components/commonDatePicker.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ export const CommonDatePicker = ({
8585
}, [day, month, year]);
8686

8787
return (
88-
<div id={id} className={isEmpty(errors) ? "govuk-form-group" : "govuk-form-group govuk-form-group--error"}>
88+
<div
89+
id={`${id}-container`}
90+
className={isEmpty(errors) ? "govuk-form-group" : "govuk-form-group govuk-form-group--error"}
91+
>
8992
<fieldset className="govuk-fieldset" role="group" aria-describedby={errorMessageText(hintText, errors)}>
9093
<legend className="govuk-fieldset__legend govuk-fieldset__legend">
9194
{labelStyle === "bold" ? (

app/components/dateInputDay.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const DateInputDay = ({
2424
label,
2525
}: DateInputDayProps) => (
2626
<div className="govuk-form-group">
27-
<label className="govuk-label govuk-date-input__label" htmlFor={`${id}-day`}>
27+
<label className="govuk-label govuk-date-input__label" htmlFor={id}>
2828
{label}
2929
</label>
3030
{isHydrated ? (
@@ -34,7 +34,7 @@ export const DateInputDay = ({
3434
? "govuk-input govuk-date-input__input govuk-input--width-2"
3535
: "govuk-input govuk-date-input__input govuk-input--width-2 govuk-input--error"
3636
}
37-
id={`${id}-day`}
37+
id={id}
3838
name={`${name}Day`}
3939
type="number"
4040
onChange={handleDayChange}
@@ -48,7 +48,7 @@ export const DateInputDay = ({
4848
? "govuk-input govuk-date-input__input govuk-input--width-2"
4949
: "govuk-input govuk-date-input__input govuk-input--width-2 govuk-input--error"
5050
}
51-
id={`${id}-day`}
51+
id={id}
5252
name={`${name}Day`}
5353
type="number"
5454
defaultValue={daySelected}

app/components/errorSummary.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useRef, useEffect } from "react";
12
import type { IError, IValidationError, LinkData } from "~/types";
23
import { useTranslation } from "react-i18next";
34
import { scrollToId } from "~/helpers";
@@ -14,6 +15,13 @@ export const ErrorSummary = ({
1415
linkData,
1516
}: React.PropsWithChildren<IErrorSummaryProps>) => {
1617
const { t } = useTranslation(["errorsText", "common"]);
18+
const summaryRef = useRef<HTMLDivElement>(null);
19+
20+
useEffect(() => {
21+
if (errors.length > 0) {
22+
summaryRef.current?.focus();
23+
}
24+
}, [errors]);
1725

1826
const onChangeHandler: (e: React.FormEvent<HTMLAnchorElement>) => void = (e: React.FormEvent<HTMLAnchorElement>) => {
1927
e.preventDefault();
@@ -25,10 +33,11 @@ export const ErrorSummary = ({
2533
return (
2634
<div
2735
id="errorIsland"
36+
ref={summaryRef}
37+
tabIndex={-1}
2838
className={`govuk-error-summary ${containerClassName}`}
2939
aria-labelledby="error-summary-title"
3040
role="alert"
31-
data-disable-auto-focus="true"
3241
data-module="govuk-error-summary"
3342
>
3443
<h2 className="govuk-error-summary__title" id="error-summary-title">

app/composite-components/checkYourInformation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export const StorageDocumentTransportDisplay = ({
218218
label: t("sdCheckYourInformationDepartureDate", { ns: "sdCheckYourInformation" }),
219219
value: transport.exportDate,
220220
hasChangeLink: true,
221-
backLinkId: "exportDate-day",
221+
backLinkId: "exportDate",
222222
},
223223
{
224224
label: t(`sdCheckYourInformationVehicleDepartureFrom${capitalize(transport.vehicle)}`, {
@@ -246,7 +246,7 @@ export const StorageDocumentTransportDisplay = ({
246246
label: t("sdCheckYourInformationDepartureDate", { ns: "sdCheckYourInformation" }),
247247
value: transport.departureDate,
248248
hasChangeLink: true,
249-
backLinkId: "departureDate-day",
249+
backLinkId: "departureDate",
250250
},
251251
];
252252

app/composite-components/howDoesTransportTakesPlaceInTheUkForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const HowDoesTransportTakesPlaceInTheUkForm = ({
8989
<div className="govuk-grid-row">
9090
<div className="govuk-grid-column-full">
9191
<SecureForm method="post" csrf={csrf}>
92-
<div className={!isEmpty(errors) ? "govuk-form-group govuk-form-group--error" : "govuk-form-group"}>
92+
<div className={isEmpty(errors) ? "govuk-form-group" : "govuk-form-group govuk-form-group--error"}>
9393
<fieldset
9494
className="govuk-fieldset"
9595
aria-describedby={isEmpty(errors) ? "vehicle-hint" : "vehicle-hint vehicle-error"}
@@ -118,7 +118,7 @@ export const HowDoesTransportTakesPlaceInTheUkForm = ({
118118
</div>
119119
)}
120120
{type === Page.StorageDocumentHowDoesTheExportLeaveTheUk && transportOption.value === "truck" && (
121-
<div id="truck-item-hint" className="govuk-hint govuk-radios__hint">
121+
<div id="vehicle-item-hint" className="govuk-hint govuk-radios__hint">
122122
{t("transportSelectionTruckGuidance", { ns: "transportation" })}
123123
</div>
124124
)}

app/helpers/storageDocument.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import type { DocIssuedInUkRadioSelectOptionType } from "~/types";
2-
3-
export const confirmDocIssuedInUkRadioSelectTypeOptions: DocIssuedInUkRadioSelectOptionType[] = [
4-
{
5-
label: "commonThereIs",
6-
value: "uk",
7-
id: "docIssuedInUkRadioSelectYes",
8-
},
9-
{
10-
label: "commonThereIsNot",
11-
value: "non_uk",
12-
id: "docIssuedInUkRadioSelectNo",
13-
},
14-
];
1+
import type { DocIssuedInUkRadioSelectOptionType } from "~/types";
2+
3+
export const confirmDocIssuedInUkRadioSelectTypeOptions: DocIssuedInUkRadioSelectOptionType[] = [
4+
{
5+
label: "commonThereIs",
6+
value: "uk",
7+
id: "",
8+
},
9+
{
10+
label: "commonThereIsNot",
11+
value: "non_uk",
12+
id: "docIssuedInUkRadioSelectNo",
13+
},
14+
];

app/helpers/transport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const transportOptions: TransportOptionType[] = [
7272
{
7373
label: "truck",
7474
value: "truck",
75-
id: "truck",
75+
id: "vehicle",
7676
},
7777
{
7878
label: "plane",

app/models/directLandings.server.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ function instanceOfIError(data: IDirectLandings | IError[]): data is IError[] {
4444
return Array.isArray(data) && "key" in data[0];
4545
}
4646

47+
// helper function to ensure form number is actually a number
48+
function isNumeric(str: string | number) {
49+
return (
50+
/^-?[\d.]+$/.test(str as string) && // ensure only numbers and dots(negative numbers will be caught later validation)
51+
!Number.isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
52+
!Number.isNaN(Number.parseFloat(str as string))
53+
); // ...and ensure strings of whitespace fail
54+
}
55+
4756
const saveActionBase: any = async (values: any, landings: IDirectLandings, isNumeric: (i: any) => boolean) => {
4857
const filterWeights: { [key: string]: string } = Object.keys(values)
4958
.filter((key) => key.includes("weight"))
@@ -69,7 +78,7 @@ const saveActionBase: any = async (values: any, landings: IDirectLandings, isNum
6978
// This prevents invalid date errors from causing spurious vessel errors
7079
const isDateValid = isValidDate(date, ["YYYY-M-D", "YYYY-MM-DD"]);
7180
const dateForVesselLookup = isDateValid ? date : moment().format("YYYY-MM-DD");
72-
const vessels: IVessel[] = !isEmpty(pln) ? await getVessels(pln.toString(), dateForVesselLookup) : [];
81+
const vessels: IVessel[] = isEmpty(pln) ? [] : await getVessels(pln.toString(), dateForVesselLookup);
7382
const selectedVessel: IVessel | undefined = vessels.find((_: IVessel) => _.pln === pln);
7483
const previousVessel: (IVessel & { isListed?: boolean }) | undefined = {};
7584
let exclusiveEconomicZones: ICountry[] = [];
@@ -395,7 +404,7 @@ export const DirectLandingsLoader = async (params: Params, request: Request) =>
395404
(totals: number, weight: IDirectLandingsDetails) =>
396405
weight.exportWeight === undefined || weight.exportWeight === null || !isNumber(weight.exportWeight)
397406
? totals
398-
: totals + parseFloat(weight.exportWeight),
407+
: totals + Number.parseFloat(weight.exportWeight),
399408
0
400409
)
401410
: 0;
@@ -434,7 +443,7 @@ export const DirectLandingsLoader = async (params: Params, request: Request) =>
434443
selectedRfmo: directLandings?.rfmo,
435444
availableExclusiveEconomicZones,
436445
selectedExclusiveEconomicZones: directLandings?.exclusiveEconomicZones,
437-
maximumEezPerLanding: parseInt(maximumEezPerLanding, 10),
446+
maximumEezPerLanding: Number.parseInt(maximumEezPerLanding, 10),
438447
isAddAnotherEEZButtonClicked: isAddAnotherEEZButtonClicked,
439448
faoArea: getSessionData(session, "selectedFaoArea"),
440449
}),
@@ -461,14 +470,6 @@ export const DirectLandingsAction = async (params: Params, request: Request): Pr
461470
const isValid = await validateCSRFToken(request, form);
462471
if (!isValid) return redirect("/forbidden");
463472
const saveToSession = (data: any) => Object.keys(data).forEach((k) => session.set(k, data[k]));
464-
// helper function to ensure form number is actually a number
465-
function isNumeric(str: string | number) {
466-
return (
467-
/^-?[\d.]+$/.test(str as string) && // ensure only numbers and dots(negative numbers will be caught later validation)
468-
!isNaN(str as number) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
469-
!isNaN(parseFloat(str as string))
470-
); // ...and ensure strings of whitespace fail
471-
}
472473
const {
473474
dateLandedDay,
474475
dateLandedMonth,

app/routes/create-catch-certificate.$documentNumber.direct-landing.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const DirectLanding = () => {
122122
? directLandings?.weights.map((weight: IDirectLandingsDetails) => ({
123123
exportWeight: (() => {
124124
const val = weight.exportWeight;
125-
const parsed = typeof val === "number" ? val : parseFloat(String(val));
125+
const parsed = typeof val === "number" ? val : Number.parseFloat(String(val));
126126
return !Number.isNaN(parsed) && parsed !== null ? parsed : 0;
127127
})(),
128128
}))
@@ -209,9 +209,9 @@ const DirectLanding = () => {
209209
};
210210

211211
const getTotalWeight = (weightDetail: WeightDetails) => {
212-
const weightDetailIndex = parseInt(weightDetail?.id.split(".")[1]);
212+
const weightDetailIndex = Number.parseInt(weightDetail?.id.split(".")[1]);
213213

214-
if (!isNaN(weightDetailIndex)) {
214+
if (!Number.isNaN(weightDetailIndex)) {
215215
const totalWeights: { exportWeight: number }[] = Array.isArray(exportWeights)
216216
? exportWeights.map((weight: { exportWeight: number }, index: number) => {
217217
if (index === weightDetailIndex) {
@@ -231,7 +231,8 @@ const DirectLanding = () => {
231231

232232
setCalculatedWeight(
233233
totalWeights.reduce(
234-
(curr: number, acc: { exportWeight: number }) => (isNaN(acc.exportWeight) ? curr : curr + acc.exportWeight),
234+
(curr: number, acc: { exportWeight: number }) =>
235+
Number.isNaN(acc.exportWeight) ? curr : curr + acc.exportWeight,
235236
0
236237
)
237238
);

app/routes/create-catch-certificate.$documentNumber.how-does-the-export-leave-the-uk.$.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const HowDoesTheExportLeaveTheUk = () => {
100100
<label htmlFor={option.id} className="govuk-label govuk-radios__label">
101101
{t(option.label, { ns: "transportation" })}
102102
</label>
103-
{option.id === "truck" && (
103+
{option.value === "truck" && (
104104
<div id={`${option.id}-item-hint`} className="govuk-hint govuk-radios__hint">
105105
{t("transportSelectionTruckGuidance", { ns: "transportation" })}
106106
</div>

0 commit comments

Comments
 (0)