@saltcorn/data 1.6.0-beta.1 → 1.6.0-beta.2

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 (154) hide show
  1. package/dist/base-plugin/index.d.ts +12 -3
  2. package/dist/base-plugin/index.d.ts.map +1 -1
  3. package/dist/base-plugin/types.d.ts +19 -9
  4. package/dist/base-plugin/types.d.ts.map +1 -1
  5. package/dist/base-plugin/types.js +35 -9
  6. package/dist/base-plugin/types.js.map +1 -1
  7. package/dist/base-plugin/viewtemplates/edit.d.ts.map +1 -1
  8. package/dist/base-plugin/viewtemplates/edit.js +2 -8
  9. package/dist/base-plugin/viewtemplates/edit.js.map +1 -1
  10. package/dist/db/state.d.ts.map +1 -1
  11. package/dist/db/state.js +15 -5
  12. package/dist/db/state.js.map +1 -1
  13. package/dist/mobile-mocks/node/fs/promises.d.ts +1 -0
  14. package/dist/mobile-mocks/node/fs/promises.d.ts.map +1 -1
  15. package/dist/mobile-mocks/node/fs/promises.js +4 -0
  16. package/dist/mobile-mocks/node/fs/promises.js.map +1 -1
  17. package/dist/mobile-mocks/node/fs.d.ts +2 -0
  18. package/dist/mobile-mocks/node/fs.d.ts.map +1 -1
  19. package/dist/mobile-mocks/node/fs.js +36 -0
  20. package/dist/mobile-mocks/node/fs.js.map +1 -1
  21. package/dist/models/index.d.ts.map +1 -1
  22. package/dist/models/scheduler.d.ts.map +1 -1
  23. package/dist/models/scheduler.js +15 -5
  24. package/dist/models/scheduler.js.map +1 -1
  25. package/dist/models/table.js +1 -1
  26. package/dist/models/table.js.map +1 -1
  27. package/dist/standard-menu.d.ts.map +1 -1
  28. package/dist/standard-menu.js +19 -0
  29. package/dist/standard-menu.js.map +1 -1
  30. package/dist/tests/actions.test.d.ts +2 -0
  31. package/dist/tests/actions.test.d.ts.map +1 -0
  32. package/dist/tests/actions.test.js +936 -0
  33. package/dist/tests/actions.test.js.map +1 -0
  34. package/dist/tests/auth.test.d.ts +2 -0
  35. package/dist/tests/auth.test.d.ts.map +1 -0
  36. package/dist/tests/auth.test.js +824 -0
  37. package/dist/tests/auth.test.js.map +1 -0
  38. package/dist/tests/auxtest.test.d.ts +2 -0
  39. package/dist/tests/auxtest.test.d.ts.map +1 -0
  40. package/dist/tests/auxtest.test.js +562 -0
  41. package/dist/tests/auxtest.test.js.map +1 -0
  42. package/dist/tests/base.test.d.ts +2 -0
  43. package/dist/tests/base.test.d.ts.map +1 -0
  44. package/dist/tests/base.test.js +30 -0
  45. package/dist/tests/base.test.js.map +1 -0
  46. package/dist/tests/calc.test.d.ts +2 -0
  47. package/dist/tests/calc.test.d.ts.map +1 -0
  48. package/dist/tests/calc.test.js +1081 -0
  49. package/dist/tests/calc.test.js.map +1 -0
  50. package/dist/tests/composite_pk.test.d.ts +2 -0
  51. package/dist/tests/composite_pk.test.d.ts.map +1 -0
  52. package/dist/tests/composite_pk.test.js +98 -0
  53. package/dist/tests/composite_pk.test.js.map +1 -0
  54. package/dist/tests/config.test.d.ts +2 -0
  55. package/dist/tests/config.test.d.ts.map +1 -0
  56. package/dist/tests/config.test.js +86 -0
  57. package/dist/tests/config.test.js.map +1 -0
  58. package/dist/tests/db.test.d.ts +2 -0
  59. package/dist/tests/db.test.d.ts.map +1 -0
  60. package/dist/tests/db.test.js +178 -0
  61. package/dist/tests/db.test.js.map +1 -0
  62. package/dist/tests/discover.test.d.ts +2 -0
  63. package/dist/tests/discover.test.d.ts.map +1 -0
  64. package/dist/tests/discover.test.js +245 -0
  65. package/dist/tests/discover.test.js.map +1 -0
  66. package/dist/tests/edit.test.d.ts +2 -0
  67. package/dist/tests/edit.test.d.ts.map +1 -0
  68. package/dist/tests/edit.test.js +1161 -0
  69. package/dist/tests/edit.test.js.map +1 -0
  70. package/dist/tests/email.test.d.ts +2 -0
  71. package/dist/tests/email.test.d.ts.map +1 -0
  72. package/dist/tests/email.test.js +255 -0
  73. package/dist/tests/email.test.js.map +1 -0
  74. package/dist/tests/exact_views.test.d.ts +2 -0
  75. package/dist/tests/exact_views.test.d.ts.map +1 -0
  76. package/dist/tests/exact_views.test.js +1363 -0
  77. package/dist/tests/exact_views.test.js.map +1 -0
  78. package/dist/tests/field.test.d.ts +2 -0
  79. package/dist/tests/field.test.d.ts.map +1 -0
  80. package/dist/tests/field.test.js +588 -0
  81. package/dist/tests/field.test.js.map +1 -0
  82. package/dist/tests/fieldviews.test.d.ts +2 -0
  83. package/dist/tests/fieldviews.test.d.ts.map +1 -0
  84. package/dist/tests/fieldviews.test.js +74 -0
  85. package/dist/tests/fieldviews.test.js.map +1 -0
  86. package/dist/tests/file.test.d.ts +2 -0
  87. package/dist/tests/file.test.d.ts.map +1 -0
  88. package/dist/tests/file.test.js +148 -0
  89. package/dist/tests/file.test.js.map +1 -0
  90. package/dist/tests/filter.test.d.ts +2 -0
  91. package/dist/tests/filter.test.d.ts.map +1 -0
  92. package/dist/tests/filter.test.js +496 -0
  93. package/dist/tests/filter.test.js.map +1 -0
  94. package/dist/tests/form.test.d.ts +2 -0
  95. package/dist/tests/form.test.d.ts.map +1 -0
  96. package/dist/tests/form.test.js +264 -0
  97. package/dist/tests/form.test.js.map +1 -0
  98. package/dist/tests/list.test.d.ts +2 -0
  99. package/dist/tests/list.test.d.ts.map +1 -0
  100. package/dist/tests/list.test.js +1037 -0
  101. package/dist/tests/list.test.js.map +1 -0
  102. package/dist/tests/models.test.d.ts +2 -0
  103. package/dist/tests/models.test.d.ts.map +1 -0
  104. package/dist/tests/models.test.js +417 -0
  105. package/dist/tests/models.test.js.map +1 -0
  106. package/dist/tests/page.test.d.ts +2 -0
  107. package/dist/tests/page.test.d.ts.map +1 -0
  108. package/dist/tests/page.test.js +26 -0
  109. package/dist/tests/page.test.js.map +1 -0
  110. package/dist/tests/page_group.test.d.ts +2 -0
  111. package/dist/tests/page_group.test.d.ts.map +1 -0
  112. package/dist/tests/page_group.test.js +51 -0
  113. package/dist/tests/page_group.test.js.map +1 -0
  114. package/dist/tests/plugin.test.d.ts +2 -0
  115. package/dist/tests/plugin.test.d.ts.map +1 -0
  116. package/dist/tests/plugin.test.js +60 -0
  117. package/dist/tests/plugin.test.js.map +1 -0
  118. package/dist/tests/show.test.d.ts +2 -0
  119. package/dist/tests/show.test.d.ts.map +1 -0
  120. package/dist/tests/show.test.js +561 -0
  121. package/dist/tests/show.test.js.map +1 -0
  122. package/dist/tests/state.test.d.ts +2 -0
  123. package/dist/tests/state.test.d.ts.map +1 -0
  124. package/dist/tests/state.test.js +82 -0
  125. package/dist/tests/state.test.js.map +1 -0
  126. package/dist/tests/table.test.d.ts +2 -0
  127. package/dist/tests/table.test.d.ts.map +1 -0
  128. package/dist/tests/table.test.js +2717 -0
  129. package/dist/tests/table.test.js.map +1 -0
  130. package/dist/tests/table_history.test.d.ts +2 -0
  131. package/dist/tests/table_history.test.d.ts.map +1 -0
  132. package/dist/tests/table_history.test.js +413 -0
  133. package/dist/tests/table_history.test.js.map +1 -0
  134. package/dist/tests/tag.test.d.ts +2 -0
  135. package/dist/tests/tag.test.d.ts.map +1 -0
  136. package/dist/tests/tag.test.js +97 -0
  137. package/dist/tests/tag.test.js.map +1 -0
  138. package/dist/tests/user.test.d.ts +2 -0
  139. package/dist/tests/user.test.d.ts.map +1 -0
  140. package/dist/tests/user.test.js +441 -0
  141. package/dist/tests/user.test.js.map +1 -0
  142. package/dist/tests/view.test.d.ts +2 -0
  143. package/dist/tests/view.test.d.ts.map +1 -0
  144. package/dist/tests/view.test.js +699 -0
  145. package/dist/tests/view.test.js.map +1 -0
  146. package/dist/tests/workflow.test.d.ts +2 -0
  147. package/dist/tests/workflow.test.d.ts.map +1 -0
  148. package/dist/tests/workflow.test.js +303 -0
  149. package/dist/tests/workflow.test.js.map +1 -0
  150. package/dist/tests/workflow_run.test.d.ts +2 -0
  151. package/dist/tests/workflow_run.test.d.ts.map +1 -0
  152. package/dist/tests/workflow_run.test.js +922 -0
  153. package/dist/tests/workflow_run.test.js.map +1 -0
  154. package/package.json +8 -8
