Skip to content

Commit

Permalink
test to prove that new file field validation does NOT set isRequired …
Browse files Browse the repository at this point in the history
…to false by default #2766
  • Loading branch information
Josh Pollock committed Nov 19, 2018
1 parent 8800eed commit d76d57e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
16 changes: 11 additions & 5 deletions clients/tests/unit/render/Fields/FileInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ describe('File Field ', () => {
});


it.skip('Prepares props from field config that is required', () => {
it('Prepares props from field config that is required', () => {
const prepared = FileInput.fieldConfigToProps(fileFieldConfigs.required_multiple_has_button_text);
expect(prepared.multiple).toEqual('true');
expect(prepared.multiple).toEqual(true);
expect(prepared.field.hasOwnProperty('required')).toEqual(true);
});

Expand Down Expand Up @@ -68,14 +68,20 @@ describe('File Field ', () => {
expect(prepared.multiUploadText).toEqual('The Custom Text');
});

it.skip('Prepares props and sets the allowed types in inputProps when it should', () => {
const prepared = FileInput.fieldConfigToProps(fileFieldConfigs.required_single);
//expect( fileFieldConfigs ).toEqual( 'image/png');
it('Prepares props and sets the allowed types in inputProps when it should', () => {
const prepared = FileInput.fieldConfigToProps(fileFieldConfigs.required_single_allow_png);
expect(prepared.accept).toEqual('image/png');
expect(prepared.inputProps).toEqual({"accept": "image/png", "type": "file"}
);
});

it( 'Sets field.isRequired to false if not passed', () => {
let field = fileFieldConfigs.required_multiple_no_button_text;
delete field.isRequired;
const prepared = FileInput.fieldConfigToProps(field);
expect(prepared.isRequired).toEqual(true);
});

Object.keys(fileFieldConfigs).forEach(fieldId => {
it(`Matches snapshot for ${fieldId}`, () => {
const field = fileFieldConfigs[fieldId];
Expand Down
26 changes: 13 additions & 13 deletions clients/tests/unit/render/Fields/Mocks/fileFieldConfigs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const fileFieldConfigs = {
export const fileFieldConfigs = {
required_single:
{
type: 'file',
Expand All @@ -16,12 +16,12 @@ export const fileFieldConfigs = {
multiple: 'false',
multiUploadText: 'My multi Upload Text',
allowedTypes: 'false',
usePreviews: 'false',
usePreviews: 'false',
previewHeight: 24,
previewWidth: 24,
}
},
required_single_allow_png:
required_single_allow_png:
{
type: 'file',
outterIdAttr: 'required_single_allow_png',
Expand All @@ -32,18 +32,18 @@ export const fileFieldConfigs = {
required: true,
isRequired: {
required: true
},
},
fieldDefault: '',
fieldValue: [],
fieldIdAttr: 'required_single',
configOptions:
{
multiple: 'false',
multiUploadText: 'Cool text for required_single_allow_png',
allowedTypes: '.png',
usePreviews: true,
previewHeight: 24,
previewWidth: 24,
allowedTypes: 'image/png',
usePreviews: true,
previewHeight: 24,
previewWidth: 24,
}
},
required_multiple_no_button_text:
Expand All @@ -63,7 +63,7 @@ export const fileFieldConfigs = {
multiple: 1,
multiUploadText: false,
allowedTypes: 'false',
usePreviews: true,
usePreviews: true,
previewHeight: 24,
previewWidth: 24,
}
Expand Down Expand Up @@ -107,7 +107,7 @@ export const fileFieldConfigs = {
multiple: 'false',
multiUploadText: false,
allowedTypes: 'false',
usePreviews: true,
usePreviews: true,
previewHeight: 24,
previewWidth: 24,
}
Expand All @@ -129,7 +129,7 @@ export const fileFieldConfigs = {
multiple: 1,
multiUploadText: false,
allowedTypes: 'false',
usePreviews: true,
usePreviews: true,
previewHeight: 24,
previewWidth: 24,
}
Expand All @@ -151,7 +151,7 @@ export const fileFieldConfigs = {
multiple: 1,
multiUploadText: 'The Default Text',
allowedTypes: 'false',
usePreviews: true,
usePreviews: true,
previewHeight: 24,
previewWidth: 24,
}
Expand All @@ -173,7 +173,7 @@ export const fileFieldConfigs = {
multiple: 1,
multiUploadText: 'The Default Text',
allowedTypes: 'false',
usePreviews: true,
usePreviews: true,
previewHeight: 20,
previewWidth: 40,
}
Expand Down

0 comments on commit d76d57e

Please sign in to comment.