Skip to content

Commit

Permalink
Merge branch 'master' into feature/apisSorter
Browse files Browse the repository at this point in the history
  • Loading branch information
webron committed Jul 7, 2017
2 parents ac3b12f + 2861604 commit fe9af65
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 7 deletions.
6 changes: 5 additions & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
module.exports = {};
module.exports = {
plugins: [
require("autoprefixer")
]
}
2 changes: 1 addition & 1 deletion src/core/components/parameter-row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class ParameterRow extends Component {
{ param.get("name") }
{ !required ? null : <span style={{color: "red"}}>&nbsp;*</span> }
</div>
<div className="parаmeter__type">{ param.get("type") } { itemType && `[${itemType}]` }</div>
<div className="parameter__type">{ param.get("type") } { itemType && `[${itemType}]` }</div>
<div className="parameter__in">({ param.get("in") })</div>
</td>

Expand Down
15 changes: 13 additions & 2 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@ export const validateInteger = ( val ) => {
}
}

export const validateFile = ( val ) => {
if ( val && !(val instanceof win.File) ) {
return "Value must be a file"
}
}

// validation of parameters before execute
export const validateParam = (param, isXml) => {
let errors = []
Expand All @@ -472,7 +478,9 @@ export const validateParam = (param, isXml) => {
let stringCheck = type === "string" && !value
let arrayCheck = type === "array" && Array.isArray(value) && !value.length
let listCheck = type === "array" && Im.List.isList(value) && !value.count()
if ( required && (stringCheck || arrayCheck || listCheck) ) {
let fileCheck = type === "file" && !(value instanceof win.File)

if ( required && (stringCheck || arrayCheck || listCheck || fileCheck) ) {
errors.push("Required field is not provided")
return errors
}
Expand Down Expand Up @@ -505,7 +513,10 @@ export const validateParam = (param, isXml) => {
errors.push({ index: index, error: err})
}
})

} else if ( type === "file" ) {
let err = validateFile(value)
if (!err) return errors
errors.push(err)
}

return errors
Expand Down
3 changes: 2 additions & 1 deletion src/style/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ label
input[type=text],
input[type=password],
input[type=search],
input[type=email]
input[type=email],
input[type=file]
{
min-width: 100px;
margin: 5px 0;
Expand Down
2 changes: 1 addition & 1 deletion src/style/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ body
}
}

.parаmeter__type
.parameter__type
{
font-size: 12px;

Expand Down
26 changes: 25 additions & 1 deletion test/core/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-env mocha */
import expect from "expect"
import { fromJS } from "immutable"
import { mapToList, validateNumber, validateInteger, validateParam } from "core/utils"
import { mapToList, validateNumber, validateInteger, validateParam, validateFile } from "core/utils"
import win from "core/window"

describe("utils", function(){

Expand Down Expand Up @@ -157,6 +158,19 @@ describe("utils", function(){
})
})

describe("validateFile", function() {
let errorMessage = "Value must be a file"

it("validates against objects which are instances of 'File'", function() {
let fileObj = new win.File([], "Test File")
expect(validateFile(fileObj)).toBeFalsy()
expect(validateFile(null)).toBeFalsy()
expect(validateFile(undefined)).toBeFalsy()
expect(validateFile(1)).toEqual(errorMessage)
expect(validateFile("string")).toEqual(errorMessage)
})
})

describe("validateParam", function() {
let param = null
let result = null
Expand All @@ -171,6 +185,16 @@ describe("utils", function(){
expect( result ).toEqual( ["Required field is not provided"] )
})

it("validates required files", function() {
param = fromJS({
required: true,
type: "file",
value: undefined
})
result = validateParam( param, false )
expect( result ).toEqual( ["Required field is not provided"] )
})

it("validates required arrays", function() {
param = fromJS({
required: true,
Expand Down

0 comments on commit fe9af65

Please sign in to comment.