@@ -0,0 +1,1161 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const table_1 = __importDefault(require("../models/table"));
7
+ const field_1 = __importDefault(require("../models/field"));
8
+ const trigger_1 = __importDefault(require("../models/trigger"));
9
+ const table_constraints_1 = __importDefault(require("../models/table_constraints"));
10
+ const view_1 = __importDefault(require("../models/view"));
11
+ const db_1 = __importDefault(require("../db"));
12
+ const mocks_1 = __importDefault(require("./mocks"));
13
+ const { mockReqRes } = mocks_1.default;
14
+ const { getState } = require("../db/state");
15
+ const globals_1 = require("@jest/globals");
16
+ const assertions_1 = require("./assertions");
17
+ let remoteQueries = false;
18
+ getState().registerPlugin("base", require("../base-plugin"));
19
+ (0, globals_1.afterAll)(db_1.default.close);
20
+ (0, globals_1.beforeAll)(async () => {
21
+ await require("../db/reset_schema")();
22
+ await require("../db/fixtures")();
23
+ });
24
+ jest.setTimeout(10000);
25
+ const mkConfig = (hasSave, onChange) => {
26
+ return {
27
+ layout: {
28
+ above: [
29
+ {
30
+ widths: [2, 10],
31
+ besides: [
32
+ {
33
+ above: [null, { type: "blank", contents: "Name", isFormula: {} }],
34
+ },
35
+ {
36
+ above: [
37
+ null,
38
+ {
39
+ type: "field",
40
+ fieldview: "edit",
41
+ field_name: "name",
42
+ ...(onChange ? { onchange_action: "fieldchangeaction" } : {}),
43
+ },
44
+ ],
45
+ },
46
+ ],
47
+ },
48
+ { type: "line_break" },
49
+ {
50
+ widths: [2, 10],
51
+ besides: [
52
+ {
53
+ above: [null, { type: "blank", contents: "Age", isFormula: {} }],
54
+ },
55
+ {
56
+ above: [
57
+ null,
58
+ { type: "field", fieldview: "edit", field_name: "age" },
59
+ ],
60
+ },
61
+ ],
62
+ },
63
+ { type: "line_break" },
64
+ ...(hasSave
65
+ ? [
66
+ {
67
+ type: "action",
68
+ rndid: "74310f",
69
+ minRole: 100,
70
+ isFormula: {},
71
+ action_name: "Save",
72
+ action_style: "btn-primary",
73
+ configuration: {},
74
+ },
75
+ ]
76
+ : []),
77
+ ],
78
+ },
79
+ columns: [
80
+ {
81
+ type: "Field",
82
+ fieldview: "edit",
83
+ field_name: "name",
84
+ ...(onChange ? { onchange_action: "fieldchangeaction" } : {}),
85
+ },
86
+ { type: "Field", fieldview: "edit", field_name: "age" },
87
+ ...(hasSave
88
+ ? [
89
+ {
90
+ type: "Action",
91
+ rndid: "74310f",
92
+ minRole: 100,
93
+ isFormula: {},
94
+ action_name: "Save",
95
+ action_style: "btn-primary",
96
+ configuration: {},
97
+ },
98
+ ]
99
+ : []),
100
+ ],
101
+ };
102
+ };
103
+ (0, globals_1.describe)("Edit view with constraints and validations", () => {
104
+ (0, globals_1.it)("should setup", async () => {
105
+ const persons = await table_1.default.create("ValidatedTable1");
106
+ await field_1.default.create({
107
+ table: persons,
108
+ name: "name",
109
+ type: "String",
110
+ });
111
+ await field_1.default.create({
112
+ table: persons,
113
+ name: "age",
114
+ type: "Integer",
115
+ });
116
+ await table_constraints_1.default.create({
117
+ table_id: persons.id,
118
+ type: "Formula",
119
+ configuration: {
120
+ formula: "age>12",
121
+ errormsg: "Must be at least a teenager",
122
+ },
123
+ });
124
+ await trigger_1.default.create({
125
+ action: "run_js_code",
126
+ table_id: persons.id,
127
+ when_trigger: "Validate",
128
+ configuration: {
129
+ code: `
130
+ if(age && age<16) return {error: "Must be 16+ to qualify"}
131
+ if(!row.name) return {set_fields: {name: "PersonAged"+age}}
132
+ `,
133
+ },
134
+ });
135
+ await view_1.default.create({
136
+ name: "ValidatedWithSave",
137
+ table_id: persons.id,
138
+ viewtemplate: "Edit",
139
+ min_role: 100,
140
+ configuration: mkConfig(true),
141
+ });
142
+ await view_1.default.create({
143
+ name: "ValidatedAutoSave",
144
+ table_id: persons.id,
145
+ viewtemplate: "Edit",
146
+ min_role: 100,
147
+ configuration: { ...mkConfig(false), auto_save: true },
148
+ });
149
+ await view_1.default.create({
150
+ name: "ValidatedShow",
151
+ table_id: persons.id,
152
+ viewtemplate: "Show",
153
+ min_role: 100,
154
+ configuration: {},
155
+ });
156
+ });
157
+ (0, globals_1.it)("should return error on save constrain violation", async () => {
158
+ const v = await view_1.default.findOne({ name: "ValidatedWithSave" });
159
+ (0, assertions_1.assertIsSet)(v);
160
+ mockReqRes.reset();
161
+ await v.runPost({}, { name: "Fred", age: 10 }, mockReqRes);
162
+ const res = mockReqRes.getStored();
163
+ (0, globals_1.expect)(res.flash).toStrictEqual(["error", "Must be at least a teenager"]);
164
+ (0, globals_1.expect)(res.sendWrap[1]).toContain("<form");
165
+ (0, globals_1.expect)(res.sendWrap[1]).toContain('value="Fred"');
166
+ //console.log(res);
167
+ (0, globals_1.expect)(await table_1.default.findOne("ValidatedTable1").countRows({ name: "Fred" })).toBe(0);
168
+ });
169
+ (0, globals_1.it)("should return error on save validate violation", async () => {
170
+ const v = await view_1.default.findOne({ name: "ValidatedWithSave" });
171
+ (0, assertions_1.assertIsSet)(v);
172
+ mockReqRes.reset();
173
+ await v.runPost({}, { name: "Fred", age: 14 }, mockReqRes);
174
+ const res = mockReqRes.getStored();
175
+ (0, globals_1.expect)(res.flash).toStrictEqual(["error", "Must be 16+ to qualify"]);
176
+ (0, globals_1.expect)(res.sendWrap[1]).toContain("<form");
177
+ (0, globals_1.expect)(res.sendWrap[1]).toContain('value="Fred"');
178
+ (0, globals_1.expect)(await table_1.default.findOne("ValidatedTable1").countRows({ name: "Fred" })).toBe(0);
179
+ //console.log(res);
180
+ });
181
+ (0, globals_1.it)("should return save normally", async () => {
182
+ const v = await view_1.default.findOne({ name: "ValidatedWithSave" });
183
+ (0, assertions_1.assertIsSet)(v);
184
+ mockReqRes.reset();
185
+ v.configuration.view_when_done = "ValidatedShow";
186
+ await v.runPost({}, { name: "Fred", age: 18 }, mockReqRes);
187
+ const res = mockReqRes.getStored();
188
+ (0, globals_1.expect)(!!res.flash).toBe(false);
189
+ (0, globals_1.expect)(res.url).toBe("/view/ValidatedShow?id=1");
190
+ (0, globals_1.expect)(await table_1.default.findOne("ValidatedTable1").countRows({ name: "Fred" })).toBe(1);
191
+ });
192
+ (0, globals_1.it)("should update normally", async () => {
193
+ const v = await view_1.default.findOne({ name: "ValidatedWithSave" });
194
+ (0, assertions_1.assertIsSet)(v);
195
+ mockReqRes.reset();
196
+ await v.runPost({}, { id: 1, name: "Fred", age: 19 }, mockReqRes);
197
+ const res = mockReqRes.getStored();
198
+ (0, globals_1.expect)(!!res.flash).toBe(false);
199
+ (0, globals_1.expect)(res.url).toBe("/");
200
+ const row = await table_1.default.findOne("ValidatedTable1").getRow({
201
+ name: "Fred",
202
+ });
203
+ (0, assertions_1.assertIsSet)(row);
204
+ (0, globals_1.expect)(row.age).toBe(19);
205
+ });
206
+ (0, globals_1.it)("should not update to violate constraint", async () => {
207
+ const v = await view_1.default.findOne({ name: "ValidatedWithSave" });
208
+ (0, assertions_1.assertIsSet)(v);
209
+ mockReqRes.reset();
210
+ await v.runPost({}, { id: 1, name: "Fred", age: 10 }, mockReqRes);
211
+ const res = mockReqRes.getStored();
212
+ (0, globals_1.expect)(res.flash).toStrictEqual(["error", "Must be at least a teenager"]);
213
+ (0, globals_1.expect)(res.sendWrap[1]).toContain("<form");
214
+ (0, globals_1.expect)(res.sendWrap[1]).toContain('value="Fred"');
215
+ const row = await table_1.default.findOne("ValidatedTable1").getRow({
216
+ name: "Fred",
217
+ });
218
+ (0, assertions_1.assertIsSet)(row);
219
+ (0, globals_1.expect)(row.age).toBe(19);
220
+ });
221
+ (0, globals_1.it)("should not update to violate constraint", async () => {
222
+ const v = await view_1.default.findOne({ name: "ValidatedWithSave" });
223
+ (0, assertions_1.assertIsSet)(v);
224
+ mockReqRes.reset();
225
+ await v.runPost({}, { id: 1, name: "Fred", age: 14 }, mockReqRes);
226
+ const res = mockReqRes.getStored();
227
+ (0, globals_1.expect)(res.flash).toStrictEqual(["error", "Must be 16+ to qualify"]);
228
+ (0, globals_1.expect)(res.sendWrap[1]).toContain("<form");
229
+ (0, globals_1.expect)(res.sendWrap[1]).toContain('value="Fred"');
230
+ const row = await table_1.default.findOne("ValidatedTable1").getRow({
231
+ name: "Fred",
232
+ });
233
+ (0, assertions_1.assertIsSet)(row);
234
+ (0, globals_1.expect)(row.age).toBe(19);
235
+ });
236
+ (0, globals_1.it)("should return error on autosave constrain violation", async () => {
237
+ const v = await view_1.default.findOne({ name: "ValidatedAutoSave" });
238
+ (0, assertions_1.assertIsSet)(v);
239
+ mockReqRes.reset();
240
+ mockReqRes.req.xhr = true;
241
+ await v.runPost({}, { name: "Alex", age: 10 }, mockReqRes);
242
+ const res = mockReqRes.getStored();
243
+ (0, globals_1.expect)(res.status).toBe(422);
244
+ (0, globals_1.expect)(res.json.error).toBe("Must be at least a teenager");
245
+ (0, globals_1.expect)(await table_1.default.findOne("ValidatedTable1").countRows({ name: "Alex" })).toBe(0);
246
+ mockReqRes.reset();
247
+ });
248
+ (0, globals_1.it)("should return error on autosave validate violation", async () => {
249
+ const v = await view_1.default.findOne({ name: "ValidatedAutoSave" });
250
+ (0, assertions_1.assertIsSet)(v);
251
+ mockReqRes.reset();
252
+ mockReqRes.req.xhr = true;
253
+ await v.runPost({}, { name: "Alex", age: 14 }, mockReqRes);
254
+ const res = mockReqRes.getStored();
255
+ (0, globals_1.expect)(res.status).toBe(422);
256
+ (0, globals_1.expect)(res.json.error).toBe("Must be 16+ to qualify");
257
+ (0, globals_1.expect)(await table_1.default.findOne("ValidatedTable1").countRows({ name: "Alex" })).toBe(0);
258
+ mockReqRes.reset();
259
+ });
260
+ (0, globals_1.it)("should autosave normally", async () => {
261
+ const v = await view_1.default.findOne({ name: "ValidatedAutoSave" });
262
+ (0, assertions_1.assertIsSet)(v);
263
+ mockReqRes.reset();
264
+ mockReqRes.req.xhr = true;
265
+ await v.runPost({}, { name: "Alex", age: 18 }, mockReqRes);
266
+ const res = mockReqRes.getStored();
267
+ (0, globals_1.expect)(res.json).toStrictEqual({
268
+ view_when_done: undefined,
269
+ url_when_done: "/",
270
+ id: 2,
271
+ });
272
+ //expect(res.json.error).toBe("Must be 16+ to qualify");
273
+ (0, globals_1.expect)(await table_1.default.findOne("ValidatedTable1").countRows({ name: "Alex" })).toBe(1);
274
+ mockReqRes.reset();
275
+ });
276
+ (0, globals_1.it)("should update autosave normally", async () => {
277
+ const v = await view_1.default.findOne({ name: "ValidatedAutoSave" });
278
+ (0, assertions_1.assertIsSet)(v);
279
+ v.configuration.view_when_done = "ValidatedShow";
280
+ mockReqRes.reset();
281
+ mockReqRes.req.xhr = true;
282
+ await v.runPost({}, { id: 1, name: "Fred", age: 20 }, mockReqRes);
283
+ const res = mockReqRes.getStored();
284
+ (0, globals_1.expect)(res.json).toStrictEqual({
285
+ view_when_done: "ValidatedShow",
286
+ url_when_done: "/view/ValidatedShow?id=1",
287
+ });
288
+ //expect(res.json.error).toBe("Must be 16+ to qualify");
289
+ const row = await table_1.default.findOne("ValidatedTable1").getRow({
290
+ name: "Fred",
291
+ });
292
+ (0, assertions_1.assertIsSet)(row);
293
+ (0, globals_1.expect)(row.age).toBe(20);
294
+ mockReqRes.reset();
295
+ });
296
+ (0, globals_1.it)("should not change existing on validation ", async () => {
297
+ const v = await view_1.default.findOne({ name: "ValidatedAutoSave" });
298
+ (0, assertions_1.assertIsSet)(v);
299
+ v.configuration.view_when_done = "ValidatedShow";
300
+ //remove name column.
301
+ v.configuration.columns = v.configuration.columns.filter((c) => c.field_name !== "name");
302
+ mockReqRes.reset();
303
+ mockReqRes.req.xhr = true;
304
+ await v.runPost({}, { id: 1, age: 41 }, mockReqRes);
305
+ const res = mockReqRes.getStored();
306
+ (0, globals_1.expect)(res.json).toStrictEqual({
307
+ view_when_done: "ValidatedShow",
308
+ url_when_done: "/view/ValidatedShow?id=1",
309
+ });
310
+ //expect(res.json.error).toBe("Must be 16+ to qualify");
311
+ const row = await table_1.default.findOne("ValidatedTable1").getRow({
312
+ id: 1,
313
+ });
314
+ (0, assertions_1.assertIsSet)(row);
315
+ (0, globals_1.expect)(row.age).toBe(41);
316
+ (0, globals_1.expect)(row.name).toBe("Fred");
317
+ mockReqRes.reset();
318
+ });
319
+ });
320
+ (0, globals_1.describe)("Edit-in-edit", () => {
321
+ (0, globals_1.it)("should setup", async () => {
322
+ await view_1.default.create({
323
+ name: "EditPublisherWithBooks",
324
+ table_id: table_1.default.findOne("publisher")?.id,
325
+ viewtemplate: "Edit",
326
+ min_role: 100,
327
+ configuration: {
328
+ layout: {
329
+ above: [
330
+ {
331
+ gx: null,
332
+ gy: null,
333
+ style: {
334
+ "margin-bottom": "1.5rem",
335
+ },
336
+ aligns: ["end", "start"],
337
+ widths: [2, 10],
338
+ besides: [
339
+ {
340
+ above: [
341
+ null,
342
+ {
343
+ font: "",
344
+ type: "blank",
345
+ block: false,
346
+ style: {},
347
+ inline: false,
348
+ contents: "Name",
349
+ labelFor: "name",
350
+ isFormula: {},
351
+ textStyle: "",
352
+ },
353
+ ],
354
+ },
355
+ {
356
+ above: [
357
+ null,
358
+ {
359
+ type: "field",
360
+ block: false,
361
+ fieldview: "edit",
362
+ textStyle: "",
363
+ field_name: "name",
364
+ configuration: {},
365
+ },
366
+ ],
367
+ },
368
+ ],
369
+ breakpoints: ["", ""],
370
+ },
371
+ {
372
+ name: "6dfcdb",
373
+ type: "view",
374
+ view: "ChildList:authoredit.books.publisher",
375
+ state: "shared",
376
+ },
377
+ {
378
+ type: "action",
379
+ block: false,
380
+ rndid: "dbf003",
381
+ minRole: 100,
382
+ isFormula: {},
383
+ action_icon: "",
384
+ action_name: "Save",
385
+ action_size: "",
386
+ action_bgcol: "",
387
+ action_label: "",
388
+ action_style: "btn-primary",
389
+ configuration: {},
390
+ action_textcol: "",
391
+ action_bordercol: "",
392
+ },
393
+ ],
394
+ },
395
+ columns: [
396
+ {
397
+ type: "Field",
398
+ block: false,
399
+ fieldview: "edit",
400
+ textStyle: "",
401
+ field_name: "name",
402
+ configuration: {},
403
+ },
404
+ {
405
+ type: "Action",
406
+ rndid: "dbf003",
407
+ minRole: 100,
408
+ isFormula: {},
409
+ action_icon: "",
410
+ action_name: "Save",
411
+ action_size: "",
412
+ action_bgcol: "",
413
+ action_label: "",
414
+ action_style: "btn-primary",
415
+ configuration: {},
416
+ action_textcol: "",
417
+ action_bordercol: "",
418
+ },
419
+ ],
420
+ viewname: "EditPublisherWithBooks",
421
+ auto_save: false,
422
+ split_paste: false,
423
+ exttable_name: null,
424
+ page_when_done: null,
425
+ view_when_done: "author_multi_edit",
426
+ dest_url_formula: null,
427
+ destination_type: "View",
428
+ formula_destinations: [],
429
+ page_group_when_done: null,
430
+ },
431
+ });
432
+ });
433
+ (0, globals_1.it)("should run get", async () => {
434
+ const v = await view_1.default.findOne({ name: "EditPublisherWithBooks" });
435
+ (0, assertions_1.assertIsSet)(v);
436
+ const vres0 = await v.run({}, mockReqRes);
437
+ (0, globals_1.expect)(vres0).toContain("<form");
438
+ (0, globals_1.expect)(vres0).toContain("add_repeater('publisher', this)");
439
+ const vres1 = await v.run({ id: 1 }, mockReqRes);
440
+ (0, globals_1.expect)(vres1).toContain("<form");
441
+ (0, globals_1.expect)(vres1).toContain("add_repeater('publisher', this)");
442
+ (0, globals_1.expect)(vres1).toContain("Leo Tolstoy");
443
+ (0, globals_1.expect)(vres1).not.toContain("Melville");
444
+ });
445
+ (0, globals_1.it)("should run post", async () => {
446
+ const v = await view_1.default.findOne({ name: "EditPublisherWithBooks" });
447
+ const books = table_1.default.findOne("books");
448
+ (0, assertions_1.assertIsSet)(books);
449
+ (0, assertions_1.assertIsSet)(v);
450
+ await v.runPost({}, {
451
+ name: "newpub",
452
+ author_0: "newpubsnewbook",
453
+ author_1: "newpubsotherbook",
454
+ }, mockReqRes);
455
+ const pubrow = await table_1.default.findOne("publisher")?.getRow({ name: "newpub" });
456
+ (0, assertions_1.assertIsSet)(pubrow);
457
+ const bookrow = await books.getRow({
458
+ author: "newpubsnewbook",
459
+ });
460
+ (0, assertions_1.assertIsSet)(bookrow);
461
+ (0, globals_1.expect)(bookrow.publisher).toBe(pubrow.id);
462
+ (0, globals_1.expect)(bookrow.pages).toBe(678);
463
+ const nbooks1 = await books.countRows({ publisher: pubrow.id });
464
+ (0, globals_1.expect)(nbooks1).toBe(2);
465
+ await v.runPost({}, {
466
+ id: pubrow.id,
467
+ name: "newpub",
468
+ author_0: "newpubsnewbook",
469
+ id_0: bookrow.id,
470
+ }, mockReqRes);
471
+ const nbooks2 = await books.countRows({ publisher: pubrow.id });
472
+ (0, globals_1.expect)(nbooks2).toBe(1);
473
+ });
474
+ });
475
+ (0, globals_1.describe)("Edit view field onchange", () => {
476
+ (0, globals_1.it)("should have onchange in get", async () => {
477
+ const persons = await table_1.default.findOne("ValidatedTable1");
478
+ (0, assertions_1.assertIsSet)(persons);
479
+ const v = await view_1.default.create({
480
+ name: "OnChangeEdit",
481
+ table_id: persons.id,
482
+ viewtemplate: "Edit",
483
+ min_role: 100,
484
+ configuration: mkConfig(false, true),
485
+ });
486
+ await trigger_1.default.create({
487
+ action: "run_js_code",
488
+ table_id: persons.id,
489
+ name: "fieldchangeaction",
490
+ when_trigger: "Never",
491
+ configuration: {
492
+ code: `return {notify: "Hello from trigger"}`,
493
+ },
494
+ });
495
+ const vres0 = await v.run({}, mockReqRes);
496
+ (0, globals_1.expect)(vres0).toContain("<form");
497
+ (0, globals_1.expect)(vres0).toContain(`onChange="view_post(this, 'run_action', {onchange_action: 'fieldchangeaction', onchange_field:'name', ...get_form_record(this) })"`);
498
+ });
499
+ (0, globals_1.it)("should run route", async () => {
500
+ const v = await view_1.default.findOne({ name: "OnChangeEdit" });
501
+ (0, assertions_1.assertIsSet)(v);
502
+ mockReqRes.reset();
503
+ const body = {
504
+ onchange_action: "fieldchangeaction",
505
+ onchange_field: "name",
506
+ };
507
+ await v.runRoute("run_action", body, mockReqRes.res, { req: { ...mockReqRes.req, body }, res: mockReqRes.res }, false);
508
+ (0, globals_1.expect)(mockReqRes.getStored().json).toStrictEqual({
509
+ notify: "Hello from trigger",
510
+ success: "ok",
511
+ });
512
+ });
513
+ });
514
+ const accordionConfig = {
515
+ name: "authoredit1",
516
+ configuration: {
517
+ layout: {
518
+ type: "tabs",
519
+ ntabs: "2",
520
+ tabId: "",
521
+ showif: [null, "pages<800"],
522
+ titles: ["By {{ author }}", "Publisher Tab title {{ publisher }}"],
523
+ contents: [
524
+ {
525
+ font: "",
526
+ icon: "",
527
+ type: "blank",
528
+ block: false,
529
+ style: {},
530
+ inline: false,
531
+ contents: "Hello 1",
532
+ labelFor: "",
533
+ isFormula: {},
534
+ textStyle: "",
535
+ },
536
+ {
537
+ above: [
538
+ {
539
+ font: "",
540
+ icon: "",
541
+ type: "blank",
542
+ block: false,
543
+ style: {},
544
+ inline: false,
545
+ contents: "Publisher JF:&nbsp;",
546
+ labelFor: "",
547
+ isFormula: {},
548
+ textStyle: "",
549
+ },
550
+ {
551
+ type: "join_field",
552
+ block: false,
553
+ fieldview: "show_with_html",
554
+ textStyle: "",
555
+ join_field: "publisher.name",
556
+ configuration: {
557
+ code: "<span>the publisher {{it}} </span>",
558
+ },
559
+ },
560
+ ],
561
+ },
562
+ ],
563
+ deeplink: true,
564
+ tabsStyle: "Accordion",
565
+ independent: false,
566
+ startClosed: false,
567
+ serverRendered: false,
568
+ disable_inactive: false,
569
+ },
570
+ columns: [
571
+ {
572
+ type: "JoinField",
573
+ block: false,
574
+ fieldview: "show_with_html",
575
+ textStyle: "",
576
+ join_field: "publisher.name",
577
+ configuration: {
578
+ code: "<span>the publisher {{it}} </span>",
579
+ },
580
+ },
581
+ ],
582
+ },
583
+ };
584
+ const mkViewWithCfg = async (viewCfg) => {
585
+ return await view_1.default.create({
586
+ viewtemplate: "Edit",
587
+ description: "",
588
+ min_role: 1,
589
+ name: `someView${Math.round(Math.random() * 100000)}`,
590
+ table_id: table_1.default.findOne("books")?.id,
591
+ default_render_page: "",
592
+ slug: {
593
+ label: "",
594
+ steps: [],
595
+ },
596
+ attributes: {
597
+ page_title: "",
598
+ popup_title: "",
599
+ popup_width: null,
600
+ popup_link_out: false,
601
+ popup_minwidth: null,
602
+ page_description: "",
603
+ popup_width_units: null,
604
+ popup_minwidth_units: null,
605
+ popup_save_indicator: false,
606
+ },
607
+ ...viewCfg,
608
+ });
609
+ };
610
+ (0, globals_1.describe)("Edit config flow", () => {
611
+ (0, globals_1.it)("should compute for author table", async () => {
612
+ const view = await mkViewWithCfg({
613
+ configuration: {},
614
+ });
615
+ const configFlow = await view.get_config_flow(mockReqRes.req);
616
+ const result = await configFlow.run({
617
+ table_id: view.table_id,
618
+ exttable_name: null,
619
+ viewname: view.name,
620
+ ...view.configuration,
621
+ }, mockReqRes.req);
622
+ const fieldNames = result?.renderBuilder?.options.fields.map((f) => f.name);
623
+ (0, globals_1.expect)(fieldNames).toContain("author");
624
+ (0, globals_1.expect)(fieldNames).not.toContain("password");
625
+ });
626
+ (0, globals_1.it)("should compute for users table", async () => {
627
+ const view = await mkViewWithCfg({
628
+ configuration: {},
629
+ table_id: table_1.default.findOne("users")?.id,
630
+ });
631
+ const configFlow = await view.get_config_flow(mockReqRes.req);
632
+ const result = await configFlow.run({
633
+ table_id: view.table_id,
634
+ exttable_name: null,
635
+ viewname: view.name,
636
+ ...view.configuration,
637
+ }, mockReqRes.req);
638
+ const fieldNames = result?.renderBuilder?.options.fields.map((f) => f.name);
639
+ (0, globals_1.expect)(fieldNames).not.toContain("author");
640
+ (0, globals_1.expect)(fieldNames).toContain("password");
641
+ (0, globals_1.expect)(fieldNames).toContain("email");
642
+ });
643
+ });
644
+ (0, globals_1.describe)("Edit view with accordion and join fields", () => {
645
+ (0, globals_1.it)("should run", async () => {
646
+ const view = await mkViewWithCfg(accordionConfig);
647
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
648
+ (0, globals_1.expect)(vres1).toContain(">By Herman Melville<");
649
+ (0, globals_1.expect)(vres1).not.toContain(">Publisher Tab title");
650
+ (0, globals_1.expect)(vres1).not.toContain(">Publisher JF:");
651
+ const vres2 = await view.run({ id: 2 }, mockReqRes);
652
+ (0, globals_1.expect)(vres2).toContain(">By Leo Tolstoy<");
653
+ (0, globals_1.expect)(vres2).toContain(">Publisher Tab title 1<");
654
+ (0, globals_1.expect)(vres2).toContain(" data-source-url=");
655
+ });
656
+ });
657
+ (0, globals_1.describe)("Edit view components", () => {
658
+ (0, globals_1.it)("runs on_page_load action", async () => {
659
+ const view = await mkViewWithCfg({
660
+ configuration: {
661
+ layout: {
662
+ type: "action",
663
+ block: false,
664
+ rndid: "b6fd72",
665
+ nsteps: 1,
666
+ confirm: false,
667
+ minRole: 100,
668
+ isFormula: {},
669
+ action_icon: "",
670
+ action_name: "toast",
671
+ action_label: "",
672
+ action_style: "on_page_load",
673
+ configuration: {
674
+ text: "Hello!",
675
+ notify_type: "Notify",
676
+ },
677
+ },
678
+ columns: [
679
+ {
680
+ type: "Action",
681
+ rndid: "b6fd72",
682
+ nsteps: 1,
683
+ confirm: false,
684
+ minRole: 100,
685
+ isFormula: {},
686
+ action_icon: "",
687
+ action_name: "toast",
688
+ action_label: "",
689
+ action_style: "on_page_load",
690
+ configuration: {
691
+ text: "Hello!",
692
+ notify_type: "Notify",
693
+ },
694
+ },
695
+ ],
696
+ },
697
+ });
698
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
699
+ (0, globals_1.expect)(vres1).toBe(`<form data-viewname="${view.name}" action="/view/${view.name}" class="form-namespace " method="post" data-row-values="%7B%22_creating%22%3Afalse%2C%22user%22%3A%7B%22id%22%3A1%2C%22role_id%22%3A1%2C%22attributes%22%3A%7B%7D%7D%2C%22author%22%3A%22Herman%20Melville%22%2C%22pages%22%3A967%2C%22publisher%22%3Anull%7D" id="test-form-id"><input type="hidden" name="_csrf" value=""><input type="hidden" class="form-control " name="id" value="1"><script>(function(f){if (document.readyState === "complete") f(); else document.addEventListener(\'DOMContentLoaded\',()=>setTimeout(f),false)})(function(){common_done({"notify":"Hello!"}, "${view.name}")});</script></form><script>(function(f){if (document.readyState === "complete") f(); else document.addEventListener('DOMContentLoaded',()=>setTimeout(f),false)})(function(){const editForm = document.getElementById('test-form-id'); if (editForm) editForm.addEventListener("change", handle_identical_fields, true);});</script>`);
700
+ });
701
+ (0, globals_1.it)("runs button action", async () => {
702
+ const view = await mkViewWithCfg({
703
+ configuration: {
704
+ layout: {
705
+ type: "action",
706
+ block: false,
707
+ rndid: "b6fd72",
708
+ nsteps: 1,
709
+ confirm: false,
710
+ minRole: 100,
711
+ isFormula: {},
712
+ action_icon: "",
713
+ action_name: "toast",
714
+ action_label: "",
715
+ action_style: "btn btn-primary",
716
+ configuration: {
717
+ text: "Hello!",
718
+ notify_type: "Notify",
719
+ },
720
+ },
721
+ columns: [
722
+ {
723
+ type: "Action",
724
+ rndid: "b6fd72",
725
+ nsteps: 1,
726
+ confirm: false,
727
+ minRole: 100,
728
+ isFormula: {},
729
+ action_icon: "",
730
+ action_name: "toast",
731
+ action_label: "",
732
+ action_style: "btn btn-primary",
733
+ configuration: {
734
+ text: "Hello!",
735
+ notify_type: "Notify",
736
+ },
737
+ },
738
+ ],
739
+ },
740
+ });
741
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
742
+ (0, globals_1.expect)(vres1).toBe(`<form data-viewname="${view.name}" action="/view/${view.name}" class="form-namespace " method="post" data-row-values="%7B%22_creating%22%3Afalse%2C%22user%22%3A%7B%22id%22%3A1%2C%22role_id%22%3A1%2C%22attributes%22%3A%7B%7D%7D%2C%22author%22%3A%22Herman%20Melville%22%2C%22pages%22%3A967%2C%22publisher%22%3Anull%7D" id="test-form-id"><input type="hidden" name="_csrf" value=""><input type="hidden" class="form-control " name="id" value="1"><a href="javascript:void(0)" onclick="view_post(this, 'run_action', {rndid:'b6fd72', ...get_form_record(this)});" class="btn btn btn-primary ">toast</a></form><script>(function(f){if (document.readyState === "complete") f(); else document.addEventListener('DOMContentLoaded',()=>setTimeout(f),false)})(function(){const editForm = document.getElementById('test-form-id'); if (editForm) editForm.addEventListener("change", handle_identical_fields, true);});</script>`);
743
+ mockReqRes.reset();
744
+ const body = { rndid: "b6fd72", id: "1" };
745
+ await view.runRoute("run_action", body, mockReqRes.res, { req: { ...mockReqRes.req, body }, res: mockReqRes.res }, false);
746
+ (0, globals_1.expect)(mockReqRes.getStored().json).toStrictEqual({
747
+ notify: "Hello!",
748
+ success: "ok",
749
+ });
750
+ });
751
+ (0, globals_1.it)("runs button action with form input", async () => {
752
+ const view = await mkViewWithCfg({
753
+ configuration: {
754
+ layout: {
755
+ above: [
756
+ {
757
+ type: "field",
758
+ block: false,
759
+ fieldview: "edit",
760
+ textStyle: "",
761
+ field_name: "author",
762
+ configuration: {},
763
+ },
764
+ {
765
+ type: "action",
766
+ block: false,
767
+ rndid: "40bb3f",
768
+ nsteps: "",
769
+ minRole: 100,
770
+ isFormula: {},
771
+ action_icon: "",
772
+ action_name: "toast",
773
+ action_size: "",
774
+ action_bgcol: "",
775
+ action_label: "",
776
+ action_style: "btn-primary",
777
+ configuration: {
778
+ text: "Hello from {{ author}}",
779
+ notify_type: "Notify",
780
+ },
781
+ step_only_ifs: "",
782
+ action_textcol: "",
783
+ action_bordercol: "",
784
+ step_action_names: "",
785
+ },
786
+ ],
787
+ },
788
+ columns: [
789
+ {
790
+ type: "Field",
791
+ block: false,
792
+ fieldview: "edit",
793
+ textStyle: "",
794
+ field_name: "author",
795
+ configuration: {},
796
+ },
797
+ {
798
+ type: "Action",
799
+ rndid: "40bb3f",
800
+ nsteps: "",
801
+ minRole: 100,
802
+ isFormula: {},
803
+ action_icon: "",
804
+ action_name: "toast",
805
+ action_size: "",
806
+ action_bgcol: "",
807
+ action_label: "",
808
+ action_style: "btn-primary",
809
+ configuration: {
810
+ text: "Hello {{ user.email}} from {{ author}}",
811
+ notify_type: "Notify",
812
+ },
813
+ step_only_ifs: "",
814
+ action_textcol: "",
815
+ action_bordercol: "",
816
+ step_action_names: "",
817
+ },
818
+ ],
819
+ },
820
+ });
821
+ mockReqRes.reset();
822
+ const body = {
823
+ rndid: "40bb3f",
824
+ user: {
825
+ email: "admin@bar.com",
826
+ id: 1,
827
+ role_id: 1,
828
+ language: "en",
829
+ },
830
+ author: "Chris Date",
831
+ };
832
+ await view.runRoute("run_action", body, mockReqRes.res, {
833
+ req: {
834
+ ...mockReqRes.req,
835
+ body,
836
+ user: {
837
+ email: "admin@foo.com",
838
+ id: 1,
839
+ role_id: 1,
840
+ language: "en",
841
+ },
842
+ },
843
+ res: mockReqRes.res,
844
+ }, false);
845
+ (0, globals_1.expect)(mockReqRes.getStored().json).toStrictEqual({
846
+ notify: "Hello admin@foo.com from Chris Date",
847
+ success: "ok",
848
+ });
849
+ });
850
+ (0, globals_1.it)("runs button action with fixed inputs", async () => {
851
+ const view = await mkViewWithCfg({
852
+ configuration: {
853
+ fixed: {
854
+ author: "MrFoo",
855
+ },
856
+ layout: {
857
+ type: "action",
858
+ block: false,
859
+ rndid: "ca9d71",
860
+ nsteps: 1,
861
+ confirm: false,
862
+ minRole: 100,
863
+ isFormula: {},
864
+ action_icon: "",
865
+ action_name: "toast",
866
+ action_label: "",
867
+ configuration: {
868
+ text: "Hello {{ user.email}} from {{ author}}",
869
+ notify_type: "Notify",
870
+ },
871
+ },
872
+ columns: [
873
+ {
874
+ type: "Action",
875
+ rndid: "ca9d71",
876
+ nsteps: 1,
877
+ confirm: false,
878
+ minRole: 100,
879
+ isFormula: {},
880
+ action_icon: "",
881
+ action_name: "toast",
882
+ action_label: "",
883
+ configuration: {
884
+ text: "Hello {{ user.email}} from {{ author}}",
885
+ notify_type: "Notify",
886
+ },
887
+ },
888
+ ],
889
+ },
890
+ });
891
+ mockReqRes.reset();
892
+ const body = {
893
+ rndid: "ca9d71",
894
+ user: {
895
+ email: "admin@bar.com",
896
+ id: 1,
897
+ role_id: 1,
898
+ language: "en",
899
+ },
900
+ };
901
+ await view.runRoute("run_action", body, mockReqRes.res, {
902
+ req: {
903
+ ...mockReqRes.req,
904
+ body,
905
+ user: {
906
+ email: "admin@foo.com",
907
+ id: 1,
908
+ role_id: 1,
909
+ language: "en",
910
+ },
911
+ },
912
+ res: mockReqRes.res,
913
+ }, false);
914
+ (0, globals_1.expect)(mockReqRes.getStored().json).toStrictEqual({
915
+ notify: "Hello admin@foo.com from MrFoo",
916
+ success: "ok",
917
+ });
918
+ });
919
+ (0, globals_1.it)("view link independent same table", async () => {
920
+ const view = await mkViewWithCfg({
921
+ configuration: {
922
+ layout: {
923
+ type: "view_link",
924
+ view: "patientlist",
925
+ block: false,
926
+ minRole: 100,
927
+ relation: ".",
928
+ isFormula: {},
929
+ link_icon: "",
930
+ view_label: "",
931
+ },
932
+ columns: [
933
+ {
934
+ type: "ViewLink",
935
+ view: "patientlist",
936
+ block: false,
937
+ label: "",
938
+ minRole: 100,
939
+ relation: ".",
940
+ link_icon: "",
941
+ },
942
+ ],
943
+ },
944
+ });
945
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
946
+ (0, globals_1.expect)(vres1).toContain('<a href="/view/patientlist">patientlist</a>');
947
+ // TODO FIX THIS
948
+ //const vres0 = await view.run({}, mockReqRes);
949
+ //expect(vres0).toContain('<a href="/view/patientlist">patientlist</a>');
950
+ });
951
+ (0, globals_1.it)("view link independent different table", async () => {
952
+ const view = await mkViewWithCfg({
953
+ configuration: {
954
+ layout: {
955
+ type: "view_link",
956
+ view: "list_employees",
957
+ block: false,
958
+ minRole: 100,
959
+ relation: ".",
960
+ isFormula: {},
961
+ link_icon: "",
962
+ view_label: "",
963
+ },
964
+ columns: [
965
+ {
966
+ type: "ViewLink",
967
+ view: "list_employees",
968
+ block: false,
969
+ label: "",
970
+ minRole: 100,
971
+ relation: ".",
972
+ link_icon: "",
973
+ },
974
+ ],
975
+ },
976
+ });
977
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
978
+ (0, globals_1.expect)(vres1).toContain('<a href="/view/list_employees">list_employees</a>');
979
+ // TODO FIX THIS
980
+ //const vres0 = await view.run({}, mockReqRes);
981
+ //expect(vres0).toContain(
982
+ // '<a href="/view/list_employees">list_employees</a>'
983
+ //);
984
+ });
985
+ (0, globals_1.it)("view link children", async () => {
986
+ const view = await mkViewWithCfg({
987
+ configuration: {
988
+ layout: {
989
+ type: "view_link",
990
+ view: "patientlist",
991
+ block: false,
992
+ minRole: 100,
993
+ relation: ".books.patients$favbook",
994
+ isFormula: {},
995
+ link_icon: "",
996
+ view_label: "",
997
+ },
998
+ columns: [
999
+ {
1000
+ type: "ViewLink",
1001
+ view: "patientlist",
1002
+ block: false,
1003
+ label: "",
1004
+ minRole: 100,
1005
+ relation: ".books.patients$favbook",
1006
+ link_icon: "",
1007
+ },
1008
+ ],
1009
+ },
1010
+ });
1011
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
1012
+ (0, globals_1.expect)(vres1).toContain('<a href="/view/patientlist?favbook=1">patientlist</a>');
1013
+ const vres0 = await view.run({}, mockReqRes);
1014
+ (0, globals_1.expect)(vres0).not.toContain("patientlist");
1015
+ });
1016
+ (0, globals_1.it)("container showif on field", async () => {
1017
+ const view = await mkViewWithCfg({
1018
+ configuration: {
1019
+ layout: {
1020
+ type: "container",
1021
+ style: {},
1022
+ contents: {
1023
+ type: "blank",
1024
+ block: false,
1025
+ style: {},
1026
+ inline: false,
1027
+ contents: "LONG",
1028
+ },
1029
+ isFormula: {},
1030
+ htmlElement: "div",
1031
+ showForRole: [],
1032
+ showIfFormula: "pages>500",
1033
+ minScreenWidth: "",
1034
+ },
1035
+ columns: [],
1036
+ },
1037
+ });
1038
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
1039
+ (0, globals_1.expect)(vres1).toContain('data-show-if="showIfFormulaInputs(');
1040
+ const vres0 = await view.run({}, mockReqRes);
1041
+ (0, globals_1.expect)(vres0).not.toContain("patientlist");
1042
+ });
1043
+ (0, globals_1.it)("container showif on row.field", async () => {
1044
+ const view = await mkViewWithCfg({
1045
+ configuration: {
1046
+ layout: {
1047
+ type: "container",
1048
+ style: {},
1049
+ contents: {
1050
+ type: "blank",
1051
+ block: false,
1052
+ style: {},
1053
+ inline: false,
1054
+ contents: "LONG",
1055
+ },
1056
+ isFormula: {},
1057
+ htmlElement: "div",
1058
+ showForRole: [],
1059
+ showIfFormula: "row.pages>500",
1060
+ minScreenWidth: "",
1061
+ },
1062
+ columns: [],
1063
+ },
1064
+ });
1065
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
1066
+ (0, globals_1.expect)(vres1).toContain('data-show-if="showIfFormulaInputs(');
1067
+ const vres0 = await view.run({}, mockReqRes);
1068
+ (0, globals_1.expect)(vres0).not.toContain("patientlist");
1069
+ });
1070
+ (0, globals_1.it)("container showif on joinfield", async () => {
1071
+ const view = await mkViewWithCfg({
1072
+ configuration: {
1073
+ layout: {
1074
+ type: "container",
1075
+ style: {},
1076
+ contents: {
1077
+ type: "blank",
1078
+ block: false,
1079
+ style: {},
1080
+ inline: false,
1081
+ contents: "LONG",
1082
+ },
1083
+ isFormula: {},
1084
+ htmlElement: "div",
1085
+ showForRole: [],
1086
+ showIfFormula: "publisher.name==='AK Press'",
1087
+ minScreenWidth: "",
1088
+ },
1089
+ columns: [],
1090
+ },
1091
+ });
1092
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
1093
+ (0, globals_1.expect)(vres1).toContain('data-show-if="showIfFormulaInputs(');
1094
+ (0, globals_1.expect)(vres1).toContain('data-show-if-joinfields="%5B%7B%22ref%22%3A%22');
1095
+ const vres0 = await view.run({}, mockReqRes);
1096
+ (0, globals_1.expect)(vres0).not.toContain("patientlist");
1097
+ });
1098
+ (0, globals_1.it)("embed view independent different table", async () => {
1099
+ const view = await mkViewWithCfg({
1100
+ configuration: {
1101
+ layout: {
1102
+ name: "f98a40",
1103
+ type: "view",
1104
+ view: "list_employees",
1105
+ state: "shared",
1106
+ relation: ".",
1107
+ },
1108
+ columns: [],
1109
+ },
1110
+ });
1111
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
1112
+ (0, globals_1.expect)(vres1).toContain("my_department");
1113
+ const vres0 = await view.run({}, mockReqRes);
1114
+ (0, globals_1.expect)(vres0).toContain("my_department");
1115
+ });
1116
+ (0, globals_1.it)("embed view independent same table", async () => {
1117
+ const view = await mkViewWithCfg({
1118
+ configuration: {
1119
+ layout: {
1120
+ name: "f98a40",
1121
+ type: "view",
1122
+ view: "authorlist",
1123
+ state: "shared",
1124
+ relation: ".",
1125
+ },
1126
+ columns: [],
1127
+ },
1128
+ });
1129
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
1130
+ (0, globals_1.expect)(vres1).toContain(">Leo Tolstoy<");
1131
+ (0, globals_1.expect)(vres1).toContain(">Herman Melville<");
1132
+ const vres0 = await view.run({}, mockReqRes);
1133
+ (0, globals_1.expect)(vres0).toContain(">Leo Tolstoy<");
1134
+ (0, globals_1.expect)(vres0).toContain(">Herman Melville<");
1135
+ });
1136
+ (0, globals_1.it)("embed view children", async () => {
1137
+ const view = await mkViewWithCfg({
1138
+ configuration: {
1139
+ layout: {
1140
+ name: "4ff12b",
1141
+ type: "view",
1142
+ view: "patientlist",
1143
+ state: "shared",
1144
+ relation: ".books.patients$favbook",
1145
+ },
1146
+ columns: [],
1147
+ },
1148
+ });
1149
+ const vres1 = await view.run({ id: 1 }, mockReqRes);
1150
+ (0, globals_1.expect)(vres1).toContain("Kirk");
1151
+ (0, globals_1.expect)(vres1).toContain('data-sc-embed-viewname="patientlist"');
1152
+ (0, globals_1.expect)(vres1).not.toContain("Michael");
1153
+ const vres0 = await view.run({}, mockReqRes);
1154
+ (0, globals_1.expect)(vres0).toContain('data-sc-embed-viewname="patientlist"');
1155
+ (0, globals_1.expect)(vres0).toContain('data-view-source="add_extra_state');
1156
+ (0, globals_1.expect)(vres0).toContain('data-view-source-need-fields');
1157
+ (0, globals_1.expect)(vres0).not.toContain('data-view-source-current');
1158
+ (0, globals_1.expect)(vres0).toContain("<form");
1159
+ });
1160
+ });
1161
+ //# sourceMappingURL=edit.test.js.map