From b4072cbf546fd55675bfbc43f2d16895a9142bbc Mon Sep 17 00:00:00 2001 From: Temi Akinsoto Date: Wed, 22 Jan 2025 09:10:58 +0000 Subject: [PATCH 01/15] add date input field for feedtypes --- src/app/components/cms/Feedback/Feedback.tsx | 3 + .../cms/Feedback/Fields/Date/DateField.tsx | 62 +++++++++++++++ .../Feedback/Fields/Date/Datefield.spec.tsx | 75 +++++++++++++++++++ .../cms/pages/fixtures/page/feedback.ts | 13 ++++ 4 files changed, 153 insertions(+) create mode 100644 src/app/components/cms/Feedback/Fields/Date/DateField.tsx create mode 100644 src/app/components/cms/Feedback/Fields/Date/Datefield.spec.tsx diff --git a/src/app/components/cms/Feedback/Feedback.tsx b/src/app/components/cms/Feedback/Feedback.tsx index 64f74a130..50996c81f 100644 --- a/src/app/components/cms/Feedback/Feedback.tsx +++ b/src/app/components/cms/Feedback/Feedback.tsx @@ -10,6 +10,7 @@ import { FormField } from '@/api/models/cms/Page/FormFields' import { handler } from '../utils/handler' import CheckboxField from './Fields/Checkbox/CheckboxField' import CheckboxesField from './Fields/Checkboxes/CheckboxesField' +import DateField from './Fields/Date/DateField' import DropdownField from './Fields/Dropdown/DropdownField' import EmailField from './Fields/Email/EmailField' import MultilineField from './Fields/Multiline/MultilineField' @@ -168,6 +169,8 @@ export const renderFormFields = ( {fieldType === 'url' && } + {fieldType === 'date' && } + {fieldType === 'dropdown' && ( )} diff --git a/src/app/components/cms/Feedback/Fields/Date/DateField.tsx b/src/app/components/cms/Feedback/Fields/Date/DateField.tsx new file mode 100644 index 000000000..2c6a2de68 --- /dev/null +++ b/src/app/components/cms/Feedback/Fields/Date/DateField.tsx @@ -0,0 +1,62 @@ +import { Fieldtype } from '../../Feedback' + +export default function DateField({ label, helpText, cleanName }: Fieldtype) { + return ( +
+
+ +

+ +

+ {helpText.length > 0 ?
{helpText}
: null} +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+
+ ) +} diff --git a/src/app/components/cms/Feedback/Fields/Date/Datefield.spec.tsx b/src/app/components/cms/Feedback/Fields/Date/Datefield.spec.tsx new file mode 100644 index 000000000..731786e12 --- /dev/null +++ b/src/app/components/cms/Feedback/Fields/Date/Datefield.spec.tsx @@ -0,0 +1,75 @@ +import { render, screen } from '@/config/test-utils' + +import DateField from './DateField' + +describe('DateField component', () => { + const mockProps = { + label: 'Date of Birth', + helpText: 'Enter a memorable date', + cleanName: 'dob', + } + + test('renders DateField component with label, helpText, and cleanName props', () => { + render() + expect(screen.getByText('Date of Birth')).toBeInTheDocument() + expect(screen.getByText('Enter a memorable date')).toBeInTheDocument() + }) + + test('renders the correct label text', () => { + render() + const label = screen.getByText('Date of Birth') + expect(label).toBeInTheDocument() + expect(label).toHaveAttribute('for', 'dob') + }) + + test('renders help text when provided', () => { + render() + expect(screen.getByText('Enter a memorable date')).toBeInTheDocument() + }) + + test('does not render help text when empty', () => { + render() + const helpText = screen.queryByText('Enter a valid date') + expect(helpText).not.toBeInTheDocument() + }) + + test('renders day, month, and year input fields', () => { + render() + const dayInput = screen.getByLabelText(/day/i) + const monthInput = screen.getByLabelText(/month/i) + const yearInput = screen.getByLabelText(/year/i) + + expect(dayInput).toBeInTheDocument() + expect(monthInput).toBeInTheDocument() + expect(yearInput).toBeInTheDocument() + }) + + test('renders labels for Day, Month, and Year', () => { + render() + + // Check for the presence of each label + expect(screen.getByLabelText(/day/i)).toBeInTheDocument() + expect(screen.getByLabelText(/month/i)).toBeInTheDocument() + expect(screen.getByLabelText(/year/i)).toBeInTheDocument() + }) + + test('input fields have correct attributes', () => { + render() + + const dayInput = screen.getByLabelText(/day/i) + const monthInput = screen.getByLabelText(/month/i) + const yearInput = screen.getByLabelText(/year/i) + + expect(dayInput).toHaveAttribute('id', 'day') + expect(monthInput).toHaveAttribute('id', 'month') + expect(yearInput).toHaveAttribute('id', 'year') + + expect(dayInput).toHaveAttribute('name', 'day') + expect(monthInput).toHaveAttribute('name', 'month') + expect(yearInput).toHaveAttribute('name', 'year') + + expect(dayInput).toHaveAttribute('type', 'number') + expect(monthInput).toHaveAttribute('type', 'number') + expect(yearInput).toHaveAttribute('type', 'number') + }) +}) diff --git a/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts b/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts index bab52cdcb..5593084f4 100644 --- a/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts +++ b/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts @@ -160,6 +160,19 @@ export const feedbackMock: PageResponse = { choices: '', default_value: '', }, + { + id: 11, + meta: { + type: 'forms.FormField', + }, + clean_name: 'enter_a_memorable_date', + label: 'Enter a memorable date', + field_type: 'date', + help_text: 'For example, 31 3 1980', + required: false, + choices: '', + default_value: '', + }, ], confirmation_slug: 'confirmation', confirmation_panel_title: 'Form submitted', From 5d3da97deca0aa54e9b0708990c4455a223a00dd Mon Sep 17 00:00:00 2001 From: Temi Akinsoto Date: Wed, 22 Jan 2025 11:09:42 +0000 Subject: [PATCH 02/15] add datefield day, month, and year values --- src/app/components/cms/Feedback/Fields/Date/DateField.tsx | 8 ++++---- .../cms/Feedback/Fields/Date/Datefield.spec.tsx | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/components/cms/Feedback/Fields/Date/DateField.tsx b/src/app/components/cms/Feedback/Fields/Date/DateField.tsx index 2c6a2de68..b249fb6ea 100644 --- a/src/app/components/cms/Feedback/Fields/Date/DateField.tsx +++ b/src/app/components/cms/Feedback/Fields/Date/DateField.tsx @@ -12,7 +12,7 @@ export default function DateField({ label, helpText, cleanName }: Fieldtype) { {helpText.length > 0 ?
{helpText}
: null} -
+