Skip to content

Commit f41a4b6

Browse files
author
Srirang Kalantri
committed
fix: fix unit test for switch widget
1 parent 137be4e commit f41a4b6

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

packages/pluggableWidgets/switch-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "switch-native",
33
"widgetName": "Switch",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"license": "Apache-2.0",
66
"repository": {
77
"type": "git",

packages/pluggableWidgets/switch-native/src/Switch.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export function Switch(props: Props): ReactElement {
7676
// Horizontal layout: label and switch in a row, validation message below
7777
<>
7878
<View
79+
testID={`${name}$horizontalContainer`}
7980
style={{
8081
flexDirection: "row",
8182
alignItems: "center",

packages/pluggableWidgets/switch-native/src/__tests__/Switch.spec.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,23 @@ describe("Switch", () => {
5656
expect(screen.getByTestId(`${name}$label`)).toBeTruthy();
5757
});
5858

59-
it("with showLabel true renders label horizontally", () => {
59+
it("with showLabel true and horizontal orientation, renders label and switch in a row", () => {
6060
const props = createProps({
61-
showLabel: true
61+
showLabel: true,
62+
labelOrientation: "horizontal",
63+
label: dynamicValue<string>("Test Label", false)
6264
});
6365

6466
render(<Switch {...props} />);
65-
const wrapper = screen.getByTestId(`${name}$wrapper`);
66-
expect(wrapper.props.style).toEqual(expect.arrayContaining([{ flexDirection: "row", alignItems: "center" }]));
67+
68+
const horizontalContainer = screen.getByTestId(`${name}$horizontalContainer`);
69+
70+
expect(horizontalContainer.props.style).toEqual(
71+
expect.objectContaining({ flexDirection: "row", alignItems: "center" })
72+
);
73+
74+
expect(horizontalContainer).toContainElement(screen.getByTestId(`${name}$label`));
75+
expect(horizontalContainer).toContainElement(screen.getByTestId(name));
6776
});
6877

6978
it("with showLabel true and labelOrientation vertical, renders vertical", () => {
@@ -75,8 +84,9 @@ describe("Switch", () => {
7584
render(<Switch {...props} />);
7685
const wrapper = screen.getByTestId(`${name}$wrapper`);
7786
expect(wrapper.props.style).toEqual(
78-
expect.not.arrayContaining([{ flexDirection: "row", alignItems: "center" }])
87+
expect.arrayContaining([{ flexDirection: "column", alignItems: "flex-start" }])
7988
);
89+
expect(screen.queryByTestId(`${name}$horizontalContainer`)).toBeNull();
8090
});
8191

8292
it("with error renders validation message", () => {

packages/pluggableWidgets/switch-native/src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="Switch" version="1.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="Switch" version="1.1.1" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="Switch.xml" />
66
</widgetFiles>

0 commit comments

Comments
 (0)