@ohos-ports/focuson-lenstest 1.44.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/src/DataDrivenFixedOptionDropDownAndDetails.spec.d.ts +1 -0
- package/dist/src/DataDrivenFixedOptionDropDownAndDetails.spec.js +70 -0
- package/dist/src/DatePicker.spec.d.ts +1 -0
- package/dist/src/DatePicker.spec.js +315 -0
- package/dist/src/DisplayStringWithLookup.spec.d.ts +1 -0
- package/dist/src/DisplayStringWithLookup.spec.js +42 -0
- package/dist/src/Label.spec.d.ts +1 -0
- package/dist/src/Label.spec.js +79 -0
- package/dist/src/Lens.spec.d.ts +1 -0
- package/dist/src/Lens.spec.js +164 -0
- package/dist/src/LensFixture.d.ts +28 -0
- package/dist/src/LensFixture.js +15 -0
- package/dist/src/LensState.spec.d.ts +1 -0
- package/dist/src/LensState.spec.js +100 -0
- package/dist/src/MonthYearDataPickerWithLength.spec.d.ts +1 -0
- package/dist/src/MonthYearDataPickerWithLength.spec.js +21 -0
- package/dist/src/WithTextLayout.spec.d.ts +1 -0
- package/dist/src/WithTextLayout.spec.js +29 -0
- package/dist/src/actions.spec.d.ts +1 -0
- package/dist/src/actions.spec.js +40 -0
- package/dist/src/composition.spec.d.ts +1 -0
- package/dist/src/composition.spec.js +28 -0
- package/dist/src/context.fixture.d.ts +6 -0
- package/dist/src/context.fixture.js +9 -0
- package/dist/src/dateutils.spec.d.ts +1 -0
- package/dist/src/dateutils.spec.js +166 -0
- package/dist/src/deleteState.spec.d.ts +1 -0
- package/dist/src/deleteState.spec.js +36 -0
- package/dist/src/dropdown.spec.d.ts +1 -0
- package/dist/src/dropdown.spec.js +46 -0
- package/dist/src/enzymeAdapterSetup.d.ts +1 -0
- package/dist/src/enzymeAdapterSetup.js +12 -0
- package/dist/src/fetcher.fixture.d.ts +38 -0
- package/dist/src/fetcher.fixture.js +20 -0
- package/dist/src/fetchers.spec.d.ts +1 -0
- package/dist/src/fetchers.spec.js +346 -0
- package/dist/src/focusedPage.spec.d.ts +1 -0
- package/dist/src/focusedPage.spec.js +70 -0
- package/dist/src/labelAnd.spec.d.ts +1 -0
- package/dist/src/labelAnd.spec.js +105 -0
- package/dist/src/labelAndDateInput.spec.d.ts +1 -0
- package/dist/src/labelAndDateInput.spec.js +26 -0
- package/dist/src/lenspath.spec.d.ts +1 -0
- package/dist/src/lenspath.spec.js +171 -0
- package/dist/src/memoisation.spec.d.ts +1 -0
- package/dist/src/memoisation.spec.js +11 -0
- package/dist/src/messages.spec.d.ts +1 -0
- package/dist/src/messages.spec.js +34 -0
- package/dist/src/modalButton.integration.spec.d.ts +23 -0
- package/dist/src/modalButton.integration.spec.js +299 -0
- package/dist/src/modalButton.spec.d.ts +1 -0
- package/dist/src/modalButton.spec.js +147 -0
- package/dist/src/newFetchers.spec.d.ts +1 -0
- package/dist/src/newFetchers.spec.js +214 -0
- package/dist/src/optics.spec.d.ts +2 -0
- package/dist/src/optics.spec.js +195 -0
- package/dist/src/page.fixture.d.ts +30 -0
- package/dist/src/page.fixture.js +55 -0
- package/dist/src/pageSelection.spec.d.ts +1 -0
- package/dist/src/pageSelection.spec.js +146 -0
- package/dist/src/post.spec.d.ts +1 -0
- package/dist/src/post.spec.js +84 -0
- package/dist/src/postButton.spec.d.ts +2 -0
- package/dist/src/postButton.spec.js +26 -0
- package/dist/src/preMutate.spec.d.ts +1 -0
- package/dist/src/preMutate.spec.js +63 -0
- package/dist/src/radioButton.spec.d.ts +1 -0
- package/dist/src/radioButton.spec.js +48 -0
- package/dist/src/restButton.spec.d.ts +13 -0
- package/dist/src/restButton.spec.js +95 -0
- package/dist/src/selectedItem.spec.d.ts +1 -0
- package/dist/src/selectedItem.spec.js +50 -0
- package/dist/src/stateAndFromApiTagFetcher.spec.d.ts +1 -0
- package/dist/src/stateAndFromApiTagFetcher.spec.js +59 -0
- package/dist/src/table.spec.d.ts +1 -0
- package/dist/src/table.spec.js +215 -0
- package/dist/src/tagFetcher.fixture.d.ts +7 -0
- package/dist/src/tagFetcher.fixture.js +16 -0
- package/dist/src/tagFetcher.spec.d.ts +1 -0
- package/dist/src/tagFetcher.spec.js +67 -0
- package/dist/src/template.spec.d.ts +1 -0
- package/dist/src/template.spec.js +58 -0
- package/dist/src/utils.spec.d.ts +1 -0
- package/dist/src/utils.spec.js +61 -0
- package/package.json +96 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//Copyright (c)2020-2022 Philip Rice. <br />Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the Software), to dealin the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: <br />The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED AS
|
|
4
|
+
const lens_1 = require("@focuson/lens");
|
|
5
|
+
const LensFixture_1 = require("./LensFixture");
|
|
6
|
+
const utils_1 = require("@focuson/utils");
|
|
7
|
+
describe("Lens", () => {
|
|
8
|
+
describe("identity", () => {
|
|
9
|
+
let lens = lens_1.Lenses.identity();
|
|
10
|
+
it("should return the same", () => {
|
|
11
|
+
expect(lens.get(LensFixture_1.a1b2ca3)).toBe(LensFixture_1.a1b2ca3);
|
|
12
|
+
});
|
|
13
|
+
it("should create the new value", () => {
|
|
14
|
+
expect(lens.set(LensFixture_1.a1b2ca3, "newValue")).toBe("newValue");
|
|
15
|
+
});
|
|
16
|
+
it("should have a description = identity", () => {
|
|
17
|
+
expect(lens.description).toEqual('I');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
describe("nth", () => {
|
|
21
|
+
it("should allow access to nth item", () => {
|
|
22
|
+
expect(lens_1.Lenses.nth(0).getOption(LensFixture_1.list123)).toBe(1);
|
|
23
|
+
expect(lens_1.Lenses.nth(1).getOption(LensFixture_1.list123)).toBe(2);
|
|
24
|
+
expect(lens_1.Lenses.nth(2).getOption(LensFixture_1.list123)).toBe(3);
|
|
25
|
+
});
|
|
26
|
+
it("should set the nth item", () => {
|
|
27
|
+
expect(lens_1.Lenses.nth(0).set(LensFixture_1.list123, 4)).toEqual([4, 2, 3]);
|
|
28
|
+
expect(lens_1.Lenses.nth(1).set(LensFixture_1.list123, 4)).toEqual([1, 4, 3]);
|
|
29
|
+
expect(lens_1.Lenses.nth(2).set(LensFixture_1.list123, 4)).toEqual([1, 2, 4]);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe("lens composition", () => {
|
|
33
|
+
expect(LensFixture_1.letnstoca.getOption(LensFixture_1.a1b2ca3)).toEqual(3);
|
|
34
|
+
expect(LensFixture_1.letnstoca.set(LensFixture_1.a1b2ca3, 9)).toEqual({ a: 1, b: 2, c: { a: 9 } });
|
|
35
|
+
expect(LensFixture_1.letnstoca.transform(old => {
|
|
36
|
+
expect(old).toEqual(3);
|
|
37
|
+
return 9;
|
|
38
|
+
})(LensFixture_1.a1b2ca3)).toEqual({ a: 1, b: 2, c: { a: 9 } });
|
|
39
|
+
expect(LensFixture_1.letnstoca.description).toEqual('toC.chain(toa)');
|
|
40
|
+
});
|
|
41
|
+
describe("'then' should use the field names", () => {
|
|
42
|
+
let dragonStomachL = lens_1.Lenses.build('dragon').focusOn('body').focusOn('chest').focusOn('stomach');
|
|
43
|
+
let contentL = dragonStomachL.focusOn('contents');
|
|
44
|
+
it("allow chained focusOn", () => {
|
|
45
|
+
expect(dragonStomachL.get(LensFixture_1.dragon)).toEqual(({ contents: ['the adventurer'] }));
|
|
46
|
+
expect(contentL.transform(old => [...old, 'moreGoodness'])(LensFixture_1.dragon)).toEqual(LensFixture_1.dragon2);
|
|
47
|
+
//and nothing should have changed
|
|
48
|
+
expect(dragonStomachL.get(LensFixture_1.dragon)).toEqual(({ contents: ['the adventurer'] }));
|
|
49
|
+
});
|
|
50
|
+
it('should have a nice description', () => {
|
|
51
|
+
expect(dragonStomachL.description).toEqual("dragon.focusOn(body).focusOn(chest).focusOn(stomach)");
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe("lens.last", () => {
|
|
55
|
+
let abc = ['a', 'b', 'c'];
|
|
56
|
+
it("should access the last item", () => {
|
|
57
|
+
expect(lens_1.Lenses.last().getOption(abc)).toEqual('c');
|
|
58
|
+
expect(lens_1.Lenses.last().setOption(abc, 'd')).toEqual(['a', 'b', 'd']);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe("lens.append", () => {
|
|
62
|
+
let abc = ['a', 'b', 'c'];
|
|
63
|
+
it("should access the last item", () => {
|
|
64
|
+
expect(lens_1.Lenses.append().getOption(abc)).toEqual(undefined);
|
|
65
|
+
expect(lens_1.Lenses.append().setOption(abc, 'd')).toEqual(['a', 'b', 'c', 'd']);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe("lens.nth", () => {
|
|
69
|
+
let abc = ['a', 'b', 'c'];
|
|
70
|
+
it("should throw exception with negative length", () => {
|
|
71
|
+
expect(() => lens_1.Lenses.nth(-1)).toThrow('Cannot give Lens.nth a negative n [-1]');
|
|
72
|
+
});
|
|
73
|
+
it("should have a description", () => {
|
|
74
|
+
expect(lens_1.Lenses.nth(0).description).toEqual('[0]');
|
|
75
|
+
expect(lens_1.Lenses.nth(5).description).toEqual('[5]');
|
|
76
|
+
});
|
|
77
|
+
describe("getOption", () => {
|
|
78
|
+
it("should getOption", () => {
|
|
79
|
+
expect(lens_1.Lenses.nth(0).getOption(abc)).toEqual('a');
|
|
80
|
+
expect(lens_1.Lenses.nth(1).getOption(abc)).toEqual('b');
|
|
81
|
+
expect(lens_1.Lenses.nth(2).getOption(abc)).toEqual('c');
|
|
82
|
+
});
|
|
83
|
+
it("should return undefined if out of range", () => {
|
|
84
|
+
expect(lens_1.Lenses.nth(4).getOption(abc)).toEqual(undefined);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe("set", () => {
|
|
88
|
+
it("should create new with data inserted", () => {
|
|
89
|
+
expect(lens_1.Lenses.nth(1).set(abc, 'd')).toEqual(["a", "d", "c"]);
|
|
90
|
+
expect(abc).toEqual(['a', 'b', 'c']);
|
|
91
|
+
});
|
|
92
|
+
it("should set if n is too big", () => {
|
|
93
|
+
expect(lens_1.Lenses.nth(4).set(abc, 'd')).toEqual(["a", "b", "c", undefined, "d"]);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe("map", () => {
|
|
98
|
+
it("should pass existing value to a fn and use the result", () => {
|
|
99
|
+
expect(LensFixture_1.letnstoca.map(LensFixture_1.a1b2ca3, old => old + 1)).toEqual({ "a": 1, "b": 2, "c": { "a": 4 } });
|
|
100
|
+
});
|
|
101
|
+
it("should work even if the original was undefined", () => {
|
|
102
|
+
expect(LensFixture_1.letnstoca.map(Object.assign(Object.assign({}, LensFixture_1.a1b2ca3), { c: undefined }), old => 4)).toEqual({ "a": 1, "b": 2, "c": { "a": 4 } });
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe("lookUp", () => {
|
|
106
|
+
it("should make a lens that maps from id to value, when id and value are object of {[name: string]: value}", () => {
|
|
107
|
+
const state = {
|
|
108
|
+
lookup: { 'one': 1, 'two': 2 },
|
|
109
|
+
date: 'one'
|
|
110
|
+
};
|
|
111
|
+
const dataL = lens_1.Lenses.identity().focusQuery('date');
|
|
112
|
+
const lookupL = lens_1.Lenses.identity().focusQuery('lookup');
|
|
113
|
+
const l = lens_1.Lenses.chainLookup(dataL, lookupL);
|
|
114
|
+
expect(l.getOption(state)).toEqual(1);
|
|
115
|
+
expect(l.setOption(state, 2)).toEqual({ lookup: { 'one': 1, 'two': 2 }, date: 'two' });
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe("lookUpTable", () => {
|
|
119
|
+
it("should make a lens that maps from id to value, when id and value are object of {[name: string]: value}", () => {
|
|
120
|
+
const state = {
|
|
121
|
+
lookup: [{ id: 'one', value: 1 }, { id: 'two', value: 2 }],
|
|
122
|
+
date: 'one'
|
|
123
|
+
};
|
|
124
|
+
const dataL = lens_1.Lenses.identity().focusQuery('date');
|
|
125
|
+
const lookupL = lens_1.Lenses.identity().focusQuery('lookup');
|
|
126
|
+
const l = lens_1.Lenses.chainLookupTable(dataL, lookupL, 'id', 'value');
|
|
127
|
+
expect(l.getOption(state)).toEqual(1);
|
|
128
|
+
expect(l.setOption(state, 2)).toEqual({ lookup: [{ id: 'one', value: 1 }, { id: 'two', value: 2 }], date: 'two' });
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
describe("trasnformTwoValues", () => {
|
|
132
|
+
let start = { item1: "one", selected: { item2: "two" } };
|
|
133
|
+
let lens1 = (0, lens_1.identityOptics)().focusQuery('item1');
|
|
134
|
+
let lens2 = (0, lens_1.identityOptics)().focusQuery('selected').focusQuery('item2');
|
|
135
|
+
const add = (infix) => (a, b) => a + infix + b;
|
|
136
|
+
let tx = (0, lens_1.transformTwoValues)(lens1, lens2)(add("+"), add("-"));
|
|
137
|
+
it("should transform when both can be set", () => {
|
|
138
|
+
expect(tx({ item1: "one", selected: { item2: "two2" } })).toEqual({ "item1": "one+two2", "selected": { "item2": "one-two2" } });
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
describe("lens utils", () => {
|
|
143
|
+
it("should have a arrays equal that returns true if the two parameters are both defined and equal", () => {
|
|
144
|
+
expect((0, utils_1.arraysEqual)(undefined, undefined)).toEqual(false);
|
|
145
|
+
expect((0, utils_1.arraysEqual)([], undefined)).toEqual(false);
|
|
146
|
+
expect((0, utils_1.arraysEqual)(["a"], undefined)).toEqual(false);
|
|
147
|
+
expect((0, utils_1.arraysEqual)(undefined, undefined)).toEqual(false);
|
|
148
|
+
expect((0, utils_1.arraysEqual)(undefined, [])).toEqual(false);
|
|
149
|
+
expect((0, utils_1.arraysEqual)(undefined, ["a"])).toEqual(false);
|
|
150
|
+
expect((0, utils_1.arraysEqual)([], ["a"])).toEqual(false);
|
|
151
|
+
expect((0, utils_1.arraysEqual)(["b"], ["a"])).toEqual(false);
|
|
152
|
+
expect((0, utils_1.arraysEqual)(["b"], [])).toEqual(false);
|
|
153
|
+
expect((0, utils_1.arraysEqual)([], [])).toEqual(true);
|
|
154
|
+
expect((0, utils_1.arraysEqual)(["a"], ["a"])).toEqual(true);
|
|
155
|
+
expect((0, utils_1.arraysEqual)(["a", "b"], ["a", "b"])).toEqual(true);
|
|
156
|
+
});
|
|
157
|
+
it("should have a areAllDefined that returns true only if the array and its contents are all defined", () => {
|
|
158
|
+
expect((0, utils_1.areAllDefined)(undefined)).toEqual(false);
|
|
159
|
+
expect((0, utils_1.areAllDefined)([undefined])).toEqual(false);
|
|
160
|
+
expect((0, utils_1.areAllDefined)([undefined, "a"])).toEqual(false);
|
|
161
|
+
expect((0, utils_1.areAllDefined)(["b", undefined, "a"])).toEqual(false);
|
|
162
|
+
expect((0, utils_1.areAllDefined)(["b", "a"])).toEqual(true);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare let a1b2ca3: {
|
|
2
|
+
a: number;
|
|
3
|
+
b: number;
|
|
4
|
+
c: {
|
|
5
|
+
a: number;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare let list123: number[];
|
|
9
|
+
export declare let lensToc: import("@focuson/lens").Lens<any, any>;
|
|
10
|
+
export declare let lenscToa: import("@focuson/lens").Optional<any, any>;
|
|
11
|
+
export declare let letnstoca: import("@focuson/lens").Optional<any, any>;
|
|
12
|
+
export declare let dragon: Dragon;
|
|
13
|
+
export declare let dragon2: Dragon;
|
|
14
|
+
export interface Dragon {
|
|
15
|
+
body: Body;
|
|
16
|
+
}
|
|
17
|
+
export interface Body {
|
|
18
|
+
chest: Chest;
|
|
19
|
+
}
|
|
20
|
+
export interface Chest {
|
|
21
|
+
stomach: Stomach;
|
|
22
|
+
heart?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface Stomach {
|
|
25
|
+
contents: any[];
|
|
26
|
+
}
|
|
27
|
+
export declare class DragonDomain {
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DragonDomain = exports.dragon2 = exports.dragon = exports.letnstoca = exports.lenscToa = exports.lensToc = exports.list123 = exports.a1b2ca3 = void 0;
|
|
4
|
+
//Copyright (c)2020-2022 Philip Rice. <br />Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the Software), to dealin the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: <br />The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED AS
|
|
5
|
+
const lens_1 = require("@focuson/lens");
|
|
6
|
+
exports.a1b2ca3 = { a: 1, b: 2, c: { a: 3 } };
|
|
7
|
+
exports.list123 = [1, 2, 3];
|
|
8
|
+
exports.lensToc = (0, lens_1.lens)(f => f.c, (m, c) => (Object.assign(Object.assign({}, m), { c })), 'toC');
|
|
9
|
+
exports.lenscToa = (0, lens_1.optional)(f => f.a, (m, a) => (Object.assign(Object.assign({}, m), { a })), 'toa');
|
|
10
|
+
exports.letnstoca = exports.lensToc.chain(exports.lenscToa);
|
|
11
|
+
exports.dragon = { body: { chest: { stomach: { contents: ["the adventurer"] } } } };
|
|
12
|
+
exports.dragon2 = { body: { chest: { stomach: { contents: ["the adventurer", "moreGoodness"] } } } };
|
|
13
|
+
class DragonDomain {
|
|
14
|
+
}
|
|
15
|
+
exports.DragonDomain = DragonDomain;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//Copyright (c)2020-2022 Philip Rice. <br />Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the Software), to dealin the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: <br />The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED AS
|
|
4
|
+
const lens_1 = require("@focuson/lens");
|
|
5
|
+
const state_1 = require("@focuson/state");
|
|
6
|
+
const LensFixture_1 = require("./LensFixture");
|
|
7
|
+
let initialMain = Object.assign({}, LensFixture_1.dragon);
|
|
8
|
+
let setMain = jest.fn();
|
|
9
|
+
const context = 'context';
|
|
10
|
+
let dragonLS = (0, state_1.lensState)(LensFixture_1.dragon, setMain, "dragon", context);
|
|
11
|
+
let chestLS = dragonLS.focusOn('body').focusOn('chest');
|
|
12
|
+
let stomachLS = chestLS.focusOn('stomach');
|
|
13
|
+
function setupForSetMain(state, fn) {
|
|
14
|
+
const setMain = jest.fn();
|
|
15
|
+
let newContext = new state_1.LensState(state.main, setMain, state.optional, context);
|
|
16
|
+
fn(newContext, setMain);
|
|
17
|
+
}
|
|
18
|
+
function checkSetMainWas(setMain, expected) {
|
|
19
|
+
expect(setMain.mock.calls.length).toEqual(1);
|
|
20
|
+
expect(setMain.mock.calls[0][0]).toEqual(expected);
|
|
21
|
+
expect(LensFixture_1.dragon).toEqual(initialMain); //just checking no sideeffects
|
|
22
|
+
}
|
|
23
|
+
function checkLensState(ls, lensDescription) {
|
|
24
|
+
expect(ls.main).toEqual(LensFixture_1.dragon);
|
|
25
|
+
expect(ls.optional.description).toEqual(lensDescription);
|
|
26
|
+
expect(ls.dangerouslySetMain).toEqual(setMain);
|
|
27
|
+
}
|
|
28
|
+
describe("LensState", () => {
|
|
29
|
+
it("create", () => {
|
|
30
|
+
checkLensState(dragonLS, 'dragon');
|
|
31
|
+
checkLensState(chestLS, 'dragon.focus?(body).focus?(chest)');
|
|
32
|
+
});
|
|
33
|
+
it("should have json equal to the focus of the lens", () => {
|
|
34
|
+
expect(dragonLS.json()).toEqual(LensFixture_1.dragon);
|
|
35
|
+
expect(chestLS.json()).toEqual(LensFixture_1.dragon.body.chest);
|
|
36
|
+
});
|
|
37
|
+
it("should have a setJson that creates even when parent isn't there", () => {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
const empty = {};
|
|
40
|
+
var remembered = {};
|
|
41
|
+
let dragonLS = (0, state_1.lensState)(empty, d => remembered = d, "dragon", context);
|
|
42
|
+
let ls = dragonLS.focusOn('body').focusOn('chest').focusOn('stomach').focusOn('contents');
|
|
43
|
+
ls.setJson([1, 2, 3], 'someReason');
|
|
44
|
+
expect(remembered).toEqual({ "body": { "chest": { "stomach": { "contents": [1, 2, 3] } } } });
|
|
45
|
+
});
|
|
46
|
+
it("with Lens should ignore the parent lens", () => {
|
|
47
|
+
let replace = chestLS.copyWithLens(chestLS.optional.withDescription('theNewLens'));
|
|
48
|
+
checkLensState(replace, 'theNewLens');
|
|
49
|
+
});
|
|
50
|
+
it("with withChildLens should concatenate with the parent lens", () => {
|
|
51
|
+
let child = chestLS.chainLens(lens_1.Lenses.identity().withDescription('childName'));
|
|
52
|
+
checkLensState(child, 'dragon.focus?(body).focus?(chest).chain(childName)');
|
|
53
|
+
});
|
|
54
|
+
it("setJson should call danagerouslySetMain with the result of passing main and the new json to the lens", () => {
|
|
55
|
+
let json = { contents: [1, 2, 3] };
|
|
56
|
+
setupForSetMain(stomachLS, (context, setMain) => {
|
|
57
|
+
context.setJson(json, 'someReason');
|
|
58
|
+
checkSetMainWas(setMain, stomachLS.optional.set(LensFixture_1.dragon, json));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
// it("setFrom should call dangerousSetMain using the lens concatenated to the current state", () => {
|
|
62
|
+
// let json = {stomach: {contents: [1, 2, 3]}};
|
|
63
|
+
// setupForSetMain(stomachLS, (context, setMain) => {
|
|
64
|
+
// let newLens = Lens.build<Dragon>('passedLens')
|
|
65
|
+
// context.setFrom(newLens, json)
|
|
66
|
+
// checkSetMainWas(setMain, context.optional.andThen(square3L).set(SimpleGameDomain.emptyGame, 'X'))
|
|
67
|
+
// })
|
|
68
|
+
// })
|
|
69
|
+
});
|
|
70
|
+
describe("lenState2", () => {
|
|
71
|
+
it("should update two lens simultaneously", () => {
|
|
72
|
+
setupForSetMain(dragonLS, (ls, setMain) => {
|
|
73
|
+
const ls2 = ls.focusOn('body').focusOn('chest').doubleUp().focus1On('stomach').focus2On('heart');
|
|
74
|
+
ls2.setJson({ contents: ['some'] }, 'thing', 'someReason');
|
|
75
|
+
checkSetMainWas(setMain, {
|
|
76
|
+
"body": {
|
|
77
|
+
"chest": {
|
|
78
|
+
"heart": "thing",
|
|
79
|
+
"stomach": { "contents": ["some"] }
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
it("should allow 'chainWithLens1 chainWithLens2", () => {
|
|
86
|
+
setupForSetMain(dragonLS, (ls, setMain) => {
|
|
87
|
+
const identity = lens_1.Lenses.identity('id');
|
|
88
|
+
const ls2 = ls.focusOn('body').focusOn('chest').doubleUp();
|
|
89
|
+
ls2.chain1(identity.focusOn('stomach')).chain2(identity.focusOn('heart')).setJson({ contents: ['some'] }, 'thing', 'reason');
|
|
90
|
+
checkSetMainWas(setMain, {
|
|
91
|
+
"body": {
|
|
92
|
+
"chest": {
|
|
93
|
+
"heart": "thing",
|
|
94
|
+
"stomach": { "contents": ["some"] }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@focuson/utils");
|
|
4
|
+
describe("addDate", () => {
|
|
5
|
+
it("should return the original date if we have funny values", () => {
|
|
6
|
+
expect((0, utils_1.addDate)(false, undefined, 10, false)).toEqual(undefined);
|
|
7
|
+
expect((0, utils_1.addDate)(false, '', 10, false)).toEqual('');
|
|
8
|
+
expect((0, utils_1.addDate)(false, 'xx', 10, false)).toEqual('xx');
|
|
9
|
+
expect((0, utils_1.addDate)(false, '12', 10, false)).toEqual('12');
|
|
10
|
+
});
|
|
11
|
+
it('should add months with /', () => {
|
|
12
|
+
expect((0, utils_1.addDate)(false, '01/2012', 10, false)).toEqual('11/2012');
|
|
13
|
+
expect((0, utils_1.addDate)(false, '1/2012', 10, false)).toEqual('11/2012');
|
|
14
|
+
expect((0, utils_1.addDate)(false, '12/2012', 10, false)).toEqual('10/2013');
|
|
15
|
+
});
|
|
16
|
+
it('should add months with -', () => {
|
|
17
|
+
expect((0, utils_1.addDate)(false, '01-2012', 10, false)).toEqual('11/2012');
|
|
18
|
+
expect((0, utils_1.addDate)(false, '1-2012', 10, false)).toEqual('11/2012');
|
|
19
|
+
expect((0, utils_1.addDate)(false, '12-2012', 10, false)).toEqual('10/2013');
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const enzymeAdapterSetup_1 = require("./enzymeAdapterSetup");
|
|
5
|
+
const form_components_1 = require("@focuson/form_components");
|
|
6
|
+
const enzyme_1 = require("enzyme");
|
|
7
|
+
const state_1 = require("@focuson/state");
|
|
8
|
+
const context_fixture_1 = require("./context.fixture");
|
|
9
|
+
(0, enzymeAdapterSetup_1.enzymeSetup)();
|
|
10
|
+
const empty = {
|
|
11
|
+
messages: [], pageSelection: [], restCommands: [], tags: {}
|
|
12
|
+
};
|
|
13
|
+
// text: string;
|
|
14
|
+
// holderClassName?: string
|
|
15
|
+
// textClassName?: string
|
|
16
|
+
// childrenClassName?: string
|
|
17
|
+
function withText(text, holderClassName, textClassName, childrenClassName) {
|
|
18
|
+
const state = (0, state_1.lensState)(empty, () => { }, '', (0, context_fixture_1.context)());
|
|
19
|
+
return (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(form_components_1.WithTextLayout, { text: text, state: state.focusOn('data'), textClassName: textClassName, holderClassName: holderClassName, childrenClassName: childrenClassName, children: (0, jsx_runtime_1.jsx)("p", { children: "Children" }) })).html();
|
|
20
|
+
}
|
|
21
|
+
describe("WithTextLayout", () => {
|
|
22
|
+
it('should render ', () => {
|
|
23
|
+
expect(withText('someText', undefined, undefined, undefined)).toEqual('<div><div>someText</div><div><p>Children</p></div></div>');
|
|
24
|
+
expect(withText('someText', 'holder', 'text', 'children')).toEqual('<div class="holder"><div class="text">someText</div><div class="children"><p>Children</p></div></div>');
|
|
25
|
+
});
|
|
26
|
+
it("should render html", () => {
|
|
27
|
+
expect(withText('someText <b>That is bold</b>', undefined, undefined, undefined)).toEqual('<div><div>someText <b>That is bold</b></div><div><p>Children</p></div></div>');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const state_1 = require("@focuson/state");
|
|
4
|
+
const actions_1 = require("@focuson/forms/src/actions");
|
|
5
|
+
const lens_1 = require("@focuson/lens");
|
|
6
|
+
const pending = { status: 'PENDING', type: 'CR', amount: '1.00' };
|
|
7
|
+
const pendingHeld = { status: 'PENDING', hold: true, type: 'CR', amount: '1.00' };
|
|
8
|
+
const approved = { status: 'APPROVED', type: 'CR', amount: '1.00' };
|
|
9
|
+
const approvedHeld = { status: 'APPROVED', hold: true, type: 'CR', amount: '1.00' };
|
|
10
|
+
const authorised = { status: 'AUTHORISED', type: 'CR', amount: '1.00' };
|
|
11
|
+
const authorisedHeld = { status: 'AUTHORISED', hold: true, type: 'CR', amount: '1.00' };
|
|
12
|
+
const state = (setMain) => (...data) => (0, state_1.lensState)({ data, CommonIds: { operatorName: 'Phil' } }, setMain, '', {}).focusOn('data');
|
|
13
|
+
describe("actions", () => {
|
|
14
|
+
it("approvePending should update pendings if they are not held", () => {
|
|
15
|
+
var remembered = {};
|
|
16
|
+
const start = state(m => remembered = m)(pending, pending, pendingHeld, pendingHeld, approved, approvedHeld, authorised, authorisedHeld);
|
|
17
|
+
expect((0, lens_1.displayTransformsInState)(start.main, (0, actions_1.approvePendingFees)(start, 'someId'))).toEqual([
|
|
18
|
+
{
|
|
19
|
+
"opt": ".focus?(data).chain([0])",
|
|
20
|
+
"value": { "amount": "1.00", "approvedBy": "Phil", "status": "APPROVED", "type": "CR" }
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"opt": ".focus?(data).chain([1])",
|
|
24
|
+
"value": { "amount": "1.00", "approvedBy": "Phil", "status": "APPROVED", "type": "CR" }
|
|
25
|
+
}
|
|
26
|
+
]);
|
|
27
|
+
expect(remembered).toEqual({});
|
|
28
|
+
});
|
|
29
|
+
it("authoriseApprovedFees should update approved if they are not held", () => {
|
|
30
|
+
var remembered = {};
|
|
31
|
+
const start = state(m => remembered = m)(pending, pending, pendingHeld, pendingHeld, approved, approvedHeld, authorised, authorisedHeld);
|
|
32
|
+
expect((0, lens_1.displayTransformsInState)(start.main, (0, actions_1.authoriseApprovedFees)(start, 'someId'))).toEqual([
|
|
33
|
+
{
|
|
34
|
+
"opt": ".focus?(data).chain([4])",
|
|
35
|
+
"value": { "amount": "1.00", "authorisedBy": "Phil", "status": "AUTHORISED", "type": "CR" }
|
|
36
|
+
}
|
|
37
|
+
]);
|
|
38
|
+
expect(remembered).toEqual({});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const utils_1 = require("@focuson/utils");
|
|
13
|
+
describe("error monad", () => {
|
|
14
|
+
it("call the functions in order", () => {
|
|
15
|
+
expect((0, utils_1.errorMonad)("start", false, (s, e) => "failed", ['one', s => s + ".1"], ['two', s => s + ".2"], ['three', s => s + ".3"])).toEqual('start.1.2.3');
|
|
16
|
+
});
|
|
17
|
+
it("stop calling functions after an error occurs, return the results of the error handler", () => {
|
|
18
|
+
expect((0, utils_1.errorMonad)("start", false, (s, e) => s + "/" + e + "/failed", ['one', s => s + ".1"], ['two', s => { throw Error('someError'); }], ['three', s => s + ".3"])).toEqual('start.1/Error: someError/failed');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe("error promise monad", () => {
|
|
22
|
+
it("call the functions in order", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
expect(yield (0, utils_1.errorPromiseMonad)((s, e) => "failed")("start", false, ['one', s => Promise.resolve(s + ".1")], ['two', s => Promise.resolve(s + ".2")], ['three', s => Promise.resolve(s + ".3")])).toEqual('start.1.2.3');
|
|
24
|
+
}));
|
|
25
|
+
it("stop calling functions after an error occurs, return the results of the error handler", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
expect(yield (0, utils_1.errorPromiseMonad)((s, e) => s + "/" + e + "/failed")("start", false, ['one', s => Promise.resolve(s + ".1")], ['two', s => { throw Error('someError'); }], ['three', s => Promise.resolve(s + ".3")])).toEqual('start.1/Error: someError/failed');
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { HasRestCommands } from "@focuson/rest";
|
|
2
|
+
import { HasPageSelection } from "@focuson/pages";
|
|
3
|
+
import { FocusOnContext } from "@focuson/focuson";
|
|
4
|
+
import { HasSimpleMessages } from "@focuson/utils";
|
|
5
|
+
import { HasTagHolder } from "@focuson/template";
|
|
6
|
+
export declare function context<S extends HasRestCommands & HasPageSelection & HasSimpleMessages & HasTagHolder>(mockJwt?: boolean): FocusOnContext<S>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.context = context;
|
|
4
|
+
const focuson_1 = require("@focuson/focuson");
|
|
5
|
+
const utils_1 = require("@focuson/utils");
|
|
6
|
+
const form_components_1 = require("@focuson/form_components");
|
|
7
|
+
function context(mockJwt) {
|
|
8
|
+
return Object.assign(Object.assign({}, (0, focuson_1.defaultPageSelectionAndRestCommandsContext)({}, {}, {}, {}, utils_1.testDateFn, mockJwt !== false)), { combine: form_components_1.MyCombined });
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|