@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,52 @@
|
|
|
1
|
+
import WidgetFactory from "../WidgetFactory";
|
|
2
|
+
|
|
3
|
+
describe("A Selection", () => {
|
|
4
|
+
it("should have an id corresponding to field name", () => {
|
|
5
|
+
const widgetFactory = new WidgetFactory();
|
|
6
|
+
const props = {
|
|
7
|
+
name: "selection1",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const widget = widgetFactory.createWidget("selection", props);
|
|
11
|
+
|
|
12
|
+
expect(widget.id).toBe("selection1");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should properly set label", () => {
|
|
16
|
+
const widgetFactory = new WidgetFactory();
|
|
17
|
+
const props = {
|
|
18
|
+
name: "selection1",
|
|
19
|
+
string: "Language",
|
|
20
|
+
};
|
|
21
|
+
const widget = widgetFactory.createWidget("selection", props);
|
|
22
|
+
|
|
23
|
+
expect(widget.label).toBe("Language");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should properly set size", () => {
|
|
27
|
+
const widgetFactory = new WidgetFactory();
|
|
28
|
+
const props = {
|
|
29
|
+
name: "selection1",
|
|
30
|
+
size: 5,
|
|
31
|
+
};
|
|
32
|
+
const widget = widgetFactory.createWidget("selection", props);
|
|
33
|
+
|
|
34
|
+
expect(widget.size).toBe(5);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should parse selection values", () => {
|
|
38
|
+
const widgetFactory = new WidgetFactory();
|
|
39
|
+
const props = {
|
|
40
|
+
name: "selection1",
|
|
41
|
+
selection: [
|
|
42
|
+
["en_US", "English"],
|
|
43
|
+
["ca_ES", "Catalan / Català"],
|
|
44
|
+
["es_ES", "Spanish / Español"],
|
|
45
|
+
["", ""],
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
const widget = widgetFactory.createWidget("selection", props);
|
|
49
|
+
|
|
50
|
+
expect(widget.selectionValues.size).toBe(4);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import WidgetFactory from "../WidgetFactory";
|
|
2
|
+
|
|
3
|
+
describe("A Separator", () => {
|
|
4
|
+
it("should have an id corresponding to field name", () => {
|
|
5
|
+
const widgetFactory = new WidgetFactory();
|
|
6
|
+
const props = {
|
|
7
|
+
string: "Text",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const widget = widgetFactory.createWidget("separator", props);
|
|
11
|
+
|
|
12
|
+
expect(widget.label).toBe("Text");
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import Tree from "../Tree";
|
|
2
|
+
import Char from "../Char";
|
|
3
|
+
|
|
4
|
+
const XML_VIEW_TREE = `<tree string="Partners">
|
|
5
|
+
<field name="name"/>
|
|
6
|
+
<field name="title"/>
|
|
7
|
+
<field name="ref"/>
|
|
8
|
+
<field name="city" select="2"/>
|
|
9
|
+
<field name="country" select="2"/>
|
|
10
|
+
<field name="lang"/>
|
|
11
|
+
</tree>
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
const FIELDS = {
|
|
15
|
+
city: {
|
|
16
|
+
digits: [16, 2],
|
|
17
|
+
string: "City",
|
|
18
|
+
type: "char",
|
|
19
|
+
views: {},
|
|
20
|
+
},
|
|
21
|
+
country: {
|
|
22
|
+
context: "",
|
|
23
|
+
digits: [16, 2],
|
|
24
|
+
domain: [],
|
|
25
|
+
relation: "res.country",
|
|
26
|
+
string: "Country",
|
|
27
|
+
type: "many2one",
|
|
28
|
+
views: {},
|
|
29
|
+
},
|
|
30
|
+
lang: {
|
|
31
|
+
help:
|
|
32
|
+
"If the selected language is loaded in the system, all documents related to this partner will be printed in this language. If not, it will be english.",
|
|
33
|
+
selection: [
|
|
34
|
+
["en_US", "English"],
|
|
35
|
+
["ca_ES", "Catalan / Català"],
|
|
36
|
+
["es_ES", "Spanish / Español"],
|
|
37
|
+
["", ""],
|
|
38
|
+
],
|
|
39
|
+
size: 5,
|
|
40
|
+
string: "Language",
|
|
41
|
+
type: "selection",
|
|
42
|
+
views: {},
|
|
43
|
+
},
|
|
44
|
+
name: {
|
|
45
|
+
required: true,
|
|
46
|
+
select: true,
|
|
47
|
+
size: 128,
|
|
48
|
+
string: "Name",
|
|
49
|
+
type: "char",
|
|
50
|
+
views: {},
|
|
51
|
+
},
|
|
52
|
+
ref: {
|
|
53
|
+
select: true,
|
|
54
|
+
size: 64,
|
|
55
|
+
string: "Code",
|
|
56
|
+
type: "char",
|
|
57
|
+
views: {},
|
|
58
|
+
},
|
|
59
|
+
title: {
|
|
60
|
+
selection: [
|
|
61
|
+
["Corp.", "Corp."],
|
|
62
|
+
["ltd", "Ltd"],
|
|
63
|
+
["", ""],
|
|
64
|
+
],
|
|
65
|
+
size: 32,
|
|
66
|
+
string: "Title",
|
|
67
|
+
type: "selection",
|
|
68
|
+
views: {},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
describe("A Tree", () => {
|
|
72
|
+
it("should parse xml", () => {
|
|
73
|
+
const tree = new Tree(FIELDS);
|
|
74
|
+
tree.parse(XML_VIEW_TREE);
|
|
75
|
+
|
|
76
|
+
expect(tree.fields).toBeDefined();
|
|
77
|
+
expect(tree.columns.length).toBe(6);
|
|
78
|
+
const nameWidget = tree.findById("name") as Char;
|
|
79
|
+
expect(nameWidget.label).toBe("Name");
|
|
80
|
+
});
|
|
81
|
+
it("Must throw an error if a field isn't present in field definitions", () => {
|
|
82
|
+
const parseInvalidTree = () => {
|
|
83
|
+
const tree = new Tree({});
|
|
84
|
+
tree.parse(`<tree string="Partners"><field name="name"/></tree>`);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
expect(parseInvalidTree).toThrow(
|
|
88
|
+
"Field name doesn't exist in fields defintion"
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("Should parse tree string title properly", () => {
|
|
93
|
+
const tree = new Tree({
|
|
94
|
+
name: {
|
|
95
|
+
required: true,
|
|
96
|
+
select: true,
|
|
97
|
+
size: 128,
|
|
98
|
+
string: "Name",
|
|
99
|
+
type: "char",
|
|
100
|
+
views: {},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
tree.parse(`<tree string="Partners"><field name="name"/></tree>`);
|
|
104
|
+
const treeTitle = tree.string;
|
|
105
|
+
expect(treeTitle).toBe("Partners");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("Should parse tree string title as null if we don't pass it", () => {
|
|
109
|
+
const tree = new Tree({
|
|
110
|
+
name: {
|
|
111
|
+
required: true,
|
|
112
|
+
select: true,
|
|
113
|
+
size: 128,
|
|
114
|
+
string: "Name",
|
|
115
|
+
type: "char",
|
|
116
|
+
views: {},
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
tree.parse(`<tree><field name="name"/></tree>`);
|
|
120
|
+
const treeTitle = tree.string;
|
|
121
|
+
expect(treeTitle).toBeNull();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("Should be able to retrieve type from Tree instance", () => {
|
|
125
|
+
const tree = new Tree({
|
|
126
|
+
name: {
|
|
127
|
+
required: true,
|
|
128
|
+
select: true,
|
|
129
|
+
size: 128,
|
|
130
|
+
string: "Name",
|
|
131
|
+
type: "char",
|
|
132
|
+
views: {},
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
tree.parse(`<tree><field name="name"/></tree>`);
|
|
136
|
+
expect(tree.type).toBe("tree");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("Must parse colors", () => {
|
|
140
|
+
const tree = new Tree({
|
|
141
|
+
name: {
|
|
142
|
+
required: true,
|
|
143
|
+
select: true,
|
|
144
|
+
size: 128,
|
|
145
|
+
string: "Name",
|
|
146
|
+
type: "char",
|
|
147
|
+
views: {},
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
tree.parse(
|
|
151
|
+
`<tree string="Partners" colors="red:type=='updated'"><field name="name"/></tree>`
|
|
152
|
+
);
|
|
153
|
+
expect(tree.colors!).toBe("red:type=='updated'");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("Must parse sum fields", () => {
|
|
157
|
+
const tree = new Tree({
|
|
158
|
+
name: {
|
|
159
|
+
required: true,
|
|
160
|
+
select: true,
|
|
161
|
+
size: 128,
|
|
162
|
+
string: "Name",
|
|
163
|
+
type: "char",
|
|
164
|
+
views: {},
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
tree.parse(
|
|
168
|
+
`<tree string="Partners" colors="red:type=='updated'"><field name="name" sum="Name" /></tree>`
|
|
169
|
+
);
|
|
170
|
+
const nameWidget = tree.findById("name") as Char;
|
|
171
|
+
expect(nameWidget.sum).toBe("Name");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("Must ignore invisible fields as columns", () => {
|
|
175
|
+
const tree = new Tree({
|
|
176
|
+
name: {
|
|
177
|
+
required: true,
|
|
178
|
+
select: true,
|
|
179
|
+
size: 128,
|
|
180
|
+
string: "Name",
|
|
181
|
+
type: "char",
|
|
182
|
+
views: {},
|
|
183
|
+
},
|
|
184
|
+
surnames: {
|
|
185
|
+
required: true,
|
|
186
|
+
select: true,
|
|
187
|
+
size: 128,
|
|
188
|
+
string: "Surnames",
|
|
189
|
+
type: "char",
|
|
190
|
+
views: {},
|
|
191
|
+
invisible: true,
|
|
192
|
+
},
|
|
193
|
+
city: {
|
|
194
|
+
required: true,
|
|
195
|
+
select: true,
|
|
196
|
+
size: 128,
|
|
197
|
+
string: "City",
|
|
198
|
+
type: "char",
|
|
199
|
+
views: {},
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
tree.parse(
|
|
203
|
+
`<tree string="Partners" colors="red:type=='updated'"><field name="name" sum="Name" invisible="1" /><field name="surnames" sum="Surnames" /><field name="city" sum="City" /></tree>`
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
const nameWidget = tree.findById("name") as Char;
|
|
207
|
+
const surnamesWidget = tree.findById("surnames") as Char;
|
|
208
|
+
const cityWidget = tree.findById("city") as Char;
|
|
209
|
+
|
|
210
|
+
expect(nameWidget).toBeUndefined();
|
|
211
|
+
expect(surnamesWidget).toBeUndefined();
|
|
212
|
+
expect(cityWidget!.id).toBe("city");
|
|
213
|
+
});
|
|
214
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Widget from "../Widget";
|
|
2
|
+
import WidgetImpl from "./fixtures/WidgetImpl";
|
|
3
|
+
|
|
4
|
+
describe('A Widget', () => {
|
|
5
|
+
it('should be constructed with a colspan by default', () => {
|
|
6
|
+
const widget = new WidgetImpl();
|
|
7
|
+
|
|
8
|
+
expect(widget.colspan).toBe(Widget.defaultColspan);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should have colspan 1 by default", () => {
|
|
12
|
+
const widget = new WidgetImpl();
|
|
13
|
+
expect(widget.colspan).toBe(1);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should properly set colspan', () => {
|
|
17
|
+
const widget = new WidgetImpl();
|
|
18
|
+
widget.colspan = 3;
|
|
19
|
+
|
|
20
|
+
expect(widget.colspan).toBe(3);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should be readOnly false by default', () => {
|
|
24
|
+
const widget = new WidgetImpl();
|
|
25
|
+
|
|
26
|
+
expect(widget.readOnly).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('colspan should be of type Number', () => {
|
|
30
|
+
const widget = new WidgetImpl();
|
|
31
|
+
|
|
32
|
+
expect(typeof widget.colspan).toBe("number");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/*
|
|
36
|
+
it('set colspan as string should store as a number', () => {
|
|
37
|
+
const widget = new WidgetImpl();
|
|
38
|
+
|
|
39
|
+
widget.colspan = "3";
|
|
40
|
+
|
|
41
|
+
expect(typeof widget.colspan).toBe("number");
|
|
42
|
+
expect(widget.colspan).toBe(3);
|
|
43
|
+
});
|
|
44
|
+
*/
|
|
45
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import Char from "../Char";
|
|
2
|
+
import Button from "../Button";
|
|
3
|
+
import NewLine from "../NewLine";
|
|
4
|
+
import WidgetFactory from "../WidgetFactory";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
describe('A WidgetFactory', () => {
|
|
8
|
+
it('should be able to build a Char widget', () => {
|
|
9
|
+
const widgetFactory = new WidgetFactory();
|
|
10
|
+
const props = {
|
|
11
|
+
name: "char1",
|
|
12
|
+
};
|
|
13
|
+
const widget = widgetFactory.createWidget("char", props);
|
|
14
|
+
expect(widget).toBeInstanceOf(Char);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should be able to build a Button widget', () => {
|
|
18
|
+
const widgetFactory = new WidgetFactory();
|
|
19
|
+
const props = {
|
|
20
|
+
name: "button1"
|
|
21
|
+
};
|
|
22
|
+
const widget = widgetFactory.createWidget("button", props);
|
|
23
|
+
expect(widget).toBeInstanceOf(Button);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should be able to build a Newline widget', () => {
|
|
27
|
+
const widgetFactory = new WidgetFactory();
|
|
28
|
+
const props = {};
|
|
29
|
+
const widget = widgetFactory.createWidget("newline", props);
|
|
30
|
+
expect(widget).toBeInstanceOf(NewLine);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should be able to retrieve widget type', () => {
|
|
34
|
+
const widgetFactory = new WidgetFactory();
|
|
35
|
+
const props = {};
|
|
36
|
+
const widget = widgetFactory.createWidget("newline", props);
|
|
37
|
+
expect(widget).toBeInstanceOf(NewLine);
|
|
38
|
+
expect(widget.type).toBe("newline");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { evaluateAttributes } from "../helpers/attributeParser";
|
|
2
|
+
|
|
3
|
+
const fields = {
|
|
4
|
+
force_potencia_adscrita: {
|
|
5
|
+
type: "boolean",
|
|
6
|
+
},
|
|
7
|
+
per_enviar: {
|
|
8
|
+
type: "char",
|
|
9
|
+
},
|
|
10
|
+
rectificative_type: {
|
|
11
|
+
type: "char",
|
|
12
|
+
},
|
|
13
|
+
in_refund: {
|
|
14
|
+
type: "char",
|
|
15
|
+
},
|
|
16
|
+
check_total: {
|
|
17
|
+
type: "float",
|
|
18
|
+
},
|
|
19
|
+
type: {
|
|
20
|
+
type: "char",
|
|
21
|
+
},
|
|
22
|
+
id: {
|
|
23
|
+
type: "integer",
|
|
24
|
+
},
|
|
25
|
+
link: {
|
|
26
|
+
type: "char",
|
|
27
|
+
},
|
|
28
|
+
change_adm: {
|
|
29
|
+
type: "boolean",
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
describe("An Attribute Parser", () => {
|
|
34
|
+
describe("in evaluateAttributes method", () => {
|
|
35
|
+
it("should properly parse a simple attribute with = operator", () => {
|
|
36
|
+
const tagAttributes = {
|
|
37
|
+
attrs: "{'invisible':[('per_enviar', '=', 'postal')]}",
|
|
38
|
+
};
|
|
39
|
+
const values = {
|
|
40
|
+
per_enviar: "postal",
|
|
41
|
+
};
|
|
42
|
+
const evaluatedAttrs = evaluateAttributes({
|
|
43
|
+
tagAttributes,
|
|
44
|
+
values,
|
|
45
|
+
fields,
|
|
46
|
+
});
|
|
47
|
+
expect(evaluatedAttrs.invisible).toBeTruthy();
|
|
48
|
+
});
|
|
49
|
+
it("should properly parse a simple attribute with == operator and numeric value", () => {
|
|
50
|
+
const tagAttributes = {
|
|
51
|
+
attrs: "{'invisible': [('check_total', '==',0.00)]}",
|
|
52
|
+
};
|
|
53
|
+
const values = {
|
|
54
|
+
check_total: 0.0,
|
|
55
|
+
};
|
|
56
|
+
const evaluatedAttrs = evaluateAttributes({
|
|
57
|
+
tagAttributes,
|
|
58
|
+
values,
|
|
59
|
+
fields,
|
|
60
|
+
});
|
|
61
|
+
expect(evaluatedAttrs.invisible).toBeTruthy();
|
|
62
|
+
});
|
|
63
|
+
it("should properly parse a simple attribute with 'in' operator", () => {
|
|
64
|
+
const tagAttributes = {
|
|
65
|
+
attrs: "{'invisible': [('rectificative_type', 'in', ('N', 'C', 'G'))]}",
|
|
66
|
+
};
|
|
67
|
+
const values = {
|
|
68
|
+
rectificative_type: "G",
|
|
69
|
+
};
|
|
70
|
+
const evaluatedAttrs = evaluateAttributes({
|
|
71
|
+
tagAttributes,
|
|
72
|
+
values,
|
|
73
|
+
fields,
|
|
74
|
+
});
|
|
75
|
+
expect(evaluatedAttrs.invisible).toBeTruthy();
|
|
76
|
+
});
|
|
77
|
+
it("should properly parse a simple attribute with 'not_in' operator", () => {
|
|
78
|
+
const tagAttributes = {
|
|
79
|
+
attrs: "{'invisible': [('type','not in',('in_refund','in_invoice'))]}",
|
|
80
|
+
};
|
|
81
|
+
const values = {
|
|
82
|
+
type: "not_found_type",
|
|
83
|
+
};
|
|
84
|
+
const evaluatedAttrs = evaluateAttributes({
|
|
85
|
+
tagAttributes,
|
|
86
|
+
values,
|
|
87
|
+
fields,
|
|
88
|
+
});
|
|
89
|
+
expect(evaluatedAttrs.invisible).toBeTruthy();
|
|
90
|
+
});
|
|
91
|
+
it("should properly parse a boolean attribute with '=' operator", () => {
|
|
92
|
+
const tagAttributes = {
|
|
93
|
+
attrs: "{'readonly':[('force_potencia_adscrita','=',0)]}",
|
|
94
|
+
};
|
|
95
|
+
const values = {
|
|
96
|
+
force_potencia_adscrita: false,
|
|
97
|
+
};
|
|
98
|
+
const evaluatedAttrs = evaluateAttributes({
|
|
99
|
+
tagAttributes,
|
|
100
|
+
values,
|
|
101
|
+
fields,
|
|
102
|
+
});
|
|
103
|
+
expect(evaluatedAttrs.readonly).toBeTruthy();
|
|
104
|
+
});
|
|
105
|
+
it("should properly parse a boolean attribute with '=' operator", () => {
|
|
106
|
+
const tagAttributes = {
|
|
107
|
+
attrs: "{'readonly':[('force_potencia_adscrita','=',0)]}",
|
|
108
|
+
};
|
|
109
|
+
const values = {
|
|
110
|
+
force_potencia_adscrita: true,
|
|
111
|
+
};
|
|
112
|
+
const evaluatedAttrs = evaluateAttributes({
|
|
113
|
+
tagAttributes,
|
|
114
|
+
values,
|
|
115
|
+
fields,
|
|
116
|
+
});
|
|
117
|
+
expect(evaluatedAttrs.readonly).toBeFalsy();
|
|
118
|
+
});
|
|
119
|
+
it("should properly parse a boolean attribute with '=' operator with True", () => {
|
|
120
|
+
const tagAttributes = {
|
|
121
|
+
attrs: "{'readonly':[('force_potencia_adscrita','=',True)]}",
|
|
122
|
+
};
|
|
123
|
+
const values = {
|
|
124
|
+
force_potencia_adscrita: true,
|
|
125
|
+
};
|
|
126
|
+
const evaluatedAttrs = evaluateAttributes({
|
|
127
|
+
tagAttributes,
|
|
128
|
+
values,
|
|
129
|
+
fields,
|
|
130
|
+
});
|
|
131
|
+
expect(evaluatedAttrs.readonly).toBeTruthy();
|
|
132
|
+
});
|
|
133
|
+
it("should properly parse a boolean attribute with several conditions", () => {
|
|
134
|
+
const tagAttributes = {
|
|
135
|
+
attrs: "{'invisible': [('id', '!=', False), ('link', '!=', False)]}",
|
|
136
|
+
};
|
|
137
|
+
const values = {
|
|
138
|
+
id: 1,
|
|
139
|
+
link: false,
|
|
140
|
+
};
|
|
141
|
+
const evaluatedAttrs = evaluateAttributes({
|
|
142
|
+
tagAttributes,
|
|
143
|
+
values,
|
|
144
|
+
fields,
|
|
145
|
+
});
|
|
146
|
+
expect(evaluatedAttrs.invisible).toBeFalsy();
|
|
147
|
+
});
|
|
148
|
+
it("should properly parse a boolean attribute without value (default false)", () => {
|
|
149
|
+
const tagAttributes = {
|
|
150
|
+
attrs: "{'invisible': [('change_adm', '!=', True)]}",
|
|
151
|
+
};
|
|
152
|
+
const values = {};
|
|
153
|
+
const evaluatedAttrs = evaluateAttributes({
|
|
154
|
+
tagAttributes,
|
|
155
|
+
values,
|
|
156
|
+
fields,
|
|
157
|
+
});
|
|
158
|
+
expect(evaluatedAttrs.invisible).toBeTruthy();
|
|
159
|
+
});
|
|
160
|
+
it("should properly parse a boolean attribute without value (default true)", () => {
|
|
161
|
+
const tagAttributes = {
|
|
162
|
+
attrs: "{'invisible': [('change_adm', '=', False)]}",
|
|
163
|
+
};
|
|
164
|
+
const values = {};
|
|
165
|
+
const evaluatedAttrs = evaluateAttributes({
|
|
166
|
+
tagAttributes,
|
|
167
|
+
values,
|
|
168
|
+
fields,
|
|
169
|
+
});
|
|
170
|
+
expect(evaluatedAttrs.invisible).toBeTruthy();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { parseContext } from "../helpers/contextParser";
|
|
2
|
+
|
|
3
|
+
describe("A Context Parser", () => {
|
|
4
|
+
describe("in parseContext method", () => {
|
|
5
|
+
it("should properly parse a blank context", () => {
|
|
6
|
+
const str = "";
|
|
7
|
+
|
|
8
|
+
const parsedContext = parseContext({ context: str });
|
|
9
|
+
|
|
10
|
+
expect(parsedContext).toBeUndefined();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should properly parse a context", () => {
|
|
14
|
+
const context =
|
|
15
|
+
"{'power': potencia, 'tarifa_id': tarifa, 'o2m': tensio_o2m, 'tensio_id': tensio_normalitzada, 'model': 'giscedata.polissa', 'field': 'potencia'}";
|
|
16
|
+
const values = {
|
|
17
|
+
potencia: 45,
|
|
18
|
+
tarifa: "test",
|
|
19
|
+
tensio_normalitzada: [43, "Test"],
|
|
20
|
+
tensio_o2m: [
|
|
21
|
+
{ operation: "original", id: 1 },
|
|
22
|
+
{ operation: "original", id: 2 },
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
const fields = {
|
|
26
|
+
potencia: {
|
|
27
|
+
type: "float",
|
|
28
|
+
},
|
|
29
|
+
tarifa: {
|
|
30
|
+
type: "char",
|
|
31
|
+
},
|
|
32
|
+
tensio_normalitzada: {
|
|
33
|
+
type: "many2one",
|
|
34
|
+
},
|
|
35
|
+
tensio_o2m: {
|
|
36
|
+
type: "one2many",
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const parsedContext: any = parseContext({ context, values, fields });
|
|
41
|
+
expect(parsedContext!["power"]).toBe(45);
|
|
42
|
+
expect(parsedContext!["tarifa_id"]).toBe("test");
|
|
43
|
+
expect(parsedContext!["tensio_id"]).toBe(43);
|
|
44
|
+
expect(parsedContext!["o2m"][0]).toBe(1);
|
|
45
|
+
expect(parsedContext!["o2m"][1]).toBe(2);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should properly parse a boolean context", () => {
|
|
49
|
+
const str = "{'active_test': False}";
|
|
50
|
+
|
|
51
|
+
const parsedContext = parseContext({ context: str });
|
|
52
|
+
|
|
53
|
+
expect(parsedContext!["active_test"]).toBeDefined();
|
|
54
|
+
expect(parsedContext!["active_test"]).toBeFalsy();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { transformDomainForChildWidget } from "../helpers/domainParser";
|
|
2
|
+
|
|
3
|
+
describe("A Domain Parser", () => {
|
|
4
|
+
it("should properly transform domain for inner widgets", () => {
|
|
5
|
+
const prevDomain = [
|
|
6
|
+
["project_id", "=", 62],
|
|
7
|
+
["foo", "=", "bar"],
|
|
8
|
+
["stage_id.name.process", "ilike", "backlog"],
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
const fields = {
|
|
12
|
+
project_id: {
|
|
13
|
+
type: "numeric",
|
|
14
|
+
},
|
|
15
|
+
stage_id: {
|
|
16
|
+
type: "numeric",
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const domainForProjectId = transformDomainForChildWidget({
|
|
21
|
+
domain: prevDomain,
|
|
22
|
+
widgetFieldName: "project_id",
|
|
23
|
+
}) as any;
|
|
24
|
+
|
|
25
|
+
expect(domainForProjectId!.length).toBe(1);
|
|
26
|
+
expect(domainForProjectId![0][0]).toBe("id");
|
|
27
|
+
expect(domainForProjectId![0][1]).toBe("=");
|
|
28
|
+
expect(domainForProjectId![0][2]).toBe(62);
|
|
29
|
+
|
|
30
|
+
const domainForStageId = transformDomainForChildWidget({
|
|
31
|
+
domain: prevDomain,
|
|
32
|
+
widgetFieldName: "stage_id",
|
|
33
|
+
}) as any;
|
|
34
|
+
|
|
35
|
+
expect(domainForStageId!.length).toBe(1);
|
|
36
|
+
expect(domainForStageId![0][0]).toBe("name.process");
|
|
37
|
+
expect(domainForStageId![0][1]).toBe("ilike");
|
|
38
|
+
expect(domainForStageId![0][2]).toBe("backlog");
|
|
39
|
+
});
|
|
40
|
+
});
|