Skip to content
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
14 changes: 14 additions & 0 deletions src/tests/createHeadlessForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
schemaInputTypeSelectMultiple,
schemaInputTypeSelectMultipleOptional,
schemaInputTypeNumber,
schemaInputTypeNumberZeroMaximum,
schemaInputTypeDate,
schemaInputTypeEmail,
schemaInputWithStatement,
Expand Down Expand Up @@ -1839,6 +1840,19 @@ describe('createHeadlessForm', () => {
).resolves.toEqual(assertObj);
});
});
describe('and maximum is set to zero', () => {
it('shows the correct validation', () => {
const { handleValidation } = createHeadlessForm(schemaInputTypeNumberZeroMaximum);
const validateForm = (vals) => friendlyError(handleValidation(vals));

expect(validateForm({ tabs: '0' })).toBeUndefined();
expect(validateForm({ tabs: '-10' })).toBeUndefined();

expect(validateForm({ tabs: 1 })).toEqual({
tabs: 'Must be smaller or equal to 0',
});
});
});
});

describe('when a field has a maxLength of 10', () => {
Expand Down
15 changes: 15 additions & 0 deletions src/tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ export const mockNumberInput = {
type: 'number',
};

export const schemaInputTypeNumberZeroMaximum = {
properties: {
tabs: {
title: 'Tabs',
description: 'How many open tabs do you have?',
'x-jsf-presentation': {
inputType: 'number',
},
minimum: -100,
maximum: 0,
type: 'number',
},
},
};

export const mockNumberInputWithPercentage = {
title: 'Shares',
description: 'What % of shares do you own?',
Expand Down
3 changes: 2 additions & 1 deletion src/yupSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ export function buildYupSchema(field, config) {
validators.push(withMinLength);
}

if (propertyFields.maximum) {
// support maximum with 0 value
if (propertyFields.maximum !== undefined) {
validators.push(withMax);
}

Expand Down