@saltcorn/data 1.6.0-rc.2 → 1.6.0-rc.3

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