Skip to content

Commit

Permalink
minor cleanups #2766
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Pollock committed Nov 20, 2018
1 parent 6505f50 commit 954c14e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
52 changes: 26 additions & 26 deletions clients/render/components/Fields/FileInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Dropzone from 'react-dropzone';
*/
export const FileInput = (props) => {

const {onChange, accept, field, describedById, style, className, multiUploadText, multiple, inputProps, usePreviews, previewHeight, previewWidth,strings} = props;
const {onChange, accept, field, describedById, style, className, multiUploadText, multiple, inputProps, usePreviews, previewHeight, previewWidth, strings} = props;
let {shouldDisable} = props;
const {
outterIdAttr,
Expand All @@ -38,34 +38,34 @@ export const FileInput = (props) => {

inputProps.id = fieldIdAttr;

if(valueSet && !multiple){
if (valueSet && !multiple) {
shouldDisable = true;
inputProps.disabled = true;
}

return (

<div className="cf2-dropzone" data-field={fieldId}>
<Dropzone
onDrop={onChange}
className={className}
accept={'string' === typeof accept ? accept : ''}
style={style}
<Dropzone
onDrop={onChange}
className={className}
accept={'string' === typeof accept ? accept : ''}
style={style}
disabled={shouldDisable}
inputProps={inputProps}
disableClick={shouldDisable}
multiple={multiple}
>
<button
type="button"
className="btn btn-block"
aria-controls={buttonControls}
aria-expanded={valueSet}
disabled={shouldDisable}
inputProps={inputProps}
disableClick={shouldDisable}
multiple={multiple}
>
<button
type="button"
className="btn btn-block"
aria-controls={buttonControls}
aria-expanded={valueSet}
disabled={shouldDisable}
>
{multiUploadText}
</button>
</Dropzone>
{multiUploadText}
</button>
</Dropzone>

{valueSet &&
<ul
Expand Down Expand Up @@ -139,7 +139,7 @@ FileInput.propTypes = {
]),
text: PropTypes.object,
multiUploadText: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.bool,
PropTypes.string
]),
message: PropTypes.shape({
Expand All @@ -159,10 +159,10 @@ FileInput.propTypes = {
PropTypes.bool,
PropTypes.string
]),
isRequired: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.object
]),
isRequired: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.object
]),
};

/**
Expand Down Expand Up @@ -203,7 +203,7 @@ FileInput.fieldConfigToProps = (fieldConfig) => {
'multiUploadText'
];

if( ! props.field.hasOwnProperty('isRequired' ) ){
if (!props.field.hasOwnProperty('isRequired')) {
props.field.isRequired = false;
}
if (fieldConfig.hasOwnProperty('configOptions')) {
Expand Down
38 changes: 19 additions & 19 deletions clients/tests/unit/render/Fields/Mocks/MockFileRenderer.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {shallow, mount} from 'enzyme';
import EnzymeAdapter from '../../../createEnzymeAdapter'
import {fileFieldConfigs, fileStrings } from "./fileFieldConfigs";
import {fileFieldConfigs, fileStrings} from "./fileFieldConfigs";
import {MockFileFieldRenderer} from "./MockFileFieldRenderer";
import React from 'react';
import {FileInput} from '../../../../../render/components/Fields/FileInput'
Expand Down Expand Up @@ -103,9 +103,9 @@ describe('DOM testing file components', () => {
/>
);
component.setProps(prepared);
expect(component.find(".btn[disabled]").html()).toBe("<button type=\"button\" class=\"btn btn-block\" aria-controls=\"required_single, cf2-list-files\" aria-expanded=\"true\" disabled=\"\">My multi Upload Text</button>");
expect(component.find(".btn[disabled]").html()).toBe("<button type=\"button\" class=\"btn btn-block\" aria-controls=\"required_single, cf2-list-files\" aria-expanded=\"true\" disabled=\"\">My multi Upload Text</button>");

});
});

it('Shows image preview if is an image', () => {
const size = 1024 * 1024 * 2;
Expand All @@ -117,7 +117,7 @@ describe('DOM testing file components', () => {
const component = mount(
<MockFileFieldRenderer
field={field}
strings={fileStrings}
strings={fileStrings}
/>
);
component.setProps(prepared);
Expand All @@ -136,7 +136,7 @@ describe('DOM testing file components', () => {
const component = mount(
<MockFileFieldRenderer
field={field}
strings={fileStrings}
strings={fileStrings}
/>
);
component.setProps(prepared);
Expand All @@ -156,7 +156,7 @@ describe('DOM testing file components', () => {
const component = mount(
<FileInput
field={field}
strings={fileStrings}
strings={fileStrings}
/>
);
component.setProps(prepared);
Expand All @@ -174,7 +174,7 @@ describe('DOM testing file components', () => {
const component = mount(
<FileInput
field={field}
strings={fileStrings}
strings={fileStrings}
/>
);
component.setProps(prepared);
Expand All @@ -194,18 +194,18 @@ describe('DOM testing file components', () => {
expect(component.find('.btn').text()).toEqual("The Custom Text");
});

it('Shows default button text', () => {
let prepared = FileInput.fieldConfigToProps(fileFieldConfigs.required_multiple_no_button_text);
const field = prepared.field;
prepared.multiUploadText = fileStrings.defaultButtonText;
const component = mount(
<FileInput
field={field}
it('Shows default button text', () => {
let prepared = FileInput.fieldConfigToProps(fileFieldConfigs.required_multiple_no_button_text);
const field = prepared.field;
prepared.multiUploadText = fileStrings.defaultButtonText;
const component = mount(
<FileInput
field={field}
strings={fileStrings}
/>
);
component.setProps(prepared);
expect(component.find('.btn').text()).toEqual("Drop files or click to select files to Upload");
});
/>
);
component.setProps(prepared);
expect(component.find('.btn').text()).toEqual("Drop files or click to select files to Upload");
});

});

0 comments on commit 954c14e

Please sign in to comment.