Skip to content

Commit

Permalink
Add typings generation tests for non-linked attribute property with r…
Browse files Browse the repository at this point in the history
…eference sets
  • Loading branch information
legio-vi-ferrata committed Jul 3, 2024
1 parent 73b09ed commit 9681bd1
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ 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";
import {
nonLinkedListAttributeNativeInput,
nonLinkedListAttributeWebInput
} from "./inputs/non-linked-list-attribute-refset";
import {
nonLinkedListAttributeNativeOutput,
nonLinkedListAttributeWebOutput
} from "./outputs/non-linked-list-attribute-refset";

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

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

it("Generates a parsed typing from XML for native using ref sets in non-linked attribute", () => {
const newContent = generateNativeTypesFor(nonLinkedListAttributeNativeInput);
expect(newContent).toBe(nonLinkedListAttributeNativeOutput);
});
});

function generateFullTypesFor(xml: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
export const nonLinkedListAttributeWebInput = `<?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="referenceDefault" type="attribute">
<caption>Reference</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
</property>
<property key="reference" type="attribute">
<caption>Reference</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
<associationTypes>
<associationType name="Reference"/>
</associationTypes>
</property>
<property key="referenceSet" type="attribute">
<caption>Reference Set</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
<associationTypes>
<associationType name="ReferenceSet"/>
</associationTypes>
</property>
<property key="referenceOrSet" type="attribute">
<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 nonLinkedListAttributeNativeInput = `<?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="referenceDefault" type="attribute">
<caption>Reference</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
</property>
<property key="reference" type="attribute">
<caption>Reference</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
<associationTypes>
<associationType name="Reference"/>
</associationTypes>
</property>
<property key="referenceSet" type="attribute">
<caption>Reference Set</caption>
<description/>
<attributeTypes>
<attributeType name="String" />
</attributeTypes>
<associationTypes>
<associationType name="ReferenceSet"/>
</associationTypes>
</property>
<property key="referenceOrSet" type="attribute">
<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,43 @@
export const nonLinkedListAttributeWebOutput = `/**
* 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 { EditableValue, EditableListValue } from "mendix";
export interface MyWidgetContainerProps {
name: string;
class: string;
style?: CSSProperties;
tabIndex?: number;
referenceDefault: EditableValue<string>;
reference: EditableValue<string>;
referenceSet: EditableListValue<string>;
referenceOrSet: EditableValue<string> | EditableListValue<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;
referenceDefault: string;
reference: string;
referenceSet: string;
referenceOrSet: string;
}
`;

export const nonLinkedListAttributeNativeOutput = `export interface MyWidgetProps<Style> {
name: string;
style: Style[];
referenceDefault: EditableValue<string>;
reference: EditableValue<string>;
referenceSet: EditableListValue<string>;
referenceOrSet: EditableValue<string> | EditableListValue<string>;
}`;

0 comments on commit 9681bd1

Please sign in to comment.