Skip to content

Commit a7887c8

Browse files
authored
Merge pull request #8903 from opengovsg/fix/remove-chromatic-noise
fix: remove noisy chromatic diffs due to dynamic dates and form link
1 parent 415f603 commit a7887c8

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

frontend/src/features/admin-form/responses/IndividualResponsePage/PrintableResponse.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ const PrintableResponseRows = ({
181181
)
182182
}
183183

184+
const isTest = import.meta.env.STORYBOOK_NODE_ENV === 'test'
185+
const MOCK_CONSTANT_FORM_LINK = 'https://form.gov.sg/64e2f7ae841cbe0012e785e7'
186+
184187
export const PrintableResponse = ({
185188
formTitle,
186189
formId,
@@ -210,9 +213,11 @@ export const PrintableResponse = ({
210213
color="white"
211214
textDecor="underline"
212215
textDecorationColor="white"
213-
data-chromatic="ignore"
214216
>
215-
{window.location.origin}/{formId}
217+
{/* RATIONALE: Prevent noisy diffs from being detected during storybook snapshot comparisons due to dynamic form link. */}
218+
{isTest
219+
? MOCK_CONSTANT_FORM_LINK
220+
: `${window.location.origin}/${formId}`}
216221
</Text>
217222
</Box>
218223
<Box mx="5%" my="30px">

frontend/src/features/public-form/PublicFormProvider.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ interface PublicFormProviderProps {
106106
isPublicFormPage?: boolean
107107
}
108108

109+
const DATE_TIME_FORMAT_STRING = 'do MMM yyyy, h:mm:ss a'
110+
const MOCK_CONSTANT_LAST_SAVED_DATETIME = '2025-11-14T12:00:00.000Z'
111+
109112
export function useCommonFormProvider(formId: string) {
110113
// For mobile section sidebar
111114
const {
@@ -1388,6 +1391,16 @@ export const PublicFormProvider = ({
13881391
return <NotFoundErrorPage />
13891392
}
13901393

1394+
// RATIONALE: Prevent noisy diffs from being detected during storybook snapshot comparisons due to dynamic date time.
1395+
const draftLastSavedDateTime =
1396+
draftSubmission?.lastUpdated && isTest
1397+
? MOCK_CONSTANT_LAST_SAVED_DATETIME
1398+
: draftSubmission?.lastUpdated
1399+
1400+
const draftLastSavedDateTimeString = draftLastSavedDateTime
1401+
? format(new Date(draftLastSavedDateTime), DATE_TIME_FORMAT_STRING)
1402+
: undefined
1403+
13911404
return (
13921405
<PublicFormContext.Provider
13931406
value={{
@@ -1412,12 +1425,7 @@ export const PublicFormProvider = ({
14121425
previousAttachments,
14131426
setPreviousSubmission,
14141427
isSaveDraftEnabled,
1415-
draftLastSavedDateTimeString: draftSubmission?.lastUpdated
1416-
? format(
1417-
new Date(draftSubmission.lastUpdated),
1418-
'do MMM yyyy, h:mm:ss a',
1419-
)
1420-
: undefined,
1428+
draftLastSavedDateTimeString,
14211429
onSaveDraft,
14221430
defaultFormValues,
14231431
augmentedFormFields,

0 commit comments

Comments
 (0)