@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.
Files changed (88) hide show
  1. package/README.md +6 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +18 -0
  4. package/dist/src/DataDrivenFixedOptionDropDownAndDetails.spec.d.ts +1 -0
  5. package/dist/src/DataDrivenFixedOptionDropDownAndDetails.spec.js +70 -0
  6. package/dist/src/DatePicker.spec.d.ts +1 -0
  7. package/dist/src/DatePicker.spec.js +315 -0
  8. package/dist/src/DisplayStringWithLookup.spec.d.ts +1 -0
  9. package/dist/src/DisplayStringWithLookup.spec.js +42 -0
  10. package/dist/src/Label.spec.d.ts +1 -0
  11. package/dist/src/Label.spec.js +79 -0
  12. package/dist/src/Lens.spec.d.ts +1 -0
  13. package/dist/src/Lens.spec.js +164 -0
  14. package/dist/src/LensFixture.d.ts +28 -0
  15. package/dist/src/LensFixture.js +15 -0
  16. package/dist/src/LensState.spec.d.ts +1 -0
  17. package/dist/src/LensState.spec.js +100 -0
  18. package/dist/src/MonthYearDataPickerWithLength.spec.d.ts +1 -0
  19. package/dist/src/MonthYearDataPickerWithLength.spec.js +21 -0
  20. package/dist/src/WithTextLayout.spec.d.ts +1 -0
  21. package/dist/src/WithTextLayout.spec.js +29 -0
  22. package/dist/src/actions.spec.d.ts +1 -0
  23. package/dist/src/actions.spec.js +40 -0
  24. package/dist/src/composition.spec.d.ts +1 -0
  25. package/dist/src/composition.spec.js +28 -0
  26. package/dist/src/context.fixture.d.ts +6 -0
  27. package/dist/src/context.fixture.js +9 -0
  28. package/dist/src/dateutils.spec.d.ts +1 -0
  29. package/dist/src/dateutils.spec.js +166 -0
  30. package/dist/src/deleteState.spec.d.ts +1 -0
  31. package/dist/src/deleteState.spec.js +36 -0
  32. package/dist/src/dropdown.spec.d.ts +1 -0
  33. package/dist/src/dropdown.spec.js +46 -0
  34. package/dist/src/enzymeAdapterSetup.d.ts +1 -0
  35. package/dist/src/enzymeAdapterSetup.js +12 -0
  36. package/dist/src/fetcher.fixture.d.ts +38 -0
  37. package/dist/src/fetcher.fixture.js +20 -0
  38. package/dist/src/fetchers.spec.d.ts +1 -0
  39. package/dist/src/fetchers.spec.js +346 -0
  40. package/dist/src/focusedPage.spec.d.ts +1 -0
  41. package/dist/src/focusedPage.spec.js +70 -0
  42. package/dist/src/labelAnd.spec.d.ts +1 -0
  43. package/dist/src/labelAnd.spec.js +105 -0
  44. package/dist/src/labelAndDateInput.spec.d.ts +1 -0
  45. package/dist/src/labelAndDateInput.spec.js +26 -0
  46. package/dist/src/lenspath.spec.d.ts +1 -0
  47. package/dist/src/lenspath.spec.js +171 -0
  48. package/dist/src/memoisation.spec.d.ts +1 -0
  49. package/dist/src/memoisation.spec.js +11 -0
  50. package/dist/src/messages.spec.d.ts +1 -0
  51. package/dist/src/messages.spec.js +34 -0
  52. package/dist/src/modalButton.integration.spec.d.ts +23 -0
  53. package/dist/src/modalButton.integration.spec.js +299 -0
  54. package/dist/src/modalButton.spec.d.ts +1 -0
  55. package/dist/src/modalButton.spec.js +147 -0
  56. package/dist/src/newFetchers.spec.d.ts +1 -0
  57. package/dist/src/newFetchers.spec.js +214 -0
  58. package/dist/src/optics.spec.d.ts +2 -0
  59. package/dist/src/optics.spec.js +195 -0
  60. package/dist/src/page.fixture.d.ts +30 -0
  61. package/dist/src/page.fixture.js +55 -0
  62. package/dist/src/pageSelection.spec.d.ts +1 -0
  63. package/dist/src/pageSelection.spec.js +146 -0
  64. package/dist/src/post.spec.d.ts +1 -0
  65. package/dist/src/post.spec.js +84 -0
  66. package/dist/src/postButton.spec.d.ts +2 -0
  67. package/dist/src/postButton.spec.js +26 -0
  68. package/dist/src/preMutate.spec.d.ts +1 -0
  69. package/dist/src/preMutate.spec.js +63 -0
  70. package/dist/src/radioButton.spec.d.ts +1 -0
  71. package/dist/src/radioButton.spec.js +48 -0
  72. package/dist/src/restButton.spec.d.ts +13 -0
  73. package/dist/src/restButton.spec.js +95 -0
  74. package/dist/src/selectedItem.spec.d.ts +1 -0
  75. package/dist/src/selectedItem.spec.js +50 -0
  76. package/dist/src/stateAndFromApiTagFetcher.spec.d.ts +1 -0
  77. package/dist/src/stateAndFromApiTagFetcher.spec.js +59 -0
  78. package/dist/src/table.spec.d.ts +1 -0
  79. package/dist/src/table.spec.js +215 -0
  80. package/dist/src/tagFetcher.fixture.d.ts +7 -0
  81. package/dist/src/tagFetcher.fixture.js +16 -0
  82. package/dist/src/tagFetcher.spec.d.ts +1 -0
  83. package/dist/src/tagFetcher.spec.js +67 -0
  84. package/dist/src/template.spec.d.ts +1 -0
  85. package/dist/src/template.spec.js +58 -0
  86. package/dist/src/utils.spec.d.ts +1 -0
  87. package/dist/src/utils.spec.js +61 -0
  88. package/package.json +96 -0
