@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,90 +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
|
-
describe("MaskedInputAnswer", () => {
|
|
11
|
-
let question, onChange, options, inputComponent, componentsOptions;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
question = {};
|
|
15
|
-
onChange = jest.fn();
|
|
16
|
-
options = {
|
|
17
|
-
intl: {
|
|
18
|
-
locale: "en",
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
componentsOptions = {
|
|
22
|
-
readOnly: false,
|
|
23
|
-
dateTimeAnswer: {
|
|
24
|
-
dateFormat: "yyyy-MM-dd",
|
|
25
|
-
timeFormat: "HH:mm:ss",
|
|
26
|
-
dateTimeFormat: "yyyy-MM-dd HH:mm:ss",
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
inputComponent = DefaultInput;
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("renders a regular input when question contains no mask", () => {
|
|
33
|
-
const value = "08/2016";
|
|
34
|
-
const answer = {
|
|
35
|
-
"@id": Generator.getRandomUri(),
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
answer[Constants.HAS_DATA_VALUE] = value;
|
|
39
|
-
question[Constants.HAS_ANSWER] = [answer];
|
|
40
|
-
question[JsonLdUtils.RDFS_LABEL] = "Test";
|
|
41
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.MASKED_INPUT];
|
|
42
|
-
|
|
43
|
-
const component = mount(
|
|
44
|
-
<ConfigurationContext.Provider
|
|
45
|
-
value={{
|
|
46
|
-
componentsOptions,
|
|
47
|
-
inputComponent,
|
|
48
|
-
options,
|
|
49
|
-
}}
|
|
50
|
-
>
|
|
51
|
-
<Answer answer={answer} question={question} onChange={onChange} />
|
|
52
|
-
</ConfigurationContext.Provider>
|
|
53
|
-
);
|
|
54
|
-
const input = component.find("input");
|
|
55
|
-
|
|
56
|
-
expect(input.props().value).toEqual(value);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("render disabled masked input with value when disabled layout class is specified", () => {
|
|
60
|
-
const value = "08/2016";
|
|
61
|
-
const mask = "11/1111";
|
|
62
|
-
const answer = {
|
|
63
|
-
"@id": Generator.getRandomUri(),
|
|
64
|
-
};
|
|
65
|
-
answer[Constants.HAS_DATA_VALUE] = value;
|
|
66
|
-
question[Constants.HAS_ANSWER] = [answer];
|
|
67
|
-
question[JsonLdUtils.RDFS_LABEL] = "Test";
|
|
68
|
-
question[Constants.INPUT_MASK] = mask;
|
|
69
|
-
question[Constants.LAYOUT_CLASS] = [
|
|
70
|
-
Constants.LAYOUT.MASKED_INPUT,
|
|
71
|
-
Constants.LAYOUT.DISABLED,
|
|
72
|
-
];
|
|
73
|
-
|
|
74
|
-
const component = mount(
|
|
75
|
-
<ConfigurationContext.Provider
|
|
76
|
-
value={{
|
|
77
|
-
componentsOptions,
|
|
78
|
-
inputComponent,
|
|
79
|
-
options,
|
|
80
|
-
}}
|
|
81
|
-
>
|
|
82
|
-
<Answer answer={answer} question={question} onChange={onChange} />
|
|
83
|
-
</ConfigurationContext.Provider>
|
|
84
|
-
);
|
|
85
|
-
const input = component.find("input");
|
|
86
|
-
|
|
87
|
-
expect(input.props().value).toEqual(value);
|
|
88
|
-
expect(input.props().disabled).toBeTruthy();
|
|
89
|
-
});
|
|
90
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Card, Accordion } from "react-bootstrap";
|
|
3
|
-
import JsonLdUtils from "jsonld-utils";
|
|
4
|
-
|
|
5
|
-
import Constants from "../../src/constants/Constants";
|
|
6
|
-
import Question from "../../src/components/Question";
|
|
7
|
-
import { ConfigurationContext } from "../../src/contexts/ConfigurationContext";
|
|
8
|
-
import DefaultInput from "../../src/components/DefaultInput";
|
|
9
|
-
|
|
10
|
-
describe("Question", () => {
|
|
11
|
-
let question, onChange, options, inputComponent, componentsOptions;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
question = {
|
|
15
|
-
"@id":
|
|
16
|
-
"http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-1223764187-q",
|
|
17
|
-
"@type": "doc:question",
|
|
18
|
-
"http://onto.fel.cvut.cz/ontologies/documentation/has_answer": {
|
|
19
|
-
"@id":
|
|
20
|
-
"http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-636079211-a",
|
|
21
|
-
"http://onto.fel.cvut.cz/ontologies/documentation/has_data_value":
|
|
22
|
-
"test",
|
|
23
|
-
},
|
|
24
|
-
"http://onto.fel.cvut.cz/ontologies/form/has-origin-type":
|
|
25
|
-
"http://onto.fel.cvut.cz/ontologies/eccairs/aviation-3.4.0.2/a-453",
|
|
26
|
-
"http://onto.fel.cvut.cz/ontologies/form/has-template-origin":
|
|
27
|
-
"http://onto.fel.cvut.cz/ontologies/eccairs/model/instance#instance-1223764187",
|
|
28
|
-
"http://onto.fel.cvut.cz/ontologies/form/has-template":
|
|
29
|
-
"http://onto.fel.cvut.cz/ontologies/eccairs/aviation-3.4.0.2/a-453-qt",
|
|
30
|
-
"http://www.w3.org/2000/01/rdf-schema#comment": {
|
|
31
|
-
"@language": "en",
|
|
32
|
-
"@value":
|
|
33
|
-
"The identification of the entity or organisation that is responsible for the report.",
|
|
34
|
-
},
|
|
35
|
-
"http://www.w3.org/2000/01/rdf-schema#label": {
|
|
36
|
-
"@language": "en",
|
|
37
|
-
"@value": "453 - Responsible entity",
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
onChange = jest.fn();
|
|
41
|
-
options = {
|
|
42
|
-
intl: {
|
|
43
|
-
locale: "en",
|
|
44
|
-
},
|
|
45
|
-
i18n: {},
|
|
46
|
-
};
|
|
47
|
-
componentsOptions = {
|
|
48
|
-
readOnly: false,
|
|
49
|
-
dateTimeAnswer: {
|
|
50
|
-
dateFormat: "yyyy-MM-dd",
|
|
51
|
-
timeFormat: "HH:mm:ss",
|
|
52
|
-
dateTimeFormat: "yyyy-MM-dd HH:mm:ss",
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
inputComponent = DefaultInput;
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("renders section collapsed when layout class is set to collapsed", () => {
|
|
59
|
-
question[Constants.LAYOUT_CLASS] = [
|
|
60
|
-
Constants.LAYOUT.QUESTION_SECTION,
|
|
61
|
-
Constants.LAYOUT.COLLAPSED,
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
const result = mount(
|
|
65
|
-
<ConfigurationContext.Provider
|
|
66
|
-
value={{
|
|
67
|
-
componentsOptions,
|
|
68
|
-
inputComponent,
|
|
69
|
-
options,
|
|
70
|
-
}}
|
|
71
|
-
>
|
|
72
|
-
<Question question={question} onChange={onChange} />
|
|
73
|
-
</ConfigurationContext.Provider>
|
|
74
|
-
);
|
|
75
|
-
const card = result.find(Accordion);
|
|
76
|
-
const label = JsonLdUtils.getLocalized(
|
|
77
|
-
question[JsonLdUtils.RDFS_LABEL],
|
|
78
|
-
options.intl
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
expect(card.prop("defaultActiveKey")).toBe(label);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("renders section by default expanded", () => {
|
|
85
|
-
question[Constants.LAYOUT_CLASS] = [Constants.LAYOUT.QUESTION_SECTION];
|
|
86
|
-
|
|
87
|
-
const result = mount(
|
|
88
|
-
<ConfigurationContext.Provider
|
|
89
|
-
value={{
|
|
90
|
-
componentsOptions,
|
|
91
|
-
inputComponent,
|
|
92
|
-
options,
|
|
93
|
-
}}
|
|
94
|
-
>
|
|
95
|
-
<Question question={question} onChange={onChange} />
|
|
96
|
-
</ConfigurationContext.Provider>
|
|
97
|
-
);
|
|
98
|
-
const card = result.find(Card);
|
|
99
|
-
|
|
100
|
-
expect(card.prop("defaultActiveKey")).toBe(undefined);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import JsonLdUtils from "jsonld-utils";
|
|
2
|
-
|
|
3
|
-
import Constants from "../../src/constants/Constants";
|
|
4
|
-
import * as Generator from "../environment/Generator";
|
|
5
|
-
import QuestionAnswerProcessor from "../../src/model/QuestionAnswerProcessor";
|
|
6
|
-
|
|
7
|
-
describe("Question answer processor", () => {
|
|
8
|
-
it("transforms answers for a question", () => {
|
|
9
|
-
const question = {};
|
|
10
|
-
generateAnswers(question);
|
|
11
|
-
const result =
|
|
12
|
-
QuestionAnswerProcessor.processQuestionAnswerHierarchy(question);
|
|
13
|
-
verifyAnswers(question, result);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
function generateAnswers(question) {
|
|
17
|
-
question[Constants.HAS_ANSWER] = [];
|
|
18
|
-
for (let i = 0; i < Generator.getRandomPositiveInt(1, 5); i++) {
|
|
19
|
-
const codeValue = Generator.getRandomBoolean();
|
|
20
|
-
const answer = {};
|
|
21
|
-
answer["@id"] = Generator.getRandomUri();
|
|
22
|
-
answer[Constants.HAS_ANSWER_ORIGIN] = Generator.getRandomUri();
|
|
23
|
-
if (codeValue) {
|
|
24
|
-
answer[Constants.HAS_OBJECT_VALUE] = {
|
|
25
|
-
"@id": Generator.getRandomUri(),
|
|
26
|
-
};
|
|
27
|
-
} else {
|
|
28
|
-
answer[Constants.HAS_DATA_VALUE] = {
|
|
29
|
-
"@value": i,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
question[Constants.HAS_ANSWER].push(answer);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function verifyAnswers(expectedQuestion, actualQuestion) {
|
|
37
|
-
if (!expectedQuestion[Constants.HAS_ANSWER]) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
expect(actualQuestion.answers).toBeDefined();
|
|
41
|
-
expect(actualQuestion.answers.length).toEqual(
|
|
42
|
-
expectedQuestion[Constants.HAS_ANSWER].length
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
for (let i = 0; i < actualQuestion.answers.length; i++) {
|
|
46
|
-
expect(actualQuestion.answers[i].uri).toEqual(
|
|
47
|
-
expectedQuestion[Constants.HAS_ANSWER][i]["@id"]
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
if (expectedQuestion[Constants.HAS_ANSWER][i][Constants.HAS_DATA_VALUE]) {
|
|
51
|
-
expect(actualQuestion.answers[i].textValue).toEqual(
|
|
52
|
-
expectedQuestion[Constants.HAS_ANSWER][i][Constants.HAS_DATA_VALUE][
|
|
53
|
-
"@value"
|
|
54
|
-
]
|
|
55
|
-
);
|
|
56
|
-
} else {
|
|
57
|
-
expect(actualQuestion.answers[i].codeValue).toEqual(
|
|
58
|
-
expectedQuestion[Constants.HAS_ANSWER][i][Constants.HAS_OBJECT_VALUE][
|
|
59
|
-
"@id"
|
|
60
|
-
]
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
it("transforms hierarchy of questions and answers", () => {
|
|
67
|
-
const question = generateQuestions();
|
|
68
|
-
const result =
|
|
69
|
-
QuestionAnswerProcessor.processQuestionAnswerHierarchy(question);
|
|
70
|
-
|
|
71
|
-
verifyQuestions(question, result);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
function generateQuestions() {
|
|
75
|
-
const question = {};
|
|
76
|
-
question["@id"] = Generator.getRandomUri();
|
|
77
|
-
question[Constants.RDFS_LABEL] = "Test0";
|
|
78
|
-
question[Constants.RDFS_COMMENT] = "Test0 Comment";
|
|
79
|
-
question[Constants.HAS_QUESTION_ORIGIN] = Generator.getRandomUri();
|
|
80
|
-
question[Constants.HAS_SUBQUESTION] = [];
|
|
81
|
-
for (let i = 0; i < Generator.getRandomPositiveInt(1, 5); i++) {
|
|
82
|
-
question[Constants.HAS_SUBQUESTION].push(generateSubQuestions(0, 5));
|
|
83
|
-
}
|
|
84
|
-
return question;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function generateSubQuestions(depth, maxDepth) {
|
|
88
|
-
const question = {};
|
|
89
|
-
question["@id"] = Generator.getRandomUri();
|
|
90
|
-
question[Constants.HAS_QUESTION_ORIGIN] = Generator.getRandomUri();
|
|
91
|
-
question[Constants.RDFS_LABEL] = "Test" + Generator.getRandomInt();
|
|
92
|
-
question[Constants.RDFS_COMMENT] = "Test Comment";
|
|
93
|
-
if (depth < maxDepth) {
|
|
94
|
-
question[Constants.HAS_SUBQUESTION] = [];
|
|
95
|
-
for (let i = 0; i < Generator.getRandomPositiveInt(1, 5); i++) {
|
|
96
|
-
question[Constants.HAS_SUBQUESTION].push(
|
|
97
|
-
generateSubQuestions(depth + 1, maxDepth)
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
generateAnswers(question);
|
|
102
|
-
return question;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function verifyQuestions(expected, actual) {
|
|
106
|
-
expect(actual.uri).toEqual(expected["@id"]);
|
|
107
|
-
verifyAnswers(expected, actual);
|
|
108
|
-
if (expected[Constants.HAS_SUBQUESTION]) {
|
|
109
|
-
expect(actual.subQuestions).toBeDefined();
|
|
110
|
-
expect(actual.subQuestions.length).toEqual(
|
|
111
|
-
expected[Constants.HAS_SUBQUESTION].length
|
|
112
|
-
);
|
|
113
|
-
for (let i = 0; i < actual.subQuestions.length; i++) {
|
|
114
|
-
verifyQuestions(
|
|
115
|
-
expected[Constants.HAS_SUBQUESTION][i],
|
|
116
|
-
actual.subQuestions[i]
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
it("Stores origin of questions", () => {
|
|
123
|
-
const question = generateQuestions();
|
|
124
|
-
const result =
|
|
125
|
-
QuestionAnswerProcessor.processQuestionAnswerHierarchy(question);
|
|
126
|
-
|
|
127
|
-
verifyPresenceOfQuestionOrigin(question, result);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
function verifyPresenceOfQuestionOrigin(expected, actual) {
|
|
131
|
-
expect(actual.origin).toBeDefined();
|
|
132
|
-
expect(actual.origin).toEqual(expected[Constants.HAS_QUESTION_ORIGIN]);
|
|
133
|
-
if (expected[Constants.HAS_SUBQUESTION]) {
|
|
134
|
-
for (let i = 0; i < actual.subQuestions.length; i++) {
|
|
135
|
-
verifyQuestions(
|
|
136
|
-
expected[Constants.HAS_SUBQUESTION][i],
|
|
137
|
-
actual.subQuestions[i]
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
it("Stores origin of answers", () => {
|
|
144
|
-
const question = {};
|
|
145
|
-
generateAnswers(question);
|
|
146
|
-
const result =
|
|
147
|
-
QuestionAnswerProcessor.processQuestionAnswerHierarchy(question);
|
|
148
|
-
verifyPresenceOfAnswerOrigin(question, result);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
function verifyPresenceOfAnswerOrigin(actualQuestion, expectedQuestion) {
|
|
152
|
-
if (!expectedQuestion[Constants.HAS_ANSWER]) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
expect(actualQuestion.answers).toBeDefined();
|
|
156
|
-
expect(actualQuestion.answers.length).toEqual(
|
|
157
|
-
expectedQuestion[Constants.HAS_ANSWER].length
|
|
158
|
-
);
|
|
159
|
-
for (let i = 0; i < actualQuestion.answers.length; i++) {
|
|
160
|
-
expect(actualQuestion.answers[i].origin).toEqual(
|
|
161
|
-
expectedQuestion[Constants.HAS_ANSWER][i][Constants.HAS_ANSWER_ORIGIN]
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
it("builds QAM from the specified questions and answers, including form root", () => {
|
|
167
|
-
const data = {
|
|
168
|
-
root: {},
|
|
169
|
-
};
|
|
170
|
-
const questions = [generateQuestions()];
|
|
171
|
-
data.root["@id"] = Generator.getRandomUri();
|
|
172
|
-
data.root[Constants.HAS_QUESTION_ORIGIN] = Generator.getRandomUri();
|
|
173
|
-
|
|
174
|
-
const result = QuestionAnswerProcessor.buildQuestionAnswerModel(
|
|
175
|
-
data,
|
|
176
|
-
questions
|
|
177
|
-
);
|
|
178
|
-
expect(result.uri).toEqual(data.root["@id"]);
|
|
179
|
-
expect(result.origin).toEqual(data.root[Constants.HAS_QUESTION_ORIGIN]);
|
|
180
|
-
expect(result.subQuestions.length).toEqual(1);
|
|
181
|
-
verifyQuestions(questions[0], result.subQuestions[0]);
|
|
182
|
-
});
|
|
183
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import QuestionCommentIcon from "../../src/components/comment/QuestionCommentIcon";
|
|
3
|
-
import { cleanup, render } from "@testing-library/react";
|
|
4
|
-
import { composeStories } from "@storybook/testing-react";
|
|
5
|
-
import { fireEvent } from "@storybook/testing-library";
|
|
6
|
-
import { expect } from "@storybook/jest";
|
|
7
|
-
|
|
8
|
-
import * as stories from "../../src/stories/QuestionCommentIcon.stories";
|
|
9
|
-
|
|
10
|
-
describe("QuestionCommentIcon", () => {
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
cleanup();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const { Default, WithComment } = composeStories(stories);
|
|
16
|
-
|
|
17
|
-
it("should have empty comment list", async () => {
|
|
18
|
-
const component = render(<Default {...Default.args} />);
|
|
19
|
-
|
|
20
|
-
fireEvent.click(component.container.querySelector(".comment-bubble"));
|
|
21
|
-
await expect(component.queryByRole("tooltip")).toBeInTheDocument();
|
|
22
|
-
await expect(component.queryByText("Comment")).not.toBeInTheDocument();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("should have two comments", async () => {
|
|
26
|
-
const component = render(<WithComment {...WithComment.args} />);
|
|
27
|
-
|
|
28
|
-
fireEvent.click(component.container.querySelector(".comment-bubble"));
|
|
29
|
-
await expect(component.queryByRole("tooltip")).toBeInTheDocument();
|
|
30
|
-
const comments = await component.findAllByText("Comment");
|
|
31
|
-
await expect(comments).toHaveLength(2);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should show link icon when hover author comment", async () => {
|
|
35
|
-
const component = render(<WithComment {...WithComment.args} />);
|
|
36
|
-
|
|
37
|
-
fireEvent.click(component.container.querySelector(".comment-bubble"));
|
|
38
|
-
const authors = await component.queryAllByText("Unknown author");
|
|
39
|
-
const author = authors[0];
|
|
40
|
-
|
|
41
|
-
await expect(component.queryByRole("link")).not.toBeInTheDocument();
|
|
42
|
-
fireEvent.mouseOver(author);
|
|
43
|
-
await expect(component.queryByRole("link")).toBeInTheDocument();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("should delete comment when click on recycle bin", async () => {
|
|
47
|
-
const component = render(<WithComment {...WithComment.args} />);
|
|
48
|
-
|
|
49
|
-
fireEvent.click(component.container.querySelector(".comment-bubble"));
|
|
50
|
-
const authors = await component.queryAllByText("Unknown author");
|
|
51
|
-
const author = authors[0];
|
|
52
|
-
|
|
53
|
-
await expect(
|
|
54
|
-
component.container.querySelector(".comment-delete")
|
|
55
|
-
).not.toBeInTheDocument();
|
|
56
|
-
fireEvent.mouseOver(author);
|
|
57
|
-
await expect(
|
|
58
|
-
component.container.querySelector(".comment-delete")
|
|
59
|
-
).toBeInTheDocument();
|
|
60
|
-
await expect(
|
|
61
|
-
component.queryByTestId("rings-loading")
|
|
62
|
-
).not.toBeInTheDocument();
|
|
63
|
-
fireEvent.click(component.container.querySelector(".comment-delete"));
|
|
64
|
-
await expect(component.queryByTestId("rings-loading")).toBeInTheDocument();
|
|
65
|
-
await new Promise((resolve) => {
|
|
66
|
-
setTimeout(() => {
|
|
67
|
-
console.log("time is up");
|
|
68
|
-
resolve();
|
|
69
|
-
}, 2000);
|
|
70
|
-
});
|
|
71
|
-
await expect(
|
|
72
|
-
component.queryByTestId("rings-loading")
|
|
73
|
-
).not.toBeInTheDocument();
|
|
74
|
-
const comments = await component.findAllByText("Comment");
|
|
75
|
-
await expect(comments).toHaveLength(1);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import JsonLdUtils from "jsonld-utils";
|
|
3
|
-
|
|
4
|
-
import * as Generator from "../environment/Generator";
|
|
5
|
-
import Constants from "../../src/constants/Constants";
|
|
6
|
-
import TypeaheadAnswer from "../../src/components/answer/TypeaheadAnswer";
|
|
7
|
-
import { FormGenContext } from "../../src/contexts/FormGenContext";
|
|
8
|
-
import { ConfigurationContext } from "../../src/contexts/ConfigurationContext";
|
|
9
|
-
import DefaultInput from "../../src/components/DefaultInput";
|
|
10
|
-
|
|
11
|
-
describe("TypeaheadAnswer", () => {
|
|
12
|
-
let question;
|
|
13
|
-
let onChange;
|
|
14
|
-
let loadFormOptions;
|
|
15
|
-
let getOptions;
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
question = {
|
|
19
|
-
"@id": Generator.getRandomUri(),
|
|
20
|
-
};
|
|
21
|
-
question[Constants.LAYOUT_CLASS] = [];
|
|
22
|
-
question[Constants.RDFS_LABEL] = {
|
|
23
|
-
"@language": "en",
|
|
24
|
-
"@value": "1 - Aerodrome General",
|
|
25
|
-
};
|
|
26
|
-
question[Constants.RDFS_COMMENT] = {
|
|
27
|
-
"@language": "en",
|
|
28
|
-
"@value":
|
|
29
|
-
"The identification of the aerodrome/helicopter landing area by name, location and status.",
|
|
30
|
-
};
|
|
31
|
-
onChange = jest.fn();
|
|
32
|
-
loadFormOptions = jest.fn();
|
|
33
|
-
getOptions = jest.fn(() => [
|
|
34
|
-
{
|
|
35
|
-
id: "123",
|
|
36
|
-
name: "123",
|
|
37
|
-
},
|
|
38
|
-
]);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("orders options using partial ordering with alphabetical ordering", () => {
|
|
42
|
-
// create options
|
|
43
|
-
const options = createOptionsWithPartialOrder(
|
|
44
|
-
["3", "2", "1", "before2"],
|
|
45
|
-
["before2<2"]
|
|
46
|
-
);
|
|
47
|
-
const query = "SELECT * WHERE { ?x ?y ?z .}";
|
|
48
|
-
|
|
49
|
-
question[Constants.LAYOUT_CLASS].push(Constants.LAYOUT.QUESTION_TYPEAHEAD);
|
|
50
|
-
question[Constants.HAS_OPTIONS_QUERY] = query;
|
|
51
|
-
|
|
52
|
-
const component = mount(
|
|
53
|
-
<ConfigurationContext.Provider
|
|
54
|
-
value={{
|
|
55
|
-
componentsOptions: { readOnly: false },
|
|
56
|
-
inputComponent: DefaultInput,
|
|
57
|
-
options: {
|
|
58
|
-
intl: {
|
|
59
|
-
locale: "en",
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
}}
|
|
63
|
-
>
|
|
64
|
-
<FormGenContext.Provider value={{ getOptions, loadFormOptions }}>
|
|
65
|
-
<TypeaheadAnswer
|
|
66
|
-
answer={{}}
|
|
67
|
-
question={question}
|
|
68
|
-
onChange={onChange}
|
|
69
|
-
label="TestLabel"
|
|
70
|
-
options={options}
|
|
71
|
-
/>
|
|
72
|
-
</FormGenContext.Provider>
|
|
73
|
-
</ConfigurationContext.Provider>
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
waitForComponentToPaint(component);
|
|
77
|
-
|
|
78
|
-
const select = component.find(TypeaheadAnswer);
|
|
79
|
-
expect(select).not.toBeNull();
|
|
80
|
-
let optionArray = [];
|
|
81
|
-
select.prop("options").forEach((i) => {
|
|
82
|
-
optionArray.push(i["@id"]);
|
|
83
|
-
});
|
|
84
|
-
expect(optionArray).toEqual(["1", "before2", "2", "3"]);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
function createOptionsWithPartialOrder(ids, orderingRules) {
|
|
88
|
-
let options = ids.map((i) => {
|
|
89
|
-
let obj = { "@id": i };
|
|
90
|
-
obj[JsonLdUtils.RDFS_LABEL] = i + ". value";
|
|
91
|
-
return obj;
|
|
92
|
-
});
|
|
93
|
-
orderingRules.forEach((rule) => {
|
|
94
|
-
const firstId = rule.substring(0, rule.indexOf("<"));
|
|
95
|
-
const secondId = rule.substring(rule.indexOf("<") + 1);
|
|
96
|
-
const secondIndex = ids.indexOf(secondId);
|
|
97
|
-
|
|
98
|
-
options[secondIndex][Constants.HAS_PRECEDING_VALUE] = firstId;
|
|
99
|
-
});
|
|
100
|
-
return options;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import JsonLdUtils from "jsonld-utils";
|
|
2
|
-
|
|
3
|
-
const _uriBase = "http://onto.fel.cvut.cz/ontologies/forms";
|
|
4
|
-
|
|
5
|
-
export const getRandomInt = () => {
|
|
6
|
-
const min = 0;
|
|
7
|
-
const bound = Number.MAX_SAFE_INTEGER;
|
|
8
|
-
return Math.floor(Math.random() * (bound - min)) + min;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const getRandomPositiveInt = (min, max) => {
|
|
12
|
-
const bound = max ? max : Number.MAX_SAFE_INTEGER;
|
|
13
|
-
if (min === null || min === undefined) {
|
|
14
|
-
min = 1;
|
|
15
|
-
}
|
|
16
|
-
return Math.floor(Math.random() * (bound - min)) + min;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const getRandomBoolean = () => {
|
|
20
|
-
return Math.random() < 0.5;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const getRandomUri = () => {
|
|
24
|
-
return _uriBase + getRandomInt();
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const generateTypeaheadOptions = (value, valueLabel) => {
|
|
28
|
-
const options = [];
|
|
29
|
-
let option;
|
|
30
|
-
|
|
31
|
-
for (let i = 0; i < getRandomPositiveInt(3, 10); i++) {
|
|
32
|
-
option = {
|
|
33
|
-
"@id": getRandomUri(),
|
|
34
|
-
};
|
|
35
|
-
option[JsonLdUtils.RDFS_LABEL] = "RandomLabel" + i;
|
|
36
|
-
options.push(option);
|
|
37
|
-
}
|
|
38
|
-
option = {
|
|
39
|
-
"@id": value,
|
|
40
|
-
};
|
|
41
|
-
option[JsonLdUtils.RDFS_LABEL] = valueLabel;
|
|
42
|
-
options.push(option);
|
|
43
|
-
return options;
|
|
44
|
-
};
|
package/test/setup.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import enzyme, { shallow, mount } from "enzyme";
|
|
2
|
-
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
|
|
3
|
-
import { act } from "react-dom/test-utils";
|
|
4
|
-
import { setGlobalConfig } from "@storybook/testing-react";
|
|
5
|
-
import * as globalStorybookConfig from "../.storybook/preview.js";
|
|
6
|
-
|
|
7
|
-
enzyme.configure({ adapter: new Adapter() });
|
|
8
|
-
|
|
9
|
-
global.shallow = shallow;
|
|
10
|
-
global.mount = mount;
|
|
11
|
-
|
|
12
|
-
global.waitForComponentToPaint = async (wrapper) => {
|
|
13
|
-
await act(async () => {
|
|
14
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
15
|
-
wrapper.update();
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
setGlobalConfig(globalStorybookConfig);
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ESNext",
|
|
4
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
-
"allowJs": true,
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"allowSyntheticDefaultImports": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
"noFallthroughCasesInSwitch": true,
|
|
12
|
-
"module": "ESNext",
|
|
13
|
-
"moduleResolution": "node",
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
"isolatedModules": true,
|
|
16
|
-
"noEmit": true,
|
|
17
|
-
"jsx": "react-jsx"
|
|
18
|
-
},
|
|
19
|
-
"include": ["src"]
|
|
20
|
-
}
|