@gisce/ooui 0.1.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/README.md +10 -0
- package/dist/Binary.d.ts +14 -0
- package/dist/Binary.js +46 -0
- package/dist/Binary.js.map +1 -0
- package/dist/Boolean.d.ts +8 -0
- package/dist/Boolean.js +26 -0
- package/dist/Boolean.js.map +1 -0
- package/dist/Button.d.ts +29 -0
- package/dist/Button.js +108 -0
- package/dist/Button.js.map +1 -0
- package/dist/Char.d.ts +26 -0
- package/dist/Char.js +89 -0
- package/dist/Char.js.map +1 -0
- package/dist/Container.d.ts +44 -0
- package/dist/Container.js +148 -0
- package/dist/Container.js.map +1 -0
- package/dist/ContainerWidget.d.ts +42 -0
- package/dist/ContainerWidget.js +125 -0
- package/dist/ContainerWidget.js.map +1 -0
- package/dist/Date.d.ts +8 -0
- package/dist/Date.js +26 -0
- package/dist/Date.js.map +1 -0
- package/dist/DateTime.d.ts +8 -0
- package/dist/DateTime.js +26 -0
- package/dist/DateTime.js.map +1 -0
- package/dist/FiberGrid.d.ts +5 -0
- package/dist/FiberGrid.js +23 -0
- package/dist/FiberGrid.js.map +1 -0
- package/dist/Field.d.ts +59 -0
- package/dist/Field.js +162 -0
- package/dist/Field.js.map +1 -0
- package/dist/Float.d.ts +24 -0
- package/dist/Float.js +64 -0
- package/dist/Float.js.map +1 -0
- package/dist/FloatTime.d.ts +7 -0
- package/dist/FloatTime.js +26 -0
- package/dist/FloatTime.js.map +1 -0
- package/dist/Form.d.ts +53 -0
- package/dist/Form.js +199 -0
- package/dist/Form.js.map +1 -0
- package/dist/Group.d.ts +5 -0
- package/dist/Group.js +23 -0
- package/dist/Group.js.map +1 -0
- package/dist/Image.d.ts +7 -0
- package/dist/Image.js +26 -0
- package/dist/Image.js.map +1 -0
- package/dist/Integer.d.ts +8 -0
- package/dist/Integer.js +26 -0
- package/dist/Integer.js.map +1 -0
- package/dist/Label.d.ts +23 -0
- package/dist/Label.js +80 -0
- package/dist/Label.js.map +1 -0
- package/dist/Many2many.d.ts +26 -0
- package/dist/Many2many.js +80 -0
- package/dist/Many2many.js.map +1 -0
- package/dist/Many2one.d.ts +20 -0
- package/dist/Many2one.js +63 -0
- package/dist/Many2one.js.map +1 -0
- package/dist/NewLine.d.ts +5 -0
- package/dist/NewLine.js +26 -0
- package/dist/NewLine.js.map +1 -0
- package/dist/Notebook.d.ts +8 -0
- package/dist/Notebook.js +41 -0
- package/dist/Notebook.js.map +1 -0
- package/dist/One2many.d.ts +44 -0
- package/dist/One2many.js +130 -0
- package/dist/One2many.js.map +1 -0
- package/dist/Page.d.ts +5 -0
- package/dist/Page.js +23 -0
- package/dist/Page.js.map +1 -0
- package/dist/ProgressBar.d.ts +7 -0
- package/dist/ProgressBar.js +26 -0
- package/dist/ProgressBar.js.map +1 -0
- package/dist/Reference.d.ts +7 -0
- package/dist/Reference.js +26 -0
- package/dist/Reference.js.map +1 -0
- package/dist/SearchFilter.d.ts +28 -0
- package/dist/SearchFilter.js +81 -0
- package/dist/SearchFilter.js.map +1 -0
- package/dist/Selection.d.ts +20 -0
- package/dist/Selection.js +63 -0
- package/dist/Selection.js.map +1 -0
- package/dist/Separator.d.ts +12 -0
- package/dist/Separator.js +46 -0
- package/dist/Separator.js.map +1 -0
- package/dist/Text.d.ts +29 -0
- package/dist/Text.js +96 -0
- package/dist/Text.js.map +1 -0
- package/dist/Timeline.d.ts +17 -0
- package/dist/Timeline.js +56 -0
- package/dist/Timeline.js.map +1 -0
- package/dist/Tree.d.ts +31 -0
- package/dist/Tree.js +96 -0
- package/dist/Tree.js.map +1 -0
- package/dist/Widget.d.ts +47 -0
- package/dist/Widget.js +116 -0
- package/dist/Widget.js.map +1 -0
- package/dist/WidgetFactory.d.ts +9 -0
- package/dist/WidgetFactory.js +157 -0
- package/dist/WidgetFactory.js.map +1 -0
- package/dist/helpers/attributeParser.d.ts +6 -0
- package/dist/helpers/attributeParser.js +83 -0
- package/dist/helpers/attributeParser.js.map +1 -0
- package/dist/helpers/contextParser.d.ts +5 -0
- package/dist/helpers/contextParser.js +52 -0
- package/dist/helpers/contextParser.js.map +1 -0
- package/dist/helpers/domainParser.d.ts +5 -0
- package/dist/helpers/domainParser.js +26 -0
- package/dist/helpers/domainParser.js.map +1 -0
- package/dist/helpers/fieldParser.d.ts +5 -0
- package/dist/helpers/fieldParser.js +20 -0
- package/dist/helpers/fieldParser.js.map +1 -0
- package/dist/helpers/nodeParser.d.ts +7 -0
- package/dist/helpers/nodeParser.js +50 -0
- package/dist/helpers/nodeParser.js.map +1 -0
- package/dist/helpers/onChangeParser.d.ts +5 -0
- package/dist/helpers/onChangeParser.js +16 -0
- package/dist/helpers/onChangeParser.js.map +1 -0
- package/dist/helpers/stateParser.d.ts +14 -0
- package/dist/helpers/stateParser.js +46 -0
- package/dist/helpers/stateParser.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
- package/src/Binary.ts +29 -0
- package/src/Boolean.ts +12 -0
- package/src/Button.ts +78 -0
- package/src/Char.ts +65 -0
- package/src/Container.ts +171 -0
- package/src/ContainerWidget.ts +105 -0
- package/src/Date.ts +12 -0
- package/src/DateTime.ts +12 -0
- package/src/FiberGrid.ts +9 -0
- package/src/Field.ts +147 -0
- package/src/Float.ts +45 -0
- package/src/FloatTime.ts +8 -0
- package/src/Form.ts +212 -0
- package/src/Group.ts +9 -0
- package/src/Image.ts +8 -0
- package/src/Integer.ts +13 -0
- package/src/Label.ts +46 -0
- package/src/Many2many.ts +59 -0
- package/src/Many2one.ts +44 -0
- package/src/NewLine.ts +9 -0
- package/src/Notebook.ts +24 -0
- package/src/One2many.ts +106 -0
- package/src/Page.ts +9 -0
- package/src/ProgressBar.ts +8 -0
- package/src/Reference.ts +10 -0
- package/src/SearchFilter.ts +81 -0
- package/src/Selection.ts +44 -0
- package/src/Separator.ts +30 -0
- package/src/Text.ts +76 -0
- package/src/Timeline.ts +44 -0
- package/src/Tree.ts +93 -0
- package/src/Widget.ts +121 -0
- package/src/WidgetFactory.ts +158 -0
- package/src/helpers/attributeParser.ts +108 -0
- package/src/helpers/contextParser.ts +66 -0
- package/src/helpers/domainParser.ts +39 -0
- package/src/helpers/fieldParser.ts +27 -0
- package/src/helpers/nodeParser.ts +57 -0
- package/src/helpers/onChangeParser.ts +18 -0
- package/src/helpers/stateParser.ts +62 -0
- package/src/index.ts +67 -0
- package/src/spec/Boolean.spec.ts +36 -0
- package/src/spec/Button.spec.ts +58 -0
- package/src/spec/Char.spec.ts +80 -0
- package/src/spec/Container.spec.ts +47 -0
- package/src/spec/ContainerWidget.spec.ts +35 -0
- package/src/spec/Date.spec.ts +36 -0
- package/src/spec/DateTime.spec.ts +36 -0
- package/src/spec/Float.spec.ts +29 -0
- package/src/spec/Form.spec.ts +976 -0
- package/src/spec/Group.spec.ts +32 -0
- package/src/spec/Label.spec.ts +46 -0
- package/src/spec/Many2many.spec.ts +36 -0
- package/src/spec/Many2one.spec.ts +36 -0
- package/src/spec/One2many.spec.ts +354 -0
- package/src/spec/SearchFilter.spec.ts +955 -0
- package/src/spec/Selection.spec.ts +52 -0
- package/src/spec/Separator.spec.ts +14 -0
- package/src/spec/Tree.spec.ts +214 -0
- package/src/spec/Widget.spec.ts +45 -0
- package/src/spec/WidgetFactory.spec.ts +40 -0
- package/src/spec/attributeParser.spec.ts +173 -0
- package/src/spec/contextParser.spec.ts +57 -0
- package/src/spec/domainParser.spec.ts +40 -0
- package/src/spec/fixtures/WidgetImpl.ts +10 -0
- package/src/spec/stateParser.spec.ts +161 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const transformDomainForChildWidget = ({
|
|
2
|
+
domain,
|
|
3
|
+
widgetFieldName,
|
|
4
|
+
}: {
|
|
5
|
+
domain: any;
|
|
6
|
+
widgetFieldName: string;
|
|
7
|
+
}) => {
|
|
8
|
+
const transformedDomain: any[] = [];
|
|
9
|
+
|
|
10
|
+
domain.forEach((domainEntry: any) => {
|
|
11
|
+
if (!Array.isArray(domainEntry)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const [fieldName, operator, value] = domainEntry;
|
|
16
|
+
|
|
17
|
+
let rootFieldName;
|
|
18
|
+
let targetFieldName;
|
|
19
|
+
|
|
20
|
+
if (fieldName.indexOf(".") !== -1) {
|
|
21
|
+
rootFieldName = fieldName.substr(0, fieldName.indexOf("."));
|
|
22
|
+
targetFieldName = fieldName.substr(
|
|
23
|
+
fieldName.indexOf(".") + 1,
|
|
24
|
+
fieldName.length - 1
|
|
25
|
+
);
|
|
26
|
+
} else {
|
|
27
|
+
rootFieldName = fieldName;
|
|
28
|
+
targetFieldName = "id";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (rootFieldName === widgetFieldName) {
|
|
32
|
+
transformedDomain.push([targetFieldName, operator, value]);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return transformedDomain;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { transformDomainForChildWidget };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function getValueForField({
|
|
2
|
+
values,
|
|
3
|
+
fieldName,
|
|
4
|
+
fields,
|
|
5
|
+
}: {
|
|
6
|
+
values: any;
|
|
7
|
+
fieldName: string;
|
|
8
|
+
fields: any;
|
|
9
|
+
}) {
|
|
10
|
+
if (!fields) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!fields[fieldName]) {
|
|
15
|
+
return values[fieldName] || false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const fieldType = fields[fieldName].type;
|
|
19
|
+
|
|
20
|
+
if (fieldType === "many2one") {
|
|
21
|
+
return values[fieldName] ? values[fieldName][0] || null : false;
|
|
22
|
+
} else if (fieldType === "one2many" || fieldType === "many2many") {
|
|
23
|
+
return values[fieldName].map((item: any) => item.id);
|
|
24
|
+
} else {
|
|
25
|
+
return values[fieldName];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
type ParsedNode = {
|
|
2
|
+
tag: string;
|
|
3
|
+
tagAttributes: any;
|
|
4
|
+
child: Element;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const parseNodes = (
|
|
8
|
+
nodes: NodeListOf<ChildNode>,
|
|
9
|
+
fields: any
|
|
10
|
+
): ParsedNode[] => {
|
|
11
|
+
const parsedNodes: ParsedNode[] = [];
|
|
12
|
+
Array.prototype.forEach.call(nodes, (child: Element) => {
|
|
13
|
+
if (child.nodeType === child.ELEMENT_NODE) {
|
|
14
|
+
let tag = child.nodeName;
|
|
15
|
+
|
|
16
|
+
let tagAttributes: any = {};
|
|
17
|
+
Array.prototype.forEach.call(child.attributes, (attr: Attr) => {
|
|
18
|
+
tagAttributes[attr.name] = attr.value;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (tag === "field") {
|
|
22
|
+
const name = child.getAttribute("name");
|
|
23
|
+
const attrWidget = child.getAttribute("widget");
|
|
24
|
+
if (attrWidget) {
|
|
25
|
+
tag = attrWidget;
|
|
26
|
+
} else if (name) {
|
|
27
|
+
if (!fields[name]) {
|
|
28
|
+
throw new Error(`Field ${name} doesn't exist in fields defintion`);
|
|
29
|
+
}
|
|
30
|
+
tag = fields[name].type;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// We do this in order to ignore the blank domain attribute in fields and to prioritize the attributes value
|
|
34
|
+
if (
|
|
35
|
+
((Array.isArray(fields[name!].domain) &&
|
|
36
|
+
fields[name!].domain.length === 0) ||
|
|
37
|
+
fields[name!].domain === false) &&
|
|
38
|
+
tagAttributes["domain"] &&
|
|
39
|
+
tagAttributes["domain"].length > 0
|
|
40
|
+
) {
|
|
41
|
+
delete fields[name!].domain;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
tagAttributes = {
|
|
45
|
+
...fields[name!],
|
|
46
|
+
...tagAttributes,
|
|
47
|
+
fieldsWidgetType: fields[name!]?.type,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
parsedNodes.push({ tag, tagAttributes, child });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return parsedNodes;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export { parseNodes };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const parseOnChange = (onChangeString: string) => {
|
|
2
|
+
const splitted = onChangeString
|
|
3
|
+
.replace(/\s/g, "")
|
|
4
|
+
.replace(/'/g, "")
|
|
5
|
+
.replace(")", "")
|
|
6
|
+
.split("(");
|
|
7
|
+
|
|
8
|
+
const method = splitted[0];
|
|
9
|
+
const argsGross = splitted[1];
|
|
10
|
+
const argsSplitted = argsGross.split(",");
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
method,
|
|
14
|
+
args: argsSplitted
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { parseOnChange };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const evaluateStates = ({
|
|
2
|
+
fieldName,
|
|
3
|
+
values,
|
|
4
|
+
fields,
|
|
5
|
+
}: {
|
|
6
|
+
fieldName: string;
|
|
7
|
+
values: any;
|
|
8
|
+
fields: any;
|
|
9
|
+
}) => {
|
|
10
|
+
if (!fieldName) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const fieldStatesConfig = fields[fieldName]?.states;
|
|
15
|
+
|
|
16
|
+
if (!fieldStatesConfig) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const newTagStateAttrs: any = {};
|
|
21
|
+
const evaluatedStates: any = {};
|
|
22
|
+
|
|
23
|
+
for (const stateCondition of Object.keys(fieldStatesConfig)) {
|
|
24
|
+
if (values["state"] === stateCondition) {
|
|
25
|
+
const configAttrValues = fieldStatesConfig[stateCondition];
|
|
26
|
+
|
|
27
|
+
for (const entryConfig of configAttrValues) {
|
|
28
|
+
const [attribute, value] = entryConfig;
|
|
29
|
+
if (!evaluatedStates[attribute]) {
|
|
30
|
+
evaluatedStates[attribute] = [];
|
|
31
|
+
}
|
|
32
|
+
evaluatedStates[attribute].push(value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for (const evaluatedState of Object.keys(evaluatedStates)) {
|
|
38
|
+
const values = evaluatedStates[evaluatedState];
|
|
39
|
+
newTagStateAttrs[evaluatedState] = values.some((i: boolean) => i === true);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return newTagStateAttrs;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const evaluateButtonStates = ({
|
|
46
|
+
states,
|
|
47
|
+
values,
|
|
48
|
+
}: {
|
|
49
|
+
states: string;
|
|
50
|
+
values: any;
|
|
51
|
+
}) => {
|
|
52
|
+
if (!values?.state) {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
const splittedStates = states.split(",");
|
|
56
|
+
if (splittedStates.length === 0) {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
return !splittedStates.includes(values.state) ? { invisible: true } : {};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { evaluateStates, evaluateButtonStates };
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import Form from "./Form";
|
|
2
|
+
import Tree from "./Tree";
|
|
3
|
+
import Char from "./Char";
|
|
4
|
+
import Container from "./Container";
|
|
5
|
+
import ContainerWidget from "./ContainerWidget";
|
|
6
|
+
import Selection from "./Selection";
|
|
7
|
+
import Many2one from "./Many2one";
|
|
8
|
+
import Field from "./Field";
|
|
9
|
+
import Widget from "./Widget";
|
|
10
|
+
import Boolean from "./Boolean";
|
|
11
|
+
import Integer from "./Integer";
|
|
12
|
+
import Float from "./Float";
|
|
13
|
+
import FloatTime from "./FloatTime";
|
|
14
|
+
import ProgressBar from "./ProgressBar";
|
|
15
|
+
import Date from "./Date";
|
|
16
|
+
import DateTime from "./DateTime";
|
|
17
|
+
import Many2many from "./Many2many";
|
|
18
|
+
import One2many from "./One2many";
|
|
19
|
+
import SearchFilter from "./SearchFilter";
|
|
20
|
+
import Text from "./Text";
|
|
21
|
+
import Label from "./Label";
|
|
22
|
+
import Notebook from "./Notebook";
|
|
23
|
+
import Group from "./Group";
|
|
24
|
+
import Page from "./Page";
|
|
25
|
+
import Separator from "./Separator";
|
|
26
|
+
import Button from "./Button";
|
|
27
|
+
import Reference from "./Reference";
|
|
28
|
+
import Binary from "./Binary";
|
|
29
|
+
import Image from "./Image";
|
|
30
|
+
import { parseContext } from "./helpers/contextParser";
|
|
31
|
+
import { transformDomainForChildWidget } from "./helpers/domainParser";
|
|
32
|
+
import Timeline from "./Timeline";
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
Char,
|
|
36
|
+
Selection,
|
|
37
|
+
Many2one,
|
|
38
|
+
Field,
|
|
39
|
+
Widget,
|
|
40
|
+
Form,
|
|
41
|
+
Tree,
|
|
42
|
+
Boolean,
|
|
43
|
+
One2many,
|
|
44
|
+
Integer,
|
|
45
|
+
Float,
|
|
46
|
+
FloatTime,
|
|
47
|
+
Date,
|
|
48
|
+
DateTime,
|
|
49
|
+
Many2many,
|
|
50
|
+
SearchFilter,
|
|
51
|
+
Container,
|
|
52
|
+
ContainerWidget,
|
|
53
|
+
Text,
|
|
54
|
+
ProgressBar,
|
|
55
|
+
Notebook,
|
|
56
|
+
Group,
|
|
57
|
+
Page,
|
|
58
|
+
Label,
|
|
59
|
+
Separator,
|
|
60
|
+
Button,
|
|
61
|
+
Reference,
|
|
62
|
+
Binary,
|
|
63
|
+
Image,
|
|
64
|
+
parseContext,
|
|
65
|
+
transformDomainForChildWidget,
|
|
66
|
+
Timeline,
|
|
67
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import WidgetFactory from "../WidgetFactory";
|
|
2
|
+
|
|
3
|
+
describe("A Boolean", () => {
|
|
4
|
+
it("should have an id corresponding to field name", () => {
|
|
5
|
+
const widgetFactory = new WidgetFactory();
|
|
6
|
+
const props = {
|
|
7
|
+
name: "boolean1",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const widget = widgetFactory.createWidget("boolean", props);
|
|
11
|
+
|
|
12
|
+
expect(widget.id).toBe("boolean1");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should properly set label", () => {
|
|
16
|
+
const widgetFactory = new WidgetFactory();
|
|
17
|
+
const props = {
|
|
18
|
+
name: "boolean1",
|
|
19
|
+
string: "Boolean caption",
|
|
20
|
+
};
|
|
21
|
+
const widget = widgetFactory.createWidget("boolean", props);
|
|
22
|
+
|
|
23
|
+
expect(widget.label).toBe("Boolean caption");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should properly set readonly", () => {
|
|
27
|
+
const widgetFactory = new WidgetFactory();
|
|
28
|
+
const props = {
|
|
29
|
+
name: "boolean1",
|
|
30
|
+
readonly: 1,
|
|
31
|
+
};
|
|
32
|
+
const widget = widgetFactory.createWidget("boolean", props);
|
|
33
|
+
|
|
34
|
+
expect(widget.readOnly).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import WidgetFactory from "../WidgetFactory";
|
|
2
|
+
|
|
3
|
+
describe("A Button", () => {
|
|
4
|
+
it("should have an id corresponding to field name", () => {
|
|
5
|
+
const widgetFactory = new WidgetFactory();
|
|
6
|
+
const props = {
|
|
7
|
+
name: "button1",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const widget = widgetFactory.createWidget("button", props);
|
|
11
|
+
|
|
12
|
+
expect(widget.id).toBe("button1");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should have colspan 1 by default (with no label)", () => {
|
|
16
|
+
const widgetFactory = new WidgetFactory();
|
|
17
|
+
const props = {
|
|
18
|
+
name: "button1",
|
|
19
|
+
};
|
|
20
|
+
const widget = widgetFactory.createWidget("button", props);
|
|
21
|
+
|
|
22
|
+
expect(widget.colspan).toBe(1);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should properly set caption", () => {
|
|
26
|
+
const widgetFactory = new WidgetFactory();
|
|
27
|
+
const props = {
|
|
28
|
+
name: "char1",
|
|
29
|
+
string: "Button caption",
|
|
30
|
+
};
|
|
31
|
+
const widget = widgetFactory.createWidget("button", props);
|
|
32
|
+
|
|
33
|
+
expect(widget.caption).toBe("Button caption");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should properly have nolabel as true by default", () => {
|
|
37
|
+
const widgetFactory = new WidgetFactory();
|
|
38
|
+
const props = {
|
|
39
|
+
name: "char1",
|
|
40
|
+
string: "Button caption",
|
|
41
|
+
};
|
|
42
|
+
const widget = widgetFactory.createWidget("button", props);
|
|
43
|
+
|
|
44
|
+
expect(widget.nolabel).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should properly have nolabel value passed as props", () => {
|
|
48
|
+
const widgetFactory = new WidgetFactory();
|
|
49
|
+
const props = {
|
|
50
|
+
name: "char1",
|
|
51
|
+
string: "Button caption",
|
|
52
|
+
nolabel: false,
|
|
53
|
+
};
|
|
54
|
+
const widget = widgetFactory.createWidget("button", props);
|
|
55
|
+
|
|
56
|
+
expect(widget.nolabel).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import WidgetFactory from "../WidgetFactory";
|
|
2
|
+
|
|
3
|
+
describe("A Char", () => {
|
|
4
|
+
it("should have an id corresponding to field name", () => {
|
|
5
|
+
const widgetFactory = new WidgetFactory();
|
|
6
|
+
const props = {
|
|
7
|
+
name: "char1",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const widget = widgetFactory.createWidget("char", props);
|
|
11
|
+
|
|
12
|
+
expect(widget.id).toBe("char1");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should have colspan 1 by default", () => {
|
|
16
|
+
const widgetFactory = new WidgetFactory();
|
|
17
|
+
const props = {
|
|
18
|
+
name: "char1",
|
|
19
|
+
};
|
|
20
|
+
const widget = widgetFactory.createWidget("char", props);
|
|
21
|
+
|
|
22
|
+
expect(widget.colspan).toBe(1);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("with label should have colspan 1 even with label", () => {
|
|
26
|
+
const widgetFactory = new WidgetFactory();
|
|
27
|
+
const props = {
|
|
28
|
+
name: "char1",
|
|
29
|
+
string: "Char caption",
|
|
30
|
+
};
|
|
31
|
+
const widget = widgetFactory.createWidget("char", props);
|
|
32
|
+
|
|
33
|
+
expect(widget.colspan).toBe(1);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should properly set label", () => {
|
|
37
|
+
const widgetFactory = new WidgetFactory();
|
|
38
|
+
const props = {
|
|
39
|
+
name: "char1",
|
|
40
|
+
string: "Char caption",
|
|
41
|
+
};
|
|
42
|
+
const widget = widgetFactory.createWidget("char", props);
|
|
43
|
+
|
|
44
|
+
expect(widget.label).toBe("Char caption");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should properly set size", () => {
|
|
48
|
+
const widgetFactory = new WidgetFactory();
|
|
49
|
+
const props = {
|
|
50
|
+
name: "char1",
|
|
51
|
+
size: 256,
|
|
52
|
+
};
|
|
53
|
+
const widget = widgetFactory.createWidget("char", props);
|
|
54
|
+
|
|
55
|
+
expect(widget.size).toBe(256);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should properly set readonly", () => {
|
|
59
|
+
const widgetFactory = new WidgetFactory();
|
|
60
|
+
const props = {
|
|
61
|
+
name: "char1",
|
|
62
|
+
readonly: 1,
|
|
63
|
+
};
|
|
64
|
+
const widget = widgetFactory.createWidget("char", props);
|
|
65
|
+
|
|
66
|
+
expect(widget.readOnly).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should properly set tooltip", () => {
|
|
70
|
+
const widgetFactory = new WidgetFactory();
|
|
71
|
+
const props = {
|
|
72
|
+
name: "char1",
|
|
73
|
+
help: "This is a help field",
|
|
74
|
+
};
|
|
75
|
+
const widget = widgetFactory.createWidget("char", props);
|
|
76
|
+
|
|
77
|
+
expect(widget.tooltip).toBe("This is a help field");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Container from "../Container";
|
|
2
|
+
import WidgetImpl from "./fixtures/WidgetImpl";
|
|
3
|
+
|
|
4
|
+
describe("A container", () => {
|
|
5
|
+
it("should have 4 columns as default", () => {
|
|
6
|
+
const cont = new Container();
|
|
7
|
+
expect(cont.columns).toEqual(4);
|
|
8
|
+
expect(cont.rows.length).toEqual(1);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should add widgets", () => {
|
|
12
|
+
const cont = new Container(2);
|
|
13
|
+
const w1 = new WidgetImpl({ name: "1" });
|
|
14
|
+
|
|
15
|
+
cont.addWidget(w1);
|
|
16
|
+
expect(cont.rows[0][0]).toEqual(w1);
|
|
17
|
+
|
|
18
|
+
const w2 = new WidgetImpl({ name: "2" });
|
|
19
|
+
cont.addWidget(w2);
|
|
20
|
+
expect(cont.rows[0][1]).toEqual(w2);
|
|
21
|
+
|
|
22
|
+
const w3 = new WidgetImpl({ name: "3" });
|
|
23
|
+
cont.addWidget(w3);
|
|
24
|
+
expect(cont.index).toEqual(1);
|
|
25
|
+
expect(cont.rows[1][0]).toEqual(w3);
|
|
26
|
+
|
|
27
|
+
const w4 = new WidgetImpl({ name: "4", colspan: 2 });
|
|
28
|
+
cont.addWidget(w4);
|
|
29
|
+
expect(cont.index).toEqual(2);
|
|
30
|
+
expect(cont.rows[2][0]).toEqual(w4);
|
|
31
|
+
|
|
32
|
+
const w5 = new WidgetImpl({ name: "5" });
|
|
33
|
+
cont.addWidget(w5);
|
|
34
|
+
expect(cont.index).toEqual(3);
|
|
35
|
+
expect(cont.rows[3][0]).toEqual(w5);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should don't count colspans of invisible widgets", () => {
|
|
39
|
+
const cont = new Container(4);
|
|
40
|
+
const w1 = new WidgetImpl({ colspan: 2 });
|
|
41
|
+
const w2 = new WidgetImpl({ colspan: 2, invisible: true });
|
|
42
|
+
cont.addWidget(w1);
|
|
43
|
+
cont.addWidget(w2);
|
|
44
|
+
expect(cont.freePosition()).toEqual(2);
|
|
45
|
+
expect(cont.rows[0].length).toEqual(2);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import ContainerWidget from "../ContainerWidget";
|
|
2
|
+
|
|
3
|
+
describe('A ContainerWidget', () => {
|
|
4
|
+
it('should be constructed with a colspan by default', () => {
|
|
5
|
+
const widget = new ContainerWidget();
|
|
6
|
+
|
|
7
|
+
expect(widget.colspan).toBeGreaterThan(0);
|
|
8
|
+
expect(widget.colspan).toBe(ContainerWidget.defaultColspan);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should properly set colspan', () => {
|
|
12
|
+
const widget = new ContainerWidget();
|
|
13
|
+
widget.colspan = 3;
|
|
14
|
+
|
|
15
|
+
expect(widget.colspan).toBe(3);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('colspan should match with internal container colspan', () => {
|
|
19
|
+
const widget = new ContainerWidget();
|
|
20
|
+
widget.colspan = 3;
|
|
21
|
+
|
|
22
|
+
expect(widget.colspan).toBe(widget.container.colspan);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
it('set colspan as string should store as a number', () => {
|
|
27
|
+
const widget = new ContainerWidget();
|
|
28
|
+
|
|
29
|
+
widget.colspan = "3";
|
|
30
|
+
|
|
31
|
+
expect(typeof widget.colspan).toBe("number");
|
|
32
|
+
expect(widget.colspan).toBe(3);
|
|
33
|
+
});
|
|
34
|
+
*/
|
|
35
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import WidgetFactory from "../WidgetFactory";
|
|
2
|
+
|
|
3
|
+
describe("A Date", () => {
|
|
4
|
+
it("should have an id corresponding to field name", () => {
|
|
5
|
+
const widgetFactory = new WidgetFactory();
|
|
6
|
+
const props = {
|
|
7
|
+
name: "date1",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const widget = widgetFactory.createWidget("date", props);
|
|
11
|
+
|
|
12
|
+
expect(widget.id).toBe("date1");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should properly set label", () => {
|
|
16
|
+
const widgetFactory = new WidgetFactory();
|
|
17
|
+
const props = {
|
|
18
|
+
name: "date1",
|
|
19
|
+
string: "Date caption",
|
|
20
|
+
};
|
|
21
|
+
const widget = widgetFactory.createWidget("date", props);
|
|
22
|
+
|
|
23
|
+
expect(widget.label).toBe("Date caption");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should properly set readonly", () => {
|
|
27
|
+
const widgetFactory = new WidgetFactory();
|
|
28
|
+
const props = {
|
|
29
|
+
name: "date1",
|
|
30
|
+
readonly: 1,
|
|
31
|
+
};
|
|
32
|
+
const widget = widgetFactory.createWidget("date", props);
|
|
33
|
+
|
|
34
|
+
expect(widget.readOnly).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import WidgetFactory from "../WidgetFactory";
|
|
2
|
+
|
|
3
|
+
describe("A DateTime", () => {
|
|
4
|
+
it("should have an id corresponding to field name", () => {
|
|
5
|
+
const widgetFactory = new WidgetFactory();
|
|
6
|
+
const props = {
|
|
7
|
+
name: "datetime1",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const widget = widgetFactory.createWidget("datetime", props);
|
|
11
|
+
|
|
12
|
+
expect(widget.id).toBe("datetime1");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should properly set label", () => {
|
|
16
|
+
const widgetFactory = new WidgetFactory();
|
|
17
|
+
const props = {
|
|
18
|
+
name: "datetime1",
|
|
19
|
+
string: "Datetime caption",
|
|
20
|
+
};
|
|
21
|
+
const widget = widgetFactory.createWidget("datetime", props);
|
|
22
|
+
|
|
23
|
+
expect(widget.label).toBe("Datetime caption");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should properly set readonly", () => {
|
|
27
|
+
const widgetFactory = new WidgetFactory();
|
|
28
|
+
const props = {
|
|
29
|
+
name: "datetime1",
|
|
30
|
+
readonly: 1,
|
|
31
|
+
};
|
|
32
|
+
const widget = widgetFactory.createWidget("datetime", props);
|
|
33
|
+
|
|
34
|
+
expect(widget.readOnly).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import WidgetFactory from "../WidgetFactory";
|
|
2
|
+
import Float from "../Float";
|
|
3
|
+
|
|
4
|
+
describe("A Float", () => {
|
|
5
|
+
it("should have 16,2 as integers/decimals digits", () => {
|
|
6
|
+
const widgetFactory = new WidgetFactory();
|
|
7
|
+
const props = {
|
|
8
|
+
name: "float",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const widget: Float = widgetFactory.createWidget("float", props);
|
|
12
|
+
|
|
13
|
+
expect(widget.integerDigits).toBe(16);
|
|
14
|
+
expect(widget.decimalDigits).toBe(2);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should be able to parse digits (integer/decimals dimensions)", () => {
|
|
18
|
+
const widgetFactory = new WidgetFactory();
|
|
19
|
+
const props = {
|
|
20
|
+
name: "float",
|
|
21
|
+
digits: [4,3]
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const widget: Float = widgetFactory.createWidget("float", props);
|
|
25
|
+
|
|
26
|
+
expect(widget.integerDigits).toBe(4);
|
|
27
|
+
expect(widget.decimalDigits).toBe(3);
|
|
28
|
+
});
|
|
29
|
+
});
|