Skip to content

Commit aad4eb1

Browse files
committed
feat(widget-plugin-test-utils): rename functions
1 parent aaf79e6 commit aad4eb1

File tree

11 files changed

+84
-39
lines changed

11 files changed

+84
-39
lines changed

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

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
import { listAttr, obj, ref, refSet, list, listAction, listRef, listRefSet, objArray, cases } from "../src/main";
1+
import {
2+
listAttribute,
3+
obj,
4+
reference,
5+
referenceSet,
6+
list,
7+
listAction,
8+
listReference,
9+
listReferenceSet,
10+
objArray,
11+
cases
12+
} from "../src/main";
213

314
describe("prop mocking functions", () => {
415
describe("list", () => {
@@ -26,15 +37,15 @@ describe("prop mocking functions", () => {
2637
});
2738
});
2839

29-
describe("listAttr", () => {
40+
describe("listAttribute", () => {
3041
it("returns ListAttributeValue mock", () => {
3142
const t: Date = new Date("2024-09-01T00:00:00.000Z");
32-
const attr = listAttr(() => new Date(t));
43+
const attr = listAttribute(() => new Date(t));
3344
expect(attr.get(obj()).value!).toEqual(t);
3445
});
3546
});
3647

37-
describe("listExp", () => {
48+
describe("listExpression", () => {
3849
it.todo("returns ListExpressionValue mock");
3950
});
4051

@@ -44,7 +55,7 @@ describe("prop mocking functions", () => {
4455

4556
describe("ref", () => {
4657
it("returns ReferenceValue mock with undefined value", () => {
47-
const ref1 = ref();
58+
const ref1 = reference();
4859
expect(ref1).toMatchObject({
4960
readOnly: false,
5061
status: "available",
@@ -57,7 +68,7 @@ describe("prop mocking functions", () => {
5768
});
5869

5970
it("take factory as first argument", () => {
60-
const ref1 = ref(builder => builder.withValue(obj("0")).isLoading().build());
71+
const ref1 = reference(builder => builder.withValue(obj("0")).isLoading().build());
6172
expect(ref1).toMatchObject({
6273
readOnly: true,
6374
status: "loading",
@@ -70,7 +81,7 @@ describe("prop mocking functions", () => {
7081

7182
describe("refSet", () => {
7283
it("returns ReferenceSetValue mock with undefined value", () => {
73-
const ref1 = refSet();
84+
const ref1 = referenceSet();
7485
expect(ref1).toMatchObject({
7586
readOnly: false,
7687
status: "available",
@@ -83,7 +94,7 @@ describe("prop mocking functions", () => {
8394
});
8495

8596
it("take factory as first argument", () => {
86-
const ref1 = refSet(builder =>
97+
const ref1 = referenceSet(builder =>
8798
builder
8899
.withValue([obj("0")])
89100
.isLoading()
@@ -99,17 +110,17 @@ describe("prop mocking functions", () => {
99110
});
100111

101112
it("returns mock with working setValue", () => {
102-
const ref1 = refSet();
113+
const ref1 = referenceSet();
103114
ref1.setValue([obj("007")]);
104115
expect(ref1.value).toEqual([obj("007")]);
105116
ref1.setValue([obj("939")]);
106117
expect(ref1.value).toEqual([obj("939")]);
107118
});
108119
});
109120

110-
describe("listRef", () => {
121+
describe("listReference", () => {
111122
it("returns ListReferenceValue mock", () => {
112-
const prop = listRef();
123+
const prop = listReference();
113124
expect(prop).toMatchObject({
114125
type: "Reference",
115126
filterable: true,
@@ -126,9 +137,9 @@ describe("prop mocking functions", () => {
126137
});
127138
});
128139

129-
describe("listRefSet", () => {
140+
describe("listReferenceSet", () => {
130141
it("returns ListReferenceSetValue mock", () => {
131-
const prop = listRefSet();
142+
const prop = listReferenceSet();
132143
expect(prop).toMatchObject({
133144
type: "ReferenceSet",
134145
filterable: true,
@@ -171,7 +182,7 @@ describe("prop mocking functions", () => {
171182
const mapFn = cases([a, "Alice"], [b, "Bob"], [c, "Chuck"], [undefined, "None"]);
172183
const props = {
173184
datasource: list(items),
174-
name: listAttr(mapFn)
185+
name: listAttribute(mapFn)
175186
};
176187

177188
expect(props.datasource.items?.map(item => props.name.get(item).value)).toEqual([

Diff for: packages/shared/widget-plugin-test-utils/src/functions/list.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { ListValue, ObjectItem } from "mendix";
22
import { ListValueBuilder } from "../builders/ListValueBuilder";
33

4+
/**
5+
* Returns `ListValue` mock.
6+
* @param arg - ether `number` or array of `ObjectItem`.
7+
* If number is given, fill `.items` with mock obj array. Array size depends on the number.
8+
*/
49
export function list(arg: number | ObjectItem[]): ListValue {
510
let builder = new ListValueBuilder();
611
if (Array.isArray(arg)) {
@@ -10,3 +15,8 @@ export function list(arg: number | ObjectItem[]): ListValue {
1015
}
1116
return builder.build();
1217
}
18+
19+
/**
20+
* Returns `ListValue` with loading status.
21+
*/
22+
list.loading = () => new ListValueBuilder().isLoading().build();

Diff for: packages/shared/widget-plugin-test-utils/src/functions/listAttr.ts renamed to packages/shared/widget-plugin-test-utils/src/functions/listAttribute.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@ import { ListAttributeValue, ObjectItem } from "mendix";
22
import { ListAttributeValueBuilder } from "../builders/ListAttributeValueBuilder";
33
import { editable } from "../primitives/editable";
44

5-
export function listAttr<T extends string | boolean | Date | Big>(get: (item: ObjectItem) => T): ListAttributeValue<T> {
5+
/**
6+
* Returns `ListAttributeValue` mock.
7+
* @param get - function to use as `.get`. Should map item to value.
8+
*/
9+
export function listAttribute<T extends string | boolean | Date | Big>(
10+
get: (item: ObjectItem) => T
11+
): ListAttributeValue<T> {
612
const attr = new ListAttributeValueBuilder<T>().build();
713
attr.get = jest.fn((item: ObjectItem) => editable<T>(b => b.withValue(get(item)).isReadOnly().build()));
814
return attr;
915
}
16+
17+
/** @deprecated Renamed to `listAttribute`. */
18+
export const listAttr = listAttribute;

Diff for: packages/shared/widget-plugin-test-utils/src/functions/listExp.ts

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ListExpressionValue, ObjectItem } from "mendix";
2+
import { dynamic } from "../primitives/dynamic";
3+
4+
/**
5+
* Returns `ListExpressionValue` mock.
6+
* @param get - function to use as `.get`. Should map item to value.
7+
*/
8+
export function listExpression<T extends string | boolean | Date | Big>(
9+
get: (item: ObjectItem) => T
10+
): ListExpressionValue<T> {
11+
return { get: (item: ObjectItem) => dynamic<T>(get(item)) };
12+
}
13+
14+
/** @deprecated Renamed to `listExpression` */
15+
export const listExp = listExpression;

Diff for: packages/shared/widget-plugin-test-utils/src/functions/listRef.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { ListReferenceValue } from "mendix";
22
import { ListReferenceValueBuilder } from "../builders/ListReferenceValueBuilder";
33

44
/**
5-
* Short function to mock ListReferenceValue.
5+
* Short function to mock `ListReferenceValue`.
66
* @param factory - optional factory function which takes
7-
* ListReferenceValueBuilder as first argument and returns new ReferenceValue.
7+
* ListReferenceValueBuilder as first argument and returns new `ListReferenceValue`.
88
*/
9-
export function listRef(factory?: (builder: ListReferenceValueBuilder) => ListReferenceValue): ListReferenceValue {
9+
export function listReference(
10+
factory?: (builder: ListReferenceValueBuilder) => ListReferenceValue
11+
): ListReferenceValue {
1012
factory ??= builder => builder.build();
1113
return factory(new ListReferenceValueBuilder());
1214
}

Diff for: packages/shared/widget-plugin-test-utils/src/functions/listRefSet.ts renamed to packages/shared/widget-plugin-test-utils/src/functions/listReferenceSet.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { ListReferenceSetValue } from "mendix";
22
import { ListReferenceSetValueBuilder } from "../builders/ListReferenceSetValueBuilder";
33

44
/**
5-
* Short function to mock ListReferenceSetValue.
5+
* Short function to mock `ListReferenceSetValue`.
66
* @param factory - optional factory function which takes
7-
* ListReferenceSetValueBuilder as first argument and returns new ReferenceValue.
7+
* ListReferenceSetValueBuilder as first argument and returns new `ListReferenceSetValue`.
88
*/
9-
export function listRefSet(
9+
export function listReferenceSet(
1010
factory?: (builder: ListReferenceSetValueBuilder) => ListReferenceSetValue
1111
): ListReferenceSetValue {
1212
factory ??= builder => builder.build();
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { ListWidgetValue, ObjectItem } from "mendix";
22

3+
/**
4+
* Returns `ListWidgetValue` mock.
5+
* @param get - function to use as `.get`. Should map item to React node.
6+
*/
37
export function listWidget(get: (item: ObjectItem) => React.ReactNode): ListWidgetValue {
4-
return { get } as unknown as ListWidgetValue;
8+
return { get } as ListWidgetValue;
59
}

Diff for: packages/shared/widget-plugin-test-utils/src/functions/ref.ts renamed to packages/shared/widget-plugin-test-utils/src/functions/reference.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { ReferenceValue } from "mendix";
22
import { ReferenceValueBuilder } from "../builders/ReferenceValueBuilder";
33

44
/**
5-
* Short function to mock ReferenceValue.
5+
* Short function to mock `ReferenceValue`.
66
* @param factory - optional factory function which takes
7-
* ReferenceValueBuilder as first argument and returns new ReferenceValue.
7+
* ReferenceValueBuilder as first argument and returns new `ReferenceValue`.
88
*/
9-
export function ref(factory?: (builder: ReferenceValueBuilder) => ReferenceValue): ReferenceValue {
9+
export function reference(factory?: (builder: ReferenceValueBuilder) => ReferenceValue): ReferenceValue {
1010
factory ??= builder => builder.build();
1111
return factory(new ReferenceValueBuilder());
1212
}

Diff for: packages/shared/widget-plugin-test-utils/src/functions/refSet.ts renamed to packages/shared/widget-plugin-test-utils/src/functions/referenceSet.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { ReferenceSetValue } from "mendix";
22
import { ReferenceSetValueBuilder } from "../builders/ReferenceSetValueBuilder";
33

44
/**
5-
* Short function to mock ReferenceSetValue.
5+
* Short function to mock `ReferenceSetValue`.
66
* @param factory - optional factory function which takes
7-
* ReferenceSetValueBuilder as first argument and returns new ReferenceValue.
7+
* ReferenceSetValueBuilder as first argument and returns new `ReferenceSetValue`.
88
*/
9-
export function refSet(factory?: (builder: ReferenceSetValueBuilder) => ReferenceSetValue): ReferenceSetValue {
9+
export function referenceSet(factory?: (builder: ReferenceSetValueBuilder) => ReferenceSetValue): ReferenceSetValue {
1010
factory ??= builder => builder.build();
1111
return factory(new ReferenceSetValueBuilder());
1212
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ export * from "./builders/SelectionMultiValueBuilder.js";
88
export * from "./functions/cases.js";
99
export * from "./functions/list.js";
1010
export * from "./functions/listAction.js";
11-
export * from "./functions/listAttr.js";
12-
export * from "./functions/listExp.js";
11+
export * from "./functions/listAttribute.js";
12+
export * from "./functions/listExpression.js";
1313
export * from "./functions/listRef.js";
14-
export * from "./functions/listRefSet.js";
14+
export * from "./functions/listReferenceSet.js";
1515
export * from "./functions/listWidget.js";
16-
export * from "./functions/ref.js";
17-
export * from "./functions/refSet.js";
16+
export * from "./functions/reference.js";
17+
export * from "./functions/referenceSet.js";
1818
export * from "./primitives/action.js";
1919
export * from "./primitives/attrId.js";
2020
export * from "./primitives/dynamic.js";

0 commit comments

Comments
 (0)