@saltcorn/data 1.5.4 → 1.5.5

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 (149) hide show
  1. package/package.json +8 -8
  2. package/dist/migrations/202603101553.d.ts +0 -4
  3. package/dist/migrations/202603101553.d.ts.map +0 -1
  4. package/dist/migrations/202603101553.js +0 -22
  5. package/dist/migrations/202603101553.js.map +0 -1
  6. package/dist/mobile-mocks/node/assert.d.ts +0 -1
  7. package/dist/mobile-mocks/node/assert.d.ts.map +0 -1
  8. package/dist/mobile-mocks/node/assert.js +0 -2
  9. package/dist/mobile-mocks/node/assert.js.map +0 -1
  10. package/dist/mobile-mocks/npm/apns2.d.ts +0 -1
  11. package/dist/mobile-mocks/npm/apns2.d.ts.map +0 -1
  12. package/dist/mobile-mocks/npm/apns2.js +0 -2
  13. package/dist/mobile-mocks/npm/apns2.js.map +0 -1
  14. package/dist/mobile-mocks/npm/vm2.d.ts +0 -1
  15. package/dist/mobile-mocks/npm/vm2.d.ts.map +0 -1
  16. package/dist/mobile-mocks/npm/vm2.js +0 -2
  17. package/dist/mobile-mocks/npm/vm2.js.map +0 -1
  18. package/dist/mobile-mocks/npm/xml2js.d.ts +0 -1
  19. package/dist/mobile-mocks/npm/xml2js.d.ts.map +0 -1
  20. package/dist/mobile-mocks/npm/xml2js.js +0 -2
  21. package/dist/mobile-mocks/npm/xml2js.js.map +0 -1
  22. package/dist/tests/actions.test.d.ts +0 -2
  23. package/dist/tests/actions.test.d.ts.map +0 -1
  24. package/dist/tests/actions.test.js +0 -936
  25. package/dist/tests/actions.test.js.map +0 -1
  26. package/dist/tests/auth.test.d.ts +0 -2
  27. package/dist/tests/auth.test.d.ts.map +0 -1
  28. package/dist/tests/auth.test.js +0 -824
  29. package/dist/tests/auth.test.js.map +0 -1
  30. package/dist/tests/auxtest.test.d.ts +0 -2
  31. package/dist/tests/auxtest.test.d.ts.map +0 -1
  32. package/dist/tests/auxtest.test.js +0 -562
  33. package/dist/tests/auxtest.test.js.map +0 -1
  34. package/dist/tests/base.test.d.ts +0 -2
  35. package/dist/tests/base.test.d.ts.map +0 -1
  36. package/dist/tests/base.test.js +0 -30
  37. package/dist/tests/base.test.js.map +0 -1
  38. package/dist/tests/calc.test.d.ts +0 -2
  39. package/dist/tests/calc.test.d.ts.map +0 -1
  40. package/dist/tests/calc.test.js +0 -1081
  41. package/dist/tests/calc.test.js.map +0 -1
  42. package/dist/tests/composite_pk.test.d.ts +0 -2
  43. package/dist/tests/composite_pk.test.d.ts.map +0 -1
  44. package/dist/tests/composite_pk.test.js +0 -98
  45. package/dist/tests/composite_pk.test.js.map +0 -1
  46. package/dist/tests/config.test.d.ts +0 -2
  47. package/dist/tests/config.test.d.ts.map +0 -1
  48. package/dist/tests/config.test.js +0 -86
  49. package/dist/tests/config.test.js.map +0 -1
  50. package/dist/tests/db.test.d.ts +0 -2
  51. package/dist/tests/db.test.d.ts.map +0 -1
  52. package/dist/tests/db.test.js +0 -178
  53. package/dist/tests/db.test.js.map +0 -1
  54. package/dist/tests/discover.test.d.ts +0 -2
  55. package/dist/tests/discover.test.d.ts.map +0 -1
  56. package/dist/tests/discover.test.js +0 -245
  57. package/dist/tests/discover.test.js.map +0 -1
  58. package/dist/tests/edit.test.d.ts +0 -2
  59. package/dist/tests/edit.test.d.ts.map +0 -1
  60. package/dist/tests/edit.test.js +0 -1161
  61. package/dist/tests/edit.test.js.map +0 -1
  62. package/dist/tests/email.test.d.ts +0 -2
  63. package/dist/tests/email.test.d.ts.map +0 -1
  64. package/dist/tests/email.test.js +0 -255
  65. package/dist/tests/email.test.js.map +0 -1
  66. package/dist/tests/exact_views.test.d.ts +0 -2
  67. package/dist/tests/exact_views.test.d.ts.map +0 -1
  68. package/dist/tests/exact_views.test.js +0 -1363
  69. package/dist/tests/exact_views.test.js.map +0 -1
  70. package/dist/tests/field.test.d.ts +0 -2
  71. package/dist/tests/field.test.d.ts.map +0 -1
  72. package/dist/tests/field.test.js +0 -588
  73. package/dist/tests/field.test.js.map +0 -1
  74. package/dist/tests/fieldviews.test.d.ts +0 -2
  75. package/dist/tests/fieldviews.test.d.ts.map +0 -1
  76. package/dist/tests/fieldviews.test.js +0 -74
  77. package/dist/tests/fieldviews.test.js.map +0 -1
  78. package/dist/tests/file.test.d.ts +0 -2
  79. package/dist/tests/file.test.d.ts.map +0 -1
  80. package/dist/tests/file.test.js +0 -148
  81. package/dist/tests/file.test.js.map +0 -1
  82. package/dist/tests/filter.test.d.ts +0 -2
  83. package/dist/tests/filter.test.d.ts.map +0 -1
  84. package/dist/tests/filter.test.js +0 -496
  85. package/dist/tests/filter.test.js.map +0 -1
  86. package/dist/tests/form.test.d.ts +0 -2
  87. package/dist/tests/form.test.d.ts.map +0 -1
  88. package/dist/tests/form.test.js +0 -264
  89. package/dist/tests/form.test.js.map +0 -1
  90. package/dist/tests/list.test.d.ts +0 -2
  91. package/dist/tests/list.test.d.ts.map +0 -1
  92. package/dist/tests/list.test.js +0 -1037
  93. package/dist/tests/list.test.js.map +0 -1
  94. package/dist/tests/models.test.d.ts +0 -2
  95. package/dist/tests/models.test.d.ts.map +0 -1
  96. package/dist/tests/models.test.js +0 -417
  97. package/dist/tests/models.test.js.map +0 -1
  98. package/dist/tests/page.test.d.ts +0 -2
  99. package/dist/tests/page.test.d.ts.map +0 -1
  100. package/dist/tests/page.test.js +0 -26
  101. package/dist/tests/page.test.js.map +0 -1
  102. package/dist/tests/page_group.test.d.ts +0 -2
  103. package/dist/tests/page_group.test.d.ts.map +0 -1
  104. package/dist/tests/page_group.test.js +0 -51
  105. package/dist/tests/page_group.test.js.map +0 -1
  106. package/dist/tests/plugin.test.d.ts +0 -2
  107. package/dist/tests/plugin.test.d.ts.map +0 -1
  108. package/dist/tests/plugin.test.js +0 -60
  109. package/dist/tests/plugin.test.js.map +0 -1
  110. package/dist/tests/show.test.d.ts +0 -2
  111. package/dist/tests/show.test.d.ts.map +0 -1
  112. package/dist/tests/show.test.js +0 -561
  113. package/dist/tests/show.test.js.map +0 -1
  114. package/dist/tests/state.test.d.ts +0 -2
  115. package/dist/tests/state.test.d.ts.map +0 -1
  116. package/dist/tests/state.test.js +0 -82
  117. package/dist/tests/state.test.js.map +0 -1
  118. package/dist/tests/table.test.d.ts +0 -2
  119. package/dist/tests/table.test.d.ts.map +0 -1
  120. package/dist/tests/table.test.js +0 -2717
  121. package/dist/tests/table.test.js.map +0 -1
  122. package/dist/tests/table_history.test.d.ts +0 -2
  123. package/dist/tests/table_history.test.d.ts.map +0 -1
  124. package/dist/tests/table_history.test.js +0 -413
  125. package/dist/tests/table_history.test.js.map +0 -1
  126. package/dist/tests/tag.test.d.ts +0 -2
  127. package/dist/tests/tag.test.d.ts.map +0 -1
  128. package/dist/tests/tag.test.js +0 -97
  129. package/dist/tests/tag.test.js.map +0 -1
  130. package/dist/tests/user.test.d.ts +0 -2
  131. package/dist/tests/user.test.d.ts.map +0 -1
  132. package/dist/tests/user.test.js +0 -441
  133. package/dist/tests/user.test.js.map +0 -1
  134. package/dist/tests/view.test.d.ts +0 -2
  135. package/dist/tests/view.test.d.ts.map +0 -1
  136. package/dist/tests/view.test.js +0 -699
  137. package/dist/tests/view.test.js.map +0 -1
  138. package/dist/tests/workflow.test.d.ts +0 -2
  139. package/dist/tests/workflow.test.d.ts.map +0 -1
  140. package/dist/tests/workflow.test.js +0 -303
  141. package/dist/tests/workflow.test.js.map +0 -1
  142. package/dist/tests/workflow_run.test.d.ts +0 -2
  143. package/dist/tests/workflow_run.test.d.ts.map +0 -1
  144. package/dist/tests/workflow_run.test.js +0 -922
  145. package/dist/tests/workflow_run.test.js.map +0 -1
  146. package/dist/viewable_fields.d.ts +0 -227
  147. package/dist/viewable_fields.d.ts.map +0 -1
  148. package/dist/viewable_fields.js +0 -1928
  149. package/dist/viewable_fields.js.map +0 -1
