@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,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tagFetcher_fixture_1 = require("./tagFetcher.fixture");
4
+ const page_fixture_1 = require("./page.fixture");
5
+ describe('tagFetcher', () => {
6
+ it('should not load if the tags are not all present', () => {
7
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tags: {}, secondPage: {} }))).toEqual(["Undefined tags. tag1Id:undefined,tag2Id:undefined"]);
8
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tags: {}, secondPage: {} }))).toEqual(["Undefined tags. tag1Id:t1,tag2Id:undefined"]);
9
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag2: 't2', tags: {}, secondPage: {} }))).toEqual(["Undefined tags. tag1Id:undefined,tag2Id:t2"]);
10
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tags: { secondPage_tag1: [] }, secondPage: {} }))).toEqual(["Undefined tags. tag1Id:undefined,tag2Id:undefined"]);
11
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tags: { secondPage_tag1: [] }, secondPage: {} }))).toEqual(["Undefined tags. tag1Id:undefined,tag2Id:undefined"]);
12
+ //and now some funny states... unlikely to get these, but just checking anyway
13
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tags: { secondPage: ['t1', undefined] }, secondPage: {} }))).toEqual(["Undefined tags. tag1Id:t1,tag2Id:undefined"]);
14
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag2: 't2', tags: { secondPage: [undefined, 't2'] }, secondPage: {} }))).toEqual(["Undefined tags. tag1Id:undefined,tag2Id:t2"]);
15
+ });
16
+ it('should load if the actual tags match the desired tags, but the target is undefined', () => {
17
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tag2: 't2', tags: { secondPage_tag1: ['t1', 't2'] }, secondPage: {} }))).toEqual([]);
18
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tag2: 't2', tags: { secondPage_tag1: ['t1', 't2'] }, secondPage: undefined }))).toEqual([]);
19
+ });
20
+ it('should not load if the actual tags match the desired tags and the target is defined', () => {
21
+ let state = Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tag2: 't2', secondPage: { fromApi: 'somevalue' }, tags: { secondPage_tag1: ['t1', 't2'] } });
22
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(state)).toEqual(["Tags all the same, and target defined"]);
23
+ });
24
+ it('should load if the actual tags are defined but the current are not', () => {
25
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tag2: 't2', tags: {}, secondPage: {} }))).toEqual([]);
26
+ });
27
+ it('should load if the actual tags are defined and the current are different', () => {
28
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tag2: 't2', tags: { secondPage_tag1: ['x1', 't2'] }, secondPage: {} }))).toEqual([]);
29
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tag2: 't2', tags: { secondPage_tag1: ['t1', 'x2'] }, secondPage: {} }))).toEqual([]);
30
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tag2: 't2', tags: { secondPage_tag1: ['x1', 'x2'] }, secondPage: {} }))).toEqual([]);
31
+ //and now some funny states... unlikely to get these, but just checking anyway
32
+ expect(tagFetcher_fixture_1.stateAndFromApiFetcher.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tag2: 't2', tags: { secondPage_tag1: [] }, secondPage: {} }))).toEqual([]);
33
+ });
34
+ it('should load using the reqFn', () => {
35
+ const loadInfo = tagFetcher_fixture_1.stateAndFromApiFetcher.load(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tag2: 't2', tags: {}, secondPage: {} }));
36
+ expect(loadInfo.requestInfo).toEqual('/someUrl?tag1Id=t1&tag2Id=t2');
37
+ expect(loadInfo.requestInit).toEqual(undefined);
38
+ expect(loadInfo.useThisInsteadOfLoad).toEqual(undefined);
39
+ });
40
+ it('should mutate the state after loading, when everything is good, putting the tags in place to make sure not called again', () => {
41
+ let start = Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { tag1: 't1', tag2: 't2', tags: {}, secondPage: { fromApi: 'someLocal' } });
42
+ const loadInfo = tagFetcher_fixture_1.stateAndFromApiFetcher.load(start);
43
+ const mutate = loadInfo.mutate;
44
+ expect(mutate(start)(200, 'someString')).toEqual({
45
+ "messages": [{ "level": "info", "msg": "someString", "time": "timeForTest" }],
46
+ "pageSelection": [{ "pageMode": "view", "pageName": "secondPage", "time": "now" }],
47
+ "restCommands": [],
48
+ "secondPage": { "fromApi": "someString" },
49
+ "tag1": "t1", "tag2": "t2",
50
+ "tags": { "secondPage_tag1": ["t1", "t2"] },
51
+ "tempData": "x"
52
+ });
53
+ expect(mutate(start)(300, 'someString')).toEqual(Object.assign(Object.assign({}, page_fixture_1.secondPageSelectedState), { "messages": [{
54
+ "level": "error",
55
+ "msg": "Failed to fetch data from [/someUrl?tag1Id=t1&tag2Id=t2,undefined] status 300\nResponse \"someString\"}",
56
+ "time": "timeForTest"
57
+ }], "secondPage": { "fromApi": "someLocal" }, "restCommands": [], "tag1": "t1", "tag2": "t2", "tags": { "secondPage_tag1": ["t1", "t2"] } }));
58
+ });
59
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,215 @@
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 form_components_1 = require("@focuson/form_components");
8
+ const utils_1 = require("@focuson/utils");
9
+ const form_components_2 = require("@focuson/form_components");
10
+ const pages_1 = require("@focuson/pages");
11
+ const lens_1 = require("@focuson/lens");
12
+ (0, enzymeAdapterSetup_1.enzymeSetup)();
13
+ const context = {
14
+ combine: (state, pages) => { throw new Error("Function not implemented."); },
15
+ pageSelectionL: (0, pages_1.pageSelectionlens)(),
16
+ pages: { main: { pageMode: 'edit', pageType: 'MainPage', lens: (0, lens_1.identityOptics)(), config: {}, pageFunction: props => (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}) } }
17
+ };
18
+ const empty = { pageSelection: [{ pageName: 'main', time: 'someTime', pageMode: 'edit' }] };
19
+ const twoRows = Object.assign({ contents: [{ a: 1, b: 'one' }, { a: 2, b: 'two' }] }, empty);
20
+ const twoRowsWithC = Object.assign({ contents: [{ a: 1, b: 'one', c: { d: 3, e: 4 } }, { a: 2, b: 'two', c: { d: 5, e: 6 } }] }, empty);
21
+ const twoRowsS0 = Object.assign(Object.assign({}, twoRows), { selected: 0 });
22
+ const twoRowsS1 = Object.assign(Object.assign({}, twoRows), { selected: 1 });
23
+ function displayAndGetTable(s, setMain, fn) {
24
+ return (0, enzyme_1.shallow)(fn((0, state_1.lensState)(s, setMain, 'ModalButton', context)));
25
+ }
26
+ describe("Table", () => {
27
+ describe("'findJoiner'", () => {
28
+ it("should find the joiner for a name", () => {
29
+ expect((0, utils_1.findJoiner)('c', undefined)).toEqual(',');
30
+ expect((0, utils_1.findJoiner)('c', 'x')).toEqual('x');
31
+ expect((0, utils_1.findJoiner)('c', [])).toEqual(',');
32
+ expect((0, utils_1.findJoiner)('c', ['a:1', 'b:2', 'c:3'])).toEqual('3');
33
+ });
34
+ });
35
+ describe("getValue", () => {
36
+ it("should getValue", () => {
37
+ expect((0, form_components_1.getValueForTable)('a', (0, utils_1.safeArray)(twoRows.contents)[0], '-')).toEqual(1);
38
+ expect((0, form_components_1.getValueForTable)('b', (0, utils_1.safeArray)(twoRows.contents)[0], '-')).toEqual("one");
39
+ expect((0, form_components_1.getValueForTable)('c', (0, utils_1.safeArray)(twoRowsWithC.contents)[0], '-')).toEqual("3-4");
40
+ });
41
+ });
42
+ describe("empty table", () => {
43
+ it("should render an empty with no selected", () => {
44
+ const table = displayAndGetTable(empty, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id' }));
45
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th></tr></thead><tbody class='grid-sub'></tbody></table>");
46
+ });
47
+ it("should render an empty with no selected and a title pointing at undefined", () => {
48
+ const table = displayAndGetTable(empty, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id', tableTitle: 'The title [{/someData}]' }));
49
+ expect(table.html().replace(/"/g, "'")).toEqual("<h2>The title []</h2><table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th></tr></thead><tbody class='grid-sub'></tbody></table>");
50
+ });
51
+ it("should render an empty with no selected and a title pointing at date", () => {
52
+ const table = displayAndGetTable(Object.assign(Object.assign({}, empty), { someData: "123" }), s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id', tableTitle: 'The title [{/someData}]' }));
53
+ expect(table.html().replace(/"/g, "'")).toEqual("<h2>The title [123]</h2><table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th></tr></thead><tbody class='grid-sub'></tbody></table>");
54
+ });
55
+ it("should render an empty with no selected and an emptyData", () => {
56
+ const table = displayAndGetTable(empty, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id', emptyData: 'No Data' }));
57
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th></tr></thead>" +
58
+ "<tbody class='grid-sub'><tr id='id[0]'><td colSpan='2'>No Data</td></tr></tbody></table>");
59
+ });
60
+ it("should render an empty with selected", () => {
61
+ const table = displayAndGetTable(empty, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id', copySelectedIndexTo: s.focusOn('selected') }));
62
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th></tr></thead><tbody class='grid-sub'></tbody></table>");
63
+ });
64
+ });
65
+ describe("table without selected", () => {
66
+ it("should render order a, b", () => {
67
+ const table = displayAndGetTable(twoRowsS0, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id' }));
68
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td><td id='id[0].b'>one</td></tr><tr id='id[1]'><td id='id[1].a'>2</td><td id='id[1].b'>two</td></tr></tbody></table>");
69
+ });
70
+ it("should render order a, b, c and use the joiner, when joiner is a string", () => {
71
+ const table = displayAndGetTable(twoRowsWithC, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b', 'c'], joiners: '-', state: s.focusOn('contents'), id: 'id' }));
72
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th><th id='id.th[2]'>C</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td><td id='id[0].b'>one</td><td id='id[0].c'>3-4</td></tr><tr id='id[1]'><td id='id[1].a'>2</td><td id='id[1].b'>two</td><td id='id[1].c'>5-6</td></tr></tbody></table>");
73
+ });
74
+ it("should still display when data is 'undefined'", () => {
75
+ let damagedData = { contents: [{ a: 1 }, { b: 'two' }] };
76
+ const table = displayAndGetTable(damagedData, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id' }));
77
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td><td id='id[0].b'></td></tr><tr id='id[1]'><td id='id[1].a'></td><td id='id[1].b'>two</td></tr></tbody></table>");
78
+ });
79
+ it("should still display when data is null ", () => {
80
+ let damagedData = { contents: [{ a: 1, b: null }, { a: null, b: 'two' }] };
81
+ const table = displayAndGetTable(damagedData, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id' }));
82
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td><td id='id[0].b'></td></tr><tr id='id[1]'><td id='id[1].a'></td><td id='id[1].b'>two</td></tr></tbody></table>");
83
+ });
84
+ it("should render order a, b, c and use the joiner, when joiner is a string[]", () => {
85
+ const table = displayAndGetTable(twoRowsWithC, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b', 'c'], joiners: ['c:*'], state: s.focusOn('contents'), id: 'id' }));
86
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th><th id='id.th[2]'>C</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td><td id='id[0].b'>one</td><td id='id[0].c'>3*4</td></tr><tr id='id[1]'><td id='id[1].a'>2</td><td id='id[1].b'>two</td><td id='id[1].c'>5*6</td></tr></tbody></table>");
87
+ });
88
+ it("should render order b,a", () => {
89
+ const table = displayAndGetTable(twoRowsS0, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['b', 'a'], state: s.focusOn('contents'), id: 'id' }));
90
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>B</th><th id='id.th[1]'>A</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].b'>one</td><td id='id[0].a'>1</td></tr><tr id='id[1]'><td id='id[1].b'>two</td><td id='id[1].a'>2</td></tr></tbody></table>");
91
+ });
92
+ it("should do nothing when selected", () => {
93
+ const table = displayAndGetTable(twoRowsS0, s => { throw Error('should not be called'); }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id' }));
94
+ const rows = table.find("tr");
95
+ expect(rows.length).toEqual(3);
96
+ rows.at(1).simulate("click");
97
+ });
98
+ });
99
+ describe("table with filter", () => {
100
+ it("should render normally IF there filterPrefix and column are set but no value for the filter in the data", () => {
101
+ const table = displayAndGetTable(twoRowsWithC, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b', 'c'], joiners: '-', prefixColumn: 'a', prefixFilter: s.focusOn('filter'), state: s.focusOn('contents'), id: 'id' }));
102
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th><th id='id.th[2]'>C</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td><td id='id[0].b'>one</td><td id='id[0].c'>3-4</td></tr><tr id='id[1]'><td id='id[1].a'>2</td><td id='id[1].b'>two</td><td id='id[1].c'>5-6</td></tr></tbody></table>");
103
+ });
104
+ it("should filter by the parameters if the filterPrefix and column are set, when the parameter is a string", () => {
105
+ const table = displayAndGetTable(Object.assign(Object.assign({}, twoRowsWithC), { filter: 'o' }), s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b', 'c'], joiners: '-', prefixColumn: 'b', prefixFilter: s.focusOn('filter'), state: s.focusOn('contents'), id: 'id' }));
106
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th><th id='id.th[2]'>C</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td><td id='id[0].b'>one</td><td id='id[0].c'>3-4</td></tr></tbody></table>");
107
+ });
108
+ it("should filter by the parameters if the filterPrefix and column are set, when the parameter is an object", () => {
109
+ const table = displayAndGetTable(Object.assign(Object.assign({}, twoRowsWithC), { filter: '5-' }), s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b', 'c'], joiners: '-', prefixColumn: 'c', prefixFilter: s.focusOn('filter'), state: s.focusOn('contents'), id: 'id' }));
110
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th><th id='id.th[2]'>C</th></tr></thead><tbody class='grid-sub'><tr id='id[1]'><td id='id[1].a'>2</td><td id='id[1].b'>two</td><td id='id[1].c'>5-6</td></tr></tbody></table>");
111
+ });
112
+ });
113
+ describe("table with maxCount", () => {
114
+ it("should obey the maxcount when that is zero", () => {
115
+ const table = displayAndGetTable(twoRowsWithC, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b', 'c'], joiners: '-', state: s.focusOn('contents'), maxCount: '0', id: 'id' }));
116
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th><th id='id.th[2]'>C</th></tr></thead><tbody class='grid-sub'></tbody></table>");
117
+ });
118
+ it("should obey the maxcount when that is one", () => {
119
+ const table = displayAndGetTable(twoRowsWithC, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b', 'c'], joiners: '-', state: s.focusOn('contents'), maxCount: '1', id: 'id' }));
120
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th><th id='id.th[2]'>C</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td><td id='id[0].b'>one</td><td id='id[0].c'>3-4</td></tr></tbody></table>");
121
+ });
122
+ it("should obey the max count when that is more than the data", () => {
123
+ const table = displayAndGetTable(twoRowsWithC, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b', 'c'], joiners: '-', state: s.focusOn('contents'), maxCount: '10', id: 'id' }));
124
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th><th id='id.th[2]'>C</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td><td id='id[0].b'>one</td><td id='id[0].c'>3-4</td></tr><tr id='id[1]'><td id='id[1].a'>2</td><td id='id[1].b'>two</td><td id='id[1].c'>5-6</td></tr></tbody></table>");
125
+ });
126
+ });
127
+ describe("table with copySelectedIndexTo", () => {
128
+ it("should render nothing selected", () => {
129
+ const table = displayAndGetTable(twoRows, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id', copySelectedIndexTo: s.focusOn('selected') }));
130
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td><td id='id[0].b'>one</td></tr><tr id='id[1]'><td id='id[1].a'>2</td><td id='id[1].b'>two</td></tr></tbody></table>");
131
+ });
132
+ it("should render 0 selected", () => {
133
+ const table = displayAndGetTable(twoRowsS0, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['b', 'a'], state: s.focusOn('contents'), id: 'id', copySelectedIndexTo: s.focusOn('selected') }));
134
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>B</th><th id='id.th[1]'>A</th></tr></thead><tbody class='grid-sub'><tr id='id[0]' class='grid-selected'><td id='id[0].b'>one</td><td id='id[0].a'>1</td></tr><tr id='id[1]'><td id='id[1].b'>two</td><td id='id[1].a'>2</td></tr></tbody></table>");
135
+ });
136
+ it("should render 1 selected", () => {
137
+ const table = displayAndGetTable(twoRowsS1, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['b', 'a'], state: s.focusOn('contents'), id: 'id', copySelectedIndexTo: s.focusOn('selected') }));
138
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>B</th><th id='id.th[1]'>A</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].b'>one</td><td id='id[0].a'>1</td></tr><tr id='id[1]' class='grid-selected'><td id='id[1].b'>two</td><td id='id[1].a'>2</td></tr></tbody></table>");
139
+ });
140
+ it("should change the selected when clicked", () => {
141
+ var remembered = undefined;
142
+ const table = displayAndGetTable(twoRowsS0, s => remembered = s, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id', copySelectedIndexTo: s.focusOn('selected') }));
143
+ const rows = table.find("tr");
144
+ expect(rows.length).toEqual(3);
145
+ rows.at(1).simulate("click");
146
+ expect(remembered).toEqual(Object.assign(Object.assign({}, empty), { "contents": [{ "a": 1, "b": "one" }, { "a": 2, "b": "two" }], "selected": 0 }));
147
+ rows.at(2).simulate("click");
148
+ expect(remembered).toEqual(Object.assign(Object.assign({}, empty), { "contents": [{ "a": 1, "b": "one" }, { "a": 2, "b": "two" }], "selected": 1 }));
149
+ });
150
+ });
151
+ describe("table with copySelectedItemTo", () => {
152
+ it("should render nothing selected", () => {
153
+ const table = displayAndGetTable(twoRows, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id', copySelectedItemTo: s.focusOn('item') }));
154
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td><td id='id[0].b'>one</td></tr><tr id='id[1]'><td id='id[1].a'>2</td><td id='id[1].b'>two</td></tr></tbody></table>");
155
+ });
156
+ it("should render 0 selected", () => {
157
+ const table = displayAndGetTable(twoRowsS0, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['b', 'a'], state: s.focusOn('contents'), id: 'id', copySelectedItemTo: s.focusOn('item') }));
158
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>B</th><th id='id.th[1]'>A</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].b'>one</td><td id='id[0].a'>1</td></tr><tr id='id[1]'><td id='id[1].b'>two</td><td id='id[1].a'>2</td></tr></tbody></table>");
159
+ });
160
+ it("should render 1 selected", () => {
161
+ const table = displayAndGetTable(twoRowsS1, s => { }, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['b', 'a'], state: s.focusOn('contents'), id: 'id', copySelectedItemTo: s.focusOn('item') }));
162
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>B</th><th id='id.th[1]'>A</th></tr></thead><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].b'>one</td><td id='id[0].a'>1</td></tr><tr id='id[1]'><td id='id[1].b'>two</td><td id='id[1].a'>2</td></tr></tbody></table>");
163
+ });
164
+ it("should change the item when selected", () => {
165
+ var remembered = undefined;
166
+ const table = displayAndGetTable(twoRowsS0, s => remembered = s, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id', copySelectedItemTo: s.focusOn('item') }));
167
+ const rows = table.find("tr");
168
+ expect(rows.length).toEqual(3);
169
+ rows.at(1).simulate("click");
170
+ expect(remembered).toEqual(Object.assign(Object.assign({}, empty), { "contents": [{ "a": 1, "b": "one" }, { "a": 2, "b": "two" }], "selected": 0, item: { a: 1, b: 'one' } }));
171
+ rows.at(2).simulate("click");
172
+ expect(remembered).toEqual(Object.assign(Object.assign({}, empty), { "contents": [{ "a": 1, "b": "one" }, { "a": 2, "b": "two" }], "selected": 0, item: { a: 2, b: 'two' } }));
173
+ });
174
+ });
175
+ describe("table with copySelectedItemTo and copySelectedIndexTo", () => {
176
+ it("should change the item and index when selected", () => {
177
+ var remembered = undefined;
178
+ const table = displayAndGetTable(twoRowsS0, s => remembered = s, s => (0, jsx_runtime_1.jsx)(form_components_1.Table, { order: ['a', 'b'], state: s.focusOn('contents'), id: 'id', copySelectedIndexTo: s.focusOn('selected'), copySelectedItemTo: s.focusOn('item') }));
179
+ const rows = table.find("tr");
180
+ expect(rows.length).toEqual(3);
181
+ rows.at(1).simulate("click");
182
+ expect(remembered).toEqual(Object.assign(Object.assign({}, empty), { "contents": [{ "a": 1, "b": "one" }, { "a": 2, "b": "two" }], "selected": 0, item: { a: 1, b: 'one' } }));
183
+ rows.at(2).simulate("click");
184
+ expect(remembered).toEqual(Object.assign(Object.assign({}, empty), { "contents": [{ "a": 1, "b": "one" }, { "a": 2, "b": "two" }], "selected": 1, item: { a: 2, b: 'two' } }));
185
+ });
186
+ });
187
+ });
188
+ describe("TableWithVaryingContext", () => {
189
+ const order = {
190
+ one: ['a', 'b'],
191
+ two: ['b', 'a']
192
+ };
193
+ it("should display nothing when selector undefined", () => {
194
+ const table = displayAndGetTable(Object.assign(Object.assign({}, twoRows), { selector: undefined }), s => { }, s => (0, jsx_runtime_1.jsx)(form_components_2.TableWithVaryingOrder, { order: order, select: s.focusOn('selector'), state: s.focusOn('contents'), id: 'id' }));
195
+ expect(table.html().replace(/"/g, "'")).toEqual("");
196
+ });
197
+ it("should display nothing when order doesn't exist", () => {
198
+ const table = displayAndGetTable(Object.assign(Object.assign({}, twoRows), { selector: 'invalid' }), s => { }, s => (0, jsx_runtime_1.jsx)(form_components_2.TableWithVaryingOrder, { order: order, select: s.focusOn('selector'), state: s.focusOn('contents'), id: 'id' }));
199
+ expect(table.html().replace(/"/g, "'")).toEqual("");
200
+ });
201
+ it("should display ab when selector is one", () => {
202
+ const table = displayAndGetTable(Object.assign(Object.assign({}, twoRows), { selector: 'one' }), s => { }, s => (0, jsx_runtime_1.jsx)(form_components_2.TableWithVaryingOrder, { order: order, select: s.focusOn('selector'), state: s.focusOn('contents'), id: 'id' }));
203
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'><thead><tr><th id='id.th[0]'>A</th><th id='id.th[1]'>B</th></tr></thead" +
204
+ "><tbody class='grid-sub'><tr id='id[0]'><td id='id[0].a'>1</td>" +
205
+ "<td id='id[0].b'>one</td></tr><tr id='id[1]'><td id='id[1].a'>2</td>" +
206
+ "<td id='id[1].b'>two</td></tr></tbody></table>");
207
+ });
208
+ it("should display ba when selector is two", () => {
209
+ const table = displayAndGetTable(Object.assign(Object.assign({}, twoRows), { selector: 'two' }), s => { }, s => (0, jsx_runtime_1.jsx)(form_components_2.TableWithVaryingOrder, { order: order, select: s.focusOn('selector'), state: s.focusOn('contents'), id: 'id' }));
210
+ expect(table.html().replace(/"/g, "'")).toEqual("<table id='id' class='grid'>" +
211
+ "<thead><tr><th id='id.th[0]'>B</th><th id='id.th[1]'>A</th></tr></thead>" +
212
+ "<tbody class='grid-sub'><tr id='id[0]'><td id='id[0].b'>one</td><td id='id[0].a'>1</td></tr>" +
213
+ "<tr id='id[1]'><td id='id[1].b'>two</td><td id='id[1].a'>2</td></tr></tbody></table>");
214
+ });
215
+ });
@@ -0,0 +1,7 @@
1
+ import { NameAndLens } from "@focuson/lens";
2
+ import { PageSpecState } from "./page.fixture";
3
+ import { Fetcher } from "@focuson/fetcher";
4
+ export declare const tagFetcherTestStateL: import("@focuson/lens").Iso<PageSpecState, PageSpecState>;
5
+ export declare const commonLens: NameAndLens<PageSpecState>;
6
+ export declare const simpleFetcherWithMessages: Fetcher<PageSpecState, string>;
7
+ export declare const stateAndFromApiFetcher: Fetcher<PageSpecState, string>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stateAndFromApiFetcher = exports.simpleFetcherWithMessages = exports.commonLens = exports.tagFetcherTestStateL = void 0;
4
+ const lens_1 = require("@focuson/lens");
5
+ const utils_1 = require("@focuson/utils");
6
+ const focuson_1 = require("@focuson/focuson");
7
+ function withMessages() {
8
+ return (0, focuson_1.commonTagFetchProps)((s, date) => [(0, utils_1.createSimpleMessage)('info', `${s}`, date)], utils_1.testDateFn)();
9
+ }
10
+ exports.tagFetcherTestStateL = lens_1.Lenses.identity('state');
11
+ exports.commonLens = {
12
+ tag1Id: (0, lens_1.identityOptics)().focusQuery('tag1'),
13
+ tag2Id: (0, lens_1.identityOptics)().focusQuery('tag2')
14
+ };
15
+ exports.simpleFetcherWithMessages = (0, focuson_1.simpleTagFetcher)(withMessages(), true, 'firstPage', lens_1.Lenses.identity().focusQuery('firstPage'), exports.commonLens, {}, ['tag1Id', 'tag2Id'], [], [], '/someUrl/{tag1Id}/{tag2Id}/?{query}');
16
+ exports.stateAndFromApiFetcher = (0, focuson_1.pageAndTagFetcher)(withMessages(), true, 'secondPage', 'tag1', lens_1.Lenses.identity().focusQuery('secondPage'), exports.commonLens, {}, ['tag1Id', 'tag2Id'], [], [], lens_1.Lenses.identity().focusQuery('fromApi'), '/someUrl?{query}');
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,67 @@
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 tagFetcher_fixture_1 = require("./tagFetcher.fixture");
14
+ const utils_1 = require("@focuson/utils");
15
+ const page_fixture_1 = require("./page.fixture");
16
+ // const tagFetcherTestStateL = Lenses.identity<PageSpecState> ( 'state' )
17
+ (0, utils_1.setIsNodeFetchForTests)();
18
+ describe('tagFetcher', () => {
19
+ it('should not load if the tags are not all present', () => {
20
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tags: {} }))).toEqual(["Undefined tags. tag1Id:undefined,tag2Id:undefined"]);
21
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag1: 't1', tags: {} }))).toEqual(["Undefined tags. tag1Id:t1,tag2Id:undefined"]);
22
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag2: 't2', tags: {} }))).toEqual(["Undefined tags. tag1Id:undefined,tag2Id:t2"]);
23
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tags: { target: [] } }))).toEqual(["Undefined tags. tag1Id:undefined,tag2Id:undefined"]);
24
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tags: { target: [] } }))).toEqual(["Undefined tags. tag1Id:undefined,tag2Id:undefined"]);
25
+ //and now some funny states... unlikely to get these, but just checking anyway
26
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag1: 't1', tags: { target: ['t1', undefined] } }))).toEqual(["Undefined tags. tag1Id:t1,tag2Id:undefined"]);
27
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag2: 't2', tags: { target: [undefined, 't2'] } }))).toEqual(["Undefined tags. tag1Id:undefined,tag2Id:t2"]);
28
+ });
29
+ it('should load if the actual tags match the desired tags, but the target is undefined', () => {
30
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { firstPage: undefined, tag1: 't1', tag2: 't2', tags: { firstPage: ['t1', 't2'] } }))).toEqual([]);
31
+ });
32
+ it('should not load if the actual tags match the desired tags and the target is defined', () => {
33
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag1: 't1', tag2: 't2', firstPage: 'somevalue', tags: { firstPage: ['t1', 't2'] } }))).toEqual(["Tags all the same, and target defined"]);
34
+ });
35
+ it('should load if the actual tags are defined but the current are not', () => {
36
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag1: 't1', tag2: 't2', tags: {} }))).toEqual([]);
37
+ });
38
+ it('should load if the actual tags are defined and the current are different', () => {
39
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag1: 't1', tag2: 't2', tags: { firstPage: ['x1', 't2'] } }))).toEqual([]);
40
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag1: 't1', tag2: 't2', tags: { firstPage: ['t1', 'x2'] } }))).toEqual([]);
41
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag1: 't1', tag2: 't2', tags: { firstPage: ['x1', 'x2'] } }))).toEqual([]);
42
+ //and now some funny states... unlikely to get these, but just checking anyway
43
+ expect(tagFetcher_fixture_1.simpleFetcherWithMessages.shouldLoad(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag1: 't1', tag2: 't2', tags: { firstPage: [] } }))).toEqual([]);
44
+ });
45
+ it('should load using the reqFn', () => {
46
+ const loadInfo = tagFetcher_fixture_1.simpleFetcherWithMessages.load(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag1: 't1', tag2: 't2', tags: {} }));
47
+ expect(loadInfo.requestInfo).toEqual('/someUrl/t1/t2/?tag1Id=t1&tag2Id=t2');
48
+ expect(loadInfo.requestInit).toEqual(undefined);
49
+ expect(loadInfo.useThisInsteadOfLoad).toEqual(undefined);
50
+ });
51
+ it('should mutate the state after loading, when everything is good, putting the tags in place to make sure not called again', () => {
52
+ let start = Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag1: 't1', tag2: 't2', tags: {} });
53
+ const loadInfo = tagFetcher_fixture_1.simpleFetcherWithMessages.load(start);
54
+ const mutate = loadInfo.mutate;
55
+ expect(mutate(start)(200, 'someString')).toEqual(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { 'tag1': 't1', 'tag2': 't2', 'tags': { 'firstPage': ['t1', 't2'] }, 'firstPage': 'someString', "messages": [{ "level": "info", "msg": "someString", "time": "timeForTest" }] }));
56
+ expect(mutate(start)(300, 'someString')).toEqual(Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { 'messages': [{ "level": "error", "msg": "Failed to fetch data from [/someUrl/t1/t2/?tag1Id=t1&tag2Id=t2,undefined] status 300\nResponse \"someString\"}", "time": "timeForTest" }], 'tag1': 't1', 'tag2': 't2', 'tags': { 'firstPage': ['t1', 't2'] } }));
57
+ });
58
+ it("should report a 'fail to connect'", () => __awaiter(void 0, void 0, void 0, function* () {
59
+ let start = Object.assign(Object.assign({}, page_fixture_1.firstPageSelectedState), { tag1: 't1', tag2: 't2', tags: {}, debug: { fetcherDebug: true } });
60
+ const ns = yield (0, fetcher_1.applyFetcher)(tagFetcher_fixture_1.simpleFetcherWithMessages, start, (0, utils_1.fetchWithPrefix)("http://localhost:9999", utils_1.defaultFetchFn));
61
+ expect(ns.messages).toEqual([{
62
+ "level": "error",
63
+ "msg": "Failed to fetch data from [/someUrl/t1/t2/?tag1Id=t1&tag2Id=t2,undefined] status 600\nResponse {\"message\":\"request to http://localhost:9999/someUrl/t1/t2/?tag1Id=t1&tag2Id=t2 failed, reason: connect ECONNREFUSED 127.0.0.1:9999\",\"type\":\"system\",\"errno\":\"ECONNREFUSED\",\"code\":\"ECONNREFUSED\"}}",
64
+ "time": "timeForTest"
65
+ }]);
66
+ }));
67
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lens_1 = require("@focuson/lens");
4
+ const template_1 = require("@focuson/template");
5
+ const state = { a: "1", b: "2", c: 3, d: { e: "5", f: "6" } };
6
+ const stateNoC = { a: "1", b: "2", d: { e: "5", f: "6" } };
7
+ const identity = lens_1.Lenses.identity();
8
+ const nLFn = (0, lens_1.nameLensFn)(identity);
9
+ describe("nameLensFn", () => {
10
+ it("should return a getOptioner to the correct part of the structure", () => {
11
+ expect(nLFn('a').getOption(state)).toEqual('1');
12
+ expect(nLFn('c').getOption(state)).toEqual(3);
13
+ });
14
+ });
15
+ const urlFn = (0, template_1.expand)(nLFn)("/{a}/{b}?c={c}&d={d}");
16
+ const urlIllegalNameFn = (0, template_1.expand)(nLFn)("/{notKnown}");
17
+ const urlFailSilentlyIllegalNameFn = (0, template_1.expand)(nLFn, true)("/{notKnown}/a");
18
+ const urlFailSilentlyFn = (0, template_1.expand)(nLFn, true)("/{a}/{b}?c={c}&d={d}");
19
+ describe("expand", () => {
20
+ it("should replace the values in the target", () => {
21
+ expect(urlFn(state).replace(/"/g, "'")).toEqual("/1/2?c=3&d={'e':'5','f':'6'}");
22
+ expect(urlFailSilentlyFn(state).replace(/"/g, "'")).toEqual("/1/2?c=3&d={'e':'5','f':'6'}");
23
+ });
24
+ it("should handle 'unknown name in template'", () => {
25
+ expect(() => urlIllegalNameFn(state)).toThrow('Could not find notKnown for /{notKnown}');
26
+ expect(urlFailSilentlyIllegalNameFn(state).replace(/"/g, "'")).toEqual('//a');
27
+ });
28
+ it("should handled undefined", () => {
29
+ expect(() => urlFn(stateNoC)).toThrow('Could not find c for /{a}/{b}?c={c}&d={d}');
30
+ expect(urlFailSilentlyFn(stateNoC).replace(/"/g, "'")).toEqual("/1/2?c=&d={'e':'5','f':'6'}");
31
+ });
32
+ });
33
+ describe("applyToTemplate", () => {
34
+ it("should replace a list of strings which is the input strings modified by the parats", () => {
35
+ const params = { a: 1, b: 2 };
36
+ expect((0, template_1.applyToTemplate)("a={a}&b={b}", params)).toEqual(["a=1&b=2"]);
37
+ expect((0, template_1.applyToTemplate)("a={a}\nb={b}", params)).toEqual(["a=1", "b=2"]);
38
+ });
39
+ it("should replace an object with JSON.stringify", () => {
40
+ const params = { a: 1, b: { c: 1, d: 1 } };
41
+ expect((0, template_1.applyToTemplate)("a={a}&b={b}", params).map(s => s.replace(/"/g, "'"))).toEqual(["a=1&b={'c':1,'d':1}"]);
42
+ });
43
+ it("should replace an array with a nice display", () => {
44
+ const params = { a: 1, b: [2, 3] };
45
+ expect((0, template_1.applyToTemplate)("a={a}&b={b}", params)).toEqual(["a=1&b=[2,3]"]);
46
+ });
47
+ });
48
+ describe('applyToTemplateOrUndefinedIfNoParamsPresent', () => {
49
+ const a1b2 = { a: 1, b: 2 };
50
+ it('should return undefined or the mapped data', () => {
51
+ expect((0, template_1.applyToTemplateOrUndefinedIfNoParamsPresent)("a={a}&b={b}", a1b2)).toEqual("a=1&b=2");
52
+ expect((0, template_1.applyToTemplateOrUndefinedIfNoParamsPresent)("a={a}&b={b}", {})).toEqual(undefined);
53
+ });
54
+ it('should return template if there are no {}', () => {
55
+ expect((0, template_1.applyToTemplateOrUndefinedIfNoParamsPresent)("someTemplateWithNoBrackets", a1b2)).toEqual('someTemplateWithNoBrackets');
56
+ expect((0, template_1.applyToTemplateOrUndefinedIfNoParamsPresent)("someTemplateWithNoBrackets", {})).toEqual('someTemplateWithNoBrackets');
57
+ });
58
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@focuson/utils");
4
+ const utils_2 = require("@focuson/utils/src/utils");
5
+ describe("beforeAfterSeparator", () => {
6
+ it("should split the string in two", () => {
7
+ expect((0, utils_1.beforeAfterSeparator)("?", "/a/b?a=1")).toEqual(['/a/b', 'a=1']);
8
+ expect((0, utils_1.beforeAfterSeparator)("?", "/a/b?")).toEqual(['/a/b', '']);
9
+ expect((0, utils_1.beforeAfterSeparator)("?", "/a/b")).toEqual(['/a/b', '']);
10
+ });
11
+ });
12
+ describe("insertAfter", () => {
13
+ it("should insert a string before the separator", () => {
14
+ expect((0, utils_2.insertBefore)("?", "here", "/a/b?a=1")).toEqual('/a/bhere?a=1');
15
+ expect((0, utils_2.insertBefore)("?", "here", "/a/b?")).toEqual('/a/bhere?');
16
+ expect((0, utils_2.insertBefore)("?", "here", "/a/b")).toEqual('/a/bhere?');
17
+ });
18
+ });
19
+ describe("check date", () => {
20
+ const d1 = '2020/1/1';
21
+ const d2 = '2020/2/2';
22
+ const d3 = '2020/3/3';
23
+ const d1Minuses = '2020-1-1';
24
+ const d2Minuses = '2020-2-2';
25
+ const d3Minuses = '2020-3-3';
26
+ function check(d1, d2, expectedLt, expectedLtEquals, expectedGtEquals, expectedGt) {
27
+ expect((0, utils_1.checkDates)(d1, d2, '<')).toEqual(expectedLt);
28
+ expect((0, utils_1.checkDates)(d1, d2, '<=')).toEqual(expectedLtEquals);
29
+ expect((0, utils_1.checkDates)(d1, d2, '>=')).toEqual(expectedGtEquals);
30
+ expect((0, utils_1.checkDates)(d1, d2, '>')).toEqual(expectedGt);
31
+ }
32
+ it('should check basic everything ok', () => {
33
+ check(d1, d1, false, true, true, false);
34
+ check(d1, d2, true, true, false, false);
35
+ check(d2, d1, false, false, true, true);
36
+ });
37
+ it('should check basic everything ok with minuses', () => {
38
+ check(d1Minuses, d1Minuses, false, true, true, false);
39
+ check(d1Minuses, d2Minuses, true, true, false, false);
40
+ check(d2Minuses, d1Minuses, false, false, true, true);
41
+ });
42
+ it('should return false with undefines', () => {
43
+ check(d1, undefined, false, false, false, false);
44
+ check(undefined, d1, false, false, false, false);
45
+ check(undefined, undefined, false, false, false, false);
46
+ });
47
+ it('should return false with null', () => {
48
+ check(d1, null, false, false, false, false);
49
+ check(null, d1, false, false, false, false);
50
+ check(null, null, false, false, false, false);
51
+ });
52
+ it('should return false with bad dates ... not enough parts', () => {
53
+ check(d1, 'junk', false, false, false, false);
54
+ check('junk', d1, false, false, false, false);
55
+ });
56
+ it('should return false with bad dates ... a part not a number', () => {
57
+ check(d1, 'asd/1/2', false, false, false, false);
58
+ check(d1, '1/asd/2', false, false, false, false);
59
+ check(d1, '1/1/asd', false, false, false, false);
60
+ });
61
+ });