@kbss-cvut/s-forms 0.4.1 → 0.4.2-alpha-f760ea7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/s-forms.min.css +1 -0
- package/dist/s-forms.cjs.map +1 -1
- package/dist/s-forms.js.map +1 -1
- package/dist/s-forms.modern.js.map +1 -1
- package/dist/s-forms.umd.js.map +1 -1
- package/package.json +20 -10
- package/{dist → types}/components/Answer.d.ts +0 -0
- package/{dist → types}/components/DefaultInput.d.ts +0 -0
- package/{dist → types}/components/FormManager.d.ts +0 -0
- package/{dist → types}/components/FormWindow.d.ts +0 -0
- package/{dist → types}/components/HelpIcon.d.ts +0 -0
- package/{dist → types}/components/IconOverlay.d.ts +0 -0
- package/{dist → types}/components/LinkIcon.d.ts +0 -0
- package/{dist → types}/components/MaskedInput.d.ts +0 -0
- package/{dist → types}/components/MediaContent.d.ts +0 -0
- package/{dist → types}/components/PrefixIcon.d.ts +0 -0
- package/{dist → types}/components/Question.d.ts +0 -0
- package/{dist → types}/components/QuestionStatic.d.ts +0 -0
- package/{dist → types}/components/SForms.d.ts +0 -0
- package/{dist → types}/components/answer/CheckboxAnswer.d.ts +0 -0
- package/{dist → types}/components/answer/DateTimeAnswer.d.ts +0 -0
- package/{dist → types}/components/answer/InputAnswer.d.ts +0 -0
- package/{dist → types}/components/answer/MaskedInputAnswer.d.ts +0 -0
- package/{dist → types}/components/answer/OptimizedMenuList.d.ts +0 -0
- package/{dist → types}/components/answer/SelectAnswer.d.ts +0 -0
- package/{dist → types}/components/answer/TypeaheadAnswer.d.ts +0 -0
- package/{dist → types}/components/comment/CommentForm.d.ts +0 -0
- package/{dist → types}/components/comment/CommentList.d.ts +0 -0
- package/{dist → types}/components/comment/CommentView.d.ts +0 -0
- package/{dist → types}/components/comment/QuestionCommentIcon.d.ts +0 -0
- package/{dist → types}/components/wizard/HorizontalWizardNav.d.ts +0 -0
- package/{dist → types}/components/wizard/VerticalWizardNav.d.ts +0 -0
- package/{dist → types}/components/wizard/Wizard.d.ts +0 -0
- package/{dist → types}/components/wizard/WizardStep.d.ts +0 -0
- package/{dist → types}/constants/Constants.d.ts +0 -0
- package/{dist → types}/contexts/ConfigurationContext.d.ts +0 -0
- package/{dist → types}/contexts/FormGenContext.d.ts +0 -0
- package/{dist → types}/contexts/FormQuestionsContext.d.ts +0 -0
- package/{dist → types}/contexts/IntlContextProvider.d.ts +2 -2
- package/{dist → types}/model/DefaultFormGenerator.d.ts +0 -0
- package/{dist → types}/model/FormGenerator.d.ts +0 -0
- package/{dist → types}/model/QuestionAnswerProcessor.d.ts +0 -0
- package/{dist → types}/model/ValidatorFactory.d.ts +0 -0
- package/types/s-forms.d.ts +16 -216
- package/{dist → types}/stories/Answer.stories.d.ts +0 -0
- package/{dist → types}/stories/CommentForm.stories.d.ts +0 -0
- package/{dist → types}/stories/HelpIcon.stories.d.ts +0 -0
- package/{dist → types}/stories/LinkIcon.stories.d.ts +0 -0
- package/{dist → types}/stories/MediaContent.stories.d.ts +0 -0
- package/{dist → types}/stories/PrefixIcon.stories.d.ts +0 -0
- package/{dist → types}/stories/Question.stories.d.ts +0 -0
- package/{dist → types}/stories/QuestionCommentIcon.stories.d.ts +0 -0
- package/{dist → types}/stories/SForms.stories.d.ts +0 -0
- package/{dist → types}/styles/icons/ArrowRight.d.ts +0 -0
- package/{dist → types}/styles/icons/CaretSquareDown.d.ts +0 -0
- package/{dist → types}/styles/icons/CaretSquareUp.d.ts +0 -0
- package/{dist → types}/styles/icons/Close.d.ts +0 -0
- package/{dist → types}/styles/icons/CommentBubble.d.ts +0 -0
- package/{dist → types}/styles/icons/ExternalLink.d.ts +0 -0
- package/{dist → types}/styles/icons/InfoCircle.d.ts +0 -0
- package/{dist → types}/styles/icons/QuestionCircle.d.ts +0 -0
- package/{dist → types}/styles/icons/RecycleBin.d.ts +0 -0
- package/{dist → types}/styles/icons/index.d.ts +0 -0
- package/{dist → types}/util/FormUtils.d.ts +0 -0
- package/{dist → types}/util/JsonLdFramingUtils.d.ts +0 -0
- package/{dist → types}/util/JsonLdObjectMap.d.ts +0 -0
- package/{dist → types}/util/JsonLdObjectUtils.d.ts +0 -0
- package/{dist → types}/util/Logger.d.ts +0 -0
- package/{dist → types}/util/MaskMapper.d.ts +0 -0
- package/{dist → types}/util/Utils.d.ts +0 -0
- package/.babelrc +0 -22
- package/.github/workflows/check-format.yml +0 -21
- package/.github/workflows/chromatic.yml +0 -24
- package/.husky/pre-commit +0 -4
- package/.prettierignore +0 -4
- package/.storybook/main.cjs +0 -11
- package/.storybook/preview.js +0 -103
- package/dist/s-forms.css +0 -2
- package/dist/s-forms.css.map +0 -1
- package/dist/s-forms.d.ts +0 -16
- package/jest.config.cjs +0 -20
- package/test/__mocks__/styleMock.js +0 -1
- package/test/__tests__/Answer.test.js +0 -399
- package/test/__tests__/DefaultFormGenerator.test.js +0 -34
- package/test/__tests__/FormUtils.test.js +0 -297
- package/test/__tests__/InputAnswer.test.js +0 -193
- package/test/__tests__/JsonLdFramingUtils.test.js +0 -29
- package/test/__tests__/JsonLdObjectUtils.test.js +0 -86
- package/test/__tests__/MaskMapper.test.js +0 -32
- package/test/__tests__/MaskedInputAnswer.test.js +0 -90
- package/test/__tests__/Question.test.js +0 -102
- package/test/__tests__/QuestionAnswerProcessor.test.js +0 -183
- package/test/__tests__/QuestionCommentIcon.test.js +0 -77
- package/test/__tests__/TypeheadAnswer.test.js +0 -102
- package/test/environment/Generator.js +0 -44
- package/test/setup.js +0 -19
- package/tsconfig.json +0 -20
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import FormUtils from "../../src/util/FormUtils";
|
|
2
|
-
import Constants from "../../src/constants/Constants";
|
|
3
|
-
import JsonObjectMap from "../../src/util/JsonLdObjectMap";
|
|
4
|
-
|
|
5
|
-
describe("FormUtils", () => {
|
|
6
|
-
let question;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
question = {};
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
describe("isForm", () => {
|
|
13
|
-
it("returns true for a form element.", () => {
|
|
14
|
-
const form = {
|
|
15
|
-
"@type": Constants.FORM,
|
|
16
|
-
hasQuestion: [{}, {}],
|
|
17
|
-
};
|
|
18
|
-
form[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.FORM];
|
|
19
|
-
expect(FormUtils.isForm(form)).toBeTruthy();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("returns false for non-form element.", () => {
|
|
23
|
-
const question = {};
|
|
24
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION];
|
|
25
|
-
expect(FormUtils.isForm(question)).toBeFalsy();
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
describe("isWizardStep", () => {
|
|
30
|
-
it("returns true for a wizard step question", () => {
|
|
31
|
-
question[Constants.LAYOUT_CLASS] = [
|
|
32
|
-
Constants.LAYOUT.QUESTION_SECTION,
|
|
33
|
-
Constants.LAYOUT.WIZARD_STEP,
|
|
34
|
-
];
|
|
35
|
-
expect(FormUtils.isWizardStep(question)).toBeTruthy();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("returns false for a section", () => {
|
|
39
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION];
|
|
40
|
-
expect(FormUtils.isWizardStep(question)).toBeFalsy();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe("isSection", () => {
|
|
45
|
-
it("returns true for a section.", () => {
|
|
46
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION];
|
|
47
|
-
expect(FormUtils.isSection(question)).toBeTruthy();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("returns false for a regular question.", () => {
|
|
51
|
-
expect(FormUtils.isSection({})).toBeFalsy();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("isTypeahead", () => {
|
|
56
|
-
it("returns true for a typeahead question.", () => {
|
|
57
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_TYPEAHEAD];
|
|
58
|
-
expect(FormUtils.isTypeahead(question)).toBeTruthy();
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it("returns false for a regular question.", () => {
|
|
62
|
-
expect(FormUtils.isTypeahead({})).toBeFalsy();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe("isTextarea", () => {
|
|
67
|
-
it("returns true for a data value longer than the input length threshold", () => {
|
|
68
|
-
let dataValue = "";
|
|
69
|
-
for (let i = 0; i < Constants.INPUT_LENGTH_THRESHOLD + 1; i++) {
|
|
70
|
-
dataValue += i.toString();
|
|
71
|
-
}
|
|
72
|
-
expect(FormUtils.isTextarea(question, dataValue)).toBeTruthy();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("returns false for a typeahead result with long value", () => {
|
|
76
|
-
let dataValue = "";
|
|
77
|
-
for (let i = 0; i < Constants.INPUT_LENGTH_THRESHOLD + 1; i++) {
|
|
78
|
-
dataValue += i.toString();
|
|
79
|
-
}
|
|
80
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_TYPEAHEAD];
|
|
81
|
-
expect(FormUtils.isTextarea(question, dataValue)).toBeFalsy();
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe("isDisabled", () => {
|
|
86
|
-
it("returns true for a disabled question.", () => {
|
|
87
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.DISABLED];
|
|
88
|
-
expect(FormUtils.isDisabled(question)).toBeTruthy();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("returns false for enabled question.", () => {
|
|
92
|
-
expect(FormUtils.isDisabled(question)).toBeFalsy();
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe("isHidden", () => {
|
|
97
|
-
it("returns true for a hidden question.", () => {
|
|
98
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.HIDDEN];
|
|
99
|
-
expect(FormUtils.isHidden(question)).toBeTruthy();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("returns false for a normal question", () => {
|
|
103
|
-
expect(FormUtils.isHidden({})).toBeFalsy();
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe("isCalendar", () => {
|
|
108
|
-
it("returns true for a date question", () => {
|
|
109
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.DATE];
|
|
110
|
-
expect(FormUtils.isCalendar(question)).toBeTruthy();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("returns false for a regular question", () => {
|
|
114
|
-
const question = {};
|
|
115
|
-
expect(FormUtils.isCalendar(question)).toBeFalsy();
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe("isDate", () => {
|
|
120
|
-
it("returns true for a date question", () => {
|
|
121
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.DATE];
|
|
122
|
-
expect(FormUtils.isCalendar(question)).toBeTruthy();
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("returns false for a regular question", () => {
|
|
126
|
-
expect(FormUtils.isCalendar(question)).toBeFalsy();
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe("isTime", () => {
|
|
131
|
-
it("returns true for a time question", () => {
|
|
132
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.TIME];
|
|
133
|
-
expect(FormUtils.isCalendar(question)).toBeTruthy();
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("returns false for a regular question", () => {
|
|
137
|
-
expect(FormUtils.isCalendar(question)).toBeFalsy();
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe("isDateTime", () => {
|
|
142
|
-
it("returns true for a datetime question", () => {
|
|
143
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.DATETIME];
|
|
144
|
-
expect(FormUtils.isCalendar(question)).toBeTruthy();
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("returns false for a regular question", () => {
|
|
148
|
-
expect(FormUtils.isCalendar(question)).toBeFalsy();
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe("isCheckbox", () => {
|
|
153
|
-
it("returns true for a checkbox question", () => {
|
|
154
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.CHECKBOX];
|
|
155
|
-
expect(FormUtils.isCheckbox(question)).toBeTruthy();
|
|
156
|
-
});
|
|
157
|
-
it("returns false for a non-checkbox question", () => {
|
|
158
|
-
question[Constants.LAYOUT_CLASS] = [];
|
|
159
|
-
expect(FormUtils.isCheckbox(question)).toBeFalsy();
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe("isAnswerable", () => {
|
|
164
|
-
it("returns true for an answerable section-question", () => {
|
|
165
|
-
question[Constants.LAYOUT_CLASS] = [
|
|
166
|
-
Constants.LAYOUT.QUESTION_SECTION,
|
|
167
|
-
Constants.LAYOUT.ANSWERABLE,
|
|
168
|
-
];
|
|
169
|
-
expect(FormUtils.isAnswerable(question)).toBeTruthy();
|
|
170
|
-
});
|
|
171
|
-
it("returns false for a non-answerable section-question", () => {
|
|
172
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION];
|
|
173
|
-
expect(FormUtils.isAnswerable(question)).toBeFalsy();
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
describe("isMaskedInput", () => {
|
|
178
|
-
it("returns true for a question with masked input layout class", () => {
|
|
179
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.MASKED_INPUT];
|
|
180
|
-
expect(FormUtils.isMaskedInput(question)).toBeTruthy();
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it("returns false for a non-masked question", () => {
|
|
184
|
-
expect(FormUtils.isMaskedInput(question)).toBeFalsy();
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
describe("resolveValue", () => {
|
|
189
|
-
it("returns null for no answer", () => {
|
|
190
|
-
expect(FormUtils.resolveValue(null)).toBeNull();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("returns identifier of code value answer", () => {
|
|
194
|
-
const id =
|
|
195
|
-
"http://onto.fel.cvut.cz/ontologies/eccairs/aviation-3.4.0.2/vl-a-431/v-100",
|
|
196
|
-
answer = {
|
|
197
|
-
"@id":
|
|
198
|
-
"http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-1495029633-a",
|
|
199
|
-
"@type": "http://onto.fel.cvut.cz/ontologies/documentation/answer",
|
|
200
|
-
"http://onto.fel.cvut.cz/ontologies/documentation/has_object_value": {
|
|
201
|
-
"@id": id,
|
|
202
|
-
},
|
|
203
|
-
};
|
|
204
|
-
expect(FormUtils.resolveValue(answer)).toEqual(id);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("returns value of data value answer", () => {
|
|
208
|
-
const value = "2016-06-21",
|
|
209
|
-
answer = {
|
|
210
|
-
"@id":
|
|
211
|
-
"http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-2018758124-a",
|
|
212
|
-
"@type": "http://onto.fel.cvut.cz/ontologies/documentation/answer",
|
|
213
|
-
"http://onto.fel.cvut.cz/ontologies/documentation/has_data_value": {
|
|
214
|
-
"@language": "en",
|
|
215
|
-
"@value": value,
|
|
216
|
-
},
|
|
217
|
-
};
|
|
218
|
-
expect(FormUtils.resolveValue(answer)).toEqual(value);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
describe("testCondition", () => {
|
|
223
|
-
const condition = {
|
|
224
|
-
"@type": ["http://onto.fel.cvut.cz/ontologies/form/condition"],
|
|
225
|
-
"http://onto.fel.cvut.cz/ontologies/form/accepts-answer-value": [
|
|
226
|
-
{
|
|
227
|
-
"@id":
|
|
228
|
-
"http://vfn.cz/ontologies/fss-form/follow-up-and-recurrence/current-status/dod",
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
"@id":
|
|
232
|
-
"http://vfn.cz/ontologies/fss-form/follow-up-and-recurrence/current-status/doc",
|
|
233
|
-
},
|
|
234
|
-
],
|
|
235
|
-
"http://onto.fel.cvut.cz/ontologies/form/has-tested-question": [
|
|
236
|
-
{
|
|
237
|
-
"@id":
|
|
238
|
-
"http://vfn.cz/ontologies/fss-form/follow-up-and-recurrence/current-status",
|
|
239
|
-
},
|
|
240
|
-
],
|
|
241
|
-
},
|
|
242
|
-
question = {
|
|
243
|
-
"@id":
|
|
244
|
-
"http://vfn.cz/ontologies/fss-form/follow-up-and-recurrence/current-status",
|
|
245
|
-
"@type": "http://onto.fel.cvut.cz/ontologies/documentation/question",
|
|
246
|
-
"http://onto.fel.cvut.cz/ontologies/documentation/has_answer": {
|
|
247
|
-
"@type": "http://onto.fel.cvut.cz/ontologies/documentation/answer",
|
|
248
|
-
"http://onto.fel.cvut.cz/ontologies/documentation/has_object_value": {
|
|
249
|
-
"@id":
|
|
250
|
-
"http://vfn.cz/ontologies/fss-form/follow-up-and-recurrence/current-status/dod",
|
|
251
|
-
},
|
|
252
|
-
},
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
beforeEach(function () {
|
|
256
|
-
jest.spyOn(JsonObjectMap, "getObject").mockReturnValue(question);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it("returns false in condition without answer values.", () => {
|
|
260
|
-
const noAnswerCondition = { ...condition };
|
|
261
|
-
delete noAnswerCondition[
|
|
262
|
-
"http://onto.fel.cvut.cz/ontologies/form/accepts-answer-value"
|
|
263
|
-
];
|
|
264
|
-
expect(FormUtils.testCondition(noAnswerCondition));
|
|
265
|
-
|
|
266
|
-
expect(JsonObjectMap.getObject).not.toHaveBeenCalled();
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it("return true if accepts value that exists in a question.", () => {
|
|
270
|
-
expect(FormUtils.testCondition(condition)).toEqual(true);
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it("return false if accepts value that does not exists in a question.", () => {
|
|
274
|
-
const wrongAnswerQuestion = { ...question };
|
|
275
|
-
wrongAnswerQuestion[
|
|
276
|
-
"http://onto.fel.cvut.cz/ontologies/documentation/has_answer"
|
|
277
|
-
]["http://onto.fel.cvut.cz/ontologies/documentation/has_object_value"] = {
|
|
278
|
-
"@id": "http://bad-value",
|
|
279
|
-
};
|
|
280
|
-
expect(FormUtils.testCondition(wrongAnswerQuestion)).toEqual(false);
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
describe("isCollapsed", () => {
|
|
285
|
-
it("returns true when question layout class contains collapsed", () => {
|
|
286
|
-
question[Constants.LAYOUT_CLASS] = [
|
|
287
|
-
Constants.LAYOUT.QUESTION_SECTION,
|
|
288
|
-
Constants.LAYOUT.COLLAPSED,
|
|
289
|
-
];
|
|
290
|
-
expect(FormUtils.isCollapsed(question)).toBeTruthy();
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it("returns false when question layout class does not contain collapsed", () => {
|
|
294
|
-
expect(FormUtils.isCollapsed(question)).toBeFalsy();
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
});
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import JsonLdUtils from "jsonld-utils";
|
|
3
|
-
|
|
4
|
-
import Answer from "../../src/components/Answer";
|
|
5
|
-
import Constants from "../../src/constants/Constants";
|
|
6
|
-
import * as Generator from "../environment/Generator";
|
|
7
|
-
import { ConfigurationContext } from "../../src/contexts/ConfigurationContext";
|
|
8
|
-
import DefaultInput from "../../src/components/DefaultInput";
|
|
9
|
-
|
|
10
|
-
const LABEL = "Input answer test";
|
|
11
|
-
|
|
12
|
-
describe("InputAnswer", () => {
|
|
13
|
-
let question, answer, onChange, options, componentsOptions, inputComponent;
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
question = {
|
|
17
|
-
"@id": Generator.getRandomUri(),
|
|
18
|
-
};
|
|
19
|
-
question[Constants.LAYOUT_CLASS] = [];
|
|
20
|
-
question[Constants.RDFS_LABEL] = {
|
|
21
|
-
"@language": "en",
|
|
22
|
-
"@value": LABEL,
|
|
23
|
-
};
|
|
24
|
-
question[Constants.RDFS_COMMENT] = {
|
|
25
|
-
"@language": "en",
|
|
26
|
-
"@value": "Javascript sucks!!!",
|
|
27
|
-
};
|
|
28
|
-
onChange = jest.fn();
|
|
29
|
-
options = {
|
|
30
|
-
intl: {
|
|
31
|
-
locale: "en",
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
componentsOptions = {
|
|
35
|
-
readOnly: false,
|
|
36
|
-
dateTimeAnswer: {
|
|
37
|
-
dateFormat: "yyyy-MM-dd",
|
|
38
|
-
timeFormat: "HH:mm:ss",
|
|
39
|
-
dateTimeFormat: "yyyy-MM-dd HH:mm:ss",
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
inputComponent = DefaultInput;
|
|
43
|
-
answer = {
|
|
44
|
-
id: Generator.getRandomUri(),
|
|
45
|
-
};
|
|
46
|
-
question[Constants.HAS_ANSWER] = [answer];
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("sets min on numeric input when xsd:minInclusive is used in question", () => {
|
|
50
|
-
const min = 100;
|
|
51
|
-
const value = 117;
|
|
52
|
-
question[Constants.HAS_DATATYPE] = Constants.XSD.INT;
|
|
53
|
-
question[Constants.XSD.MIN_INCLUSIVE] = min;
|
|
54
|
-
answer[Constants.HAS_DATA_VALUE] = value;
|
|
55
|
-
|
|
56
|
-
const component = mount(
|
|
57
|
-
<ConfigurationContext.Provider
|
|
58
|
-
value={{
|
|
59
|
-
componentsOptions,
|
|
60
|
-
inputComponent,
|
|
61
|
-
options,
|
|
62
|
-
}}
|
|
63
|
-
>
|
|
64
|
-
<Answer question={question} answer={answer} onChange={onChange} />
|
|
65
|
-
</ConfigurationContext.Provider>
|
|
66
|
-
);
|
|
67
|
-
const input = component.find("input");
|
|
68
|
-
|
|
69
|
-
expect(input.props().type).toEqual("number");
|
|
70
|
-
expect(input.props().min).toEqual(min);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("sets min on numeric input when xsd:minExclusive is used in question", () => {
|
|
74
|
-
const min = 100;
|
|
75
|
-
const value = 117;
|
|
76
|
-
question[Constants.HAS_DATATYPE] = Constants.XSD.INT;
|
|
77
|
-
question[Constants.XSD.MIN_EXCLUSIVE] = min;
|
|
78
|
-
answer[Constants.HAS_DATA_VALUE] = value;
|
|
79
|
-
|
|
80
|
-
const component = mount(
|
|
81
|
-
<ConfigurationContext.Provider
|
|
82
|
-
value={{
|
|
83
|
-
componentsOptions,
|
|
84
|
-
inputComponent,
|
|
85
|
-
options,
|
|
86
|
-
}}
|
|
87
|
-
>
|
|
88
|
-
<Answer question={question} answer={answer} onChange={onChange} />
|
|
89
|
-
</ConfigurationContext.Provider>
|
|
90
|
-
);
|
|
91
|
-
const input = component.find("input");
|
|
92
|
-
|
|
93
|
-
expect(input.props().type).toEqual("number");
|
|
94
|
-
expect(input.props().min).toEqual(min + 1);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("sets max on numeric input when xsd:maxExclusive is used in question", () => {
|
|
98
|
-
const max = 1000;
|
|
99
|
-
const value = 117;
|
|
100
|
-
question[Constants.HAS_DATATYPE] = Constants.XSD.INT;
|
|
101
|
-
question[Constants.XSD.MAX_EXCLUSIVE] = max;
|
|
102
|
-
answer[Constants.HAS_DATA_VALUE] = value;
|
|
103
|
-
|
|
104
|
-
const component = mount(
|
|
105
|
-
<ConfigurationContext.Provider
|
|
106
|
-
value={{
|
|
107
|
-
componentsOptions,
|
|
108
|
-
inputComponent,
|
|
109
|
-
options,
|
|
110
|
-
}}
|
|
111
|
-
>
|
|
112
|
-
<Answer question={question} answer={answer} onChange={onChange} />
|
|
113
|
-
</ConfigurationContext.Provider>
|
|
114
|
-
);
|
|
115
|
-
const input = component.find("input");
|
|
116
|
-
|
|
117
|
-
expect(input.props().type).toEqual("number");
|
|
118
|
-
expect(input.props().max).toEqual(max - 1);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("sets max on numeric input when xsd:maxInclusive is used in question", () => {
|
|
122
|
-
const max = 1000;
|
|
123
|
-
const value = 117;
|
|
124
|
-
question[Constants.HAS_DATATYPE] = Constants.XSD.INT;
|
|
125
|
-
question[Constants.XSD.MAX_INCLUSIVE] = max;
|
|
126
|
-
answer[Constants.HAS_DATA_VALUE] = value;
|
|
127
|
-
|
|
128
|
-
const component = mount(
|
|
129
|
-
<ConfigurationContext.Provider
|
|
130
|
-
value={{
|
|
131
|
-
componentsOptions,
|
|
132
|
-
inputComponent,
|
|
133
|
-
options,
|
|
134
|
-
}}
|
|
135
|
-
>
|
|
136
|
-
<Answer question={question} answer={answer} onChange={onChange} />
|
|
137
|
-
</ConfigurationContext.Provider>
|
|
138
|
-
);
|
|
139
|
-
const input = component.find("input");
|
|
140
|
-
|
|
141
|
-
expect(input.props().type).toEqual("number");
|
|
142
|
-
expect(input.props().max).toEqual(max);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it("sets both min and max on numeric input when both are used in question", () => {
|
|
146
|
-
const max = 1000;
|
|
147
|
-
const min = 100;
|
|
148
|
-
const value = 117;
|
|
149
|
-
question[Constants.HAS_DATATYPE] = Constants.XSD.INT;
|
|
150
|
-
question[Constants.XSD.MAX_INCLUSIVE] = max;
|
|
151
|
-
question[Constants.XSD.MIN_INCLUSIVE] = min;
|
|
152
|
-
answer[Constants.HAS_DATA_VALUE] = value;
|
|
153
|
-
|
|
154
|
-
const component = mount(
|
|
155
|
-
<ConfigurationContext.Provider
|
|
156
|
-
value={{
|
|
157
|
-
componentsOptions,
|
|
158
|
-
inputComponent,
|
|
159
|
-
options,
|
|
160
|
-
}}
|
|
161
|
-
>
|
|
162
|
-
<Answer question={question} answer={answer} onChange={onChange} />
|
|
163
|
-
</ConfigurationContext.Provider>
|
|
164
|
-
);
|
|
165
|
-
const input = component.find("input");
|
|
166
|
-
|
|
167
|
-
expect(input.props().type).toEqual("number");
|
|
168
|
-
expect(input.props().max).toEqual(max);
|
|
169
|
-
expect(input.props().min).toEqual(min);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("sets min when xsd:positiveInteger is used as question datatype", () => {
|
|
173
|
-
const value = 117;
|
|
174
|
-
question[Constants.HAS_DATATYPE] = Constants.XSD.POSITIVE_INTEGER;
|
|
175
|
-
answer[Constants.HAS_DATA_VALUE] = value;
|
|
176
|
-
|
|
177
|
-
const component = mount(
|
|
178
|
-
<ConfigurationContext.Provider
|
|
179
|
-
value={{
|
|
180
|
-
componentsOptions,
|
|
181
|
-
inputComponent,
|
|
182
|
-
options,
|
|
183
|
-
}}
|
|
184
|
-
>
|
|
185
|
-
<Answer question={question} answer={answer} onChange={onChange} />
|
|
186
|
-
</ConfigurationContext.Provider>
|
|
187
|
-
);
|
|
188
|
-
const input = component.find("input");
|
|
189
|
-
|
|
190
|
-
expect(input.props().type).toEqual("number");
|
|
191
|
-
expect(input.props().min).toEqual(1);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import JsonLdFramingUtils from "../../src/util/JsonLdFramingUtils";
|
|
3
|
-
|
|
4
|
-
describe("JsonLd framing utils", () => {
|
|
5
|
-
let formDocument;
|
|
6
|
-
let formQuestion;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
formQuestion = {
|
|
10
|
-
"@id":
|
|
11
|
-
"http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-1223764187-q",
|
|
12
|
-
"@type": "http://onto.fel.cvut.cz/ontologies/documentation/question",
|
|
13
|
-
"http://onto.fel.cvut.cz/ontologies/form-layout/has-layout-class": "form",
|
|
14
|
-
"http://www.w3.org/2000/01/rdf-schema#label": {
|
|
15
|
-
"@language": "en",
|
|
16
|
-
"@value": "453 - Responsible entity",
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
formDocument = {
|
|
20
|
-
"@graph": [formQuestion],
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("returns expanded jsonld object map from expandStructure", () => {
|
|
25
|
-
const id2objectMap = JsonLdFramingUtils.expandStructure(formDocument);
|
|
26
|
-
|
|
27
|
-
expect(id2objectMap[formQuestion["@id"]]).toBe(formQuestion);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import JsonLdObjectUtils from "../../src/util/JsonLdObjectUtils";
|
|
3
|
-
|
|
4
|
-
describe("JsonLd object utils", () => {
|
|
5
|
-
let trueValues, falseValues;
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
trueValues = [
|
|
9
|
-
true,
|
|
10
|
-
{ "@value": true },
|
|
11
|
-
{ "@value": "true" },
|
|
12
|
-
{ "@value": "true", "@language": "en" },
|
|
13
|
-
];
|
|
14
|
-
falseValues = [
|
|
15
|
-
false,
|
|
16
|
-
{ "@value": false },
|
|
17
|
-
{ "@value": "false" },
|
|
18
|
-
{ "@value": "false", "@language": "en" },
|
|
19
|
-
];
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("returns true for comparison of json-ld objects with same @id-s", () => {
|
|
23
|
-
const value1 = {
|
|
24
|
-
"@id": "http://vfn.cz/ontologies/study-model/answer-value-yes",
|
|
25
|
-
};
|
|
26
|
-
const value2 = {
|
|
27
|
-
"@id": "http://vfn.cz/ontologies/study-model/answer-value-yes",
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
expect(JsonLdObjectUtils.compareValues(value1, value2)).toBe(true);
|
|
31
|
-
expect(JsonLdObjectUtils.compareValues(value2, value1)).toBe(true);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("returns false for comparison of json-ld objects with different @id-s", () => {
|
|
35
|
-
const value1 = {
|
|
36
|
-
"@id": "http://vfn.cz/ontologies/study-model/answer-value-no",
|
|
37
|
-
};
|
|
38
|
-
const value2 = {
|
|
39
|
-
"@id": "http://vfn.cz/ontologies/study-model/answer-value-yes",
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
expect(JsonLdObjectUtils.compareValues(value1, value2)).toBe(false);
|
|
43
|
-
expect(JsonLdObjectUtils.compareValues(value2, value1)).toBe(false);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("returns true for comparison of same boolean values represented as string", () => {
|
|
47
|
-
for (let i = 0; i < trueValues.length; i++) {
|
|
48
|
-
for (let j = 0; j < trueValues.length; j++) {
|
|
49
|
-
expect(
|
|
50
|
-
JsonLdObjectUtils.compareValues(trueValues[i], trueValues[j])
|
|
51
|
-
).toBe(
|
|
52
|
-
true,
|
|
53
|
-
"when comparing " +
|
|
54
|
-
JSON.stringify(trueValues[i]) +
|
|
55
|
-
" with " +
|
|
56
|
-
JSON.stringify(trueValues[j])
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("returns false for comparison of different boolean values represented as string", () => {
|
|
63
|
-
for (let i = 0; i < trueValues.length; i++) {
|
|
64
|
-
for (let j = 0; j < falseValues.length; j++) {
|
|
65
|
-
expect(
|
|
66
|
-
JsonLdObjectUtils.compareValues(trueValues[i], falseValues[j])
|
|
67
|
-
).toBe(
|
|
68
|
-
false,
|
|
69
|
-
"when comparing " +
|
|
70
|
-
JSON.stringify(trueValues[i]) +
|
|
71
|
-
" with " +
|
|
72
|
-
JSON.stringify(falseValues[j])
|
|
73
|
-
);
|
|
74
|
-
expect(
|
|
75
|
-
JsonLdObjectUtils.compareValues(falseValues[j], trueValues[i])
|
|
76
|
-
).toBe(
|
|
77
|
-
false,
|
|
78
|
-
"when comparing " +
|
|
79
|
-
JSON.stringify(falseValues[j]) +
|
|
80
|
-
" with " +
|
|
81
|
-
JSON.stringify(trueValues[i])
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import MaskMapper from "../../src/util/MaskMapper";
|
|
2
|
-
|
|
3
|
-
describe("MaskMapper", () => {
|
|
4
|
-
it("maps date/time/datetime masks to numeric input mask", () => {
|
|
5
|
-
const data = [
|
|
6
|
-
{
|
|
7
|
-
mask: "DD-MM-YYYY",
|
|
8
|
-
expected: "11-11-1111",
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
mask: "hh:mm:ss",
|
|
12
|
-
expected: "11:11:11",
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
mask: "DD/MM/YYYY hh:mm:ss",
|
|
16
|
-
expected: "11/11/1111 11:11:11",
|
|
17
|
-
},
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
data.forEach((d) => {
|
|
21
|
-
expect(MaskMapper.mapMask(d.mask)).toEqual(d.expected);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("returns null form null value passed in", () => {
|
|
26
|
-
expect(MaskMapper.mapMask(null)).toBeNull();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("returns undefined for undefined passed in", () => {
|
|
30
|
-
expect(MaskMapper.mapMask(undefined)).not.toBeDefined();
|
|
31
|
-
});
|
|
32
|
-
});
|