Skip to content

Commit 1ecf75b

Browse files
committed
Add unit tests
1 parent 3959256 commit 1ecf75b

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed

packages/pluggable-widgets-tools/src/typings-generator/__tests__/index.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import { associationMetaDataNativeInput, associationMetaDataWebInput } from "./i
4545
import { associationMetaDataNativeOutput, associationMetaDataWebOutput } from "./outputs/metadata-association";
4646
import {listActionWithVariablesInput, listActionWithVariablesInputNative} from "./inputs/list-action-with-variables";
4747
import {listActionWithVariablesOutput, listActionWithVariablesOutputNative} from "./outputs/list-action-with-variables";
48+
import {imageWebInput, imageNativeInput} from "./inputs/image";
49+
import {imageWebOutput, imageNativeOutput} from "./outputs/image";
4850

4951
describe("Generating tests", () => {
5052
it("Generates a parsed typing from XML for native", () => {
@@ -236,6 +238,16 @@ describe("Generating tests", () => {
236238
const newContent = generateNativeTypesFor(associationMetaDataNativeInput);
237239
expect(newContent).toBe(associationMetaDataNativeOutput);
238240
});
241+
242+
it("Generates a parsed typing from XML for web using images", () => {
243+
const newContent = generateFullTypesFor(imageWebInput);
244+
expect(newContent).toBe(imageWebOutput);
245+
});
246+
247+
it("Generates a parsed typing from XML for native using images", () => {
248+
const newContent = generateNativeTypesFor(imageNativeInput);
249+
expect(newContent).toBe(imageNativeOutput);
250+
});
239251
});
240252

241253
function generateFullTypesFor(xml: string) {

packages/pluggable-widgets-tools/src/typings-generator/__tests__/inputs/file.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export const fileInput = `<?xml version="1.0" encoding="utf-8"?>
1212
<caption>File 2</caption>
1313
<description />
1414
</property>
15+
<property key="file3" type="file" allowUpload="true">
16+
<caption>File 3</caption>
17+
<description />
18+
</property>
1519
</propertyGroup>
1620
<propertyGroup caption="Actions">
1721
<property key="description" type="attribute">
@@ -49,6 +53,10 @@ export const fileInputNative = `<?xml version="1.0" encoding="utf-8"?>
4953
<caption>File 2</caption>
5054
<description />
5155
</property>
56+
<property key="file3" type="file" allowUpload="true">
57+
<caption>File 3</caption>
58+
<description />
59+
</property>
5260
</propertyGroup>
5361
<propertyGroup caption="Actions">
5462
<property key="description" type="attribute">
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
export const imageWebInput = `<?xml version="1.0" encoding="utf-8"?>
2+
<widget id="mendix.mywidget.MyWidget" needsEntityContext="true" offlineCapable="true" pluginWidget="true"
3+
xmlns="http://www.mendix.com/widget/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.mendix.com/widget/1.0/ ../xsd/widget.xsd">
5+
<properties>
6+
<propertyGroup caption="General">
7+
<property key="image" type="image">
8+
<caption>Image</caption>
9+
<description />
10+
</property>
11+
<property key="image2" type="image" required="false">
12+
<caption>Image 2</caption>
13+
<description />
14+
</property>
15+
<property key="image3" type="image" allowUpload="true">
16+
<caption>Image 3</caption>
17+
<description />
18+
</property>
19+
</propertyGroup>
20+
<propertyGroup caption="Actions">
21+
<property key="description" type="attribute">
22+
<caption>Action</caption>
23+
<description />
24+
<attributeTypes>
25+
<attributeType name="String"/>
26+
</attributeTypes>
27+
</property>
28+
<property key="action" type="action">
29+
<caption>Action</caption>
30+
<description />
31+
</property>
32+
</propertyGroup>
33+
<propertyGroup caption="Other">
34+
<propertyGroup caption="System Properties">
35+
<systemProperty key="Label"></systemProperty>
36+
<systemProperty key="TabIndex"></systemProperty>
37+
</propertyGroup>
38+
</propertyGroup>
39+
</properties>
40+
</widget>`;
41+
42+
export const imageNativeInput = `<?xml version="1.0" encoding="utf-8"?>
43+
<widget id="mendix.mywidget.MyWidget" needsEntityContext="true" offlineCapable="true" pluginWidget="true" supportedPlatform="Native"
44+
xmlns="http://www.mendix.com/widget/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
45+
xsi:schemaLocation="http://www.mendix.com/widget/1.0/ ../xsd/widget.xsd">
46+
<properties>
47+
<propertyGroup caption="General">
48+
<property key="image" type="image">
49+
<caption>Image</caption>
50+
<description />
51+
</property>
52+
<property key="image2" type="image" required="false">
53+
<caption>Image 2</caption>
54+
<description />
55+
</property>
56+
<property key="image3" type="image" allowUpload="true">
57+
<caption>Image 3</caption>
58+
<description />
59+
</property>
60+
</propertyGroup>
61+
<propertyGroup caption="Actions">
62+
<property key="description" type="attribute">
63+
<caption>Action</caption>
64+
<description />
65+
<attributeTypes>
66+
<attributeType name="String"/>
67+
</attributeTypes>
68+
</property>
69+
<property key="action" type="action">
70+
<caption>Action</caption>
71+
<description />
72+
</property>
73+
</propertyGroup>
74+
<propertyGroup caption="Other">
75+
<propertyGroup caption="System Properties">
76+
<systemProperty key="Label"></systemProperty>
77+
<systemProperty key="TabIndex"></systemProperty>
78+
</propertyGroup>
79+
</propertyGroup>
80+
</properties>
81+
</widget>`;

packages/pluggable-widgets-tools/src/typings-generator/__tests__/outputs/file.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface MyWidgetContainerProps {
1111
id: string;
1212
file: DynamicValue<FileValue>;
1313
file2?: DynamicValue<FileValue>;
14+
file3: EditableFileValue<FileValue>;
1415
description: EditableValue<string>;
1516
action?: ActionValue;
1617
}
@@ -21,6 +22,7 @@ export interface MyWidgetPreviewProps {
2122
translate: (text: string) => string;
2223
file: string;
2324
file2: string;
25+
file3: string;
2426
description: string;
2527
action: {} | null;
2628
}
@@ -30,6 +32,7 @@ export const fileNativeOutput = `export interface MyWidgetProps<Style> {
3032
style: Style[];
3133
file: DynamicValue<FileValue>;
3234
file2?: DynamicValue<FileValue>;
35+
file3: EditableFileValue<FileValue>;
3336
description: EditableValue<string>;
3437
action?: ActionValue;
3538
}`;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
export const imageWebOutput = `/**
2+
* This file was generated from MyWidget.xml
3+
* WARNING: All changes made to this file will be overwritten
4+
* @author Mendix Widgets Framework Team
5+
*/
6+
import { ActionValue, DynamicValue, EditableValue, FileValue } from "mendix";
7+
8+
export interface MyWidgetContainerProps {
9+
name: string;
10+
tabIndex?: number;
11+
id: string;
12+
image: DynamicValue<WebImage>;
13+
image2?: DynamicValue<WebImage>;
14+
image3: EditableImageValue<WebImage>;
15+
description: EditableValue<string>;
16+
action?: ActionValue;
17+
}
18+
19+
export interface MyWidgetPreviewProps {
20+
readOnly: boolean;
21+
renderMode: "design" | "xray" | "structure";
22+
translate: (text: string) => string;
23+
image: { type: "static"; imageUrl: string; } | { type: "dynamic"; entity: string; } | null;
24+
image2?: { type: "static"; imageUrl: string; } | { type: "dynamic"; entity: string; } | null;
25+
image3: { type: "static"; imageUrl: string; } | { type: "dynamic"; entity: string; } | null;
26+
description: string;
27+
action: {} | null;
28+
}
29+
`;
30+
export const imageNativeOutput = `export interface MyWidgetProps<Style> {
31+
name: string;
32+
style: Style[];
33+
image: DynamicValue<NativeImage>;
34+
image2?: DynamicValue<NativeImage>;
35+
image3: EditableImageValue<NativeImage>;
36+
description: EditableValue<string>;
37+
action?: ActionValue;
38+
}`;

0 commit comments

Comments
 (0)