@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,147 @@
|
|
|
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 pages_1 = require("@focuson/pages");
|
|
7
|
+
const lens_1 = require("@focuson/lens");
|
|
8
|
+
const utils_1 = require("@focuson/utils");
|
|
9
|
+
const rest_1 = require("@focuson/rest");
|
|
10
|
+
const enzymeAdapterSetup_1 = require("./enzymeAdapterSetup");
|
|
11
|
+
(0, enzymeAdapterSetup_1.enzymeSetup)();
|
|
12
|
+
const context = {
|
|
13
|
+
simpleMessagesL: (0, pages_1.simpleMessagesL)(),
|
|
14
|
+
combine: (state, pages) => (0, jsx_runtime_1.jsx)("div", { children: pages.map(c => c.element) }),
|
|
15
|
+
pageSelectionL: (0, pages_1.pageSelectionlens)(),
|
|
16
|
+
pages: {
|
|
17
|
+
a: { lens: lens_1.Lenses.identity().focusQuery('a'), pageFunction: () => (0, jsx_runtime_1.jsx)("span", {}), config: {}, pageType: 'MainPage', pageMode: "edit" },
|
|
18
|
+
b: { lens: lens_1.Lenses.identity().focusQuery('b'), pageFunction: () => (0, jsx_runtime_1.jsx)("span", {}), config: {}, pageType: 'MainPage', pageMode: "edit" },
|
|
19
|
+
},
|
|
20
|
+
restL: (0, rest_1.restL)(),
|
|
21
|
+
dateFn: utils_1.testDateFn,
|
|
22
|
+
closeOnePageTxs: pages_1.rawCloseOnePageTxs,
|
|
23
|
+
tagHolderL: lens_1.Lenses.identity().focusQuery('tags'),
|
|
24
|
+
pathToLens: function (s, currentLens) {
|
|
25
|
+
throw new Error("Function not implemented.");
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
let startState = { pageSelection: [{ pageName: 'a', pageMode: 'view', time: 'now' }], messages: [], restCommands: [] };
|
|
29
|
+
describe("modal button", () => {
|
|
30
|
+
it("should render with an id and title", () => {
|
|
31
|
+
const state = (0, state_1.lensState)(startState, (s) => { }, 'ModalButton', context);
|
|
32
|
+
const comp = (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(pages_1.ModalButton, { text: 'someTitle', id: 'someId', state: state, modal: 'someModal', focusOn: '', pageMode: 'view', dateFn: utils_1.testDateFn }));
|
|
33
|
+
const button = comp.find("button");
|
|
34
|
+
expect(button.text()).toEqual('someTitle');
|
|
35
|
+
});
|
|
36
|
+
it("should change the state to have a model when clicked", () => {
|
|
37
|
+
var remembered = {};
|
|
38
|
+
const state = (0, state_1.lensState)(startState, (s) => { remembered = s; }, 'ModalButton', context);
|
|
39
|
+
const comp = (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(pages_1.ModalButton, { text: 'someTitle', id: 'someId', state: state, modal: 'someModal', focusOn: '~/', pageMode: 'edit', dateFn: utils_1.testDateFn }));
|
|
40
|
+
const button = comp.find("button");
|
|
41
|
+
button.simulate('click');
|
|
42
|
+
expect(remembered).toEqual({
|
|
43
|
+
messages: [], "pageSelection": [
|
|
44
|
+
{ "pageMode": "view", "pageName": "a", "time": "now" },
|
|
45
|
+
{ "firstTime": true, "focusOn": "~/", "pageMode": "edit", "pageName": "someModal", "time": "timeForTest" }
|
|
46
|
+
],
|
|
47
|
+
"restCommands": []
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
it("should create an empty if needed when clicked", () => {
|
|
51
|
+
var remembered = {};
|
|
52
|
+
const state = (0, state_1.lensState)(startState, (s) => { remembered = s; }, 'ModalButton', context);
|
|
53
|
+
const comp = (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(pages_1.ModalButton, { text: 'someTitle', id: 'someId', state: state.focusOn('data'), modal: 'someModal', focusOn: '~/', pageMode: 'edit', createEmpty: 'someData', dateFn: utils_1.testDateFn }));
|
|
54
|
+
const button = comp.find("button");
|
|
55
|
+
button.simulate('click');
|
|
56
|
+
expect(remembered).toEqual({
|
|
57
|
+
"a": "someData",
|
|
58
|
+
messages: [],
|
|
59
|
+
"pageSelection": [
|
|
60
|
+
{ "pageMode": "view", "pageName": "a", "time": "now" },
|
|
61
|
+
{ "firstTime": true, "focusOn": "~/", "pageMode": "edit", "pageName": "someModal", "time": "timeForTest" }
|
|
62
|
+
],
|
|
63
|
+
"restCommands": []
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
it("should delete on open", () => {
|
|
67
|
+
var remembered = {};
|
|
68
|
+
const state = (0, state_1.lensState)(startState, (s) => { remembered = s; }, 'ModalButton', context);
|
|
69
|
+
const comp = (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(pages_1.ModalButton, { text: 'someTitle', id: 'someId', state: state.focusOn('data'), modal: 'someModal', focusOn: '~/', pageMode: 'edit', deleteOnOpen: ['~'], dateFn: utils_1.testDateFn }));
|
|
70
|
+
const button = comp.find("button");
|
|
71
|
+
button.simulate('click');
|
|
72
|
+
expect(remembered).toEqual({
|
|
73
|
+
messages: [],
|
|
74
|
+
"pageSelection": [
|
|
75
|
+
{ "pageMode": "view", "pageName": "a", "time": "now" },
|
|
76
|
+
{ "firstTime": true, "focusOn": "~/", "pageMode": "edit", "pageName": "someModal", "time": "timeForTest" }
|
|
77
|
+
],
|
|
78
|
+
"restCommands": []
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe("modal button adding a main page", () => {
|
|
83
|
+
it("should change the state to have a main when clicked", () => {
|
|
84
|
+
var remembered = {};
|
|
85
|
+
const state = (0, state_1.lensState)(startState, (s) => { remembered = s; }, 'ModalButton', context);
|
|
86
|
+
const comp = (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(pages_1.ModalButton, { text: 'someTitle', id: 'someId', state: state, main: 'b', pageMode: 'edit', dateFn: utils_1.testDateFn }));
|
|
87
|
+
const button = comp.find("button");
|
|
88
|
+
button.simulate('click');
|
|
89
|
+
expect(remembered).toEqual({
|
|
90
|
+
"restCommands": [], messages: [],
|
|
91
|
+
"pageSelection": [
|
|
92
|
+
{ "pageMode": "view", "pageName": "a", "time": "now" },
|
|
93
|
+
{ "firstTime": true, "pageMode": "edit", "pageName": "b", "time": "timeForTest" }
|
|
94
|
+
]
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
it("should support copy in with paths using the original page for copy from and the new page for copy to", () => {
|
|
98
|
+
var remembered = {};
|
|
99
|
+
const state = (0, state_1.lensState)(Object.assign(Object.assign({}, startState), { a: 123 }), (s) => { remembered = s; }, 'ModalButton', context);
|
|
100
|
+
const comp = (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(pages_1.ModalButton, { text: 'someTitle', id: 'someId', state: state, main: 'b', pageMode: 'edit', dateFn: utils_1.testDateFn, copy: [{ from: '~', to: '~' }], copyOnClose: [{ from: '~' }] }));
|
|
101
|
+
const button = comp.find("button");
|
|
102
|
+
button.simulate('click');
|
|
103
|
+
expect(remembered).toEqual({
|
|
104
|
+
"a": 123,
|
|
105
|
+
"b": 123, // copied from page a
|
|
106
|
+
"restCommands": [], messages: [],
|
|
107
|
+
"pageSelection": [
|
|
108
|
+
{ "pageMode": "view", "pageName": "a", "time": "now" },
|
|
109
|
+
{ "firstTime": true, "pageMode": "edit", "pageName": "b", "time": "timeForTest", "copyOnClose": [{ "from": "~" }] }
|
|
110
|
+
]
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
it("should support copy on close with defaults using the new page for copy from and the original page for copy to", () => {
|
|
114
|
+
var remembered = {};
|
|
115
|
+
const start = {
|
|
116
|
+
"a": undefined,
|
|
117
|
+
"b": 123,
|
|
118
|
+
"restCommands": [], messages: [],
|
|
119
|
+
"pageSelection": [
|
|
120
|
+
{ "pageMode": "view", "pageName": "a", "time": "now" },
|
|
121
|
+
{ "firstTime": true, "pageMode": "edit", "pageName": "b", "time": "timeForTest", "copyOnClose": [{ "from": "~", to: '~' }] }
|
|
122
|
+
]
|
|
123
|
+
};
|
|
124
|
+
const state = (0, state_1.lensState)(start, (s) => { remembered = s; }, 'ModalButton', context);
|
|
125
|
+
const comp = (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(pages_1.ModalCommitButton, { text: 'someTitle', id: 'someId', state: state }));
|
|
126
|
+
const button = comp.find("button");
|
|
127
|
+
button.simulate('click');
|
|
128
|
+
expect(remembered).toEqual({
|
|
129
|
+
"a": 123,
|
|
130
|
+
"b": 123,
|
|
131
|
+
"messages": [],
|
|
132
|
+
"pageSelection": [{ "pageMode": "view", "pageName": "a", "time": "now" }],
|
|
133
|
+
"restCommands": []
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
describe("restOnOpen", () => {
|
|
138
|
+
it("should create restCommands when clicked", () => {
|
|
139
|
+
var remembered = {};
|
|
140
|
+
const state = (0, state_1.lensState)(startState, (s) => { remembered = s; }, 'ModalButton', context);
|
|
141
|
+
const restOnOpen = { name: 'someRestName', restAction: 'get' };
|
|
142
|
+
const comp = (0, enzyme_1.mount)((0, jsx_runtime_1.jsx)(pages_1.ModalButton, { text: 'someTitle', id: 'someId', state: state, main: 'b', pageMode: 'edit', restOnOpen: restOnOpen, dateFn: utils_1.testDateFn }));
|
|
143
|
+
const button = comp.find("button");
|
|
144
|
+
button.simulate('click');
|
|
145
|
+
expect(remembered.restCommands).toEqual([restOnOpen]);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,214 @@
|
|
|
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 jsx_runtime_1 = require("react/jsx-runtime");
|
|
13
|
+
const rest_1 = require("@focuson/rest");
|
|
14
|
+
const utils_1 = require("@focuson/utils");
|
|
15
|
+
const focuson_1 = require("@focuson/focuson");
|
|
16
|
+
const lens_1 = require("@focuson/lens");
|
|
17
|
+
const pages_1 = require("@focuson/pages");
|
|
18
|
+
const messages_1 = require("@focuson/rest/src/messages");
|
|
19
|
+
const empty = {
|
|
20
|
+
pageSelection: [{ pageName: 'pageName', pageMode: 'view', time: 'now' }],
|
|
21
|
+
tags: {},
|
|
22
|
+
restCommands: [],
|
|
23
|
+
messages: [],
|
|
24
|
+
debug: { restDebug: false, tagFetcherDebug: false }
|
|
25
|
+
};
|
|
26
|
+
const pageIdL = lens_1.Lenses.identity();
|
|
27
|
+
const dataidL = lens_1.Lenses.identity();
|
|
28
|
+
const fdd = {};
|
|
29
|
+
const cd = {
|
|
30
|
+
id1: pageIdL.focusQuery('ids').focusQuery('id1'),
|
|
31
|
+
id2: pageIdL.focusQuery('ids').focusQuery('id2'),
|
|
32
|
+
};
|
|
33
|
+
const newFetchers = {
|
|
34
|
+
pageName: [{ tagName: 'someTag', restName: 'someRestName', postFetchCommands: [], on404Commands: [], onErrorCommands: [], onCompleteCommands: [] }]
|
|
35
|
+
};
|
|
36
|
+
function MyLoading() {
|
|
37
|
+
return (0, jsx_runtime_1.jsx)("p", { children: "Loading" });
|
|
38
|
+
}
|
|
39
|
+
const pages = {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
pageName: { pageType: "MainPage", pageMode: 'view', lens: pageIdL.focusQuery('data'), namedOptionals: {}, config: (0, pages_1.simpleMessagesPageConfig)(MyLoading) }
|
|
42
|
+
};
|
|
43
|
+
const oneRestDetails = {
|
|
44
|
+
extractData(status, body) { return body; },
|
|
45
|
+
fdLens: pageIdL.focusQuery('data'),
|
|
46
|
+
//From PostCodeMainPage.rest[address].targetFromPath (~/main). Does the path exist? Is the 'type' at the end of the path, the type that rest is fetching?
|
|
47
|
+
dLens: dataidL.focusQuery('a'),
|
|
48
|
+
cd,
|
|
49
|
+
fdd,
|
|
50
|
+
ids: ['id1', 'id2'],
|
|
51
|
+
jwtIds: ['id2'],
|
|
52
|
+
resourceId: [],
|
|
53
|
+
messages: (status, body) => status === undefined ?
|
|
54
|
+
[(0, utils_1.createSimpleMessage)('error', `Cannot connect. ${JSON.stringify(body)}`, (0, utils_1.testDateFn)())] :
|
|
55
|
+
[(0, utils_1.createSimpleMessage)('info', `${status}/${JSON.stringify(body)}`, (0, utils_1.testDateFn)())],
|
|
56
|
+
url: "/api/address?{query}",
|
|
57
|
+
states: {},
|
|
58
|
+
messagePostProcessors: (0, messages_1.justInfoToSuccessMessagesPostProcessor)(),
|
|
59
|
+
postProcessors: ['infoToSuccess']
|
|
60
|
+
};
|
|
61
|
+
const restDetails = {
|
|
62
|
+
someRestName: oneRestDetails
|
|
63
|
+
};
|
|
64
|
+
function fetchFn(a, b) {
|
|
65
|
+
return Promise.resolve([200, 123]);
|
|
66
|
+
}
|
|
67
|
+
function config(mockJwt) {
|
|
68
|
+
return {
|
|
69
|
+
fetchFn: fetchFn,
|
|
70
|
+
messageL: (0, pages_1.simpleMessagesL)(),
|
|
71
|
+
newFetchers: newFetchers,
|
|
72
|
+
onError(s, e) { throw Error(`on error. ${e}\n${JSON.stringify(s)}`); },
|
|
73
|
+
pageL: pageIdL.focusOn('pageSelection'),
|
|
74
|
+
pages,
|
|
75
|
+
postMutate(s) { return Promise.resolve(s); },
|
|
76
|
+
preMutate(s) { return s; },
|
|
77
|
+
restDetails,
|
|
78
|
+
restL: (0, rest_1.restL)(),
|
|
79
|
+
restUrlMutator(r, url) { return url; },
|
|
80
|
+
stringToMsg: (0, utils_1.stringToSimpleMsg)(utils_1.testDateFn, 'info'),
|
|
81
|
+
tagHolderL: pageIdL.focusQuery('tags'),
|
|
82
|
+
maxRestCount: 5,
|
|
83
|
+
restCountL: (0, focuson_1.restCountL)()
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const someConfig = config(true);
|
|
87
|
+
const pathToLens = (s) => (path) => {
|
|
88
|
+
throw new Error(`called path to lens with ${path}`);
|
|
89
|
+
};
|
|
90
|
+
describe("test setup for new fetcher", () => {
|
|
91
|
+
it("just check the rest works ", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
+
const pageL = (0, lens_1.identityOptics)().focusQuery('pageSelection');
|
|
93
|
+
const props = {
|
|
94
|
+
fetchFn, mockJwt: true, d: restDetails, urlMutatorForRest: someConfig.restUrlMutator, pathToLens, messageL: someConfig.messageL,
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
pageL,
|
|
97
|
+
traceL: (0, focuson_1.traceL)(), stringToMsg: someConfig.stringToMsg
|
|
98
|
+
};
|
|
99
|
+
const [actual] = yield (0, rest_1.restToTransforms)(props, () => empty, {}, [{ name: 'someRestName', restAction: 'get' }]);
|
|
100
|
+
expect(actual.restCommand).toEqual({ name: 'someRestName', restAction: 'get' });
|
|
101
|
+
expect(actual.status).toEqual(200);
|
|
102
|
+
const txs = actual.txs.map(([l, tx]) => [l.description, tx(l.getOption(empty))]);
|
|
103
|
+
expect(txs).toEqual([
|
|
104
|
+
[
|
|
105
|
+
"I.focus?(messages)",
|
|
106
|
+
[
|
|
107
|
+
{
|
|
108
|
+
"level": "success",
|
|
109
|
+
"msg": "200/123",
|
|
110
|
+
"time": "timeForTest"
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
],
|
|
114
|
+
[
|
|
115
|
+
"I.focus?(data).chain(I.focus?(a))",
|
|
116
|
+
123
|
|
117
|
+
]
|
|
118
|
+
]);
|
|
119
|
+
}));
|
|
120
|
+
});
|
|
121
|
+
describe("restCommandsFromFetchers should create a rest command when needed", () => {
|
|
122
|
+
it("empty - no tags - should not load", () => {
|
|
123
|
+
expect((0, focuson_1.restCommandsFromFetchers)(someConfig.tagHolderL, someConfig.newFetchers, someConfig.restDetails, 'pageName', empty)).toEqual([]);
|
|
124
|
+
});
|
|
125
|
+
it("populated but the tags undefined - should not load", () => {
|
|
126
|
+
expect((0, focuson_1.restCommandsFromFetchers)(someConfig.tagHolderL, someConfig.newFetchers, someConfig.restDetails, 'pageName', Object.assign(Object.assign({}, empty), { data: { a: 123 } }))).toEqual([]);
|
|
127
|
+
});
|
|
128
|
+
it("current tags defined and same - should not load", () => {
|
|
129
|
+
expect((0, focuson_1.restCommandsFromFetchers)(someConfig.tagHolderL, someConfig.newFetchers, someConfig.restDetails, 'pageName', Object.assign(Object.assign({}, empty), { tags: { pageName_someTag: ['111', '222'] }, ids: { id1: 111, id2: 222 }, data: { a: 123 } }))).toEqual([]);
|
|
130
|
+
});
|
|
131
|
+
it("current tags defined -tags different - should load", () => {
|
|
132
|
+
expect((0, focuson_1.restCommandsFromFetchers)(someConfig.tagHolderL, someConfig.newFetchers, someConfig.restDetails, 'pageName', Object.assign(Object.assign({}, empty), { tags: { pageName_someTag: ['111', '222'] }, ids: { id1: 111, id2: 333 }, data: { a: 123 } }))).toEqual([
|
|
133
|
+
{
|
|
134
|
+
"comment": "Fetcher",
|
|
135
|
+
"changeOnCompletion": [],
|
|
136
|
+
"changeOnSuccess": [],
|
|
137
|
+
"name": "someRestName",
|
|
138
|
+
on404: [],
|
|
139
|
+
onError: [],
|
|
140
|
+
"restAction": "get",
|
|
141
|
+
"tagNameAndTags": { "tagName": "pageName_someTag", "tags": ["111", "333"] }
|
|
142
|
+
}
|
|
143
|
+
]);
|
|
144
|
+
});
|
|
145
|
+
it("not populated tags defined and same - should load", () => {
|
|
146
|
+
expect((0, focuson_1.restCommandsFromFetchers)(someConfig.tagHolderL, someConfig.newFetchers, someConfig.restDetails, 'pageName', Object.assign(Object.assign({}, empty), { tags: { pageName_someTag: ['111', '222'] }, ids: { id1: 111, id2: 222 } }))).toEqual([
|
|
147
|
+
{ "comment": "Fetcher", "changeOnSuccess": [], "changeOnCompletion": [], "name": "someRestName", on404: [], onError: [], "restAction": "get", "tagNameAndTags": { "tagName": "pageName_someTag", "tags": ["111", "222"] } }
|
|
148
|
+
]);
|
|
149
|
+
});
|
|
150
|
+
it(" populated tags not defined - should load", () => {
|
|
151
|
+
expect((0, focuson_1.restCommandsFromFetchers)(someConfig.tagHolderL, someConfig.newFetchers, someConfig.restDetails, 'pageName', Object.assign(Object.assign({}, empty), { ids: { id1: 111, id2: 222 }, data: { a: 123 } }))).toEqual([
|
|
152
|
+
{ "comment": "Fetcher", "changeOnCompletion": [], "changeOnSuccess": [], "name": "someRestName", on404: [], onError: [], "restAction": "get", "tagNameAndTags": { "tagName": "pageName_someTag", "tags": ["111", "222"] } }
|
|
153
|
+
]);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
describe("processRestsAndFetchers", () => {
|
|
157
|
+
it("should load if fetcher needs it - mockJwt true", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
158
|
+
const [actual] = yield (0, focuson_1.processRestsAndFetchers)(config(true), (0, focuson_1.defaultPageSelectionAndRestCommandsContext)(pages, {}, newFetchers, restDetails, utils_1.testDateFn, true))([])(() => (Object.assign(Object.assign({}, empty), { ids: { id1: 111, id2: 222 } })));
|
|
159
|
+
expect(actual.restCommand).toEqual({
|
|
160
|
+
name: 'someRestName', on404: [], onError: [], restAction: 'get', comment: 'Fetcher', "changeOnSuccess": [], "changeOnCompletion": [],
|
|
161
|
+
"tagNameAndTags": { "tagName": "pageName_someTag", "tags": ["111", "222"] }
|
|
162
|
+
});
|
|
163
|
+
expect(actual.status).toEqual(200);
|
|
164
|
+
const txs = actual.txs.map(([l, tx]) => [l.description, tx(l.getOption(empty))]);
|
|
165
|
+
expect(txs).toEqual([
|
|
166
|
+
["I.focus?(messages)",
|
|
167
|
+
[{ "level": "success", "msg": "200/123", "time": "timeForTest" }]],
|
|
168
|
+
["I.focus?(data).chain(I.focus?(a))", 123],
|
|
169
|
+
["I.focus?(tags).focusOn(pageName_someTag)", ["111", "222"]]
|
|
170
|
+
]);
|
|
171
|
+
}));
|
|
172
|
+
it("should load if fetcher needs it - mockJwt false", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
+
const [actual] = yield (0, focuson_1.processRestsAndFetchers)(config(true), (0, focuson_1.defaultPageSelectionAndRestCommandsContext)(pages, {}, newFetchers, restDetails, utils_1.testDateFn, false))([])(() => (Object.assign(Object.assign({}, empty), { ids: { id1: 111, id2: 222 } })));
|
|
174
|
+
expect(actual.restCommand).toEqual({
|
|
175
|
+
name: 'someRestName', on404: [], onError: [], restAction: 'get', comment: 'Fetcher', "changeOnSuccess": [], "changeOnCompletion": [],
|
|
176
|
+
"tagNameAndTags": { "tagName": "pageName_someTag", "tags": ["111", "222"] }
|
|
177
|
+
});
|
|
178
|
+
expect(actual.status).toEqual(200);
|
|
179
|
+
const txs = actual.txs.map(([l, tx]) => [l.description, tx(l.getOption(empty))]);
|
|
180
|
+
expect(txs).toEqual([
|
|
181
|
+
["I.focus?(messages)",
|
|
182
|
+
[{ "level": "success", "msg": "200/123", "time": "timeForTest" }]],
|
|
183
|
+
["I.focus?(data).chain(I.focus?(a))", 123],
|
|
184
|
+
["I.focus?(tags).focusOn(pageName_someTag)", ["111", "222"]]
|
|
185
|
+
]);
|
|
186
|
+
}));
|
|
187
|
+
it("should load and record trace if fetcher needs it and recordTrace is on", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
188
|
+
const [actual] = yield (0, focuson_1.processRestsAndFetchers)(config(true), (0, focuson_1.defaultPageSelectionAndRestCommandsContext)(pages, {}, newFetchers, restDetails, utils_1.testDateFn, true))([])(() => (Object.assign(Object.assign({}, empty), { ids: { id1: 111, id2: 222 }, debug: { recordTrace: true } })));
|
|
189
|
+
expect(actual.restCommand).toEqual({
|
|
190
|
+
name: 'someRestName', on404: [], onError: [], restAction: 'get', comment: 'Fetcher', "changeOnSuccess": [], "changeOnCompletion": [],
|
|
191
|
+
"tagNameAndTags": { "tagName": "pageName_someTag", "tags": ["111", "222"] }
|
|
192
|
+
});
|
|
193
|
+
expect(actual.status).toEqual(200);
|
|
194
|
+
const txs = actual.txs.map(([l, tx]) => [l.description, tx(l.getOption(empty))]);
|
|
195
|
+
expect(txs).toEqual([
|
|
196
|
+
["I.focus?(messages)", [{ "level": "success", "msg": "200/123", "time": "timeForTest" }]],
|
|
197
|
+
["I.focus?(data).chain(I.focus?(a))", 123],
|
|
198
|
+
["I.focus?(trace)",
|
|
199
|
+
[{
|
|
200
|
+
"lensTxs": [
|
|
201
|
+
["I.focus?(messages)", [{ "level": "success", "msg": "200/123", "time": "timeForTest" }]],
|
|
202
|
+
["I.focus?(data).chain(I.focus?(a))", 123],
|
|
203
|
+
],
|
|
204
|
+
"restCommand": { "comment": "Fetcher", "changeOnCompletion": [], "changeOnSuccess": [], "name": "someRestName", on404: [], onError: [], "restAction": "get", "tagNameAndTags": { "tagName": "pageName_someTag", "tags": ["111", "222"] } }
|
|
205
|
+
}]
|
|
206
|
+
],
|
|
207
|
+
["I.focus?(tags).focusOn(pageName_someTag)", ["111", "222"]]
|
|
208
|
+
]);
|
|
209
|
+
}));
|
|
210
|
+
it("should not load if fetcher doesn't needs it", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
211
|
+
const actual = yield (0, focuson_1.processRestsAndFetchers)(config(true), (0, focuson_1.defaultPageSelectionAndRestCommandsContext)(pages, {}, newFetchers, restDetails, utils_1.testDateFn, true))([])(() => empty);
|
|
212
|
+
expect(actual).toEqual([]);
|
|
213
|
+
}));
|
|
214
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.state = void 0;
|
|
4
|
+
const lens_1 = require("@focuson/lens");
|
|
5
|
+
exports.state = {};
|
|
6
|
+
let ab = { a: "a", b: "b" };
|
|
7
|
+
let holder = { ab, c: "c" };
|
|
8
|
+
describe("identityOptics ", () => {
|
|
9
|
+
it("should implement 'identity' for the four methods", () => {
|
|
10
|
+
expect((0, lens_1.identityOptics)().set(1, 2)).toBe(2);
|
|
11
|
+
expect((0, lens_1.identityOptics)().get(1)).toBe(1);
|
|
12
|
+
expect((0, lens_1.identityOptics)().getOption(1)).toBe(1);
|
|
13
|
+
expect((0, lens_1.identityOptics)().reverseGet(1)).toBe(1);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe("iso", () => {
|
|
17
|
+
let iso = new lens_1.Iso(i => [i.a, i.b], ab => ({
|
|
18
|
+
a: ab[0],
|
|
19
|
+
b: ab[1]
|
|
20
|
+
}), "desc");
|
|
21
|
+
it("should have a description", () => {
|
|
22
|
+
expect(iso.toString()).toEqual("Iso(desc)");
|
|
23
|
+
expect((0, lens_1.identityOptics)().toString()).toEqual("Iso(I)");
|
|
24
|
+
expect((0, lens_1.identityOptics)("desc").toString()).toEqual("Iso(desc)");
|
|
25
|
+
});
|
|
26
|
+
it("should flip between the two representations", () => {
|
|
27
|
+
expect(iso.get(ab)).toEqual(["a", "b"]);
|
|
28
|
+
expect(iso.getOption(ab)).toEqual(["a", "b"]);
|
|
29
|
+
expect(iso.set({ "a": "not", "b": "used" }, ["a", "b"])).toEqual(ab);
|
|
30
|
+
expect(iso.reverseGet(["a", "b"])).toEqual({ "a": "a", "b": "b" });
|
|
31
|
+
});
|
|
32
|
+
it("should have be focusable, and return a lens", () => {
|
|
33
|
+
let toA = (0, lens_1.identityOptics)().focusOn('a');
|
|
34
|
+
expect(toA.set(ab, "newA")).toEqual({ a: "newA", b: "b" });
|
|
35
|
+
expect(toA.get(ab)).toBe("a");
|
|
36
|
+
expect(toA.getOption(ab)).toEqual("a");
|
|
37
|
+
expect(toA.toString()).toEqual("Lens(I.focusOn(a))");
|
|
38
|
+
});
|
|
39
|
+
it("should have be focusQuery and return an optional", () => {
|
|
40
|
+
let toA = (0, lens_1.identityOptics)().focusQuery('a');
|
|
41
|
+
expect(toA.set(ab, "newA")).toEqual({ a: "newA", b: "b" });
|
|
42
|
+
expect(toA.getOption(ab)).toEqual("a");
|
|
43
|
+
expect(toA.getOption({})).toEqual(undefined);
|
|
44
|
+
expect(toA.toString()).toEqual("Optional(I.focus?(a))");
|
|
45
|
+
});
|
|
46
|
+
it("should return a lens if chained with a lens", () => {
|
|
47
|
+
let toA = (0, lens_1.identityOptics)().chainLens((0, lens_1.identityOptics)().focusOn('a'));
|
|
48
|
+
expect(toA.set(ab, "newA")).toEqual({ a: "newA", b: "b" });
|
|
49
|
+
expect(toA.getOption(ab)).toEqual("a");
|
|
50
|
+
expect(toA.toString()).toEqual("Lens(I.chain(I.focusOn(a)))");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
let lensToAWithDefault = (0, lens_1.identityOptics)().focusOn('ab').focusWithDefault('a', "defaultA");
|
|
54
|
+
describe("lens", () => {
|
|
55
|
+
it("should be focusable and return a lens", () => {
|
|
56
|
+
let lensToa = (0, lens_1.identityOptics)().focusOn('ab').focusOn('a');
|
|
57
|
+
expect(lensToa.set(holder, "newA")).toEqual({ ab: { a: "newA", b: "b" }, c: "c" });
|
|
58
|
+
expect(lensToa.setOption(holder, "newA")).toEqual({ ab: { a: "newA", b: "b" }, c: "c" });
|
|
59
|
+
expect(lensToa.get(holder)).toEqual("a");
|
|
60
|
+
expect(lensToa.getOption(holder)).toEqual("a");
|
|
61
|
+
expect(lensToa.toString()).toEqual("Lens(I.focusOn(ab).focusOn(a))");
|
|
62
|
+
});
|
|
63
|
+
it("should allow chained lens", () => {
|
|
64
|
+
let lensToa = (0, lens_1.identityOptics)().chainLens((0, lens_1.identityOptics)().focusOn('ab')).chainLens((0, lens_1.identityOptics)().focusOn('a'));
|
|
65
|
+
expect(lensToa.set(holder, "newA")).toEqual({ ab: { a: "newA", b: "b" }, c: "c" });
|
|
66
|
+
expect(lensToa.setOption(holder, "newA")).toEqual({ ab: { a: "newA", b: "b" }, c: "c" });
|
|
67
|
+
expect(lensToa.get(holder)).toEqual("a");
|
|
68
|
+
expect(lensToa.getOption(holder)).toEqual("a");
|
|
69
|
+
expect(lensToa.toString()).toEqual("Lens(I.chain(I.focusOn(ab)).chain(I.focusOn(a)))");
|
|
70
|
+
});
|
|
71
|
+
it("should allow focusWithDefault creating a lens with a default value ", () => {
|
|
72
|
+
expect(lensToAWithDefault.get({ ab: {}, c: "c" })).toEqual("defaultA");
|
|
73
|
+
expect(lensToAWithDefault.getOption({ ab: {}, c: "c" })).toEqual("defaultA");
|
|
74
|
+
expect(lensToAWithDefault.set({ ab: {}, c: "c" }, "someA")).toEqual({ ab: { a: "someA" }, c: "c" });
|
|
75
|
+
expect(lensToAWithDefault.setOption({ ab: {}, c: "c" }, "someA")).toEqual({ ab: { a: "someA" }, c: "c" });
|
|
76
|
+
expect(lensToAWithDefault.toString()).toEqual("Lens(I.focusOn(ab).focusWithDefault(a))");
|
|
77
|
+
});
|
|
78
|
+
it("should have a focusQuery creating an optional", () => {
|
|
79
|
+
let optToQueryA = (0, lens_1.identityOptics)().focusOn('ab').focusQuery('a');
|
|
80
|
+
expect(optToQueryA.getOption({ ab: {}, c: "c" })).toEqual(undefined);
|
|
81
|
+
expect(optToQueryA.getOption({ ab: { a: "a" }, c: "c" })).toEqual("a");
|
|
82
|
+
expect(optToQueryA.set({ ab: {}, c: "c" }, "newA")).toEqual({ ab: { a: "newA" }, c: "c" });
|
|
83
|
+
expect(optToQueryA.set({ ab: { a: "a" }, c: "c" }, "newA")).toEqual({ ab: { a: "newA" }, c: "c" });
|
|
84
|
+
expect(optToQueryA.setOption({ ab: {}, c: "c" }, "newA")).toEqual({ ab: { a: "newA" }, c: "c" });
|
|
85
|
+
expect(optToQueryA.setOption({ ab: { a: "a" }, c: "c" }, "newA")).toEqual({ ab: { a: "newA" }, c: "c" });
|
|
86
|
+
expect(optToQueryA.toString()).toEqual("Optional(I.focusOn(ab).focus?(a))");
|
|
87
|
+
});
|
|
88
|
+
it("should have a focusQuery that keeps on nesting: depth 2, and the getOption returns undefined if nothing there", () => {
|
|
89
|
+
let optToQueryA = (0, lens_1.identityOptics)().focusOn('ab').focusQuery('ab').focusQuery('ab').focusQuery('a');
|
|
90
|
+
expect(optToQueryA.getOption({ ab: {}, c: "c" })).toEqual(undefined);
|
|
91
|
+
expect(optToQueryA.getOption({ ab: { ab: {} }, c: "c" })).toEqual(undefined);
|
|
92
|
+
expect(optToQueryA.getOption({ ab: { ab: { ab: {} } }, c: "c" })).toEqual(undefined);
|
|
93
|
+
expect(optToQueryA.getOption({ ab: { ab: { ab: { a: "a" } } }, c: "c" })).toEqual("a");
|
|
94
|
+
expect(optToQueryA.toString()).toEqual("Optional(I.focusOn(ab).focus?(ab).focus?(ab).focus?(a))");
|
|
95
|
+
});
|
|
96
|
+
it("should have a focusQuery that keeps on nesting: depth 2, and the setOption put it's there anyway", () => {
|
|
97
|
+
let lensToqueryA = (0, lens_1.identityOptics)().focusOn('ab').focusQuery('ab').focusQuery('ab').focusQuery('a');
|
|
98
|
+
expect(lensToqueryA.setOption({ ab: {}, c: "c" }, "a")).toEqual({
|
|
99
|
+
"ab": { "ab": { "ab": { "a": "a" } } },
|
|
100
|
+
"c": "c"
|
|
101
|
+
});
|
|
102
|
+
expect(lensToqueryA.setOption({ ab: { ab: {} }, c: "c" }, "a")).toEqual({
|
|
103
|
+
"ab": { "ab": { "ab": { "a": "a" } } },
|
|
104
|
+
"c": "c"
|
|
105
|
+
});
|
|
106
|
+
expect(lensToqueryA.setOption({ ab: { ab: { ab: {} } }, c: "c" }, "a")).toEqual({
|
|
107
|
+
"ab": { "ab": { "ab": { "a": "a" } } },
|
|
108
|
+
"c": "c"
|
|
109
|
+
});
|
|
110
|
+
expect(lensToqueryA.setOption({ ab: { ab: { ab: { a: "oldA" } } }, c: "c" }, "a")).toEqual({
|
|
111
|
+
ab: { ab: { ab: { a: "a" } } },
|
|
112
|
+
c: "c"
|
|
113
|
+
});
|
|
114
|
+
expect(lensToqueryA.toString()).toEqual("Optional(I.focusOn(ab).focus?(ab).focus?(ab).focus?(a))");
|
|
115
|
+
});
|
|
116
|
+
it("should have a focusQuery that keeps on nesting: depth 2, ", () => {
|
|
117
|
+
let lensToqueryA = (0, lens_1.identityOptics)().focusOn('ab').focusQuery('ab').focusQuery('ab').focusQuery('a');
|
|
118
|
+
expect(lensToqueryA.set({ ab: {}, c: "c" }, "a")).toEqual({ "ab": { "ab": { "ab": { "a": "a" } } }, "c": "c" });
|
|
119
|
+
expect(lensToqueryA.set({ ab: { ab: {} }, c: "c" }, "a")).toEqual({ "ab": { "ab": { "ab": { "a": "a" } } }, "c": "c" });
|
|
120
|
+
expect(lensToqueryA.set({ ab: { ab: { ab: {} } }, c: "c" }, "a")).toEqual({ ab: { ab: { ab: { a: "a" } } }, c: "c" });
|
|
121
|
+
expect(lensToqueryA.set({ ab: { ab: { ab: { a: "oldA" } } }, c: "c" }, "a")).toEqual({ ab: { ab: { ab: { a: "a" } } }, c: "c" });
|
|
122
|
+
expect(lensToqueryA.toString()).toEqual("Optional(I.focusOn(ab).focus?(ab).focus?(ab).focus?(a))");
|
|
123
|
+
});
|
|
124
|
+
it("should have a combineWith creating a lens focused on both", () => {
|
|
125
|
+
let abL = (0, lens_1.identityOptics)().focusOn('ab');
|
|
126
|
+
let aL = abL.focusOn('a');
|
|
127
|
+
let bL = abL.focusOn('b');
|
|
128
|
+
let aCombinedBL = aL.combineLens(bL);
|
|
129
|
+
expect(aCombinedBL.get(holder)).toEqual(["a", "b"]);
|
|
130
|
+
expect(aCombinedBL.getOption(holder)).toEqual(["a", "b"]);
|
|
131
|
+
expect(aCombinedBL.set(holder, ["newA", "newB"])).toEqual({ ab: { a: "newA", b: "newB" }, c: "c" });
|
|
132
|
+
expect(aCombinedBL.toString()).toEqual("Lens(combine(I.focusOn(ab).focusOn(a),I.focusOn(ab).focusOn(b)))");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe("optional.setOption", () => {
|
|
136
|
+
const lensToB = lens_1.Lenses.identity().focusQuery("a").focusQuery('b').focusQuery('c');
|
|
137
|
+
const lensToTheTag = lens_1.Lenses.identity().focusQuery("tags").focusQuery('tag').focusQuery('thetag');
|
|
138
|
+
const targetAndTagL = lensToB.combine(lensToTheTag);
|
|
139
|
+
let expected = {
|
|
140
|
+
"a": { "b": { "c": "newTarget" } },
|
|
141
|
+
"tags": { "tag": { "thetag": "newTag" } }
|
|
142
|
+
};
|
|
143
|
+
it("should allow a nested focuses lens to create parents - depth 2", () => {
|
|
144
|
+
expect(lensToTheTag.setOption({}, 'newTarget')).toEqual({ "tags": { "tag": { "thetag": "newTarget" } } });
|
|
145
|
+
});
|
|
146
|
+
it("should allow a nested focuses lens to create parents - depth 3", () => {
|
|
147
|
+
expect(lensToB.setOption({}, 'newTag')).toEqual({ "a": { "b": { "c": "newTag" } } });
|
|
148
|
+
});
|
|
149
|
+
it("should allowed a combined 'tags' plus 'value' optional to work when neither parent is there", () => {
|
|
150
|
+
expect(targetAndTagL.setOption({}, ['newTarget', 'newTag'])).toEqual(expected);
|
|
151
|
+
});
|
|
152
|
+
it("should allowed a combined 'tags' plus 'value' optional to work when only tags parent present", () => {
|
|
153
|
+
expect(targetAndTagL.setOption({ tags: { tag: {} } }, ['newTarget', 'newTag'])).toEqual(expected);
|
|
154
|
+
expect(targetAndTagL.setOption({ tags: {} }, ['newTarget', 'newTag'])).toEqual(expected);
|
|
155
|
+
});
|
|
156
|
+
it("should allowed a combined 'tags' plus 'value' optional to work when only target parent present", () => {
|
|
157
|
+
expect(targetAndTagL.setOption({ a: { b: { c: '' } } }, ['newTarget', 'newTag'])).toEqual(expected);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
const dataA = {
|
|
161
|
+
cond: 'a',
|
|
162
|
+
true: { a: 1 }
|
|
163
|
+
};
|
|
164
|
+
const dataB = {
|
|
165
|
+
cond: 'b',
|
|
166
|
+
false: { b: 2 }
|
|
167
|
+
};
|
|
168
|
+
describe("conditional lens", () => {
|
|
169
|
+
const id = lens_1.Lenses.identity();
|
|
170
|
+
const condL = id.focusOn('cond');
|
|
171
|
+
const trueL = id.focusQuery('true').focusOn('a');
|
|
172
|
+
const falseL = id.focusQuery('false').focusOn('b');
|
|
173
|
+
const lens = lens_1.Lenses.condition(condL, c => c === 'a', trueL, falseL);
|
|
174
|
+
it("should be able to get data", () => {
|
|
175
|
+
expect(lens.getOption(dataA)).toEqual(1);
|
|
176
|
+
expect(lens.getOption(dataB)).toEqual(2);
|
|
177
|
+
});
|
|
178
|
+
it("should be able to set data", () => {
|
|
179
|
+
expect(lens.setOption(dataA, 3)).toEqual({ "cond": "a", "true": { "a": 3 } });
|
|
180
|
+
expect(lens.setOption(dataB, 3)).toEqual({ "cond": "b", "false": { "b": 3 } });
|
|
181
|
+
});
|
|
182
|
+
it("should have a description", () => {
|
|
183
|
+
expect(lens.description).toEqual('If(I.focusOn(cond)) then I.focus?(true).focusOn(a) else I.focus?(false).focusOn(b)');
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
describe("calculatedNth", () => {
|
|
187
|
+
const id = lens_1.Lenses.identity();
|
|
188
|
+
const l = lens_1.Lenses.calculatedNth(id.focusQuery('n'), id.focusQuery('ts'));
|
|
189
|
+
it('should get the nth item', () => {
|
|
190
|
+
expect(l.getOption({ n: 1, ts: ['zero', 'one', 'two'] })).toEqual('one');
|
|
191
|
+
});
|
|
192
|
+
it('should set the nth item', () => {
|
|
193
|
+
expect(l.setOption({ n: 1, ts: ['zero', 'one', 'two'] }, 'x')).toEqual({ "n": 1, "ts": ["zero", "x", "two"] });
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HasPageSelection, MultiPageDetails, PageConfig } from "@focuson/pages";
|
|
2
|
+
import { HasSimpleMessages, PageMode, SimpleMessage } from "@focuson/utils";
|
|
3
|
+
import { FocusOnContext } from "@focuson/focuson";
|
|
4
|
+
import { HasTagHolder } from "@focuson/template";
|
|
5
|
+
import { HasRestCommands, RestCommand } from "@focuson/rest";
|
|
6
|
+
export interface PageSpecState extends HasPageSelection, HasSimpleMessages, HasTagHolder, HasRestCommands {
|
|
7
|
+
tag1?: string;
|
|
8
|
+
tag2?: string;
|
|
9
|
+
tempData?: string;
|
|
10
|
+
firstPage?: string;
|
|
11
|
+
secondPage?: SecondPageDomain;
|
|
12
|
+
}
|
|
13
|
+
export interface SecondPageDomain {
|
|
14
|
+
fromApi?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const emptyState: PageSpecState;
|
|
17
|
+
export declare const rootState: PageSpecState;
|
|
18
|
+
export declare const dataDefinedState: PageSpecState;
|
|
19
|
+
export declare const firstPageSelectedState: PageSpecState;
|
|
20
|
+
export declare const firstPageWithFirstTime: PageSpecState;
|
|
21
|
+
export declare const secondPageSelectedState: PageSpecState;
|
|
22
|
+
export declare const invalidPageState: PageSpecState;
|
|
23
|
+
export declare function stateWith(main: PageSpecState, ...nameAndModes: [string, PageMode, RestCommand | undefined][]): PageSpecState;
|
|
24
|
+
export declare function stateWithFirstTimes(main: PageSpecState, ...nameAndModes: [string, PageMode, RestCommand | undefined][]): PageSpecState;
|
|
25
|
+
export declare function lensStateWith(main: PageSpecState, setMain: (s: PageSpecState) => void, ...nameAndModes: [string, PageMode, RestCommand | undefined][]): import("@focuson/state").LensState<PageSpecState, PageSpecState, ContextForTest>;
|
|
26
|
+
export type ContextForTest = FocusOnContext<PageSpecState>;
|
|
27
|
+
export declare function pageSpecStateConfig<D>(): PageConfig<PageSpecState, D, SimpleMessage[], ContextForTest>;
|
|
28
|
+
export declare const pageDetails: MultiPageDetails<PageSpecState, ContextForTest>;
|
|
29
|
+
export type PageDetails = typeof pageDetails;
|
|
30
|
+
export declare const context: ContextForTest;
|