Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-8288: do not validate dates in textfield components with calendar widgets #90

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 2 additions & 34 deletions src/process/validation/rules/__tests__/validateDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,44 +73,12 @@ it('Validating a textField calendar picker component with no data will return nu
expect(result).to.equal(null);
});

it('Validating a textField calendar picker component with an invalid date string value will return a FieldError', async () => {
it('Textfield calendar picker component date values should not be validated and return null', async () => {
const component = calendarTextField;
const data = {
component: 'hello, world!',
};
const context = generateProcessorContext(component, data);
const result = await validateDate(context);
expect(result).to.be.instanceOf(FieldError);
expect(result?.errorKeyOrMessage).to.equal('invalidDate');
});

it('Validating a textField calendar picker component with an valid date string value will return null', async () => {
const component = calendarTextField;
const data = {
component: '2023-03-09T12:00:00-06:00',
};
const context = generateProcessorContext(component, data);
const result = await validateDate(context);
expect(result).to.equal(null);
});

it('Validating a textField calendar picker component with an invalid Date object will return a FieldError', async () => {
const component = calendarTextField;
const data = {
component: new Date('Hello, world!'),
};
const context = generateProcessorContext(component, data);
const result = await validateDate(context);
expect(result).to.be.instanceOf(FieldError);
expect(result?.errorKeyOrMessage).to.equal('invalidDate');
});

it('Validating a textField calendar picker component with a valid Date object will return null', async () => {
const component = calendarTextField;
const data = {
component: new Date(),
};
const context = generateProcessorContext(component, data);
const result = await validateDate(context);
expect(result).to.equal(null);
expect(result).to.be.equal(null);
});
6 changes: 1 addition & 5 deletions src/process/validation/rules/validateDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ const isValidatableDateTimeComponent = (obj: any): obj is DateTimeComponent => {
return !!obj && !!obj.type && obj.type === 'datetime';
};

const isValidatableTextFieldComponent = (obj: any): obj is TextFieldComponent => {
return !!obj && !!obj.type && obj.widget && obj.widget.type === 'calendar';
};

const isValidatable = (component: any) => {
return isValidatableDateTimeComponent(component) || isValidatableTextFieldComponent(component);
return isValidatableDateTimeComponent(component);
};

export const shouldValidate = (context: ValidationContext) => {
Expand Down
Loading