From 836d074f29ff12938a3502403eac791020e288db Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Thu, 7 Apr 2022 15:09:21 +0200 Subject: [PATCH] [Fix #5] Remove tests --- test/__tests__/Answer.test.js | 387 ------------------ test/__tests__/DefaultFormGenerator.test.js | 32 -- test/__tests__/FormUtils.test.js | 278 ------------- test/__tests__/InputAnswer.test.js | 193 --------- test/__tests__/JsonLdFramingUtils.test.js | 28 -- test/__tests__/JsonLdObjectUtils.test.js | 53 --- test/__tests__/MaskMapper.test.js | 32 -- test/__tests__/MaskedInputAnswer.test.js | 87 ---- test/__tests__/Question.test.js | 92 ----- .../__tests__/QuestionAnswerProcessor.test.js | 156 ------- test/__tests__/TypeaheadAnswer.test.js | 89 ---- 11 files changed, 1427 deletions(-) delete mode 100644 test/__tests__/Answer.test.js delete mode 100644 test/__tests__/DefaultFormGenerator.test.js delete mode 100644 test/__tests__/FormUtils.test.js delete mode 100644 test/__tests__/InputAnswer.test.js delete mode 100644 test/__tests__/JsonLdFramingUtils.test.js delete mode 100644 test/__tests__/JsonLdObjectUtils.test.js delete mode 100644 test/__tests__/MaskMapper.test.js delete mode 100644 test/__tests__/MaskedInputAnswer.test.js delete mode 100644 test/__tests__/Question.test.js delete mode 100644 test/__tests__/QuestionAnswerProcessor.test.js delete mode 100644 test/__tests__/TypeaheadAnswer.test.js diff --git a/test/__tests__/Answer.test.js b/test/__tests__/Answer.test.js deleted file mode 100644 index 780da7cf..00000000 --- a/test/__tests__/Answer.test.js +++ /dev/null @@ -1,387 +0,0 @@ -import React from 'react'; -import JsonLdUtils from 'jsonld-utils'; -import { format } from 'date-fns'; -import DatePicker from 'react-datepicker'; -import Select from 'react-select'; - -import * as Generator from '../environment/Generator'; -import Answer from '../../src/components/Answer'; -import Constants from '../../src/constants/Constants'; -import TypeaheadAnswer from '../../src/components/answer/TypeaheadAnswer'; -import MaskedInput from '../../src/components/MaskedInput'; -import { FormGenContext } from '../../src/contexts/FormGenContext'; -import { ConfigurationContext } from '../../src/contexts/ConfigurationContext'; -import DefaultInput from '../../src/components/DefaultInput'; - -describe('Answer component', () => { - let question, onChange, answer, getOptions, loadFormOptions, options, inputComponent, componentsOptions; - - beforeEach(() => { - question = { - '@id': Generator.getRandomUri() - }; - question[Constants.LAYOUT_CLASS] = []; - question[Constants.RDFS_LABEL] = { - '@language': 'en', - '@value': '1 - Aerodrome General' - }; - question[Constants.RDFS_COMMENT] = { - '@language': 'en', - '@value': 'The identification of the aerodrome/helicopter landing area by name, location and status.' - }; - onChange = jest.fn(); - options = { - intl: { - locale: 'en' - } - }; - componentsOptions = { - readOnly: false, - dateTimeAnswer: { - dateFormat: 'yyyy-MM-dd', - timeFormat: 'HH:mm:ss', - dateTimeFormat: 'yyyy-MM-dd HH:mm:ss' - } - }; - inputComponent = DefaultInput; - getOptions = jest.fn(() => []); - loadFormOptions = jest.fn(); - }); - - it('renders a Typeahead when layout class is typeahead', () => { - question[Constants.LAYOUT_CLASS].push(Constants.LAYOUT.QUESTION_TYPEAHEAD); - const component = mount( - - - - - - ); - - const typeahead = component.find(Select); - expect(typeahead).not.toBeNull(); - }); - - it('maps answer object value to string label for the typeahead component', () => { - const value = Generator.getRandomUri(); - const valueLabel = 'masterchief'; - const typeAheadOptions = Generator.generateTypeaheadOptions(value, valueLabel); - answer = answerWithCodeValue(value); - getOptions = jest.fn(() => typeAheadOptions); - question[Constants.HAS_ANSWER] = [answer]; - question[Constants.LAYOUT_CLASS].push(Constants.LAYOUT.QUESTION_TYPEAHEAD); - question[Constants.HAS_OPTIONS_QUERY] = 'SELECT * WHERE {?x ?y ?z. }'; - - const component = mount( - - typeAheadOptions }}> - - - - ); - - waitForComponentToPaint(component); - const typeahead = component.find(Answer).find(TypeaheadAnswer).find(Select); - - expect(typeahead).not.toBeNull(); - - expect(typeahead.state('value')[0].name).toEqual(valueLabel); - }); - - it('loads typeahead options when layout class is typeahead and no possible values are specified', () => { - question[Constants.LAYOUT_CLASS].push(Constants.LAYOUT.QUESTION_TYPEAHEAD); - const query = 'SELECT * WHERE { ?x ?y ?z .}'; - question[Constants.HAS_OPTIONS_QUERY] = query; - - const component = mount( - - - - - - ); - - waitForComponentToPaint(component); - - expect(loadFormOptions).toHaveBeenCalled(); - expect(loadFormOptions.mock.calls[0][1]).toEqual(query); - }); - - function answerWithCodeValue(value) { - const res = { - '@id': Generator.getRandomUri() - }; - res[Constants.HAS_OBJECT_VALUE] = { - '@id': value - }; - return res; - } - - it('shows input with text value of the answer when no layout class is specified', () => { - const value = 'masterchief'; - answer = answerWithTextValue(value); - question[Constants.HAS_ANSWER] = [answer]; - - const component = mount( - - s - - ); - const input = component.find('input'); - - expect(input).not.toBeNull(); - expect(input.props().type).toEqual('text'); - expect(input.props().value).toEqual(value); - }); - - function answerWithTextValue(value) { - const res = { - '@id': Generator.getRandomUri() - }; - res[Constants.HAS_DATA_VALUE] = { - '@language': 'en', - '@value': value - }; - return res; - } - - it('renders date picker with answer value when date layout class is specified', () => { - const date = new Date('2000-01-01'); - const value = format(date, 'yyyy-MM-dd HH:mm:ss'); - - answer = answerWithTextValue(value); - question[Constants.HAS_ANSWER] = [answer]; - question[Constants.LAYOUT_CLASS].push(Constants.LAYOUT.DATE); - - const component = mount( - - - - ); - const picker = component.find(DatePicker); - - expect(picker).not.toBeNull(); - expect(picker.props().showTimeSelect).toEqual(false); - expect(picker.props().showTimeSelectOnly).toEqual(false); - expect(picker.props().selected).toEqual(date); - }); - - it('renders time picker with answer value when time layout class is specified', () => { - const date = new Date(); - const value = format(date, 'HH:mm:ss'); - - answer = answerWithTextValue(value); - question[Constants.HAS_ANSWER] = [answer]; - question[Constants.LAYOUT_CLASS].push(Constants.LAYOUT.TIME); - - const component = mount( - - - - ); - const picker = component.find(DatePicker); - - expect(picker).not.toBeNull(); - expect(picker.props().showTimeSelect).toEqual(true); - expect(picker.props().showTimeSelectOnly).toEqual(true); - expect(picker.props().selected).toEqual(new Date(`0 ${value}`)); - }); - - it('renders datetime picker with answer value when datetime layout class is specified', () => { - const date = new Date(); - const value = format(date, 'yyyy-MM-dd HH:mm:ss'); - answer = answerWithTextValue(value); - question[Constants.HAS_ANSWER] = [answer]; - question[Constants.LAYOUT_CLASS].push(Constants.LAYOUT.DATETIME); - - const component = mount( - - - - ); - const picker = component.find(DatePicker); - - expect(picker).not.toBeNull(); - expect(picker.props().showTimeSelect).toEqual(true); - expect(picker.props().showTimeSelectOnly).toEqual(false); - expect(picker.props().selected).toEqual(new Date(value)); - }); - - it('renders datetime picker with answer value when no layout class is specified and numeric answer value is used', () => { - const value = Number(new Date()); - answer = { - '@id': Generator.getRandomUri() - }; - answer[Constants.HAS_DATA_VALUE] = value; - question[Constants.HAS_ANSWER] = [answer]; - question[Constants.LAYOUT_CLASS].push(Constants.LAYOUT.DATETIME); - - const component = mount( - - - - ); - const picker = component.find(DatePicker); - - expect(picker).not.toBeNull(); - expect(picker.props().showTimeSelect).toEqual(true); - expect(picker.props().showTimeSelectOnly).toEqual(false); - expect(picker.props().selected).toEqual(new Date(value)); - }); - - it('renders checkbox with answer value when checkbox layout class is specified', () => { - const answer = { - '@id': Generator.getRandomUri() - }; - answer[Constants.HAS_DATA_VALUE] = true; - question[Constants.HAS_ANSWER] = [answer]; - question[Constants.LAYOUT_CLASS].push(Constants.LAYOUT.CHECKBOX); - - const component = mount( - - - - ); - const input = component.find('input'); - - expect(input).toBeDefined(); - expect(input.props().type).toEqual('checkbox'); - expect(input.props().checked).toBeTruthy(); - }); - - it('renders numeric input with answer value when number layout class is specified', () => { - const value = 117; - const answer = { - '@id': Generator.getRandomUri() - }; - answer[Constants.HAS_DATA_VALUE] = value; - question[Constants.HAS_ANSWER] = [answer]; - question[Constants.HAS_DATATYPE] = Constants.XSD.INT; - - const component = mount( - - - - ); - const input = component.find('input'); - - expect(input).toBeDefined(); - expect(input.props().type).toEqual('number'); - expect(input.props().value).toEqual(value); - }); - - it('renders textarea for answer with long value', () => { - let value = ''; - for (let i = 0; i < Constants.INPUT_LENGTH_THRESHOLD + 1; i++) { - value += 'a'; - } - answer = answerWithTextValue(value); - answer[Constants.HAS_DATA_VALUE] = value; - question[Constants.HAS_ANSWER] = [answer]; - - const component = mount( - - - - ); - const input = component.find('textarea'); - - expect(input).toBeDefined(); - expect(input.props().value).toEqual(value); - }); - - it('renders masked input for question with masked-input layout class', () => { - const value = '08/2016'; - const mask = '11/1111'; - const answer = { - '@id': Generator.getRandomUri() - }; - answer[Constants.HAS_DATA_VALUE] = value; - question[Constants.HAS_ANSWER] = [answer]; - question[Constants.LAYOUT_CLASS].push(Constants.LAYOUT.MASKED_INPUT); - question[Constants.INPUT_MASK] = mask; - - const component = mount( - - - - ); - const input = component.find(MaskedInput); - - expect(input).toBeDefined(); - expect(input.props().value).toEqual(value); - expect(input.props().mask).toEqual(mask); - }); -}); diff --git a/test/__tests__/DefaultFormGenerator.test.js b/test/__tests__/DefaultFormGenerator.test.js deleted file mode 100644 index 95f2b7f8..00000000 --- a/test/__tests__/DefaultFormGenerator.test.js +++ /dev/null @@ -1,32 +0,0 @@ -import Constants from '../../src/constants/Constants'; -import FormGenerator from '../../src/model/FormGenerator'; -import DefaultFormGenerator from '../../src/model/DefaultFormGenerator'; - -describe('Default form generator', () => { - let textValue; - - beforeEach(() => { - textValue = 'masterchief'; - }); - - it('generates empty one-step wizard as a default form', async () => { - const form = DefaultFormGenerator.generateForm(); - const [formProperties, structure] = await FormGenerator.constructDefaultForm(null); - - expect(formProperties.formQuestions.length).toEqual(1); - - expect(structure).toEqual({ root: form['@graph'][0] }); - - expect(formProperties.formQuestions[0][Constants.HAS_SUBQUESTION]).toEqual([ - form['@graph'][0][Constants.HAS_SUBQUESTION][0][Constants.HAS_SUBQUESTION][0] - ]); - }); - - it('creates a clone of the form template, so that modifications to the form do not affect the original template', () => { - const formOne = DefaultFormGenerator.generateForm(); - let formTwo; - formOne['newAttribute'] = 12345; - formTwo = DefaultFormGenerator.generateForm(); - expect(formTwo['newAttribute']).not.toBeDefined(); - }); -}); diff --git a/test/__tests__/FormUtils.test.js b/test/__tests__/FormUtils.test.js deleted file mode 100644 index a260890f..00000000 --- a/test/__tests__/FormUtils.test.js +++ /dev/null @@ -1,278 +0,0 @@ -import FormUtils from '../../src/util/FormUtils'; -import Constants from '../../src/constants/Constants'; -import JsonObjectMap from '../../src/util/JsonLdObjectMap'; - -describe('FormUtils', () => { - let question; - - beforeEach(() => { - question = {}; - }); - - describe('isForm', () => { - it('returns true for a form element.', () => { - const form = { - '@type': Constants.FORM, - hasQuestion: [{}, {}] - }; - form[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.FORM]; - expect(FormUtils.isForm(form)).toBeTruthy(); - }); - - it('returns false for non-form element.', () => { - const question = {}; - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION]; - expect(FormUtils.isForm(question)).toBeFalsy(); - }); - }); - - describe('isWizardStep', () => { - it('returns true for a wizard step question', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION, Constants.LAYOUT.WIZARD_STEP]; - expect(FormUtils.isWizardStep(question)).toBeTruthy(); - }); - - it('returns false for a section', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION]; - expect(FormUtils.isWizardStep(question)).toBeFalsy(); - }); - }); - - describe('isSection', () => { - it('returns true for a section.', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION]; - expect(FormUtils.isSection(question)).toBeTruthy(); - }); - - it('returns false for a regular question.', () => { - expect(FormUtils.isSection({})).toBeFalsy(); - }); - }); - - describe('isTypeahead', () => { - it('returns true for a typeahead question.', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_TYPEAHEAD]; - expect(FormUtils.isTypeahead(question)).toBeTruthy(); - }); - - it('returns false for a regular question.', () => { - expect(FormUtils.isTypeahead({})).toBeFalsy(); - }); - }); - - 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]; - expect(FormUtils.isDisabled(question)).toBeTruthy(); - }); - - it('returns false for enabled question.', () => { - expect(FormUtils.isDisabled(question)).toBeFalsy(); - }); - }); - - describe('isHidden', () => { - it('returns true for a hidden question.', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.HIDDEN]; - expect(FormUtils.isHidden(question)).toBeTruthy(); - }); - - it('returns false for a normal question', () => { - expect(FormUtils.isHidden({})).toBeFalsy(); - }); - }); - - describe('isCalendar', () => { - it('returns true for a date question', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.DATE]; - expect(FormUtils.isCalendar(question)).toBeTruthy(); - }); - - it('returns false for a regular question', () => { - const question = {}; - expect(FormUtils.isCalendar(question)).toBeFalsy(); - }); - }); - - describe('isDate', () => { - it('returns true for a date question', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.DATE]; - expect(FormUtils.isCalendar(question)).toBeTruthy(); - }); - - it('returns false for a regular question', () => { - expect(FormUtils.isCalendar(question)).toBeFalsy(); - }); - }); - - describe('isTime', () => { - it('returns true for a time question', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.TIME]; - expect(FormUtils.isCalendar(question)).toBeTruthy(); - }); - - it('returns false for a regular question', () => { - expect(FormUtils.isCalendar(question)).toBeFalsy(); - }); - }); - - describe('isDateTime', () => { - it('returns true for a datetime question', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.DATETIME]; - expect(FormUtils.isCalendar(question)).toBeTruthy(); - }); - - it('returns false for a regular question', () => { - expect(FormUtils.isCalendar(question)).toBeFalsy(); - }); - }); - - describe('isCheckbox', () => { - it('returns true for a checkbox question', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.CHECKBOX]; - expect(FormUtils.isCheckbox(question)).toBeTruthy(); - }); - it('returns false for a non-checkbox question', () => { - question[Constants.LAYOUT_CLASS] = []; - expect(FormUtils.isCheckbox(question)).toBeFalsy(); - }); - }); - - describe('isAnswerable', () => { - it('returns true for an answerable section-question', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION, Constants.LAYOUT.ANSWERABLE]; - expect(FormUtils.isAnswerable(question)).toBeTruthy(); - }); - it('returns false for a non-answerable section-question', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION]; - expect(FormUtils.isAnswerable(question)).toBeFalsy(); - }); - }); - - describe('isMaskedInput', () => { - it('returns true for a question with masked input layout class', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.MASKED_INPUT]; - expect(FormUtils.isMaskedInput(question)).toBeTruthy(); - }); - - it('returns false for a non-masked question', () => { - expect(FormUtils.isMaskedInput(question)).toBeFalsy(); - }); - }); - - describe('resolveValue', () => { - it('returns null for no answer', () => { - expect(FormUtils.resolveValue(null)).toBeNull(); - }); - - it('returns identifier of code value answer', () => { - 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', - 'http://onto.fel.cvut.cz/ontologies/documentation/has_object_value': { - '@id': id - } - }; - expect(FormUtils.resolveValue(answer)).toEqual(id); - }); - - it('returns value of data value answer', () => { - 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', - 'http://onto.fel.cvut.cz/ontologies/documentation/has_data_value': { - '@language': 'en', - '@value': value - } - }; - expect(FormUtils.resolveValue(answer)).toEqual(value); - }); - }); - - describe('testCondition', () => { - const condition = { - '@type': ['http://onto.fel.cvut.cz/ontologies/form/condition'], - 'http://onto.fel.cvut.cz/ontologies/form/accepts-answer-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/doc' - } - ], - 'http://onto.fel.cvut.cz/ontologies/form/has-tested-question': [ - { - '@id': 'http://vfn.cz/ontologies/fss-form/follow-up-and-recurrence/current-status' - } - ] - }, - question = { - '@id': 'http://vfn.cz/ontologies/fss-form/follow-up-and-recurrence/current-status', - '@type': 'http://onto.fel.cvut.cz/ontologies/documentation/question', - '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' - } - } - }; - - beforeEach(function () { - jest.spyOn(JsonObjectMap, 'getObject').mockReturnValue(question); - }); - - it('returns false in condition without answer values.', () => { - const noAnswerCondition = { ...condition }; - delete noAnswerCondition['http://onto.fel.cvut.cz/ontologies/form/accepts-answer-value']; - expect(FormUtils.testCondition(noAnswerCondition)); - - expect(JsonObjectMap.getObject).not.toHaveBeenCalled(); - }); - - it('return true if accepts value that exists in a question.', () => { - expect(FormUtils.testCondition(condition)).toEqual(true); - }); - - it('return false if accepts value that does not exists in a question.', () => { - const wrongAnswerQuestion = { ...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' - }; - expect(FormUtils.testCondition(wrongAnswerQuestion)).toEqual(false); - }); - }); - - describe('isCollapsed', () => { - it('returns true when question layout class contains collapsed', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION, Constants.LAYOUT.COLLAPSED]; - expect(FormUtils.isCollapsed(question)).toBeTruthy(); - }); - - it('returns false when question layout class does not contain collapsed', () => { - expect(FormUtils.isCollapsed(question)).toBeFalsy(); - }); - }); -}); diff --git a/test/__tests__/InputAnswer.test.js b/test/__tests__/InputAnswer.test.js deleted file mode 100644 index d3c57faf..00000000 --- a/test/__tests__/InputAnswer.test.js +++ /dev/null @@ -1,193 +0,0 @@ -import React from 'react'; -import JsonLdUtils from 'jsonld-utils'; - -import Answer from '../../src/components/Answer'; -import Constants from '../../src/constants/Constants'; -import * as Generator from '../environment/Generator'; -import { ConfigurationContext } from '../../src/contexts/ConfigurationContext'; -import DefaultInput from '../../src/components/DefaultInput'; - -const LABEL = 'Input answer test'; - -describe('InputAnswer', () => { - let question, answer, onChange, options, componentsOptions, inputComponent; - - beforeEach(() => { - question = { - '@id': Generator.getRandomUri() - }; - question[Constants.LAYOUT_CLASS] = []; - question[Constants.RDFS_LABEL] = { - '@language': 'en', - '@value': LABEL - }; - question[Constants.RDFS_COMMENT] = { - '@language': 'en', - '@value': 'Javascript sucks!!!' - }; - onChange = jest.fn(); - options = { - intl: { - locale: 'en' - } - }; - componentsOptions = { - readOnly: false, - dateTimeAnswer: { - dateFormat: 'yyyy-MM-dd', - timeFormat: 'HH:mm:ss', - dateTimeFormat: 'yyyy-MM-dd HH:mm:ss' - } - }; - inputComponent = DefaultInput; - answer = { - id: Generator.getRandomUri() - }; - question[Constants.HAS_ANSWER] = [answer]; - }); - - it('sets min on numeric input when xsd:minInclusive is used in question', () => { - const min = 100; - const value = 117; - question[Constants.HAS_DATATYPE] = Constants.XSD.INT; - question[Constants.XSD.MIN_INCLUSIVE] = min; - answer[Constants.HAS_DATA_VALUE] = value; - - const component = mount( - - - - ); - const input = component.find('input'); - - expect(input.props().type).toEqual('number'); - expect(input.props().min).toEqual(min); - }); - - it('sets min on numeric input when xsd:minExclusive is used in question', () => { - const min = 100; - const value = 117; - question[Constants.HAS_DATATYPE] = Constants.XSD.INT; - question[Constants.XSD.MIN_EXCLUSIVE] = min; - answer[Constants.HAS_DATA_VALUE] = value; - - const component = mount( - - - - ); - const input = component.find('input'); - - expect(input.props().type).toEqual('number'); - expect(input.props().min).toEqual(min + 1); - }); - - it('sets max on numeric input when xsd:maxExclusive is used in question', () => { - const max = 1000; - const value = 117; - question[Constants.HAS_DATATYPE] = Constants.XSD.INT; - question[Constants.XSD.MAX_EXCLUSIVE] = max; - answer[Constants.HAS_DATA_VALUE] = value; - - const component = mount( - - - - ); - const input = component.find('input'); - - expect(input.props().type).toEqual('number'); - expect(input.props().max).toEqual(max - 1); - }); - - it('sets max on numeric input when xsd:maxInclusive is used in question', () => { - const max = 1000; - const value = 117; - question[Constants.HAS_DATATYPE] = Constants.XSD.INT; - question[Constants.XSD.MAX_INCLUSIVE] = max; - answer[Constants.HAS_DATA_VALUE] = value; - - const component = mount( - - - - ); - const input = component.find('input'); - - expect(input.props().type).toEqual('number'); - expect(input.props().max).toEqual(max); - }); - - it('sets both min and max on numeric input when both are used in question', () => { - const max = 1000; - const min = 100; - const value = 117; - question[Constants.HAS_DATATYPE] = Constants.XSD.INT; - question[Constants.XSD.MAX_INCLUSIVE] = max; - question[Constants.XSD.MIN_INCLUSIVE] = min; - answer[Constants.HAS_DATA_VALUE] = value; - - const component = mount( - - - - ); - const input = component.find('input'); - - expect(input.props().type).toEqual('number'); - expect(input.props().max).toEqual(max); - expect(input.props().min).toEqual(min); - }); - - it('sets min when xsd:positiveInteger is used as question datatype', () => { - const value = 117; - question[Constants.HAS_DATATYPE] = Constants.XSD.POSITIVE_INTEGER; - answer[Constants.HAS_DATA_VALUE] = value; - - const component = mount( - - - - ); - const input = component.find('input'); - - expect(input.props().type).toEqual('number'); - expect(input.props().min).toEqual(1); - }); -}); diff --git a/test/__tests__/JsonLdFramingUtils.test.js b/test/__tests__/JsonLdFramingUtils.test.js deleted file mode 100644 index ad9c64d4..00000000 --- a/test/__tests__/JsonLdFramingUtils.test.js +++ /dev/null @@ -1,28 +0,0 @@ -import React from 'react'; -import JsonLdFramingUtils from '../../src/util/JsonLdFramingUtils'; - -describe('JsonLd framing utils', () => { - let formDocument; - let formQuestion; - - beforeEach(() => { - formQuestion = { - '@id': 'http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-1223764187-q', - '@type': 'http://onto.fel.cvut.cz/ontologies/documentation/question', - 'http://onto.fel.cvut.cz/ontologies/form-layout/has-layout-class': 'form', - 'http://www.w3.org/2000/01/rdf-schema#label': { - '@language': 'en', - '@value': '453 - Responsible entity' - } - }; - formDocument = { - '@graph': [formQuestion] - }; - }); - - it('returns expanded jsonld object map from expandStructure', () => { - const id2objectMap = JsonLdFramingUtils.expandStructure(formDocument); - - expect(id2objectMap[formQuestion['@id']]).toBe(formQuestion); - }); -}); diff --git a/test/__tests__/JsonLdObjectUtils.test.js b/test/__tests__/JsonLdObjectUtils.test.js deleted file mode 100644 index 8f669456..00000000 --- a/test/__tests__/JsonLdObjectUtils.test.js +++ /dev/null @@ -1,53 +0,0 @@ -import React from 'react'; -import JsonLdObjectUtils from '../../src/util/JsonLdObjectUtils'; - -describe('JsonLd object utils', () => { - let trueValues, falseValues; - - beforeEach(() => { - trueValues = [true, { '@value': true }, { '@value': 'true' }, { '@value': 'true', '@language': 'en' }]; - falseValues = [false, { '@value': false }, { '@value': 'false' }, { '@value': 'false', '@language': 'en' }]; - }); - - it('returns true for comparison of json-ld objects with same @id-s', () => { - const value1 = { '@id': 'http://vfn.cz/ontologies/study-model/answer-value-yes' }; - const value2 = { '@id': 'http://vfn.cz/ontologies/study-model/answer-value-yes' }; - - expect(JsonLdObjectUtils.compareValues(value1, value2)).toBe(true); - expect(JsonLdObjectUtils.compareValues(value2, value1)).toBe(true); - }); - - it('returns false for comparison of json-ld objects with different @id-s', () => { - const value1 = { '@id': 'http://vfn.cz/ontologies/study-model/answer-value-no' }; - const value2 = { '@id': 'http://vfn.cz/ontologies/study-model/answer-value-yes' }; - - expect(JsonLdObjectUtils.compareValues(value1, value2)).toBe(false); - expect(JsonLdObjectUtils.compareValues(value2, value1)).toBe(false); - }); - - it('returns true for comparison of same boolean values represented as string', () => { - for (let i = 0; i < trueValues.length; i++) { - for (let j = 0; j < trueValues.length; j++) { - expect(JsonLdObjectUtils.compareValues(trueValues[i], trueValues[j])).toBe( - true, - 'when comparing ' + JSON.stringify(trueValues[i]) + ' with ' + JSON.stringify(trueValues[j]) - ); - } - } - }); - - it('returns false for comparison of different boolean values represented as string', () => { - for (let i = 0; i < trueValues.length; i++) { - for (let j = 0; j < falseValues.length; j++) { - expect(JsonLdObjectUtils.compareValues(trueValues[i], falseValues[j])).toBe( - false, - 'when comparing ' + JSON.stringify(trueValues[i]) + ' with ' + JSON.stringify(falseValues[j]) - ); - expect(JsonLdObjectUtils.compareValues(falseValues[j], trueValues[i])).toBe( - false, - 'when comparing ' + JSON.stringify(falseValues[j]) + ' with ' + JSON.stringify(trueValues[i]) - ); - } - } - }); -}); diff --git a/test/__tests__/MaskMapper.test.js b/test/__tests__/MaskMapper.test.js deleted file mode 100644 index d8856e46..00000000 --- a/test/__tests__/MaskMapper.test.js +++ /dev/null @@ -1,32 +0,0 @@ -import MaskMapper from '../../src/util/MaskMapper'; - -describe('MaskMapper', () => { - it('maps date/time/datetime masks to numeric input mask', () => { - const data = [ - { - mask: 'DD-MM-YYYY', - expected: '11-11-1111' - }, - { - mask: 'hh:mm:ss', - expected: '11:11:11' - }, - { - mask: 'DD/MM/YYYY hh:mm:ss', - expected: '11/11/1111 11:11:11' - } - ]; - - data.forEach((d) => { - expect(MaskMapper.mapMask(d.mask)).toEqual(d.expected); - }); - }); - - it('returns null form null value passed in', () => { - expect(MaskMapper.mapMask(null)).toBeNull(); - }); - - it('returns undefined for undefined passed in', () => { - expect(MaskMapper.mapMask(undefined)).not.toBeDefined(); - }); -}); diff --git a/test/__tests__/MaskedInputAnswer.test.js b/test/__tests__/MaskedInputAnswer.test.js deleted file mode 100644 index b9ae610d..00000000 --- a/test/__tests__/MaskedInputAnswer.test.js +++ /dev/null @@ -1,87 +0,0 @@ -import React from 'react'; -import JsonLdUtils from 'jsonld-utils'; - -import Answer from '../../src/components/Answer'; -import Constants from '../../src/constants/Constants'; -import * as Generator from '../environment/Generator'; -import { ConfigurationContext } from '../../src/contexts/ConfigurationContext'; -import DefaultInput from '../../src/components/DefaultInput'; - -describe('MaskedInputAnswer', () => { - let question, onChange, options, inputComponent, componentsOptions; - - beforeEach(() => { - question = {}; - onChange = jest.fn(); - options = { - intl: { - locale: 'en' - } - }; - componentsOptions = { - readOnly: false, - dateTimeAnswer: { - dateFormat: 'yyyy-MM-dd', - timeFormat: 'HH:mm:ss', - dateTimeFormat: 'yyyy-MM-dd HH:mm:ss' - } - }; - inputComponent = DefaultInput; - }); - - it('renders a regular input when question contains no mask', () => { - const value = '08/2016'; - const answer = { - '@id': Generator.getRandomUri() - }; - - answer[Constants.HAS_DATA_VALUE] = value; - question[Constants.HAS_ANSWER] = [answer]; - question[JsonLdUtils.RDFS_LABEL] = 'Test'; - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.MASKED_INPUT]; - - const component = mount( - - - - ); - const input = component.find('input'); - - expect(input.props().value).toEqual(value); - }); - - it('render disabled masked input with value when disabled layout class is specified', () => { - const value = '08/2016'; - const mask = '11/1111'; - const answer = { - '@id': Generator.getRandomUri() - }; - answer[Constants.HAS_DATA_VALUE] = value; - question[Constants.HAS_ANSWER] = [answer]; - question[JsonLdUtils.RDFS_LABEL] = 'Test'; - question[Constants.INPUT_MASK] = mask; - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.MASKED_INPUT, Constants.LAYOUT.DISABLED]; - - const component = mount( - - - - ); - const input = component.find('input'); - - expect(input.props().value).toEqual(value); - expect(input.props().disabled).toBeTruthy(); - }); -}); diff --git a/test/__tests__/Question.test.js b/test/__tests__/Question.test.js deleted file mode 100644 index 55c825e3..00000000 --- a/test/__tests__/Question.test.js +++ /dev/null @@ -1,92 +0,0 @@ -import React from 'react'; -import { Card, Accordion } from 'react-bootstrap'; -import JsonLdUtils from 'jsonld-utils'; - -import Constants from '../../src/constants/Constants'; -import Question from '../../src/components/Question'; -import { ConfigurationContext } from '../../src/contexts/ConfigurationContext'; -import DefaultInput from '../../src/components/DefaultInput'; - -describe('Question', () => { - let question, onChange, options, inputComponent, componentsOptions; - - beforeEach(() => { - question = { - '@id': 'http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-1223764187-q', - '@type': 'doc:question', - 'http://onto.fel.cvut.cz/ontologies/documentation/has_answer': { - '@id': 'http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-636079211-a', - 'http://onto.fel.cvut.cz/ontologies/documentation/has_data_value': 'test' - }, - 'http://onto.fel.cvut.cz/ontologies/form/has-origin-type': - 'http://onto.fel.cvut.cz/ontologies/eccairs/aviation-3.4.0.2/a-453', - 'http://onto.fel.cvut.cz/ontologies/form/has-template-origin': - 'http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-1223764187', - 'http://onto.fel.cvut.cz/ontologies/form/has-template': - 'http://onto.fel.cvut.cz/ontologies/eccairs/aviation-3.4.0.2/a-453-qt', - 'http://www.w3.org/2000/01/rdf-schema#comment': { - '@language': 'en', - '@value': 'The identification of the entity or organisation that is responsible for the report.' - }, - 'http://www.w3.org/2000/01/rdf-schema#label': { - '@language': 'en', - '@value': '453 - Responsible entity' - } - }; - onChange = jest.fn(); - options = { - intl: { - locale: 'en' - }, - i18n: {} - }; - componentsOptions = { - readOnly: false, - dateTimeAnswer: { - dateFormat: 'yyyy-MM-dd', - timeFormat: 'HH:mm:ss', - dateTimeFormat: 'yyyy-MM-dd HH:mm:ss' - } - }; - inputComponent = DefaultInput; - }); - - it('renders section collapsed when layout class is set to collapsed', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION, Constants.LAYOUT.COLLAPSED]; - - const result = mount( - - - - ); - const card = result.find(Accordion); - const label = JsonLdUtils.getLocalized(question[JsonLdUtils.RDFS_LABEL], options.intl); - - expect(card.prop('defaultActiveKey')).toBe(label); - }); - - it('renders section by default expanded', () => { - question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION]; - - const result = mount( - - - - ); - const card = result.find(Card); - - expect(card.prop('defaultActiveKey')).toBe(undefined); - }); -}); diff --git a/test/__tests__/QuestionAnswerProcessor.test.js b/test/__tests__/QuestionAnswerProcessor.test.js deleted file mode 100644 index b6a89c5b..00000000 --- a/test/__tests__/QuestionAnswerProcessor.test.js +++ /dev/null @@ -1,156 +0,0 @@ -import JsonLdUtils from 'jsonld-utils'; - -import Constants from '../../src/constants/Constants'; -import * as Generator from '../environment/Generator'; -import QuestionAnswerProcessor from '../../src/model/QuestionAnswerProcessor'; - -describe('Question answer processor', () => { - it('transforms answers for a question', () => { - const question = {}; - generateAnswers(question); - const result = QuestionAnswerProcessor.processQuestionAnswerHierarchy(question); - verifyAnswers(question, result); - }); - - function generateAnswers(question) { - question[Constants.HAS_ANSWER] = []; - for (let i = 0; i < Generator.getRandomPositiveInt(1, 5); i++) { - const codeValue = Generator.getRandomBoolean(); - const answer = {}; - answer['@id'] = Generator.getRandomUri(); - answer[Constants.HAS_ANSWER_ORIGIN] = Generator.getRandomUri(); - if (codeValue) { - answer[Constants.HAS_OBJECT_VALUE] = { - '@id': Generator.getRandomUri() - }; - } else { - answer[Constants.HAS_DATA_VALUE] = { - '@value': i - }; - } - question[Constants.HAS_ANSWER].push(answer); - } - } - - function verifyAnswers(expectedQuestion, actualQuestion) { - if (!expectedQuestion[Constants.HAS_ANSWER]) { - return; - } - expect(actualQuestion.answers).toBeDefined(); - expect(actualQuestion.answers.length).toEqual(expectedQuestion[Constants.HAS_ANSWER].length); - - for (let i = 0; i < actualQuestion.answers.length; i++) { - expect(actualQuestion.answers[i].uri).toEqual(expectedQuestion[Constants.HAS_ANSWER][i]['@id']); - - if (expectedQuestion[Constants.HAS_ANSWER][i][Constants.HAS_DATA_VALUE]) { - expect(actualQuestion.answers[i].textValue).toEqual( - expectedQuestion[Constants.HAS_ANSWER][i][Constants.HAS_DATA_VALUE]['@value'] - ); - } else { - expect(actualQuestion.answers[i].codeValue).toEqual( - expectedQuestion[Constants.HAS_ANSWER][i][Constants.HAS_OBJECT_VALUE]['@id'] - ); - } - } - } - - it('transforms hierarchy of questions and answers', () => { - const question = generateQuestions(); - const result = QuestionAnswerProcessor.processQuestionAnswerHierarchy(question); - - verifyQuestions(question, result); - }); - - function generateQuestions() { - const question = {}; - question['@id'] = Generator.getRandomUri(); - question[Constants.RDFS_LABEL] = 'Test0'; - question[Constants.RDFS_COMMENT] = 'Test0 Comment'; - question[Constants.HAS_QUESTION_ORIGIN] = Generator.getRandomUri(); - question[Constants.HAS_SUBQUESTION] = []; - for (let i = 0; i < Generator.getRandomPositiveInt(1, 5); i++) { - question[Constants.HAS_SUBQUESTION].push(generateSubQuestions(0, 5)); - } - return question; - } - - function generateSubQuestions(depth, maxDepth) { - const question = {}; - question['@id'] = Generator.getRandomUri(); - question[Constants.HAS_QUESTION_ORIGIN] = Generator.getRandomUri(); - question[Constants.RDFS_LABEL] = 'Test' + Generator.getRandomInt(); - question[Constants.RDFS_COMMENT] = 'Test Comment'; - if (depth < maxDepth) { - question[Constants.HAS_SUBQUESTION] = []; - for (let i = 0; i < Generator.getRandomPositiveInt(1, 5); i++) { - question[Constants.HAS_SUBQUESTION].push(generateSubQuestions(depth + 1, maxDepth)); - } - } - generateAnswers(question); - return question; - } - - function verifyQuestions(expected, actual) { - expect(actual.uri).toEqual(expected['@id']); - verifyAnswers(expected, actual); - if (expected[Constants.HAS_SUBQUESTION]) { - expect(actual.subQuestions).toBeDefined(); - expect(actual.subQuestions.length).toEqual(expected[Constants.HAS_SUBQUESTION].length); - for (let i = 0; i < actual.subQuestions.length; i++) { - verifyQuestions(expected[Constants.HAS_SUBQUESTION][i], actual.subQuestions[i]); - } - } - } - - it('Stores origin of questions', () => { - const question = generateQuestions(); - const result = QuestionAnswerProcessor.processQuestionAnswerHierarchy(question); - - verifyPresenceOfQuestionOrigin(question, result); - }); - - function verifyPresenceOfQuestionOrigin(expected, actual) { - expect(actual.origin).toBeDefined(); - expect(actual.origin).toEqual(expected[Constants.HAS_QUESTION_ORIGIN]); - if (expected[Constants.HAS_SUBQUESTION]) { - for (let i = 0; i < actual.subQuestions.length; i++) { - verifyQuestions(expected[Constants.HAS_SUBQUESTION][i], actual.subQuestions[i]); - } - } - } - - it('Stores origin of answers', () => { - const question = {}; - generateAnswers(question); - const result = QuestionAnswerProcessor.processQuestionAnswerHierarchy(question); - verifyPresenceOfAnswerOrigin(question, result); - }); - - function verifyPresenceOfAnswerOrigin(actualQuestion, expectedQuestion) { - if (!expectedQuestion[Constants.HAS_ANSWER]) { - return; - } - expect(actualQuestion.answers).toBeDefined(); - expect(actualQuestion.answers.length).toEqual(expectedQuestion[Constants.HAS_ANSWER].length); - for (let i = 0; i < actualQuestion.answers.length; i++) { - expect(actualQuestion.answers[i].origin).toEqual( - expectedQuestion[Constants.HAS_ANSWER][i][Constants.HAS_ANSWER_ORIGIN] - ); - } - } - - it('builds QAM from the specified questions and answers, including form root', () => { - const data = { - root: {} - }; - const questions = [generateQuestions()]; - data.root['@id'] = Generator.getRandomUri(); - data.root[Constants.HAS_QUESTION_ORIGIN] = Generator.getRandomUri(); - - const result = QuestionAnswerProcessor.buildQuestionAnswerModel(data, questions); - expect(result.uri).toEqual(data.root['@id']); - expect(result.origin).toEqual(data.root[Constants.HAS_QUESTION_ORIGIN]); - expect(result.subQuestions.length).toEqual(1); - verifyQuestions(questions[0], result.subQuestions[0]); - }); -}); diff --git a/test/__tests__/TypeaheadAnswer.test.js b/test/__tests__/TypeaheadAnswer.test.js deleted file mode 100644 index 989aabcd..00000000 --- a/test/__tests__/TypeaheadAnswer.test.js +++ /dev/null @@ -1,89 +0,0 @@ -import React from 'react'; -import JsonLdUtils from 'jsonld-utils'; -import Select from 'react-select'; - -import * as Generator from '../environment/Generator'; -import Constants from '../../src/constants/Constants'; -import TypeaheadAnswer from '../../src/components/answer/TypeaheadAnswer'; -import { FormGenContext } from '../../src/contexts/FormGenContext'; -import { ConfigurationContext } from '../../src/contexts/ConfigurationContext'; -import DefaultInput from '../../src/components/DefaultInput'; - -describe('TypeaheadAnswer', () => { - let question; - let onChange; - let loadFormOptions; - let getOptions; - - beforeEach(() => { - question = { - '@id': Generator.getRandomUri() - }; - question[Constants.LAYOUT_CLASS] = []; - question[Constants.RDFS_LABEL] = { - '@language': 'en', - '@value': '1 - Aerodrome General' - }; - question[Constants.RDFS_COMMENT] = { - '@language': 'en', - '@value': 'The identification of the aerodrome/helicopter landing area by name, location and status.' - }; - onChange = jest.fn(); - loadFormOptions = jest.fn(); - getOptions = jest.fn(() => [ - { - id: '123', - name: '123' - } - ]); - }); - - it('orders options using partial ordering with alphabetical ordering', () => { - // create options - const options = createOptionsWithPartialOrder(['3', '2', '1', 'before2'], ['before2<2']); - const query = 'SELECT * WHERE { ?x ?y ?z .}'; - - question[Constants.LAYOUT_CLASS].push(Constants.LAYOUT.QUESTION_TYPEAHEAD); - question[Constants.HAS_OPTIONS_QUERY] = query; - - const component = mount( - - - - - - ); - - waitForComponentToPaint(component); - - const select = component.find(TypeaheadAnswer).find(Select); - expect(select).not.toBeNull(); - expect(select.prop('options').map((i) => i['id'])).toEqual(['1', 'before2', '2', '3']); - }); - - function createOptionsWithPartialOrder(ids, orderingRules) { - let options = ids.map((i) => { - let obj = { '@id': i }; - obj[JsonLdUtils.RDFS_LABEL] = i + '. value'; - return obj; - }); - orderingRules.forEach((rule) => { - const firstId = rule.substring(0, rule.indexOf('<')); - const secondId = rule.substring(rule.indexOf('<') + 1); - const secondIndex = ids.indexOf(secondId); - - options[secondIndex][Constants.HAS_PRECEDING_VALUE] = firstId; - }); - return options; - } -});