Skip to content

Commit

Permalink
[Fix] Do not treat typeahead value as textarea value just because it …
Browse files Browse the repository at this point in the history
…exceeds the input length threshold.
  • Loading branch information
ledsoft committed Dec 8, 2016
1 parent 6c4fa30 commit 6555357
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
18 changes: 9 additions & 9 deletions src/model/Configuration.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

var actions = null;
var intl = null;
var optionsStore = null;
var wizardStore = null;
var typeaheadResultList = null;
var inputComponent = null;
var dateFormat = null;
var timeFormat = null;
var dateTimeFormat = null;
let actions = null;
let intl = null;
let optionsStore = null;
let wizardStore = null;
let typeaheadResultList = null;
let inputComponent = null;
let dateFormat = null;
let timeFormat = null;
let dateTimeFormat = null;

export default class Configuration {
static get actions() {
Expand Down
8 changes: 4 additions & 4 deletions src/util/FormUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class FormUtils {
}

static isTextarea(question, answerValue) {
return answerValue && answerValue.length > Constants.INPUT_LENGTH_THRESHOLD
return answerValue && answerValue.length > Constants.INPUT_LENGTH_THRESHOLD && !FormUtils.isTypeahead(question)
|| JsonLdUtils.hasValue(question, Constants.LAYOUT_CLASS, Constants.LAYOUT.TEXTAREA);
}

Expand Down Expand Up @@ -117,7 +117,7 @@ export default class FormUtils {
return false;
}
for (subQ of Utils.asArray(question[Constants.HAS_SUBQUESTION])) {
if (this.isValid(subQ) === false) {
if (this.isValid(subQ) === false) {
return false;
}
}
Expand All @@ -137,7 +137,7 @@ export default class FormUtils {
}

// valid answers
if (acceptedValidationsValues && testedQuestions) {
if (acceptedValidationsValues && testedQuestions) {

var arr = Utils.asArray(acceptedValidationsValues);
if ((arr.length !== 1) || ((arr[0] !== true) && (arr[0] !== "true"))) {
Expand All @@ -158,7 +158,7 @@ export default class FormUtils {

// concrete values
if (acceptedAnswerValues && testedQuestions) {
question = JsonObjectMap.getObject(testedQuestions["@id"]);
question = JsonObjectMap.getObject(testedQuestions["@id"]);
for (var expValue of Utils.asArray(acceptedAnswerValues)) {
var answers = jsonld.getValues(question, Constants.HAS_ANSWER);

Expand Down
45 changes: 32 additions & 13 deletions test/__tests__/FormUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import assign from "object-assign";

describe('FormUtils', () => {

var question;
let question;

beforeEach(() => {
question = {};
});

describe('isForm', () => {
it('returns true for a form element.', () => {
var form = {
const form = {
'@type': Constants.FORM,
'hasQuestion': [
{}, {}
Expand All @@ -26,7 +26,7 @@ describe('FormUtils', () => {
});

it('returns false for non-form element.', () => {
var question = {};
const question = {};
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION];
expect(FormUtils.isForm(question)).toBeFalsy();
});
Expand Down Expand Up @@ -66,6 +66,25 @@ describe('FormUtils', () => {
});
});

describe('isTextarea', () => {
it('returns true for a data value longer than the input length threshold', () => {
let dataValue = '';
for (let i = 0; i < Constants.INPUT_LENGTH_THRESHOLD + 1; i++) {
dataValue += i.toString();
}
expect(FormUtils.isTextarea(question, dataValue)).toBeTruthy();
});

it('returns false for a typeahead result with long value', () => {
let dataValue = '';
for (let i = 0; i < Constants.INPUT_LENGTH_THRESHOLD + 1; i++) {
dataValue += i.toString();
}
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_TYPEAHEAD];
expect(FormUtils.isTextarea(question, dataValue)).toBeFalsy();
});
});

describe('isDisabled', () => {
it('returns true for a disabled question.', () => {
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.DISABLED];
Expand Down Expand Up @@ -95,7 +114,7 @@ describe('FormUtils', () => {
});

it('returns false for a regular question', () => {
var question = {};
const question = {};
expect(FormUtils.isCalendar(question)).toBeFalsy();
});
});
Expand Down Expand Up @@ -172,7 +191,7 @@ describe('FormUtils', () => {
});

it('returns identifier of code value answer', () => {
var id = "http://onto.fel.cvut.cz/ontologies/eccairs/aviation-3.4.0.2/vl-a-431/v-100",
const id = "http://onto.fel.cvut.cz/ontologies/eccairs/aviation-3.4.0.2/vl-a-431/v-100",
answer = {
"@id": "http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-1495029633-a",
"@type": "http://onto.fel.cvut.cz/ontologies/documentation/answer",
Expand All @@ -184,7 +203,7 @@ describe('FormUtils', () => {
});

it('returns value of data value answer', () => {
var value = "2016-06-21",
const value = "2016-06-21",
answer = {
"@id": "http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-2018758124-a",
"@type": "http://onto.fel.cvut.cz/ontologies/documentation/answer",
Expand All @@ -199,7 +218,7 @@ describe('FormUtils', () => {

describe('testCondition', () => {

var condition = {
const condition = {
"@type": ["http://onto.fel.cvut.cz/ontologies/form/condition"],
"http://onto.fel.cvut.cz/ontologies/form/accepts-answer-value": [
{
Expand All @@ -218,8 +237,8 @@ describe('FormUtils', () => {
"http://onto.fel.cvut.cz/ontologies/documentation/has_answer": {
"@type": "http://onto.fel.cvut.cz/ontologies/documentation/answer",
"http://onto.fel.cvut.cz/ontologies/documentation/has_object_value": {
"@id": "http://vfn.cz/ontologies/fss-form/follow-up-and-recurrence/current-status/dod"
}
"@id": "http://vfn.cz/ontologies/fss-form/follow-up-and-recurrence/current-status/dod"
}
}
};

Expand All @@ -229,7 +248,7 @@ describe('FormUtils', () => {

it('returns false in condition without answer values.', () => {

var noAnswerCondition = assign({}, condition);
const noAnswerCondition = assign({}, condition);
delete noAnswerCondition["http://onto.fel.cvut.cz/ontologies/form/accepts-answer-value"];
expect(FormUtils.testCondition(noAnswerCondition));

Expand All @@ -244,12 +263,12 @@ describe('FormUtils', () => {

it('return false if accepts value that does not exists in a question.', () => {

var wrongAnswerQuestion = assign({}, question);
const wrongAnswerQuestion = assign({}, question);
wrongAnswerQuestion
["http://onto.fel.cvut.cz/ontologies/documentation/has_answer"]
["http://onto.fel.cvut.cz/ontologies/documentation/has_object_value"] = {
"@id": "http://bad-value"
};
"@id": "http://bad-value"
};
expect(FormUtils.testCondition(wrongAnswerQuestion)).toEqual(false);
});

Expand Down

0 comments on commit 6555357

Please sign in to comment.