Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alihcsumer committed Jun 20, 2024
1 parent 6821de6 commit 1cb33dc
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { expressionInput, expressionInputNative } from "./inputs/expression";
import { expressionWebOutput, expressionNativeOutput } from "./outputs/expression";
import { selectionInput, selectionInputNative } from "./inputs/selection";
import { selectionNativeOutput, selectionWebOutput } from "./outputs/selection";
import { listAttributeNativeInput, listAttributeWebInput } from "./inputs/list-attribute-refset";
import { listAttributeNativeOutput, listAttributeWebOutput } from "./outputs/list-attribute-refset";

describe("Generating tests", () => {
it("Generates a parsed typing from XML for native", () => {
Expand Down Expand Up @@ -170,6 +172,16 @@ describe("Generating tests", () => {
const newContent = generateNativeTypesFor(selectionInputNative);
expect(newContent).toBe(selectionNativeOutput);
});

it("Generates a parsed typing from XML for web using ref sets in linked attribute", () => {
const newContent = generateFullTypesFor(listAttributeWebInput);
expect(newContent).toBe(listAttributeWebOutput);
});

it("Generates a parsed typing from XML for web using ref sets in linked attribute", () => {
const newContent = generateNativeTypesFor(listAttributeNativeInput);
expect(newContent).toBe(listAttributeNativeOutput);
});
});

function generateFullTypesFor(xml: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
export const listAttributeWebInput = `<?xml version="1.0" encoding="utf-8"?>
<widget id="mendix.mywidget.MyWidget" needsEntityContext="true" offlineCapable="true" pluginWidget="true"
xmlns="http://www.mendix.com/widget/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mendix.com/widget/1.0/ ../xsd/widget.xsd">
<properties>
<propertyGroup caption="General">
<property key="dataSource" type="datasource" isList="true" required="false">
<caption>Data source</caption>
<description />
</property>
<property key="referenceDefault" type="attribute" dataSource="dataSource">
<caption>Reference</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
</property>
<property key="reference" type="attribute" dataSource="dataSource">
<caption>Reference</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
<associationTypes>
<associationType name="Reference"/>
</associationTypes>
</property>
<property key="referenceSet" type="attribute" dataSource="dataSource">
<caption>Reference Set</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
<associationTypes>
<associationType name="ReferenceSet"/>
</associationTypes>
</property>
<property key="referenceOrSet" type="attribute" dataSource="dataSource">
<caption>Reference or Set</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
<associationTypes>
<associationType name="Reference"/>
<associationType name="ReferenceSet"/>
</associationTypes>
</property>
</propertyGroup>
</properties>
</widget>`;

export const listAttributeNativeInput = `<?xml version="1.0" encoding="utf-8"?>
<widget id="mendix.mywidget.MyWidget" needsEntityContext="true" offlineCapable="true" pluginWidget="true" supportedPlatform="Native"
xmlns="http://www.mendix.com/widget/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mendix.com/widget/1.0/ ../xsd/widget.xsd">
<properties>
<propertyGroup caption="General">
<property key="dataSource" type="datasource" isList="true" required="false">
<caption>Data source</caption>
<description />
</property>
<property key="referenceDefault" type="attribute" dataSource="dataSource">
<caption>Reference</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
</property>
<property key="reference" type="attribute" dataSource="dataSource">
<caption>Reference</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
<associationTypes>
<associationType name="Reference"/>
</associationTypes>
</property>
<property key="referenceSet" type="attribute" dataSource="dataSource">
<caption>Reference Set</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
<associationTypes>
<associationType name="ReferenceSet"/>
</associationTypes>
</property>
<property key="referenceOrSet" type="attribute" dataSource="dataSource">
<caption>Reference or Set</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
<associationTypes>
<associationType name="Reference"/>
<associationType name="ReferenceSet"/>
</associationTypes>
</property>
</propertyGroup>
</properties>
</widget>`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export const listAttributeWebOutput = `/**
* This file was generated from MyWidget.xml
* WARNING: All changes made to this file will be overwritten
* @author Mendix Widgets Framework Team
*/
import { CSSProperties } from "react";
import { ListValue, ListAttributeValue, ListAttributeListValue } from "mendix";
export interface MyWidgetContainerProps {
name: string;
class: string;
style?: CSSProperties;
tabIndex?: number;
dataSource?: ListValue;
referenceDefault?: ListAttributeValue<string>;
reference?: ListAttributeValue<string>;
referenceSet?: ListAttributeListValue<string>;
referenceOrSet?: ListAttributeValue<string> | ListAttributeListValue<string>;
}
export interface MyWidgetPreviewProps {
/**
* @deprecated Deprecated since version 9.18.0. Please use class property instead.
*/
className: string;
class: string;
style: string;
styleObject?: CSSProperties;
readOnly: boolean;
dataSource: {} | { caption: string } | { type: string } | null;
referenceDefault: string;
reference: string;
referenceSet: string;
referenceOrSet: string;
}
`;

export const listAttributeNativeOutput = `export interface MyWidgetProps<Style> {
name: string;
style: Style[];
dataSource?: ListValue;
referenceDefault?: ListAttributeValue<string>;
reference?: ListAttributeValue<string>;
referenceSet?: ListAttributeListValue<string>;
referenceOrSet?: ListAttributeValue<string> | ListAttributeListValue<string>;
}`;

0 comments on commit 1cb33dc

Please sign in to comment.