Skip to content

Commit c7cf57f

Browse files
committed
test(widget-plugin-test-utils): add listRefSet function
1 parent dd3d5ce commit c7cf57f

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

packages/shared/widget-plugin-test-utils/__tests__/functions.test.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { listAttr, obj, ref, refSet, list, listAction, listRef } from "../src/main";
1+
import { listAttr, obj, ref, refSet, list, listAction, listRef, listRefSet } from "../src/main";
22

33
describe("prop mocking functions", () => {
44
describe("list", () => {
@@ -102,9 +102,10 @@ describe("prop mocking functions", () => {
102102
it("returns ListReferenceValue mock", () => {
103103
const prop = listRef();
104104
expect(prop).toMatchObject({
105+
type: "Reference",
105106
filterable: true,
106107
id: expect.stringMatching(/listRef_.+/),
107-
get: expect.any(jest.fn.constructor)
108+
get: expect.any(Function)
108109
});
109110
expect(jest.isMockFunction(prop.get)).toBe(true);
110111
expect(prop.get(obj())).toMatchObject({
@@ -117,6 +118,23 @@ describe("prop mocking functions", () => {
117118
});
118119

119120
describe("listRefSet", () => {
120-
it.todo("returns ListReferenceSetValue mock");
121+
it("returns ListReferenceSetValue mock", () => {
122+
const prop = listRefSet();
123+
expect(prop).toMatchObject({
124+
type: "ReferenceSet",
125+
filterable: true,
126+
id: expect.stringMatching(/listRefSet_.+/),
127+
get: expect.any(Function)
128+
});
129+
expect(jest.isMockFunction(prop.get)).toBe(true);
130+
expect(prop.get(obj())).toMatchObject({
131+
status: expect.any(String),
132+
value: [
133+
{
134+
id: expect.stringMatching(/obj_.+/)
135+
}
136+
]
137+
});
138+
});
121139
});
122140
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ListReferenceSetValue } from "mendix";
2+
import { ListReferenceSetValueBuilder } from "../builders/ListReferenceSetValueBuilder";
3+
4+
/**
5+
* Short function to mock ListReferenceSetValue.
6+
* @param factory - optional factory function which takes
7+
* ListReferenceSetValueBuilder as first argument and returns new ReferenceValue.
8+
*/
9+
export function listRefSet(
10+
factory?: (builder: ListReferenceSetValueBuilder) => ListReferenceSetValue
11+
): ListReferenceSetValue {
12+
factory ??= builder => builder.build();
13+
return factory(new ListReferenceSetValueBuilder());
14+
}

packages/shared/widget-plugin-test-utils/src/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export * from "./functions/listAction.js";
1010
export * from "./functions/listAttr.js";
1111
export * from "./functions/listExp.js";
1212
export * from "./functions/listRef.js";
13+
export * from "./functions/listRefSet.js";
1314
export * from "./functions/listWidget.js";
1415
export * from "./functions/ref.js";
1516
export * from "./functions/refSet.js";

0 commit comments

Comments
 (0)