@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,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.context = exports.pageDetails = exports.invalidPageState = exports.secondPageSelectedState = exports.firstPageWithFirstTime = exports.firstPageSelectedState = exports.dataDefinedState = exports.rootState = exports.emptyState = void 0;
4
+ exports.stateWith = stateWith;
5
+ exports.stateWithFirstTimes = stateWithFirstTimes;
6
+ exports.lensStateWith = lensStateWith;
7
+ exports.pageSpecStateConfig = pageSpecStateConfig;
8
+ const jsx_runtime_1 = require("react/jsx-runtime");
9
+ const state_1 = require("@focuson/state");
10
+ const lens_1 = require("@focuson/lens");
11
+ const pages_1 = require("@focuson/pages");
12
+ const utils_1 = require("@focuson/utils");
13
+ const focuson_1 = require("@focuson/focuson");
14
+ exports.emptyState = {
15
+ pageSelection: [], messages: [], tags: {}, restCommands: []
16
+ };
17
+ exports.rootState = Object.assign(Object.assign({}, exports.emptyState), { messages: [], pageSelection: [], tempData: 'x' });
18
+ exports.dataDefinedState = Object.assign(Object.assign({}, exports.emptyState), { firstPage: 'one', secondPage: { fromApi: 'two' }, messages: [], pageSelection: [], tempData: 'x' });
19
+ exports.firstPageSelectedState = stateWith(exports.rootState, ['firstPage', 'view', undefined]);
20
+ exports.firstPageWithFirstTime = stateWithFirstTimes(exports.rootState, ['firstPage', 'view', undefined]);
21
+ exports.secondPageSelectedState = stateWith(exports.rootState, ['secondPage', 'view', undefined]);
22
+ exports.invalidPageState = stateWithFirstTimes(exports.rootState, ['unknownpage', 'view', undefined]);
23
+ function stateWith(main, ...nameAndModes) {
24
+ return Object.assign(Object.assign({}, main), { pageSelection: nameAndModes.map(([pageName, pageMode, rest]) => ({ pageName, pageMode, rest, time: 'now' })) });
25
+ }
26
+ function stateWithFirstTimes(main, ...nameAndModes) {
27
+ return Object.assign(Object.assign({}, main), { pageSelection: nameAndModes.map(([pageName, pageMode, rest]) => ({ pageName, pageMode, firstTime: true, rest, time: 'now' })) });
28
+ }
29
+ function lensStateWith(main, setMain, ...nameAndModes) {
30
+ return (0, state_1.lensState)(stateWith(main, ...nameAndModes), setMain, 'displayMain / focusedPage', exports.context);
31
+ }
32
+ const DisplayPageSpecState = (prefix, haveTopRightCrossToCancel) => (0, pages_1.focusedPage)(() => ({ title: `[${prefix}Title]:` }), haveTopRightCrossToCancel === true)((s, d, mode) => ((0, jsx_runtime_1.jsxs)("p", { children: [prefix, "[", d, "]/", mode] })));
33
+ function pageSpecStateConfig() {
34
+ // @ts-ignore There is some crazy thing going on here around SimpleMessage and SimpleMessage[].
35
+ let pageConfig = (0, pages_1.simpleMessagesPageConfig)(pages_1.Loading);
36
+ return pageConfig;
37
+ }
38
+ exports.pageDetails = {
39
+ firstPage: { pageType: 'MainPage', config: pageSpecStateConfig(), lens: (0, lens_1.identityOptics)().focusQuery('firstPage'), pageFunction: DisplayPageSpecState('firstPage'), pageMode: 'edit' },
40
+ clearAtStart: { pageType: 'MainPage', config: pageSpecStateConfig(), lens: (0, lens_1.identityOptics)().focusQuery('firstPage'), pageFunction: DisplayPageSpecState('firstPage'), clearAtStart: true, pageMode: 'edit' },
41
+ init: {
42
+ pageType: 'MainPage', config: pageSpecStateConfig(), lens: (0, lens_1.identityOptics)().focusQuery('firstPage'), pageFunction: DisplayPageSpecState('firstPage'),
43
+ initialValue: [{ command: 'set', path: '~', value: "Initial Value" }], pageMode: 'edit'
44
+ },
45
+ secondPage: { pageType: 'MainPage', config: pageSpecStateConfig(), lens: (0, lens_1.identityOptics)().focusQuery('secondPage').focusQuery('fromApi'), pageFunction: DisplayPageSpecState('secondPage'), clearAtStart: true, pageMode: 'edit' },
46
+ modalData: {
47
+ pageType: 'MainPage', config: pageSpecStateConfig(), lens: (0, lens_1.identityOptics)().focusQuery('tempData'), pageFunction: DisplayPageSpecState('modalData'),
48
+ initialValue: [{ command: 'set', path: '~', value: "Initial Value" }], pageMode: 'edit'
49
+ },
50
+ error: {
51
+ pageType: 'MainPage', config: pageSpecStateConfig(), lens: (0, lens_1.identityOptics)().focusQuery('tempData'), pageFunction: DisplayPageSpecState('error'), clearAtStart: true,
52
+ initialValue: [{ command: 'set', path: '~', value: "Initial Value" }], pageMode: 'edit'
53
+ },
54
+ };
55
+ exports.context = (0, focuson_1.defaultPageSelectionAndRestCommandsContext)(exports.pageDetails, {}, {}, {}, utils_1.testDateFn, true);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ const lens_1 = require("@focuson/lens");
5
+ const focuson_1 = require("@focuson/focuson");
6
+ const state_1 = require("@focuson/state");
7
+ const pages_1 = require("@focuson/pages");
8
+ const utils_1 = require("@focuson/utils");
9
+ let pageSelection = { pageName: 'a', pageMode: 'view', time: 'now' };
10
+ const x = { g: 1, h: ['h0', 'h1'], i: { j: 2 } };
11
+ const textForLabelState = {
12
+ messages: [],
13
+ tags: {},
14
+ pageSelection: [pageSelection],
15
+ restCommands: [],
16
+ a: {
17
+ b: { c: 'cValue', x },
18
+ d: ['zero', 'one', 'two', 'three', 'four', 'five'],
19
+ selecteda: 3,
20
+ e: 5,
21
+ f: 6,
22
+ holdse: 'e',
23
+ holdsf: 'e',
24
+ },
25
+ selected: 2,
26
+ holdseinroot: 'e'
27
+ };
28
+ const identity = lens_1.Lenses.identity();
29
+ const aL = identity.focusQuery('a');
30
+ const abL = identity.focusOn('a').focusQuery('b');
31
+ const abxL = identity.focusOn('a').focusQuery('b').focusQuery('x');
32
+ const pageDetails = {
33
+ a: { config: {}, pageType: 'MainPage', pageFunction: () => (0, jsx_runtime_1.jsx)("span", {}), lens: aL, pageMode: 'edit' }
34
+ };
35
+ const state = (0, state_1.lensState)(textForLabelState, s => { }, '', (0, focuson_1.defaultPageSelectionAndRestCommandsContext)(pageDetails, {}, {}, {}, utils_1.testDateFn, true));
36
+ // const fromPath: ( path: string[], description?: string ) => Optional<TextForLabelState, any> = fromPathFor ( state )
37
+ let stateabx = state.copyWithLens(abxL);
38
+ const fromL = (path) => (0, pages_1.fromPathGivenState)(stateabx)(path);
39
+ const from = (path) => fromL(path).getOption(state.main);
40
+ const set = (path, value) => fromL(path).set(state.main, value);
41
+ const ps1 = { pageName: 'one', pageMode: 'view', time: 'time1' };
42
+ const ps2 = { pageName: 'two', pageMode: 'view', time: 'time2' };
43
+ const ps3 = { pageName: 'three', pageMode: 'view', time: 'time3' };
44
+ const psNew = { pageName: 'new', pageMode: 'view', time: 'timeNew' };
45
+ describe("applyPageOps", () => {
46
+ describe("should select - replace whatever is there with this page", () => {
47
+ it("should select with no current pages", () => {
48
+ expect((0, pages_1.applyPageOps)('select', psNew)([])).toEqual([psNew]);
49
+ });
50
+ it("should select with one or more pages", () => {
51
+ expect((0, pages_1.applyPageOps)('select', psNew)([ps1])).toEqual([psNew]);
52
+ expect((0, pages_1.applyPageOps)('select', psNew)([ps1, ps2, ps3])).toEqual([psNew]);
53
+ });
54
+ });
55
+ describe("should popup - add this page", () => {
56
+ it("should popup with no current pages", () => {
57
+ expect((0, pages_1.applyPageOps)('popup', psNew)([])).toEqual([psNew]);
58
+ });
59
+ it("should popup with no one pages", () => {
60
+ expect((0, pages_1.applyPageOps)('popup', psNew)([ps1])).toEqual([ps1, psNew]);
61
+ expect((0, pages_1.applyPageOps)('popup', psNew)([ps1, ps2])).toEqual([ps1, ps2, psNew]);
62
+ expect((0, pages_1.applyPageOps)('popup', psNew)([ps1, ps2, ps3])).toEqual([ps1, ps2, ps3, psNew]);
63
+ });
64
+ });
65
+ describe("should replace - replace the top page", () => {
66
+ it("should replace with no current pages", () => {
67
+ expect((0, pages_1.applyPageOps)('replace', psNew)([])).toEqual([psNew]);
68
+ });
69
+ it("should replace the top page", () => {
70
+ expect((0, pages_1.applyPageOps)('replace', psNew)([ps1])).toEqual([psNew]);
71
+ expect((0, pages_1.applyPageOps)('replace', psNew)([ps1, ps2])).toEqual([ps1, psNew]);
72
+ expect((0, pages_1.applyPageOps)('replace', psNew)([ps1, ps2, ps3])).toEqual([ps1, ps2, psNew]);
73
+ });
74
+ });
75
+ });
76
+ describe("fromPathStringFor. Page is 'a'. The current lens is a/b/x", () => {
77
+ it("should default to a path from 'here'. i.e. a/b/x'", () => {
78
+ expect(from("g")).toEqual(1);
79
+ expect(set("g", 1).a.b.x).toEqual({ "g": 1, "h": ["h0", "h1"], "i": { "j": 2 } });
80
+ expect(from("i/j")).toEqual(2);
81
+ expect(set("i/j", 5).a.b.x.i).toEqual({ "j": 5 });
82
+ });
83
+ it("should allow / as a 'root' marker", () => {
84
+ expect(from("/a/e")).toEqual(5);
85
+ expect(from("/a/b/c")).toEqual('cValue');
86
+ expect(set("/a/b/c", 'xx').a.b).toEqual({ "c": "xx", x });
87
+ });
88
+ it("should allow ~ as a 'home' marker i.e. current main page", () => {
89
+ expect(from("~/e")).toEqual(5);
90
+ expect(from("~/b/c")).toEqual('cValue');
91
+ expect(set("~/b/c", 'x').a).toEqual({
92
+ "b": { "c": "x", "x": { "g": 1, "h": ["h0", "h1"], "i": { "j": 2 } } },
93
+ "d": ["zero", "one", "two", "three", "four", "five"],
94
+ "e": 5, "f": 6, "holdse": "e", "holdsf": "e", "selecteda": 3
95
+ });
96
+ });
97
+ it("should allow [ .. ] notation with numbers - default", () => {
98
+ expect(from("h[0]")).toEqual('h0');
99
+ expect(set("h[0]", 'xx').a.b.x.h).toEqual(["xx", "h1"]);
100
+ expect(from("h[0][0]")).toEqual('h');
101
+ expect(from("h[0][1]")).toEqual('0');
102
+ });
103
+ it("should allow [ .. ] notation with numbers - root", () => {
104
+ expect(from("/a/b/c[0]")).toEqual('c');
105
+ expect(from("/a/b/c[1]")).toEqual('V');
106
+ expect(from("/a/b/c[2]")).toEqual('a');
107
+ expect(from("/a/d[2]")).toEqual('two');
108
+ });
109
+ it("should allow [ .. ] notation with numbers - page", () => {
110
+ expect(from("~/b/c[0]")).toEqual('c');
111
+ expect(from("~/b/c[1]")).toEqual('V');
112
+ expect(from("~/b/c[2]")).toEqual('a');
113
+ expect(from("~/d[2]")).toEqual('two');
114
+ });
115
+ it("should allow { ... } notation with special marker {last}", () => {
116
+ expect(from("/a/d[$last]")).toEqual('five');
117
+ expect(fromL("/a/d[$last]").set(textForLabelState, 'x').a.d).toEqual(["zero", "one", "two", "three", "four", "x"]);
118
+ });
119
+ it("should allow [ ... ] notation with special marker {append}", () => {
120
+ expect(from("/a/d[$append]")).toEqual(undefined);
121
+ expect(fromL("/a/d[$append]").set(textForLabelState, 'x').a.d).toEqual(["zero", "one", "two", "three", "four", "five", "x"]);
122
+ });
123
+ it("should allow a path in the [ .. ] notation - default", () => {
124
+ expect(fromL("/a/d[selected]").description).toEqual('I.focus?(a).focus?(d).chainCalc(I.focusOn(a).focus?(b).focus?(x).focus?(selected))');
125
+ expect(fromL("/a/d[/selected]").description).toEqual('I.focus?(a).focus?(d).chainCalc(I.focus?(selected))');
126
+ });
127
+ it("should allow a path in the [ .. ] notation - root", () => {
128
+ expect(from("/a/d[/selected][/selected]")).toEqual('o');
129
+ expect(from("/a/d[/selected]")).toEqual('two');
130
+ expect(from("/a/d[/a/selecteda]")).toEqual('three');
131
+ expect(from("/a/d[/selected][1]")).toEqual('w');
132
+ });
133
+ it("should allow a path in the [ .. ] notation - home", () => {
134
+ expect(from("/a/d[~/e]")).toEqual('five');
135
+ expect(from("/a/d[~/selecteda]")).toEqual('three');
136
+ });
137
+ });
138
+ //Note that the raw behaviour is tested about. Here we just check we make suitable lens
139
+ describe("fromPathFromRaw", () => {
140
+ it("should make lens", () => {
141
+ const fromPath = (0, pages_1.fromPathFromRaw)((0, pages_1.pageSelectionlens)(), pageDetails)(textForLabelState);
142
+ expect(fromPath("~/b/c").description).toEqual('I.focus?(a).focus?(b).focus?(c)');
143
+ expect(fromPath("/a/b/c").description).toEqual('I.focus?(a).focus?(b).focus?(c)');
144
+ expect(() => fromPath("b/c").description).toThrow("Error parsing 'b/c'. Cannot find initial ''");
145
+ });
146
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,84 @@
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 lens_1 = require("@focuson/lens");
13
+ const poster_1 = require("@focuson/poster");
14
+ const identityL = lens_1.Lenses.identity("testPostState");
15
+ const postDebugL = identityL.focusQuery('debug');
16
+ const errorL = identityL.focusQuery('errors');
17
+ const postCommandsL = identityL.focusQuery('postCommands');
18
+ function urlFn(expected) {
19
+ return (args) => {
20
+ expect(args).toEqual(expected);
21
+ return ["/" + args, undefined];
22
+ };
23
+ }
24
+ const onePostDetails = { urlFn: urlFn("args1"), targetLn: identityL.focusQuery('one'), shape: s => s + "_1", errorFn: (0, poster_1.addDebugErrorMessage)(errorL) };
25
+ const twoPostDetails = { urlFn: urlFn("args2"), targetLn: identityL.focusQuery('two'), shape: s => s + "_2", errorFn: (0, poster_1.addDebugErrorMessage)(errorL) };
26
+ const threePostDetails = { urlFn: urlFn("args3"), targetLn: identityL.focusQuery('three'), shape: s => s + "_3", errorFn: (0, poster_1.addDebugErrorMessage)(errorL) };
27
+ const fourPostDetails = { urlFn: urlFn("args4"), targetLn: identityL.focusQuery('four'), shape: s => s + "_4", errorFn: (0, poster_1.addDebugErrorMessage)(errorL) };
28
+ const postDetails = {
29
+ one: onePostDetails,
30
+ two: twoPostDetails,
31
+ three: threePostDetails,
32
+ four: fourPostDetails
33
+ };
34
+ function testFetchFn(requestInfo, requestInit) {
35
+ if (requestInfo === "/args1")
36
+ return Promise.resolve([200, "oneRes"]);
37
+ if (requestInfo === "/args2")
38
+ return Promise.resolve([200, "twoRes"]);
39
+ if (requestInfo === "/args3")
40
+ return Promise.resolve([200, "threeRes"]);
41
+ if (requestInfo === "/args4")
42
+ return Promise.resolve([200, "fourRes"]);
43
+ throw 'failed';
44
+ }
45
+ function testNon200FetchFn(requestInfo, requestInit) {
46
+ if (requestInfo === "/args1")
47
+ return Promise.resolve([200, "oneRes"]);
48
+ if (requestInfo === "/args2")
49
+ return Promise.resolve([400, "twoRes"]);
50
+ if (requestInfo === "/args3")
51
+ return Promise.resolve([500, "threeRes"]);
52
+ if (requestInfo === "/args4")
53
+ return Promise.reject("failed");
54
+ throw 'failed';
55
+ }
56
+ const poster = (0, poster_1.post)(testFetchFn, postDetails, postCommandsL, postDebugL);
57
+ const errorPoster = (0, poster_1.post)(testNon200FetchFn, postDetails, postCommandsL, postDebugL);
58
+ const fourPostCommands = [
59
+ { poster: 'one', args: "args1" },
60
+ { poster: 'two', args: "args2" },
61
+ { poster: 'three', args: "args3" },
62
+ { poster: 'four', args: "args4" }
63
+ ];
64
+ const emptyState = { errors: [], debug: { postDebug: true } };
65
+ describe('addDebugErrorMessage', () => {
66
+ it("should add an error message to the state", () => {
67
+ expect((0, poster_1.addDebugErrorMessage)(errorL)(emptyState, "someDetail", "someArgs", 200, "someresp")).toEqual({ "debug": { "postDebug": true }, "errors": ["someDetail \"someArgs\" Status(200) Resp: someresp)"] });
68
+ });
69
+ });
70
+ describe("post", () => {
71
+ it("should return a promise of the input state if no post commands", () => __awaiter(void 0, void 0, void 0, function* () {
72
+ expect(yield poster(emptyState)).toEqual(emptyState);
73
+ }));
74
+ it("should aggreagate successful posts, removing existing postcommands ", () => __awaiter(void 0, void 0, void 0, function* () {
75
+ expect(yield poster(Object.assign(Object.assign({}, emptyState), { postCommands: fourPostCommands }))).toEqual(Object.assign(Object.assign({}, emptyState), { "postCommands": [], "one": "oneRes_1", "two": "twoRes_2", "three": "threeRes_3", "four": "fourRes_4" }));
76
+ }));
77
+ it("should aggreagate successful posts and non200 results, removing existing postcommands", () => __awaiter(void 0, void 0, void 0, function* () {
78
+ expect(yield errorPoster(Object.assign(Object.assign({}, emptyState), { postCommands: fourPostCommands }))).toEqual(Object.assign(Object.assign({}, emptyState), { errors: [
79
+ "two \"args2\" Status(400) Resp: twoRes)",
80
+ "three \"args3\" Status(500) Resp: threeRes)",
81
+ "four \"args4\" Status(undefined) Resp: failed)"
82
+ ], "postCommands": [], "one": "oneRes_1" }));
83
+ }));
84
+ });
@@ -0,0 +1,2 @@
1
+ export type Context = 'context';
2
+ export declare const context = "context";
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.context = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const state_1 = require("@focuson/state");
6
+ const enzyme_1 = require("enzyme");
7
+ const poster_1 = require("@focuson/poster");
8
+ const enzymeAdapterSetup_1 = require("./enzymeAdapterSetup");
9
+ (0, enzymeAdapterSetup_1.enzymeSetup)();
10
+ exports.context = 'context';
11
+ describe("post button", () => {
12
+ it("should render with an id and title", () => {
13
+ const state = (0, state_1.lensState)({ postCommands: [] }, (s) => { }, 'postbutton', exports.context);
14
+ const comp = (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(poster_1.PostButton, { state: state, text: 'someTitle', id: 'someId', poster: 'somePoster', args: 'someArgs', postCommandL: (0, poster_1.postCommandsL)() }));
15
+ const button = comp.find("button");
16
+ expect(button.text()).toEqual('someTitle');
17
+ });
18
+ it("should change the state to have a model when clicked", () => {
19
+ var remembered = { postCommands: [] };
20
+ const state = (0, state_1.lensState)({ postCommands: [] }, (s) => { remembered = s; }, 'PostButton', exports.context);
21
+ const comp = (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(poster_1.PostButton, { state: state, text: 'someTitle', id: 'someId', poster: 'somePoster', args: 'someArgs', postCommandL: (0, poster_1.postCommandsL)() }));
22
+ const button = comp.find("button");
23
+ button.simulate('click');
24
+ expect(remembered).toEqual({ "postCommands": [{ poster: "somePoster", args: "someArgs" }] });
25
+ });
26
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //** This clears up the state if it is the first time something is called */
4
+ const pages_1 = require("@focuson/pages");
5
+ const page_fixture_1 = require("./page.fixture");
6
+ const focuson_1 = require("@focuson/focuson");
7
+ const config = (0, focuson_1.makeModalProcessorsConfig)(page_fixture_1.firstPageSelectedState, page_fixture_1.context);
8
+ const preMutate = (0, pages_1.preMutateForPages)(page_fixture_1.context, config);
9
+ let viewPageMode = "view";
10
+ describe("preMutateForPages", () => {
11
+ it("should throw an error if the page is not valid", () => {
12
+ expect(() => preMutate(page_fixture_1.invalidPageState)).toThrow('Could not find details for unknownpage. LegalValues are firstPage,clearAtStart,init,secondPage,modalData,error');
13
+ });
14
+ it("should return the state if firstTime not true", () => {
15
+ expect(preMutate(page_fixture_1.firstPageSelectedState)).toEqual(page_fixture_1.firstPageSelectedState);
16
+ });
17
+ it("should not clear the state if first time is false", () => {
18
+ expect(preMutate(Object.assign(Object.assign({}, (0, page_fixture_1.stateWith)(page_fixture_1.rootState, ['clearAtStart', 'view', undefined])), { firstPage: 'data' }))).toEqual({
19
+ "messages": [],
20
+ "pageSelection": [{ "pageMode": "view", "pageName": "clearAtStart", "time": "now", }],
21
+ "tags": {},
22
+ restCommands: [],
23
+ firstPage: 'data',
24
+ "tempData": "x"
25
+ });
26
+ });
27
+ it("should clear the firstTime, and clear the domain, if firstTime true, and clearAtStart is true", () => {
28
+ expect(preMutate((0, page_fixture_1.stateWithFirstTimes)(page_fixture_1.rootState, ['clearAtStart', 'view', undefined])))
29
+ .toEqual({
30
+ "messages": [],
31
+ firstPage: undefined,
32
+ restCommands: [],
33
+ "pageSelection": [{ "firstTime": false, "pageMode": "view", "pageName": "clearAtStart", "time": "now", }],
34
+ "tags": {},
35
+ "tempData": "x"
36
+ });
37
+ });
38
+ it("should clear the firstTime, and set the domain to the initial value, if firstTime true, and initialValue is defined", () => {
39
+ expect(preMutate(Object.assign(Object.assign({}, (0, page_fixture_1.stateWithFirstTimes)(page_fixture_1.rootState, ['init', 'view', undefined])), { firstPage: "some Data" })))
40
+ .toEqual({
41
+ "firstPage": "Initial Value",
42
+ "messages": [],
43
+ restCommands: [],
44
+ "pageSelection": [{ "firstTime": false, "pageMode": "view", "pageName": "init", "time": "now", }],
45
+ "tags": {},
46
+ "tempData": "x"
47
+ });
48
+ });
49
+ it("should not set the domain to the initial value, if firstTime is false, and initialValue is defined", () => {
50
+ expect(preMutate(Object.assign(Object.assign({}, (0, page_fixture_1.stateWith)(page_fixture_1.rootState, ['init', 'view', undefined])), { firstPage: "some Data" })))
51
+ .toEqual({
52
+ "firstPage": "some Data",
53
+ "messages": [],
54
+ restCommands: [],
55
+ "pageSelection": [{ "pageMode": "view", "pageName": "init", "time": "now", }],
56
+ "tags": {},
57
+ "tempData": "x"
58
+ });
59
+ });
60
+ it("should throw an error if first time is true and both clearAtStart and initialValue are set", () => {
61
+ expect(() => preMutate((0, page_fixture_1.stateWithFirstTimes)(page_fixture_1.rootState, ['error', 'view', undefined]))).toThrow('page error has both clear at start and initialValue set');
62
+ });
63
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
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 enzyme_1 = require("enzyme");
6
+ const form_components_1 = require("@focuson/form_components");
7
+ const state_1 = require("@focuson/state");
8
+ (0, enzymeAdapterSetup_1.enzymeSetup)();
9
+ const enumForTest = {
10
+ a: "A",
11
+ b: "B"
12
+ };
13
+ function makeComponent(state, setMain) {
14
+ // @ts-ignore - because we aren't using any of the focus on context stuff
15
+ let lensState1 = (0, state_1.lensState)(state, setMain, '', {});
16
+ return (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(form_components_1.LabelAndRadio, { label: 'someLabel', allButtons: {}, enums: enumForTest, state: lensState1.focusOn('a'), id: 'someId' }));
17
+ }
18
+ describe("LabelAndRadio", () => {
19
+ it("should render", () => {
20
+ expect(makeComponent({ a: undefined }, () => { }).html().replace(/"/g, "'")).toEqual("<div class='labelRadioButton'><label class='input-label'>someLabel</label>" +
21
+ "<div class='radio-group-container ' id='someId'><div class='radio-container '>" +
22
+ "<input id='someIdA' type='radio' name='someId' value=''><span class='checkmark'></span>" +
23
+ "<label for='someIdA' class='input-label'>A</label></div><div class='radio-container '>" +
24
+ "<input id='someIdB' type='radio' name='someId' value=''>" +
25
+ "<span class='checkmark'></span><label for='someIdB' class='input-label'>B</label></div></div></div>");
26
+ });
27
+ it("should render for value a", () => {
28
+ let html = makeComponent({ a: 'a' }, () => { }).html().replace(/"/g, "'");
29
+ expect(html).toContain("<div class='radio-container checked '><input id='someIdA' type='radio' name='someId' value='a' checked=''>");
30
+ expect(html).not.toContain("<div class='radio-container checked '><input id='someIdB'");
31
+ });
32
+ it("should render for invalid value", () => {
33
+ let html = makeComponent({ a: 'A' }, () => { }).html().replace(/"/g, "'");
34
+ expect(html).toContain("<div class='radio-container '><input id='someIdA' type='radio' name='someId' value='A'>");
35
+ expect(html).toContain("<div class='radio-container '><input id='someIdB' type='radio' name='someId' value='A'>");
36
+ expect(html).not.toContain("checked");
37
+ });
38
+ it("should click and change value", () => {
39
+ var remembered = undefined;
40
+ const component = makeComponent({ a: 'A' }, x => remembered = x);
41
+ const radios = component.find('.radio-container');
42
+ expect(radios).toHaveLength(2);
43
+ radios.at(0).simulate('click');
44
+ expect(remembered).toEqual({ "a": "a" });
45
+ radios.at(1).simulate('click');
46
+ expect(remembered).toEqual({ "a": "b" });
47
+ });
48
+ });
@@ -0,0 +1,13 @@
1
+ import { HasPageSelection } from "@focuson/pages";
2
+ import { HasRestCommands } from "@focuson/rest";
3
+ import { SimpleMessage } from "@focuson/utils";
4
+ import { HasTagHolder } from "@focuson/template";
5
+ interface PageData {
6
+ a?: string;
7
+ b?: string;
8
+ }
9
+ export interface RestButtonStateForTest extends HasPageSelection, HasRestCommands, HasTagHolder {
10
+ messages: SimpleMessage[];
11
+ mainPage?: PageData;
12
+ }
13
+ export {};
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ const state_1 = require("@focuson/state");
5
+ const enzyme_1 = require("enzyme");
6
+ const enzymeAdapterSetup_1 = require("./enzymeAdapterSetup");
7
+ const pages_1 = require("@focuson/pages");
8
+ const rest_1 = require("@focuson/rest");
9
+ const utils_1 = require("@focuson/utils");
10
+ const lens_1 = require("@focuson/lens");
11
+ const form_components_1 = require("@focuson/form_components");
12
+ (0, enzymeAdapterSetup_1.enzymeSetup)();
13
+ const emptyS = {
14
+ messages: [],
15
+ tags: {},
16
+ pageSelection: [{ "pageName": "mainPage", "pageMode": "view", time: 'now' }],
17
+ restCommands: [],
18
+ mainPage: {}
19
+ };
20
+ let pageDetails = { mainPage: { lens: (0, lens_1.identityOptics)().focusQuery('mainPage'), pageType: 'MainPage', pageFunction: () => (0, jsx_runtime_1.jsx)("span", {}), config: {}, pageMode: 'edit' } };
21
+ const context = {
22
+ restL: (0, rest_1.restL)(),
23
+ combine: (state, pages) => (0, jsx_runtime_1.jsx)("div", { children: pages.map(p => p.element) }),
24
+ pageSelectionL: (0, pages_1.pageSelectionlens)(),
25
+ simpleMessagesL: (0, pages_1.simpleMessagesL)(),
26
+ pathToLens: (0, pages_1.fromPathFromRaw)((0, pages_1.pageSelectionlens)(), pageDetails),
27
+ pages: pageDetails,
28
+ commonIds: {},
29
+ dateFn: utils_1.testDateFn,
30
+ newFetchers: {},
31
+ restDetails: {},
32
+ closeOnePageTxs: pages_1.rawCloseOnePageTxs,
33
+ tagHolderL: lens_1.Lenses.identity().focusQuery('tags'),
34
+ currentState(state) { return state; },
35
+ messagePostProcessor: {},
36
+ mockJwt: true
37
+ };
38
+ function displayAndGetButton(s, setMain, fn) {
39
+ const comp = (0, enzyme_1.shallow)(fn((0, state_1.lensState)(s, setMain, 'ModalButton', context).focusOn('mainPage')));
40
+ return comp.find("button");
41
+ }
42
+ describe("RestButton", () => {
43
+ it("should render as a button", () => {
44
+ const button = displayAndGetButton(emptyS, () => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.RestButton, { rest: 'someRestName', action: 'get', state: s, id: 'someId', name: 'someButtonName' }));
45
+ expect(button.html()).toEqual('<button aria-errormessage="someId.error" aria-invalid="false" class="button">someButtonName</button>');
46
+ });
47
+ it("should place a rest command in the state - simple RestAction", () => {
48
+ let remembered = undefined;
49
+ const button = displayAndGetButton(emptyS, s => remembered = s, s => (0, jsx_runtime_1.jsx)(form_components_1.RestButton, { rest: 'someRestName', action: 'get', state: s, id: 'someId' }));
50
+ button.simulate('click');
51
+ expect(remembered).toEqual({
52
+ "mainPage": {},
53
+ "messages": [],
54
+ "tags": {},
55
+ "pageSelection": [{ "pageMode": "view", "pageName": "mainPage", "time": "now" }],
56
+ "restCommands": [{ "name": "someRestName", "restAction": "get" }]
57
+ });
58
+ });
59
+ it("should place a rest command in the state - stateChange RestAction", () => {
60
+ let remembered = undefined;
61
+ const button = displayAndGetButton(emptyS, s => remembered = s, s => (0, jsx_runtime_1.jsx)(form_components_1.RestButton, { rest: 'someRestName', action: { state: 'newState' }, state: s, id: 'someId' }));
62
+ button.simulate('click');
63
+ expect(remembered).toEqual({
64
+ "mainPage": {},
65
+ "messages": [],
66
+ "tags": {},
67
+ "pageSelection": [{ "pageMode": "view", "pageName": "mainPage", "time": "now" }],
68
+ "restCommands": [{ "name": "someRestName", "restAction": { "state": "newState" } }]
69
+ });
70
+ });
71
+ it("should place a rest command in the state - copyOnSuccessAndDeleteOnSuccess", () => {
72
+ let remembered = undefined;
73
+ const button = displayAndGetButton(emptyS, s => remembered = s, s => (0, jsx_runtime_1.jsx)(form_components_1.RestButton, { rest: 'someRestName', action: { state: 'newState' }, state: s, id: 'someId', onSuccess: [
74
+ { command: 'copyResult', from: 'from', to: 'to' },
75
+ { command: 'delete', path: 'del1' },
76
+ { command: 'delete', path: 'del2' }
77
+ ] }));
78
+ button.simulate('click');
79
+ expect(remembered).toEqual({
80
+ "mainPage": {},
81
+ "tags": {},
82
+ "messages": [],
83
+ "pageSelection": [{ "pageMode": "view", "pageName": "mainPage", "time": "now" }],
84
+ "restCommands": [{
85
+ "name": "someRestName",
86
+ "restAction": { "state": "newState" },
87
+ "changeOnSuccess": [
88
+ { "command": "copyResult", "from": "from", "to": "to" },
89
+ { "command": "delete", "path": "del1" },
90
+ { "command": "delete", "path": "del2" }
91
+ ],
92
+ }]
93
+ });
94
+ });
95
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
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 enzyme_1 = require("enzyme");
6
+ const form_components_1 = require("@focuson/form_components");
7
+ const state_1 = require("@focuson/state");
8
+ const lens_1 = require("@focuson/lens");
9
+ (0, enzymeAdapterSetup_1.enzymeSetup)();
10
+ function displaySelectedItem(s, selectedItemThings, setMain) {
11
+ function display({ state, mode, id }) {
12
+ const optJson = state.optJson();
13
+ return (0, jsx_runtime_1.jsxs)("span", { id: id, children: [mode, "/", optJson] });
14
+ }
15
+ const state = (0, state_1.lensState)(s, setMain, 'desc', {});
16
+ return (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(form_components_1.SelectedItem, Object.assign({}, selectedItemThings, { id: 'someId', display: display, state: state.focusOn('data'), allButtons: {} })));
17
+ }
18
+ describe("selectedItem", () => {
19
+ it("should display the selected item", () => {
20
+ const x = lens_1.Lenses.identity().focusQuery('data').chain(lens_1.Lenses.nth(1)).getOption({ data: ['1', '2', '3'] });
21
+ expect(displaySelectedItem({ data: ['a', 'b'] }, { index: 1, mode: 'view' }, () => { }).html()).toEqual('<span id="someId">view/b</span>');
22
+ expect(displaySelectedItem({ data: ['a', 'b'] }, { index: 999, mode: 'view' }, () => { }).html()).toEqual('<span id="someId">view/</span>');
23
+ expect(displaySelectedItem({ data: [] }, { index: 999, mode: 'view' }, () => { }).html()).toEqual('<span id="someId">view/</span>');
24
+ });
25
+ it("should display the selected item with a header", () => {
26
+ expect(displaySelectedItem({ data: ['a', 'b'] }, { index: 1, mode: 'view', header: 'someTitle' }, () => { }).html()).toEqual('<div><h2>someTitle</h2><span id="someId">view/b</span></div>');
27
+ expect(displaySelectedItem({ data: ['a', 'b'] }, { index: 999, mode: 'view', header: 'someTitle' }, () => { }).html()).toEqual('<div><h2>someTitle</h2><span id="someId">view/</span></div>');
28
+ expect(displaySelectedItem({ data: [] }, { index: 999, mode: 'view', header: 'someTitle' }, () => { }).html()).toEqual('<div><h2>someTitle</h2><span id="someId">view/</span></div>');
29
+ });
30
+ it("should display the selected item with a n of m", () => {
31
+ expect(displaySelectedItem({ data: ['a', 'b'] }, { index: 1, mode: 'view', showNofM: true }, () => { }).html()).toEqual('<div><h2><span id="someId.nOfM"> 2 / 2</span></h2><span id="someId">view/b</span></div>');
32
+ expect(displaySelectedItem({ data: ['a', 'b'] }, { index: 999, mode: 'view', showNofM: true }, () => { }).html()).toEqual('<div><h2><span id="someId.nOfM"> 1000 / 2</span></h2><span id="someId">view/</span></div>');
33
+ expect(displaySelectedItem({ data: [] }, { index: 999, mode: 'view', showNofM: true }, () => { }).html()).toEqual('<div><h2><span id="someId.nOfM"> 1000 / 0</span></h2><span id="someId">view/</span></div>');
34
+ });
35
+ it("should display the selected item with a header and n of m", () => {
36
+ expect(displaySelectedItem({ data: ['a', 'b'] }, { index: 1, mode: 'view', header: 'someTitle', showNofM: true }, () => { }).html()).toEqual('<div><h2>someTitle<span id="someId.nOfM"> 2 / 2</span></h2><span id="someId">view/b</span></div>');
37
+ expect(displaySelectedItem({ data: ['a', 'b'] }, { index: 999, mode: 'view', header: 'someTitle', showNofM: true }, () => { }).html()).toEqual('<div><h2>someTitle<span id="someId.nOfM"> 1000 / 2</span></h2><span id="someId">view/</span></div>');
38
+ expect(displaySelectedItem({ data: [] }, { index: 999, mode: 'view', header: 'someTitle', showNofM: true }, () => { }).html()).toEqual('<div><h2>someTitle<span id="someId.nOfM"> 1000 / 0</span></h2><span id="someId">view/</span></div>');
39
+ });
40
+ it("should display the selected item headerIfEmpty and data empty", () => {
41
+ expect(displaySelectedItem({ data: [] }, { index: 1, mode: 'view', headerIfEmpty: 'emptyHeader' }, () => { }).html()).toEqual('<div><h2><span id="someId.emptyHeader">emptyHeader</span></h2><span id="someId">view/</span></div>');
42
+ expect(displaySelectedItem({ data: [] }, { index: 1, mode: 'view', header: 'theHeader', headerIfEmpty: 'emptyHeader' }, () => { }).html()).toEqual('<div><h2>theHeader<span id="someId.emptyHeader">emptyHeader</span></h2><span id="someId">view/</span></div>');
43
+ expect(displaySelectedItem({ data: [] }, { index: 1, mode: 'view', header: 'theHeader', headerIfEmpty: 'emptyHeader', showNofM: true }, () => { }).html()).toEqual('<div><h2>theHeader<span id="someId.emptyHeader">emptyHeader</span></h2><span id="someId">view/</span></div>');
44
+ });
45
+ it("should display the selected item headerIfEmpty and data not empty", () => {
46
+ expect(displaySelectedItem({ data: ['a', 'b'] }, { index: 1, mode: 'view', headerIfEmpty: 'emptyHeader' }, () => { }).html()).toEqual('<div><h2></h2><span id="someId">view/b</span></div>');
47
+ expect(displaySelectedItem({ data: ['a', 'b'] }, { index: 1, mode: 'view', header: 'theHeader', headerIfEmpty: 'emptyHeader' }, () => { }).html()).toEqual('<div><h2>theHeader</h2><span id="someId">view/b</span></div>');
48
+ expect(displaySelectedItem({ data: ['a', 'b'] }, { index: 1, mode: 'view', header: 'theHeader', headerIfEmpty: 'emptyHeader', showNofM: true }, () => { }).html()).toEqual('<div><h2>theHeader<span id="someId.nOfM"> 2 / 2</span></h2><span id="someId">view/b</span></div>');
49
+ });
50
+ });
@@ -0,0 +1 @@
1
+ export {};