@@ -0,0 +1,346 @@
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 fetcher_1 = require("@focuson/fetcher");
13
+ const lens_1 = require("@focuson/lens");
14
+ const shouldLoadTrue = (t) => [];
15
+ const shouldLoadFalse = (t) => ['some reason'];
16
+ const reqInit = { keepalive: true };
17
+ const loadAddsDot = (s) => (0, fetcher_1.loadInfo)(`load url from ${s}`, reqInit, (state) => (status, json) => "." + state + "/" + status + "/" + json);
18
+ let loadTrueF = (0, fetcher_1.fetcher)(shouldLoadTrue, loadAddsDot, "loadTrueF");
19
+ let loadFalseF = (0, fetcher_1.fetcher)(shouldLoadFalse, loadAddsDot, "loadFalseF");
20
+ let useInsteadOfLoad = (0, fetcher_1.loadDirectly)((s) => s + "loaded");
21
+ let loadTrueAndUseInstead = (0, fetcher_1.fetcher)(shouldLoadTrue, s => useInsteadOfLoad, "");
22
+ describe("fetcher", () => {
23
+ it("should make a fetcher", () => {
24
+ expect(loadTrueF).toEqual({ shouldLoad: shouldLoadTrue, load: loadAddsDot, "description": "loadTrueF" });
25
+ });
26
+ });
27
+ function myfetch(req, init) {
28
+ return Promise.resolve([200, "someString"]);
29
+ }
30
+ describe("apply fetcher", () => {
31
+ it("load when load returns true", () => __awaiter(void 0, void 0, void 0, function* () {
32
+ expect(yield (0, fetcher_1.applyFetcher)(loadTrueF, "original", myfetch)).toEqual(".original/200/someString");
33
+ }));
34
+ it("not load when load returns false", () => __awaiter(void 0, void 0, void 0, function* () {
35
+ expect(yield (0, fetcher_1.applyFetcher)(loadFalseF, "original", myfetch)).toEqual("original");
36
+ }));
37
+ it("uses this instead of load if defined", () => __awaiter(void 0, void 0, void 0, function* () {
38
+ expect(yield (0, fetcher_1.applyFetcher)(loadTrueAndUseInstead, "oldstate", myfetch)).toEqual("oldstateloaded");
39
+ }));
40
+ });
41
+ describe("lens fetcher ", () => {
42
+ const opticsTo = (0, lens_1.identityOptics)().focusQuery('ab').focusQuery('a');
43
+ let fTrue = (0, fetcher_1.lensFetcher)(opticsTo, loadTrueF);
44
+ let fFalse = (0, fetcher_1.lensFetcher)(opticsTo, loadFalseF, "fFalse");
45
+ it("should have a description", () => {
46
+ expect(fTrue.description).toEqual("lensFetcher(Optional(I.focus?(ab).focus?(a)),loadTrueF)");
47
+ expect(fFalse.description).toEqual("fFalse");
48
+ });
49
+ it("when child condition is false", () => {
50
+ expect(fFalse.shouldLoad({})).toEqual(["emptyFocusedOnState"]);
51
+ });
52
+ it.skip("when child condition is true BUT the place the child is going to be added to is undefined", () => {
53
+ expect(fTrue.shouldLoad({})).toEqual(false); //there is no ab to put the value loaded into
54
+ // const [req, reqInit, mutate] = fTrue.load({ab: {}})
55
+ });
56
+ it("when child doesnt exist, even if the condition would be true", () => {
57
+ let state = { ab: {} };
58
+ expect(fTrue.shouldLoad(state)).toEqual(["emptyFocusedOnState"]);
59
+ });
60
+ it("when child condition is true", () => {
61
+ let state = { ab: { a: 'something' } };
62
+ expect(fTrue.shouldLoad(state)).toEqual([]);
63
+ const { requestInfo, requestInit, mutate } = fTrue.load({ ab: { a: '' } });
64
+ expect(mutate(state)(200, "someValue")).toEqual({ "ab": { "a": ".something/200/someValue" } });
65
+ });
66
+ });
67
+ describe("lens fetcher", () => {
68
+ it("when state defined but holder is undefined", () => {
69
+ const opticsTo = (0, lens_1.identityOptics)().focusQuery('ab').focusQuery('a');
70
+ let f = (0, fetcher_1.lensFetcher)(opticsTo, loadTrueF);
71
+ expect(f.shouldLoad({})).toEqual(["emptyFocusedOnState"]);
72
+ });
73
+ it("when state defined, holder is defined and condition is false", () => {
74
+ const opticsTo = (0, lens_1.identityOptics)().focusQuery('ab').focusQuery('a');
75
+ let f = (0, fetcher_1.lensFetcher)(opticsTo, loadFalseF);
76
+ expect(f.shouldLoad({ ab: {} })).toEqual(["emptyFocusedOnState"]);
77
+ });
78
+ it("when state defined, holder is defined child is undefined and coniditon is true", () => {
79
+ const opticsTo = (0, lens_1.identityOptics)().focusQuery('ab').focusQuery('a');
80
+ let f = (0, fetcher_1.lensFetcher)(opticsTo, loadTrueF);
81
+ let state = { ab: {} };
82
+ expect(f.shouldLoad(state)).toEqual(["emptyFocusedOnState"]);
83
+ // const {requestInfo, requestInit, mutate} = f.load(state)
84
+ // expect(requestInfo).toEqual("load url from undefined")
85
+ // expect(mutate(state)(200, "newValue")).toEqual({"ab": {"a": ".undefined/200/newValue"}})
86
+ });
87
+ it("when state defined, holder is defined child is defined and coniditon is true", () => {
88
+ const opticsTo = (0, lens_1.identityOptics)().focusQuery('ab').focusQuery('a');
89
+ let f = (0, fetcher_1.lensFetcher)(opticsTo, loadTrueF);
90
+ let state = { ab: { a: "a" } };
91
+ expect(f.shouldLoad(state)).toEqual([]);
92
+ const { requestInfo, requestInit, mutate } = f.load(state);
93
+ expect(requestInfo).toEqual("load url from a");
94
+ expect(mutate(state)(200, "newValue")).toEqual({ "ab": { "a": ".a/200/newValue" } });
95
+ });
96
+ });
97
+ describe("fetcherWhenUndefined", () => {
98
+ let opticToA = (0, lens_1.identityOptics)().focusQuery('a');
99
+ const fOKToLoad = (0, fetcher_1.fetcherWhenUndefined)(opticToA, s => ["someUrl", reqInit]);
100
+ const fErrorIfLoad = (0, fetcher_1.fetcherWhenUndefined)(opticToA, () => {
101
+ throw Error('');
102
+ }, "fErrorIfLoad");
103
+ it("should have a description", () => {
104
+ expect(fOKToLoad.description).toEqual("fetcherWhenUndefined(Optional(I.focus?(a)))");
105
+ expect(fErrorIfLoad.description).toEqual("fErrorIfLoad");
106
+ });
107
+ it('doesnt loads when the focused on thing is defined', () => __awaiter(void 0, void 0, void 0, function* () {
108
+ expect(fOKToLoad.shouldLoad({ a: "someValue" })).toEqual(["defined"]);
109
+ }));
110
+ it('loads when the focused on thing is undefined', () => __awaiter(void 0, void 0, void 0, function* () {
111
+ expect(fOKToLoad.shouldLoad({})).toEqual([]);
112
+ const { requestInfo, requestInit, mutate } = fOKToLoad.load({});
113
+ expect(requestInfo).toEqual("someUrl");
114
+ expect(requestInit).toEqual(reqInit);
115
+ expect(mutate({})(200, "someString")).toEqual({
116
+ "a": "someString"
117
+ });
118
+ }));
119
+ });
120
+ let entityAndNameI = (0, lens_1.dirtyPrism)(en => [en.tags, en.entity], arr => ({
121
+ tags: arr[0],
122
+ entity: arr[1]
123
+ }));
124
+ describe("fetchAndMutate", () => {
125
+ const fMutateTrue = (0, fetcher_1.fetchAndMutate)(loadTrueF, s => s + "_mut");
126
+ const fMutateFalse = (0, fetcher_1.fetchAndMutate)(loadFalseF, s => s + "_mut", "someDesc");
127
+ it("should have a description", () => {
128
+ expect(fMutateTrue.description).toEqual("loadTrueF.withMutate");
129
+ expect(fMutateFalse.description).toEqual("someDesc");
130
+ });
131
+ it("shouldLoad if the original shouldLoad", () => {
132
+ expect(fMutateTrue.shouldLoad).toBe(loadTrueF.shouldLoad);
133
+ expect(fMutateFalse.shouldLoad).toBe(loadFalseF.shouldLoad);
134
+ });
135
+ it("should load and then mutate", () => {
136
+ const { requestInfo, requestInit, mutate } = fMutateTrue.load("someString");
137
+ expect(requestInfo).toEqual("load url from someString");
138
+ expect(requestInit).toEqual(reqInit);
139
+ expect(mutate("startState")(200, "loaded")).toEqual(".startState/200/loaded_mut");
140
+ });
141
+ });
142
+ describe("loadIfMarkerChangesFetcher", () => {
143
+ const id = (0, lens_1.identityOptics)();
144
+ const fetcher = (0, fetcher_1.markerFetcher)(id.focusQuery('desired'), (0, fetcher_1.holderIso)('holderForMarkerFetcher'), (desired, actual) => desired == actual, id.focusQuery('target'), marker => s => ["someUrlBasedOn" + marker, {}], "someFetcher");
145
+ it("should not load if the desired is undefined", () => {
146
+ expect(fetcher.shouldLoad({})).toEqual(["Desired Marker undefined"]);
147
+ });
148
+ it("should load if the desired is defined and the target undefined", () => {
149
+ expect(fetcher.shouldLoad({ desired: "something" })).toEqual([]);
150
+ });
151
+ it("should not load if the selected and actual are the same", () => {
152
+ expect(fetcher.shouldLoad({ desired: "tag", target: { tags: "tag", t: "anything" } })).toEqual(["Markers match"]);
153
+ });
154
+ it("should load if the selected and actual are different, and the actual should be updated", () => {
155
+ let state = { target: { tags: "different", t: "something" }, desired: "newTag" };
156
+ expect(fetcher.shouldLoad(state)).toEqual(["Markers match"]);
157
+ const { requestInfo, requestInit, mutate } = fetcher.load(state);
158
+ expect(requestInfo).toEqual("someUrlBasedOnnewTag");
159
+ expect(requestInit).toEqual({});
160
+ expect(mutate(state)(200, "targetString")).toEqual({ target: { tags: "newTag", t: "targetString" }, desired: "newTag" });
161
+ });
162
+ });
163
+ describe("loadSelectedFetcher", () => {
164
+ const reqFn = (s) => ["someUrl", reqInit];
165
+ const f = (0, fetcher_1.loadSelectedFetcher)(s => [s.selState.selProfile, s.selState.selEntity], entityAndNameI, (0, lens_1.identityOptics)().focusQuery('entityAndName'), reqFn);
166
+ const fignoreerror = (0, fetcher_1.loadSelectedFetcher)(s => { throw Error('error loading'); }, entityAndNameI, (0, lens_1.identityOptics)().focusQuery('entityAndName'), reqFn, fetcher_1.not200MeansError, e => s => (Object.assign(Object.assign({}, s), { msg: "errorhandled" })));
167
+ const fDontIgnoreerror = (0, fetcher_1.loadSelectedFetcher)(s => { throw Error('error loading'); }, entityAndNameI, (0, lens_1.identityOptics)().focusQuery('entityAndName'), reqFn);
168
+ it("should have a description", () => {
169
+ expect(f.description).toEqual("selStateFetcher(holder=DirtyPrism(prism),target=Optional(I.focus?(entityAndName)),onError=false)");
170
+ expect(fignoreerror.description).toEqual("selStateFetcher(holder=DirtyPrism(prism),target=Optional(I.focus?(entityAndName)),onError=true)");
171
+ const f2 = (0, fetcher_1.loadSelectedFetcher)(s => [s.selState.selProfile, s.selState.selEntity], entityAndNameI, (0, lens_1.identityOptics)().focusQuery('entityAndName'), reqFn, fetcher_1.not200MeansError, e => s => (Object.assign(Object.assign({}, s), { msg: "errorhandled" })), "someDescription");
172
+ expect(f2.description).toEqual("someDescription");
173
+ });
174
+ it("should not load if any of the tags are undefined", () => {
175
+ expect(f.shouldLoad({ selState: {} })).toEqual(["not all tags defined"]);
176
+ expect(f.shouldLoad({ selState: { selEntity: 'someEntity' } })).toEqual(["not all tags defined"]);
177
+ expect(f.shouldLoad({ selState: { selProfile: 'someProfile' } })).toEqual(["not all tags defined"]);
178
+ });
179
+ it("should load if there is an error in reqFn and the onError is defined", () => {
180
+ let start = { selState: {} };
181
+ expect(fignoreerror.shouldLoad(start)).toEqual([]);
182
+ const { requestInfo, requestInit, mutate, useThisInsteadOfLoad } = fignoreerror.load(start);
183
+ expect(useThisInsteadOfLoad && useThisInsteadOfLoad(start)).toEqual({ "msg": "errorhandled", "selState": {} });
184
+ });
185
+ it("should still throw shouldload error if there is an error and the ignoreError is true", () => {
186
+ expect(() => fDontIgnoreerror.shouldLoad({ selState: {} })).toThrow('error loading');
187
+ });
188
+ it("should load if the tags are defined, and the target is undefined", () => {
189
+ let startState = { selState: { selEntity: 'someEntity', selProfile: 'someProfile' } };
190
+ expect(f.shouldLoad(startState)).toEqual([]);
191
+ const { requestInfo, requestInit, mutate } = f.load(startState);
192
+ expect(requestInfo).toEqual("someUrl");
193
+ expect(requestInit).toEqual(reqInit);
194
+ expect(mutate(startState)(200, { "desc": "loaded" })).toEqual({
195
+ "entityAndName": {
196
+ "entity": { "desc": "loaded" },
197
+ "tags": ["someProfile", "someEntity"]
198
+ },
199
+ "selState": { "selEntity": "someEntity", "selProfile": "someProfile" }
200
+ });
201
+ });
202
+ it("should not load if the tags are defined, and the tags are identical", () => {
203
+ let s = {
204
+ "entityAndName": {
205
+ "entity": { "desc": "oldDataSoShouldntChange" },
206
+ "tags": ["someProfile", "someEntity"]
207
+ },
208
+ "selState": { "selEntity": "someEntity", "selProfile": "someProfile" }
209
+ };
210
+ expect(f.shouldLoad(s)).toEqual(["tags match"]);
211
+ });
212
+ it("should load if the tags are defined, and the tags are not identical", () => __awaiter(void 0, void 0, void 0, function* () {
213
+ let s = {
214
+ "entityAndName": {
215
+ "entity": { "desc": "oldDataWillChange" },
216
+ "tags": ["someProfile", "someEntity"]
217
+ },
218
+ "selState": { "selEntity": "someNewEntity", "selProfile": "someProfile" }
219
+ };
220
+ expect(f.shouldLoad(s)).toEqual([]);
221
+ const { requestInfo, requestInit, mutate } = f.load(s);
222
+ expect(requestInfo).toEqual("someUrl");
223
+ expect(requestInit).toEqual(reqInit);
224
+ expect(mutate(s)(200, { "desc": "loaded" })).toEqual({
225
+ "entityAndName": {
226
+ "entity": { "desc": "loaded" },
227
+ "tags": ["someProfile", "someNewEntity"]
228
+ },
229
+ "selState": { "selEntity": "someNewEntity", "selProfile": "someProfile" }
230
+ });
231
+ }));
232
+ it("should handle a 404 if the onNotFound is defined", () => __awaiter(void 0, void 0, void 0, function* () {
233
+ let s = {
234
+ "entityAndName": {
235
+ "entity": { "desc": "oldDataWillChange" },
236
+ "tags": ["someProfile", "someEntity"]
237
+ },
238
+ "selState": { "selEntity": "someNewEntity", "selProfile": "someProfile" }
239
+ };
240
+ const f = (0, fetcher_1.loadSelectedFetcher)(s => [s.selState.selProfile, s.selState.selEntity], entityAndNameI, (0, lens_1.identityOptics)().focusQuery('entityAndName'), reqFn, (req, tags, s) => ({ entity: { "desc": "notFound" }, tags }));
241
+ const { requestInfo, requestInit, mutate } = f.load(s);
242
+ expect(mutate(s)(404, { "desc": "not used" })).toEqual({
243
+ "entityAndName": {
244
+ "entity": { "desc": "notFound" },
245
+ "tags": ["someProfile", "someNewEntity"]
246
+ },
247
+ "selState": { "selEntity": "someNewEntity", "selProfile": "someProfile" }
248
+ });
249
+ }));
250
+ it("should throw an error with a 404 if the onNotFound is not defined", () => __awaiter(void 0, void 0, void 0, function* () {
251
+ let s = {
252
+ "entityAndName": {
253
+ "entity": { "desc": "oldDataWillChange" },
254
+ "tags": ["someProfile", "someEntity"]
255
+ },
256
+ "selState": { "selEntity": "someNewEntity", "selProfile": "someProfile" }
257
+ };
258
+ const { requestInfo, requestInit, mutate } = f.load(s);
259
+ expect(() => mutate(s)(404, { "desc": "not used" })).toThrow("req someUrl [object Object] caused status code 404");
260
+ }));
261
+ });
262
+ const radioL = (0, lens_1.identityOptics)().focusQuery('radio');
263
+ const radioTagL = (0, lens_1.identityOptics)().focusQuery('radioTag');
264
+ function loaderForRadio(radio) {
265
+ return s => [`url for ${radio}`, reqInit];
266
+ }
267
+ const r1Fetcher = (0, fetcher_1.fetcherWhenUndefined)(radioL, loaderForRadio("1"));
268
+ const r2Fetcher = (0, fetcher_1.fetcherWhenUndefined)(radioL, loaderForRadio("2"));
269
+ const r3Fetcher = (0, fetcher_1.fetcherWhenUndefined)(radioL, loaderForRadio("3"));
270
+ let radioGroup = ({
271
+ tag1: r1Fetcher,
272
+ tag2: r2Fetcher,
273
+ tag3: r3Fetcher,
274
+ });
275
+ describe("fetchRadioButton", () => {
276
+ let f = (0, fetcher_1.radioButtonFetcher)(s => s.selState.selRadioTag, radioTagL, (0, fetcher_1.fromTaggedFetcher)(radioGroup));
277
+ it("should have a description", () => {
278
+ expect(f.description).toEqual("fetchRadioButton(Optional(I.focus?(radioTag)))");
279
+ });
280
+ it("should not fetch if tag is undefined", () => __awaiter(void 0, void 0, void 0, function* () {
281
+ expect(f.shouldLoad({ selState: {} })).toEqual(["Cannot find f"]);
282
+ }));
283
+ it("should fetch if tag is defined and legal and the target is undefined. It should set 'actual tag'", () => __awaiter(void 0, void 0, void 0, function* () {
284
+ expect(f.shouldLoad({ selState: { selRadioTag: "doesntexist" } })).toEqual(["Cannot find f"]);
285
+ let tag1State = { selState: { selRadioTag: "tag1" } };
286
+ expect(f.shouldLoad(tag1State)).toEqual([]);
287
+ const { requestInfo, requestInit, mutate } = f.load(tag1State);
288
+ expect(requestInfo).toEqual("url for 1");
289
+ expect(requestInit).toEqual(reqInit);
290
+ expect(mutate(tag1State)(200, { r1: "r1value" })).toEqual({
291
+ "radio": { "r1": "r1value" },
292
+ "radioTag": "tag1",
293
+ "selState": { "selRadioTag": "tag1" }
294
+ });
295
+ }));
296
+ it("should fetch if the tag is defined, but a different value. It should set 'actualTag'", () => __awaiter(void 0, void 0, void 0, function* () {
297
+ let state = { selState: { selRadioTag: "tag2" }, radioTag: "tag1", radio: { "r1": "r1value" } };
298
+ expect(f.shouldLoad(state)).toEqual([]);
299
+ const { requestInfo, requestInit, mutate } = f.load(state);
300
+ expect(requestInfo).toEqual("url for 2");
301
+ expect(requestInit).toEqual(reqInit);
302
+ expect(mutate(state)(200, { r2: "r2value" })).toEqual({
303
+ "radio": { "r2": "r2value" },
304
+ "radioTag": "tag2",
305
+ "selState": { "selRadioTag": "tag2" }
306
+ });
307
+ }));
308
+ it("should fetch if the tag is defined, but a different value. Even if the target is empty It should set 'actualTag'", () => __awaiter(void 0, void 0, void 0, function* () {
309
+ let state = { selState: { selRadioTag: "tag2" }, radioTag: "tag1" };
310
+ expect(f.shouldLoad(state)).toEqual([]);
311
+ const { requestInfo, requestInit, mutate } = f.load(state);
312
+ expect(requestInfo).toEqual("url for 2");
313
+ expect(requestInit).toEqual(reqInit);
314
+ expect(mutate(state)(200, { r2: "r2value" })).toEqual({
315
+ "radio": { "r2": "r2value" },
316
+ "radioTag": "tag2",
317
+ "selState": { "selRadioTag": "tag2" }
318
+ });
319
+ }));
320
+ });
321
+ describe("ifErrorFetcher", () => {
322
+ let rawError = (0, fetcher_1.fetcher)(shouldLoadTrue, s => { throw Error('msg'); }, "loadFalseF");
323
+ const fFalse = (0, fetcher_1.ifErrorFetcher)(loadFalseF, () => { throw Error('failed'); });
324
+ const fTrue = (0, fetcher_1.ifErrorFetcher)(loadTrueF, () => { throw Error('failed'); });
325
+ const fError = (0, fetcher_1.ifErrorFetcher)(rawError, e => s => `${e}+${s}`);
326
+ it("shouldLoad should act as the old one ", () => {
327
+ expect(fFalse.shouldLoad("'")).toEqual(["some reason"]);
328
+ expect(fTrue.shouldLoad("'")).toEqual([]);
329
+ expect(fError.shouldLoad("'")).toEqual([]);
330
+ });
331
+ it("load should act as old if there are no errors", () => {
332
+ const { requestInfo, requestInit, mutate, useThisInsteadOfLoad } = (fTrue.load('oldState'));
333
+ expect(requestInfo).toEqual('load url from oldState');
334
+ expect(requestInit).toEqual({ "keepalive": true });
335
+ expect(useThisInsteadOfLoad).toEqual(undefined);
336
+ expect(mutate("someValue")(200, "loaded")).toEqual('.someValue/200/loaded');
337
+ });
338
+ it("should return the on error when there was an error", () => {
339
+ const { requestInfo, requestInit, mutate, useThisInsteadOfLoad } = (fError.load('oldState'));
340
+ expect(requestInfo).toEqual('');
341
+ expect(requestInit).toEqual(undefined);
342
+ if (!useThisInsteadOfLoad)
343
+ throw Error();
344
+ expect(useThisInsteadOfLoad("oldstate")).toEqual("Error: msg+oldstate");
345
+ });
346
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ const enzyme_1 = require("enzyme");
5
+ const pages_1 = require("@focuson/pages");
6
+ const page_fixture_1 = require("./page.fixture");
7
+ const enzymeAdapterSetup_1 = require("./enzymeAdapterSetup");
8
+ (0, enzymeAdapterSetup_1.enzymeSetup)();
9
+ let view = 'view';
10
+ const nothingDisplayed = Object.assign(Object.assign({}, page_fixture_1.emptyState), { messages: [], pageSelection: [{ pageName: 'nothing', pageMode: view, time: 'now' }] });
11
+ describe("selectedPage", () => {
12
+ // it ( "should display zero pages", () => {
13
+ // const state = lensState<PageSpecState, ContextForTest> ( rootState, () => {}, 'displayMain / focusedPage', context )
14
+ // const comp = shallow ( <SelectedPage state={state}/> )
15
+ // // expect ( comp.html () ).toEqual ( '' )
16
+ // expect ( comp.text () ).toEqual ( "" )
17
+ // } )
18
+ it("should display one page", () => {
19
+ const state = (0, page_fixture_1.lensStateWith)(page_fixture_1.dataDefinedState, () => { }, ['firstPage', 'edit', undefined]);
20
+ const comp = (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(pages_1.SelectedPage, { state: state }));
21
+ expect(comp.html()).toEqual("<div class=\"combine\"><div class=\"focus-page\"><div id=\"default_template\">" +
22
+ "<h1>[firstPageTitle]:</h1>" +
23
+ "<p>firstPage[one]/edit</p>" +
24
+ "</div></div></div>");
25
+ });
26
+ it("should display two pages", () => {
27
+ const state = (0, page_fixture_1.lensStateWith)(page_fixture_1.dataDefinedState, () => { }, ['firstPage', 'edit', undefined], ['secondPage', 'view', undefined]);
28
+ const comp = (0, enzyme_1.shallow)((0, jsx_runtime_1.jsx)(pages_1.SelectedPage, { state: state }));
29
+ // expect ( comp.html () ).toEqual ( '' )
30
+ expect(comp.html()).toEqual('<div class="combine"><div class="focus-page"><div id="default_template">' +
31
+ '<h1>[firstPageTitle]:</h1>' +
32
+ '<p>firstPage[one]/edit</p></div></div>' +
33
+ '<div class="focus-page"><div id="default_template">' +
34
+ '<h1>[secondPageTitle]:</h1>' +
35
+ '<p>secondPage[two]/view</p></div></div></div>');
36
+ });
37
+ it("should display three pages", () => {
38
+ const state = (0, page_fixture_1.lensStateWith)(page_fixture_1.dataDefinedState, () => { }, ['firstPage', 'edit', undefined], ['secondPage', 'view', undefined], ['modalData', 'edit', undefined]);
39
+ const comp = (0, enzyme_1.shallow)((0, jsx_runtime_1.jsx)(pages_1.SelectedPage, { state: state }));
40
+ // expect ( comp.html () ).toEqual ( '' )
41
+ expect(comp.html()).toEqual('<div class="combine"><div class="focus-page"><div id="default_template">' +
42
+ '<h1>[firstPageTitle]:</h1>' +
43
+ '<p>firstPage[one]/edit</p></div></div>' +
44
+ '<div class="focus-page"><div id="default_template">' +
45
+ '<h1>[secondPageTitle]:</h1>' +
46
+ '<p>secondPage[two]/view</p></div></div>' +
47
+ '<div class="focus-page"><div id="default_template">' +
48
+ '<h1>[modalDataTitle]:</h1>' +
49
+ '<p>modalData[x]/edit</p></div></div></div>');
50
+ });
51
+ it("shouldbe using the combine for multiple pages", () => {
52
+ const state = (0, page_fixture_1.lensStateWith)(page_fixture_1.dataDefinedState, () => { }, ['firstPage', 'edit', undefined], ['secondPage', 'view', undefined], ['modalData', 'edit', undefined]);
53
+ const comp = (0, enzyme_1.shallow)((0, jsx_runtime_1.jsx)(pages_1.SelectedPage, { state: state }));
54
+ expect(comp.find('.combine').length).toEqual(1);
55
+ });
56
+ it("display loading when no data", () => {
57
+ const state = (0, page_fixture_1.lensStateWith)(page_fixture_1.rootState, () => { }, ['firstPage', 'edit', undefined], ['secondPage', 'view', undefined], ['modalData', 'edit', undefined]);
58
+ const comp = (0, enzyme_1.shallow)((0, jsx_runtime_1.jsx)(pages_1.SelectedPage, { state: state }));
59
+ expect(comp.html()).toEqual('<div class="combine">' +
60
+ '<div class="focus-page"><div id="default_template"><h1>[firstPageTitle]:</h1>' +
61
+ '<div><p>Loading</p><span class="tooltip-wrap">' +
62
+ '<button class="button" id="loading.cancel" aria-errormessage="loading.cancel.error" aria-invalid="false">Cancel </button>' +
63
+ '<ul hidden="" class="errormessage tooltip" id="loading.cancel.error"></ul></span></div></div></div><div class="focus-page">' +
64
+ '<div id="default_template"><h1>[secondPageTitle]:</h1><div><p>Loading</p>' +
65
+ '<span class="tooltip-wrap"><button class="button" id="loading.cancel" aria-errormessage="loading.cancel.error" aria-invalid="false">Cancel </button>' +
66
+ '<ul hidden="" class="errormessage tooltip" id="loading.cancel.error"></ul></span></div></div></div>' +
67
+ '<div class="focus-page"><div id="default_template">' +
68
+ '<h1>[modalDataTitle]:</h1><p>modalData[x]/edit</p></div></div></div>');
69
+ });
70
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,105 @@
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 state_1 = require("@focuson/state");
6
+ const context_fixture_1 = require("./context.fixture");
7
+ const enzyme_1 = require("enzyme");
8
+ const form_components_1 = require("@focuson/form_components");
9
+ (0, enzymeAdapterSetup_1.enzymeSetup)();
10
+ const empty = {
11
+ messages: [], pageSelection: [], restCommands: [], tags: {}
12
+ };
13
+ function labelAndString(label, string, className) {
14
+ const state = (0, state_1.lensState)(Object.assign(Object.assign({}, empty), { string }), () => { }, '', (0, context_fixture_1.context)());
15
+ // @ts-ignore
16
+ const focusedState = state.focusOn('string');
17
+ return (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(form_components_1.LabelAndStringInput, { id: 'someId', state: focusedState, label: label, allButtons: {}, className: className }));
18
+ }
19
+ function labelAndNumber(label, number, className) {
20
+ const state = (0, state_1.lensState)(Object.assign(Object.assign({}, empty), { number }), () => { }, '', (0, context_fixture_1.context)());
21
+ // @ts-ignore
22
+ const focusedState = state.focusOn('number');
23
+ return (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(form_components_1.LabelAndNumberInput, { id: 'someId', state: focusedState, label: label, allButtons: {}, className: className }));
24
+ }
25
+ function labelAndBoolean(label, boolean, className) {
26
+ const state = (0, state_1.lensState)(Object.assign(Object.assign({}, empty), { boolean }), () => { }, '', (0, context_fixture_1.context)());
27
+ // @ts-ignore
28
+ const focusedState = state.focusOn('boolean');
29
+ return (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(form_components_1.LabelAndBooleanInput, { id: 'someId', state: focusedState, label: label, allButtons: {}, className: className }));
30
+ }
31
+ function labelAndYNBoolean(label, yn, className) {
32
+ const state = (0, state_1.lensState)(Object.assign(Object.assign({}, empty), { yn }), () => { }, '', (0, context_fixture_1.context)());
33
+ // @ts-ignore
34
+ const focusedState = state.focusOn('yn');
35
+ return (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(form_components_1.LabelAndYNBooleanInput, { id: 'someId', state: focusedState, label: label, allButtons: {}, className: className }));
36
+ }
37
+ describe('LabelAndString', () => {
38
+ it('should render with data', () => {
39
+ expect(labelAndString('someLabel', 'someString').html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class=""><input class="input" type="text" id="someId" data-validationmessage="someLabel" value="someString"></div><div id="someId.error" hidden="" class=""></div></div>');
40
+ });
41
+ it('should render with html label', () => {
42
+ expect(labelAndString('some <b>bold</b> Label', 'someString').html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">some <b>bold</b> Label</label><div class=""><input class="input" type="text" id="someId" data-validationmessage="some <b>bold</b> Label" value="someString"></div><div id="someId.error" hidden="" class=""></div></div>');
43
+ });
44
+ it('should render with undefined', () => {
45
+ // @ts-ignore
46
+ const string = undefined;
47
+ expect(labelAndString('someLabel', string).html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class=""><input class="input" type="text" id="someId" data-validationmessage="someLabel" value=""></div><div id="someId.error" hidden="" class=""></div></div>');
48
+ });
49
+ it('should render with null', () => {
50
+ // @ts-ignore
51
+ const string = null;
52
+ expect(labelAndString('someLabel', string).html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class=""><input class="input" type="text" id="someId" data-validationmessage="someLabel" value=""></div><div id="someId.error" hidden="" class=""></div></div>');
53
+ });
54
+ it('should include a className if specified', () => {
55
+ // @ts-ignore
56
+ const number = 'someString';
57
+ expect(labelAndString('someLabel', number, 'theClass').html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class="theClass"><input class="input" type="text" id="someId" data-validationmessage="someLabel" value="someString"></div><div id="someId.error" hidden="" class=""></div></div>');
58
+ });
59
+ });
60
+ describe('LabelAndNumber', () => {
61
+ it('should render with data', () => {
62
+ expect(labelAndNumber('someLabel', 123).html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class=""><input class="input" type="number" id="someId" data-validationmessage="someLabel" value="123"></div><div id="someId.error" hidden="" class=""></div></div>');
63
+ });
64
+ it('should render with html label', () => {
65
+ expect(labelAndNumber('some <b>bold</b> Label', 123).html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">some <b>bold</b> Label</label><div class=""><input class="input" type="number" id="someId" data-validationmessage="some <b>bold</b> Label" value="123"></div><div id="someId.error" hidden="" class=""></div></div>');
66
+ });
67
+ it('should render with undefined', () => {
68
+ // @ts-ignore
69
+ const number = undefined;
70
+ expect(labelAndNumber('someLabel', number).html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class=""><input class="input" type="number" id="someId" data-validationmessage="someLabel" value=""></div><div id="someId.error" hidden="" class=""></div></div>');
71
+ });
72
+ it('should render with null', () => {
73
+ // @ts-ignore
74
+ const number = null;
75
+ expect(labelAndNumber('someLabel', number).html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class=""><input class="input" type="number" id="someId" data-validationmessage="someLabel" value=""></div><div id="someId.error" hidden="" class=""></div></div>');
76
+ });
77
+ it('should include a className if specified', () => {
78
+ // @ts-ignore
79
+ const number = 123;
80
+ expect(labelAndNumber('someLabel', number, 'theClass').html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class="theClass"><input class="input" type="number" id="someId" data-validationmessage="someLabel" value="123"></div><div id="someId.error" hidden="" class=""></div></div>');
81
+ });
82
+ });
83
+ describe('LabelAndBoolean', () => {
84
+ it('should render with data - true', () => {
85
+ expect(labelAndBoolean('someLabel', true).html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class="checkbox-container"><input type="checkbox" id="someId" data-validationmessage="someLabel" class="input" checked=""><span class="checkmark"></span></div><div id="someId.error" hidden="" class=""></div></div>');
86
+ });
87
+ it('should render with data - false', () => {
88
+ expect(labelAndBoolean('someLabel', false).html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class="checkbox-container"><input type="checkbox" id="someId" data-validationmessage="someLabel" class="input"><span class="checkmark"></span></div><div id="someId.error" hidden="" class=""></div></div>');
89
+ });
90
+ it('should render with undefined', () => {
91
+ // @ts-ignore
92
+ const number = undefined;
93
+ expect(labelAndBoolean('someLabel', number).html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class="checkbox-container"><input type="checkbox" id="someId" data-validationmessage="someLabel" class="input"><span class="checkmark"></span></div><div id="someId.error" hidden="" class=""></div></div>');
94
+ });
95
+ it('should render with null', () => {
96
+ // @ts-ignore
97
+ const number = null;
98
+ expect(labelAndBoolean('someLabel', number).html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class="checkbox-container"><input type="checkbox" id="someId" data-validationmessage="someLabel" class="input"><span class="checkmark"></span></div><div id="someId.error" hidden="" class=""></div></div>');
99
+ });
100
+ it('should include a className if specified', () => {
101
+ // @ts-ignore
102
+ const number = true;
103
+ expect(labelAndBoolean('someLabel', number, 'theClass').html()).toEqual('<div class="labelValueButton "> <label for="someId" class="input-label">someLabel</label><div class="checkbox-container theClass"><input type="checkbox" id="someId" data-validationmessage="someLabel" class="input" checked=""><span class="checkmark"></span></div><div id="someId.error" hidden="" class=""></div></div>');
104
+ });
105
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const form_components_1 = require("@focuson/form_components");
4
+ const firstMay2020 = new Date('2020/05/01');
5
+ describe("parseDate", () => {
6
+ it("should parse yyyy/MM/dd", () => {
7
+ expect((0, form_components_1.parseDate)('prefix', 'yyyy/MM/dd')('2020/05/01')).toEqual(firstMay2020);
8
+ expect((0, form_components_1.parseDate)('prefix', 'yyyy/MM/dd')('2020-05-01')).toEqual(firstMay2020);
9
+ });
10
+ it("should parse yyyy-MM-dd", () => {
11
+ expect((0, form_components_1.parseDate)('prefix', 'yyyy-MM-dd')('2020-05-01')).toEqual(firstMay2020);
12
+ expect((0, form_components_1.parseDate)('prefix', 'yyyy-MM-dd')('2020-05-01')).toEqual(firstMay2020);
13
+ });
14
+ it("should parse dd/yyyy/MM", () => {
15
+ expect((0, form_components_1.parseDate)('prefix', 'dd/yyyy-MM')('01-2020-05')).toEqual(firstMay2020);
16
+ expect((0, form_components_1.parseDate)('prefix', 'dd/yyyy-MM')('01/2020/05')).toEqual(firstMay2020);
17
+ });
18
+ it("should parse dd-yyyy-MM", () => {
19
+ expect((0, form_components_1.parseDate)('prefix', 'dd-yyyy-MM')('01-2020-05')).toEqual(firstMay2020);
20
+ expect((0, form_components_1.parseDate)('prefix', 'dd-yyyy-MM')('01-2020-05')).toEqual(firstMay2020);
21
+ });
22
+ it("should parse dd/MM/yyyy", () => {
23
+ expect((0, form_components_1.parseDate)('prefix', 'dd-MM-yyyy')('01-05-2020')).toEqual(firstMay2020);
24
+ expect((0, form_components_1.parseDate)('prefix', 'dd-MM-yyyy')('01/05/2020')).toEqual(firstMay2020);
25
+ });
26
+ });
@@ -0,0 +1 @@
1
+ export {};