@@ -1,699 +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 view_1 = __importDefault(require("../models/view"));
9
- const db_1 = __importDefault(require("../db"));
10
- const mocks_1 = __importDefault(require("./mocks"));
11
- const { plugin_with_routes, mockReqRes } = mocks_1.default;
12
- const { getState } = require("../db/state");
13
- const assertions_1 = require("./assertions");
14
- const globals_1 = require("@jest/globals");
15
- const remote_query_helper_1 = require("./remote_query_helper");
16
- const common_helpers_1 = require("./common_helpers");
17
- getState().registerPlugin("base", require("../base-plugin"));
18
- (0, globals_1.afterAll)(db_1.default.close);
19
- (0, globals_1.beforeAll)(async () => {
20
- await require("../db/reset_schema")();
21
- await require("../db/fixtures")();
22
- });
23
- (0, globals_1.describe)("Misc view tests", () => {
24
- (0, globals_1.it)("should run with no query", async () => {
25
- const v = await view_1.default.findOne({ name: "authorlist" });
26
- (0, assertions_1.assertIsSet)(v);
27
- (0, globals_1.expect)(v.min_role).toBe(100);
28
- const res = await v.run({}, mockReqRes);
29
- (0, globals_1.expect)(res.length > 0).toBe(true);
30
- });
31
- (0, globals_1.it)("should run on page", async () => {
32
- const v = await view_1.default.findOne({ name: "authorlist" });
33
- (0, assertions_1.assertIsSet)(v);
34
- const res = await v.run_possibly_on_page({}, mockReqRes.req, mockReqRes.res);
35
- (0, globals_1.expect)(typeof res === "string" && res.length > 0).toBe(true);
36
- });
37
- (0, globals_1.it)("should run with string query", async () => {
38
- const v = await view_1.default.findOne({ name: "authorlist" });
39
- (0, assertions_1.assertIsSet)(v);
40
- const res = await v.run({ author: "Mel" }, mockReqRes);
41
- (0, globals_1.expect)(res.length > 0).toBe(true);
42
- });
43
- (0, globals_1.it)("should run with integer query as int", async () => {
44
- const v = await view_1.default.findOne({ name: "authorlist" });
45
- (0, assertions_1.assertIsSet)(v);
46
- const res = await v.run({ pages: 967 }, mockReqRes);
47
- (0, globals_1.expect)(res.length > 0).toBe(true);
48
- });
49
- (0, globals_1.it)("should run with integer query as string", async () => {
50
- const v = await view_1.default.findOne({ name: "authorlist" });
51
- (0, assertions_1.assertIsSet)(v);
52
- const res = await v.run({ pages: "967" }, mockReqRes);
53
- (0, globals_1.expect)(res.length > 0).toBe(true);
54
- });
55
- (0, globals_1.it)("should get config flow", async () => {
56
- const v = await view_1.default.findOne({ name: "authorlist" });
57
- (0, assertions_1.assertIsSet)(v);
58
- const res = await v.get_config_flow({ __: (s) => s });
59
- (0, globals_1.expect)(res.constructor.name).toBe("Workflow");
60
- (0, globals_1.expect)(res.steps.length > 0).toBe(true);
61
- });
62
- (0, globals_1.it)("should runMany with no query", async () => {
63
- const v = await view_1.default.findOne({ name: "authorshow" });
64
- (0, assertions_1.assertIsSet)(v);
65
- const res = await v.runMany({}, mockReqRes);
66
- (0, globals_1.expect)(res.length > 0).toBe(true);
67
- });
68
- (0, globals_1.it)("should runMany with operator", async () => {
69
- const v = await view_1.default.findOne({ name: "authorshow" });
70
- (0, assertions_1.assertIsSet)(v);
71
- const res = await v.runMany({ _orderBy: { operator: "near", field: "pages", target: 950 } }, mockReqRes);
72
- (0, globals_1.expect)(res[0].row.pages).toBe(967);
73
- const res1 = await v.runMany({ _orderBy: { operator: "near", field: "pages", target: 720 } }, mockReqRes);
74
- (0, globals_1.expect)(res1[0].row.pages).toBe(728);
75
- });
76
- (0, globals_1.it)("should runPost", async () => {
77
- const v = await view_1.default.findOne({ name: "authoredit" });
78
- (0, assertions_1.assertIsSet)(v);
79
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
80
- const rows = await db_1.default.select("books", {});
81
- (0, globals_1.expect)(rows).toContainEqual({
82
- author: "James Joyce",
83
- id: 3,
84
- pages: 678,
85
- publisher: null,
86
- });
87
- });
88
- (0, globals_1.it)("should runPost with edit in edit", async () => {
89
- const readingsTbl = table_1.default.findOne({ name: "readings" });
90
- (0, assertions_1.assertIsSet)(readingsTbl);
91
- await view_1.default.create({
92
- name: "innerReads",
93
- table_id: readingsTbl.id,
94
- min_role: 100,
95
- configuration: remote_query_helper_1.renderEditInEditConfig.innerEdit,
96
- viewtemplate: "Edit",
97
- });
98
- const patientsTable = table_1.default.findOne({ name: "patients" });
99
- (0, assertions_1.assertIsSet)(patientsTable);
100
- const v = await view_1.default.create({
101
- table_id: patientsTable.id,
102
- name: "PatientEditWithReads",
103
- viewtemplate: "Edit",
104
- configuration: remote_query_helper_1.renderEditInEditConfig.outerEdit,
105
- min_role: 100,
106
- });
107
- await v.runPost({}, { id: 1, favbook: 1, name: "foo", parent: 2 }, mockReqRes);
108
- const rows = await db_1.default.select("patients", {});
109
- (0, globals_1.expect)(rows).toContainEqual({
110
- favbook: 1,
111
- name: "foo",
112
- parent: 2,
113
- id: 1,
114
- });
115
- });
116
- (0, globals_1.it)("should find", async () => {
117
- const table = table_1.default.findOne({ name: "books" });
118
- (0, assertions_1.assertIsSet)(table);
119
- const link_views = await view_1.default.find({
120
- table_id: table.id,
121
- });
122
- (0, globals_1.expect)(link_views.length).toBe(11);
123
- });
124
- (0, globals_1.it)("should find where", async () => {
125
- const link_views = await view_1.default.find_all_views_where(({ viewrow }) => viewrow.name === "authorshow");
126
- (0, globals_1.expect)(link_views.length).toBe(1);
127
- });
128
- (0, globals_1.it)("should create and delete", async () => {
129
- const table = table_1.default.findOne({ name: "books" });
130
- (0, assertions_1.assertIsSet)(table);
131
- const v = await view_1.default.create({
132
- table_id: table.id,
133
- name: "anewview",
134
- viewtemplate: "List",
135
- configuration: { columns: [], default_state: { foo: "bar" } },
136
- min_role: 100,
137
- });
138
- (0, globals_1.expect)(typeof v.id).toBe("number");
139
- (0, globals_1.expect)(typeof v.viewtemplateObj).toBe("object");
140
- const st = v.combine_state_and_default_state({ baz: 3 });
141
- (0, globals_1.expect)(st).toStrictEqual({ baz: 3, foo: "bar" });
142
- await v.delete();
143
- const v1 = await view_1.default.create({
144
- table_id: table.id,
145
- name: "anewview",
146
- viewtemplate: "List",
147
- configuration: { columns: [], default_state: { foo: "bar" } },
148
- min_role: 100,
149
- });
150
- (0, assertions_1.assertIsSet)(v1.id);
151
- await view_1.default.update({ name: "anewestview" }, v1.id);
152
- await view_1.default.delete({ name: "anewestview" });
153
- });
154
- (0, globals_1.it)("should clone", async () => {
155
- const v = await view_1.default.findOne({ name: "authorlist" });
156
- (0, assertions_1.assertIsSet)(v);
157
- await v.clone();
158
- await v.clone();
159
- const v1 = await view_1.default.findOne({ name: "authorlist-copy" });
160
- (0, assertions_1.assertIsSet)(v1);
161
- (0, globals_1.expect)(!!v1).toBe(true);
162
- const v2 = await view_1.default.findOne({ name: "authorlist-copy-1" });
163
- (0, assertions_1.assertIsSet)(v2);
164
- (0, globals_1.expect)(!!v2).toBe(true);
165
- const res = await v1.run({ author: "Mel" }, mockReqRes);
166
- (0, globals_1.expect)(res.length > 0).toBe(true);
167
- });
168
- (0, globals_1.it)("list join-aggs", async () => {
169
- const table = table_1.default.findOne({ name: "books" });
170
- (0, assertions_1.assertIsSet)(table);
171
- const v = await view_1.default.create({
172
- table_id: table.id,
173
- name: "AggJoinTest",
174
- viewtemplate: "List",
175
- configuration: {
176
- columns: [
177
- {
178
- type: "Field",
179
- fieldview: "as_text",
180
- field_name: "author",
181
- state_field: "on",
182
- },
183
- {
184
- stat: "Count",
185
- type: "Aggregation",
186
- aggwhere: "",
187
- agg_field: "id",
188
- col_width: "",
189
- agg_relation: "publisher->books.publisher",
190
- header_label: "",
191
- },
192
- ],
193
- default_state: {},
194
- },
195
- min_role: 100,
196
- });
197
- const res = await v.run({}, mockReqRes);
198
- (0, globals_1.expect)(res).toBe('<div class="table-responsive"><table class="table table-sm table-valign-middle "><thead><tr><th><span onclick="sortby(\'author\', false, \'249ab\', this)" class="link-style">Author</span></th><th><span onclick="sortby(\'count_books_publisher_id_\', false, \'249ab\', this)" class="link-style">Count books</span></th></tr></thead><tbody><tr data-row-id="1"><td>Herman Melville</td><td>0</td></tr><tr data-row-id="2"><td>Leo Tolstoy</td><td>1</td></tr><tr data-row-id="3"><td>James Joyce</td><td>0</td></tr></tbody></table></div>');
199
- });
200
- (0, globals_1.it)("should interpolate titles string in Show", async () => {
201
- const v = await view_1.default.findOne({ name: "authorshow" });
202
- (0, assertions_1.assertIsSet)(v);
203
- const title = await v.interpolate_title_string("Hello {{author}} from {{publisher.name}}", { id: 2 });
204
- (0, globals_1.expect)(title).toBe("Hello Leo Tolstoy from AK Press");
205
- });
206
- (0, globals_1.it)("should interpolate titles string in Edit", async () => {
207
- const v = await view_1.default.findOne({ name: "authoredit" });
208
- (0, assertions_1.assertIsSet)(v);
209
- const title = await v.interpolate_title_string("Hello {{row?.author}}", {
210
- id: 2,
211
- });
212
- (0, globals_1.expect)(title).toBe("Hello Leo Tolstoy");
213
- });
214
- (0, globals_1.it)("should interpolate titles string in Edit", async () => {
215
- const v = await view_1.default.findOne({ name: "authoredit" });
216
- (0, assertions_1.assertIsSet)(v);
217
- const title = await v.interpolate_title_string("Hello {{row?.author}}", {});
218
- (0, globals_1.expect)(title).toBe("Hello ");
219
- });
220
- });
221
- (0, globals_1.describe)("View with routes", () => {
222
- (0, globals_1.it)("should create and delete", async () => {
223
- getState().registerPlugin("mock_plugin", plugin_with_routes());
224
- (0, globals_1.expect)(getState().viewtemplates.ViewWithRoutes.name).toBe("ViewWithRoutes");
225
- var html, json;
226
- const spy = {
227
- ...mockReqRes.res,
228
- send(h) {
229
- html = h;
230
- },
231
- json(h) {
232
- json = h;
233
- },
234
- };
235
- const table = table_1.default.findOne({ name: "books" });
236
- (0, assertions_1.assertIsSet)(table);
237
- const v = await view_1.default.create({
238
- table_id: table.id,
239
- name: "aviewwithroutes",
240
- viewtemplate: "ViewWithRoutes",
241
- configuration: {},
242
- min_role: 100,
243
- });
244
- await v.runRoute("the_json_route", {}, spy, mockReqRes);
245
- await v.runRoute("the_html_route", {}, spy, mockReqRes);
246
- await v.runRoute("the_null_route", {}, spy, mockReqRes);
247
- (0, globals_1.expect)(json).toEqual({ success: "ok" });
248
- (0, globals_1.expect)(html).toEqual("<div>Hello</div>");
249
- });
250
- });
251
- (0, globals_1.describe)("nested views", () => {
252
- (0, globals_1.it)("should create and run", async () => {
253
- const table = table_1.default.findOne({ name: "books" });
254
- (0, assertions_1.assertIsSet)(table);
255
- const small = await view_1.default.create({
256
- table_id: table.id,
257
- name: "small",
258
- viewtemplate: "Show",
259
- configuration: {
260
- layout: {
261
- above: [
262
- {
263
- aligns: ["left", "left"],
264
- widths: [2, 10],
265
- besides: [
266
- { above: [null, { type: "blank", contents: "Pages" }] },
267
- {
268
- above: [
269
- null,
270
- { type: "field", fieldview: "show", field_name: "pages" },
271
- ],
272
- },
273
- ],
274
- },
275
- { type: "line_break" },
276
- ],
277
- },
278
- columns: [{ type: "Field", fieldview: "show", field_name: "pages" }],
279
- viewname: "small",
280
- },
281
- min_role: 100,
282
- });
283
- const medium = await view_1.default.create({
284
- table_id: table.id,
285
- name: "medium",
286
- viewtemplate: "Show",
287
- configuration: {
288
- layout: {
289
- above: [
290
- {
291
- aligns: ["left", "left"],
292
- widths: [2, 10],
293
- besides: [
294
- { above: [null, { type: "blank", contents: "Author" }] },
295
- {
296
- above: [
297
- null,
298
- {
299
- type: "field",
300
- fieldview: "as_text",
301
- field_name: "author",
302
- },
303
- ],
304
- },
305
- ],
306
- },
307
- { type: "line_break" },
308
- { name: "64063e", type: "view", view: "small", state: "shared" },
309
- ],
310
- },
311
- columns: [
312
- { type: "Field", fieldview: "as_text", field_name: "author" },
313
- ],
314
- viewname: "medium",
315
- },
316
- min_role: 100,
317
- });
318
- const res = await medium.run({ id: 2 }, mockReqRes);
319
- (0, globals_1.expect)(res).toContain("Tolstoy");
320
- (0, globals_1.expect)(res).toContain("728");
321
- (0, globals_1.expect)(res).not.toContain("967");
322
- (0, globals_1.expect)(res).not.toContain("Melville");
323
- });
324
- (0, globals_1.it)("should create and run feed of nested", async () => {
325
- const table = table_1.default.findOne({ name: "books" });
326
- (0, assertions_1.assertIsSet)(table);
327
- const large = await view_1.default.create({
328
- table_id: table.id,
329
- name: "large",
330
- viewtemplate: "Feed",
331
- configuration: {
332
- cols_lg: 1,
333
- cols_md: 1,
334
- cols_sm: 1,
335
- cols_xl: 1,
336
- in_card: false,
337
- viewname: "large",
338
- show_view: "medium",
339
- descending: false,
340
- order_field: "author",
341
- view_to_create: "",
342
- create_view_display: "Link",
343
- },
344
- min_role: 100,
345
- });
346
- const res = await large.run({}, mockReqRes);
347
- (0, globals_1.expect)(res).toContain("Tolstoy");
348
- (0, globals_1.expect)(res).toContain("728");
349
- (0, globals_1.expect)(res).toContain("967");
350
- (0, globals_1.expect)(res).toContain("Melville");
351
- });
352
- });
353
- (0, globals_1.describe)("view with two level select", () => {
354
- (0, globals_1.it)("should preselect the state value", async () => {
355
- const v = view_1.default.findOne({ name: "view_with_two_level_select" });
356
- (0, assertions_1.assertIsSet)(v);
357
- const resA = await v.run({ album: 1 }, mockReqRes);
358
- (0, globals_1.expect)(resA).toContain(`value=\"1\" selected`);
359
- (0, globals_1.expect)(resA).toContain(`data-selected=\"1\"`);
360
- const resB = await v.run({ album: 2 }, mockReqRes);
361
- (0, globals_1.expect)(resB).toContain(`value=\"2\" selected`);
362
- (0, globals_1.expect)(resB).toContain(`data-selected=\"2\"`);
363
- });
364
- (0, globals_1.it)("should render without any state", async () => {
365
- const v = view_1.default.findOne({ name: "view_with_two_level_select" });
366
- (0, assertions_1.assertIsSet)(v);
367
- const resA = await v.run({ album: 1 }, mockReqRes);
368
- (0, globals_1.expect)(resA).toContain(`value=\"1\" selected`);
369
- (0, globals_1.expect)(resA).toContain(`data-selected=\"1\"`);
370
- });
371
- });
372
- (0, globals_1.describe)("subviews with relations", () => {
373
- (0, globals_1.it)("show_user_with_independent_feed", async () => {
374
- const testser = (res) => {
375
- (0, globals_1.expect)(res).toContain("Content of post APost A");
376
- (0, globals_1.expect)(res).toContain("Content of post BPost B");
377
- (0, globals_1.expect)(res).toContain("Content of post CPost C");
378
- (0, globals_1.expect)(res).toContain("blog_posts_feed");
379
- };
380
- const v = view_1.default.findOne({ name: "show_user_with_independent_feed" });
381
- (0, assertions_1.assertIsSet)(v);
382
- testser(await v.run({ id: 1 }, mockReqRes));
383
- testser(await v.run({ id: 2 }, mockReqRes));
384
- testser(await v.run({ id: 3 }, mockReqRes));
385
- });
386
- (0, globals_1.it)("blog_posts_feed with inbound relation", async () => {
387
- const v = view_1.default.findOne({ name: "show_user_with_blog_posts_feed" });
388
- (0, assertions_1.assertIsSet)(v);
389
- {
390
- const res = await v.run({ id: 1 }, mockReqRes);
391
- (0, globals_1.expect)(res).toContain("Content of post APost A");
392
- (0, globals_1.expect)(res).toContain("Content of post BPost B");
393
- (0, globals_1.expect)(res).toContain("Content of post CPost C");
394
- }
395
- {
396
- const res = await v.run({ id: 2 }, mockReqRes);
397
- (0, globals_1.expect)(res.length > 0).toBe(true);
398
- (0, globals_1.expect)(res.search("Content of post APost A")).toBe(-1);
399
- (0, globals_1.expect)(res.search("Content of post BPost B") >= 0).toBe(true);
400
- (0, globals_1.expect)(res.search("Content of post CPost C")).toBe(-1);
401
- }
402
- {
403
- const res = await v.run({ id: 3 }, mockReqRes);
404
- (0, globals_1.expect)(res.length > 0).toBe(true);
405
- (0, globals_1.expect)(res).toContain("Content of post APost A");
406
- (0, globals_1.expect)(res).toContain("Content of post BPost B");
407
- (0, globals_1.expect)(res).toContain("Content of post CPost C");
408
- }
409
- });
410
- (0, globals_1.it)("blog_in_topic_feed with inbound relation", async () => {
411
- const v = view_1.default.findOne({ name: "show_user_with_blog_in_topic_feed" });
412
- (0, assertions_1.assertIsSet)(v);
413
- {
414
- const res = await v.run({ id: 1 }, mockReqRes);
415
- (0, globals_1.expect)(res.length > 0).toBe(true);
416
- (0, globals_1.expect)(res.search("Post ATopic A") >= 0).toBe(true);
417
- (0, globals_1.expect)(res.search("Post BTopic A") >= 0).toBe(true);
418
- (0, globals_1.expect)(res.search("Post CTopic A") >= 0).toBe(true);
419
- }
420
- {
421
- const res = await v.run({ id: 2 }, mockReqRes);
422
- (0, globals_1.expect)(res.length > 0).toBe(true);
423
- (0, globals_1.expect)(res.search("Post BTopic B") >= 0).toBe(true);
424
- }
425
- {
426
- const res = await v.run({ id: 3 }, mockReqRes);
427
- (0, globals_1.expect)(res.length > 0).toBe(true);
428
- (0, globals_1.expect)(res.search("Post ATopic A") >= 0).toBe(true);
429
- (0, globals_1.expect)(res.search("Post BTopic A") >= 0).toBe(true);
430
- (0, globals_1.expect)(res.search("Post CTopic A") >= 0).toBe(true);
431
- (0, globals_1.expect)(res.search("Post BTopic B") >= 0).toBe(true);
432
- }
433
- });
434
- (0, globals_1.it)("two levels inbound", async () => {
435
- const v = view_1.default.findOne({
436
- name: "show_user_with_blog_posts_feed_two_levels",
437
- });
438
- (0, assertions_1.assertIsSet)(v);
439
- const res = await v.run({ id: 1 }, mockReqRes);
440
- (0, globals_1.expect)(res.length > 0).toBe(true);
441
- (0, globals_1.expect)(res.search("Content of post APost A") >= 0).toBe(true);
442
- (0, globals_1.expect)(res.search("Content of post BPost B")).toBe(-1);
443
- (0, globals_1.expect)(res.search("Content of post CPost C") >= 0).toBe(true);
444
- });
445
- (0, globals_1.it)("three levels inbound", async () => {
446
- /*
447
- inbound_level_two bp_inbound post
448
- inbound_level_three -> inbound_inbound -> blog_post_inbound -> blog_posts
449
- */
450
- const levelThreeInbound = await table_1.default.create("inbound_level_three");
451
- const inbound_inbound = table_1.default.findOne({ name: "inbound_inbound" });
452
- (0, assertions_1.assertIsSet)(inbound_inbound);
453
- const topics = table_1.default.findOne({ name: "topics" });
454
- (0, assertions_1.assertIsSet)(topics);
455
- await field_1.default.create({
456
- table: levelThreeInbound,
457
- name: "inbound_level_two",
458
- reftable: inbound_inbound,
459
- label: "inbound to level 2",
460
- type: "Key",
461
- attributes: { summary_field: "id" },
462
- });
463
- await field_1.default.create({
464
- table: levelThreeInbound,
465
- name: "topic",
466
- reftable: topics,
467
- label: "Topic",
468
- type: "Key",
469
- attributes: { summary_field: "id" },
470
- });
471
- await db_1.default.insert("blog_post_inbound", {
472
- post: 1,
473
- }, {
474
- ignoreExisting: true,
475
- });
476
- await db_1.default.insert("blog_post_inbound", {
477
- post: 3,
478
- }, {
479
- ignoreExisting: true,
480
- });
481
- await db_1.default.insert("inbound_inbound", {
482
- bp_inbound: 1,
483
- topic: 1,
484
- }, {
485
- ignoreExisting: true,
486
- });
487
- await db_1.default.insert("inbound_inbound", {
488
- bp_inbound: 2,
489
- topic: 1,
490
- }, {
491
- ignoreExisting: true,
492
- });
493
- const v = await view_1.default.create({
494
- table_id: 1,
495
- name: "show_user_with_blog_posts_feed_three_levels",
496
- viewtemplate: "Show",
497
- configuration: {
498
- columns: [],
499
- layout: {
500
- above: [
501
- {
502
- type: "view",
503
- view: "blog_posts_feed",
504
- relation: ".users.user_interested_in_topic$user.topic.inbound_level_three$topic.inbound_level_two.bp_inbound.post",
505
- name: "bc653",
506
- state: "shared",
507
- },
508
- ],
509
- },
510
- },
511
- min_role: 100,
512
- });
513
- {
514
- const res = await v.run({ id: 1 }, mockReqRes);
515
- (0, globals_1.expect)(res.length > 0).toBe(true);
516
- (0, globals_1.expect)(res.search("Content of post APost A")).toBe(-1);
517
- (0, globals_1.expect)(res.search("Content of post BPost B")).toBe(-1);
518
- (0, globals_1.expect)(res.search("Content of post CPost C")).toBe(-1);
519
- }
520
- await db_1.default.insert("inbound_level_three", {
521
- inbound_level_two: 1,
522
- topic: 1,
523
- });
524
- await db_1.default.insert("inbound_level_three", {
525
- inbound_level_two: 2,
526
- topic: 1,
527
- });
528
- {
529
- const res = await v.run({ id: 1 }, mockReqRes);
530
- (0, globals_1.expect)(res.length > 0).toBe(true);
531
- (0, globals_1.expect)(res.search("Content of post APost A") >= 0).toBe(true);
532
- (0, globals_1.expect)(res.search("Content of post BPost B")).toBe(-1);
533
- (0, globals_1.expect)(res.search("Content of post CPost C") >= 0).toBe(true);
534
- }
535
- });
536
- (0, globals_1.it)("employee department relation", async () => {
537
- const v = view_1.default.findOne({ name: "show_employee" });
538
- (0, assertions_1.assertIsSet)(v);
539
- {
540
- const res = await v.run({ id: 1 }, mockReqRes);
541
- (0, globals_1.expect)(res.length > 0).toBe(true);
542
- (0, globals_1.expect)(res.match(/manager/g).length).toBe(5);
543
- }
544
- {
545
- const res = await v.run({ id: 2 }, mockReqRes);
546
- (0, globals_1.expect)(res.length > 0).toBe(true);
547
- (0, globals_1.expect)(res).toContain("my_employee");
548
- (0, globals_1.expect)(res).toContain("manager");
549
- }
550
- });
551
- (0, globals_1.it)("simple post topic relation", async () => {
552
- await (0, common_helpers_1.prepareSimpleTopicPostRelation)();
553
- const v = view_1.default.findOne({ name: "show_user_with_simple_posts_list" });
554
- (0, assertions_1.assertIsSet)(v);
555
- {
556
- const res = await v.run({ id: 1 }, mockReqRes);
557
- (0, globals_1.expect)(res.length > 0).toBe(true);
558
- (0, globals_1.expect)(res.search("first post in topic A") >= 0).toBe(true);
559
- (0, globals_1.expect)(res.search("second post in topic A") >= 0).toBe(true);
560
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
561
- }
562
- {
563
- const res = await v.run({ id: 2 }, mockReqRes);
564
- (0, globals_1.expect)(res.length > 0).toBe(true);
565
- (0, globals_1.expect)(res.search("first post in topic A")).toBe(-1);
566
- (0, globals_1.expect)(res.search("second post in topic A")).toBe(-1);
567
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
568
- }
569
- {
570
- const res = await v.run({ id: 3 }, mockReqRes);
571
- (0, globals_1.expect)(res.length > 0).toBe(true);
572
- (0, globals_1.expect)(res.search("first post in topic A")).toBe(-1);
573
- (0, globals_1.expect)(res.search("second post in topic A")).toBe(-1);
574
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
575
- }
576
- const vlevels = view_1.default.findOne({
577
- name: "show_user_with_simple_posts_list_levels",
578
- });
579
- (0, assertions_1.assertIsSet)(vlevels);
580
- {
581
- const res = await vlevels.run({ id: 1 }, mockReqRes);
582
- (0, globals_1.expect)(res.length > 0).toBe(true);
583
- (0, globals_1.expect)(res.search("first post in topic A") >= 0).toBe(true);
584
- (0, globals_1.expect)(res.search("second post in topic A")).toBe(-1);
585
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
586
- }
587
- {
588
- const res = await vlevels.run({ id: 2 }, mockReqRes);
589
- (0, globals_1.expect)(res.length > 0).toBe(true);
590
- (0, globals_1.expect)(res.search("first post in topic A")).toBe(-1);
591
- (0, globals_1.expect)(res.search("second post in topic A")).toBe(-1);
592
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
593
- }
594
- {
595
- const res = await vlevels.run({ id: 3 }, mockReqRes);
596
- (0, globals_1.expect)(res.length > 0).toBe(true);
597
- (0, globals_1.expect)(res.search("first post in topic A")).toBe(-1);
598
- (0, globals_1.expect)(res.search("second post in topic A")).toBe(-1);
599
- (0, globals_1.expect)(res.search("post in topic B")).toBe(-1);
600
- }
601
- });
602
- });
603
- (0, globals_1.describe)("edit dest", () => {
604
- (0, globals_1.it)("standard list view", async () => {
605
- mockReqRes.reset();
606
- const v = await view_1.default.findOne({ name: "authoredit" });
607
- (0, assertions_1.assertIsSet)(v);
608
- v.configuration.view_when_done = "authorlist";
609
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
610
- (0, globals_1.expect)(mockReqRes.getStored().url).toBe("/view/authorlist");
611
- });
612
- (0, globals_1.it)("standard show view", async () => {
613
- mockReqRes.reset();
614
- const v = await view_1.default.findOne({ name: "authoredit" });
615
- (0, assertions_1.assertIsSet)(v);
616
- v.configuration.view_when_done = "authorshow";
617
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
618
- (0, globals_1.expect)(mockReqRes.getStored().url).toContain("/view/authorshow?id=");
619
- });
620
- (0, globals_1.it)("back to referrer", async () => {
621
- mockReqRes.reset();
622
- const v = await view_1.default.findOne({ name: "authoredit" });
623
- (0, assertions_1.assertIsSet)(v);
624
- v.configuration.destination_type = "Back to referer";
625
- mockReqRes.req.headers = { referer: "/bananas" };
626
- const res = await v.run({}, mockReqRes);
627
- (0, globals_1.expect)(res).toContain('<input type="hidden" class="form-control " name="_referer" value="/bananas">');
628
- await v.runPost({}, { author: "James Joyce", _referer: "/bananas" }, mockReqRes);
629
- (0, globals_1.expect)(mockReqRes.getStored().url).toBe("/bananas");
630
- });
631
- (0, globals_1.it)("url formula", async () => {
632
- mockReqRes.reset();
633
- const v = await view_1.default.findOne({ name: "authoredit" });
634
- (0, assertions_1.assertIsSet)(v);
635
- v.configuration.destination_type = "URL formula";
636
- v.configuration.dest_url_formula = "'/view/foo/'+author";
637
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
638
- (0, globals_1.expect)(mockReqRes.getStored().url).toBe("/view/foo/James Joyce");
639
- });
640
- (0, globals_1.it)("formula", async () => {
641
- mockReqRes.reset();
642
- const v = await view_1.default.findOne({ name: "authoredit" });
643
- (0, assertions_1.assertIsSet)(v);
644
- v.configuration.destination_type = "Formulas";
645
- v.configuration.formula_destinations = [
646
- {
647
- expression: "author.length>7",
648
- view: "authorlist",
649
- },
650
- {
651
- expression: "author.length<=7",
652
- view: "authorshow",
653
- },
654
- ];
655
- (0, assertions_1.assertIsSet)(v.viewtemplateObj);
656
- await v.viewtemplateObj.configCheck?.(v);
657
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
658
- (0, globals_1.expect)(mockReqRes.getStored().url).toBe("/view/authorlist");
659
- await v.runPost({}, { author: "T. Lin" }, mockReqRes);
660
- (0, globals_1.expect)(mockReqRes.getStored().url).toContain("/view/authorshow?id=");
661
- });
662
- (0, globals_1.it)("self", async () => {
663
- mockReqRes.reset();
664
- const v = await view_1.default.findOne({ name: "authoredit" });
665
- (0, assertions_1.assertIsSet)(v);
666
- v.configuration.view_when_done = "authoredit";
667
- await v.runPost({}, { author: "James Joyce" }, mockReqRes);
668
- (0, globals_1.expect)(mockReqRes.getStored().url).toBe("/view/authoredit");
669
- });
670
- });
671
- (0, globals_1.describe)("view slug", () => {
672
- (0, globals_1.it)("should enable and run", async () => {
673
- const v = await view_1.default.findOne({ name: "authorshow" });
674
- (0, assertions_1.assertIsSet)(v);
675
- const slug = {
676
- label: "/:id",
677
- steps: [
678
- {
679
- field: "id",
680
- unique: true,
681
- transform: null,
682
- },
683
- ],
684
- };
685
- v.slug = slug;
686
- await view_1.default.update({ slug }, v.id);
687
- const query = {};
688
- v.rewrite_query_from_slug(query, ["1"]);
689
- (0, globals_1.expect)(query.id).toBe("1");
690
- //const res = await v.run({}, mockReqRes);
691
- });
692
- (0, globals_1.it)("set link", async () => {
693
- const v = await view_1.default.findOne({ name: "authorlist" });
694
- (0, assertions_1.assertIsSet)(v);
695
- const res = await v.run({}, mockReqRes);
696
- (0, globals_1.expect)(res).toContain('<a href="/view/authorshow/1">authorshow</a>');
697
- });
698
- });
699
- //# sourceMappingURL=view.test.js.map