@datagrok/hit-triage 1.10.9 → 1.11.0

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 (123) hide show
  1. package/.grokignore +2 -0
  2. package/.turbo/turbo-build.log +25 -3
  3. package/CHANGELOG.md +78 -0
  4. package/CLAUDE.md +87 -10
  5. package/README_HD.md +14 -14
  6. package/README_HT.md +6 -6
  7. package/README_PH.md +110 -0
  8. package/bdd/bdd.config.json +3 -1
  9. package/bdd/bindings/campaign.ts +626 -0
  10. package/bdd/bindings/hit-design.ts +36 -42
  11. package/bdd/bindings/landing.ts +839 -0
  12. package/bdd/bindings/pepti-hit.ts +35 -0
  13. package/bdd/features/campaign/crumbs.feature +22 -0
  14. package/bdd/features/campaign/grid.feature +56 -0
  15. package/bdd/features/campaign/merge.feature +105 -0
  16. package/bdd/features/campaign/molecule-vid.feature +40 -0
  17. package/bdd/features/campaign/permissions.feature +46 -0
  18. package/bdd/features/campaign/progress-tracker.feature +89 -0
  19. package/bdd/features/campaign/refresh-hint.feature +33 -0
  20. package/bdd/features/campaign/ribbon.feature +49 -0
  21. package/bdd/features/campaign/stage-choices.feature +39 -0
  22. package/bdd/features/campaign/submit.feature +135 -0
  23. package/bdd/features/campaign/tracker-cards.feature +46 -0
  24. package/bdd/features/campaign/view-only.feature +37 -0
  25. package/bdd/features/landing/campaign-deep-links.feature +61 -0
  26. package/bdd/features/landing/hit-design-campaigns-fixes.feature +116 -0
  27. package/bdd/features/landing/hit-design-campaigns.feature +153 -0
  28. package/bdd/features/landing/hit-triage-campaigns.feature +99 -0
  29. package/bdd/features/landing/new-campaign.feature +69 -0
  30. package/bdd/features/landing/pep-triage-campaigns.feature +41 -0
  31. package/bdd/features/landing/pepti-hit-landing.feature +132 -0
  32. package/bdd/features/pepti-hit/helm-edit.feature +47 -0
  33. package/bdd/features/templates/template-editor.feature +130 -0
  34. package/bdd/features/templates/template-picker.feature +112 -0
  35. package/bdd/features/templates/triage-forms.feature +59 -0
  36. package/bdd/fixtures/bar-chart.layout +1 -0
  37. package/bdd/fixtures/merge-local.csv +2 -0
  38. package/bdd/generated/campaign/crumbs.test.ts +33 -0
  39. package/bdd/generated/campaign/grid.test.ts +79 -0
  40. package/bdd/generated/campaign/merge.test.ts +134 -0
  41. package/bdd/generated/campaign/molecule-vid.test.ts +52 -0
  42. package/bdd/generated/campaign/permissions.test.ts +58 -0
  43. package/bdd/generated/campaign/progress-tracker.test.ts +129 -0
  44. package/bdd/generated/campaign/refresh-hint.test.ts +44 -0
  45. package/bdd/generated/campaign/ribbon.test.ts +65 -0
  46. package/bdd/generated/campaign/stage-choices.test.ts +55 -0
  47. package/bdd/generated/campaign/submit.test.ts +167 -0
  48. package/bdd/generated/campaign/tracker-cards.test.ts +49 -0
  49. package/bdd/generated/campaign/view-only.test.ts +51 -0
  50. package/bdd/generated/hit-design/campaign-column-metadata.test.ts +1 -0
  51. package/bdd/generated/landing/campaign-deep-links.test.ts +68 -0
  52. package/bdd/generated/landing/hit-design-campaigns-fixes.test.ts +99 -0
  53. package/bdd/generated/landing/hit-design-campaigns.test.ts +160 -0
  54. package/bdd/generated/landing/hit-triage-campaigns.test.ts +107 -0
  55. package/bdd/generated/landing/new-campaign.test.ts +78 -0
  56. package/bdd/generated/landing/pep-triage-campaigns.test.ts +52 -0
  57. package/bdd/generated/landing/pepti-hit-landing.test.ts +130 -0
  58. package/bdd/generated/pepti-hit/helm-edit.test.ts +64 -0
  59. package/bdd/generated/templates/template-editor.test.ts +137 -0
  60. package/bdd/generated/templates/template-picker.test.ts +119 -0
  61. package/bdd/generated/templates/triage-forms.test.ts +68 -0
  62. package/css/hit-triage.css +27 -23
  63. package/dist/package-test.js +690 -4
  64. package/dist/package-test.js.map +1 -1
  65. package/dist/package.js +318 -73
  66. package/dist/package.js.map +1 -1
  67. package/package.json +11 -7
  68. package/queries/locks.sql +37 -0
  69. package/src/app/accordeons/layout-input.ts +52 -44
  70. package/src/app/accordeons/new-campaign-accordeon.ts +91 -54
  71. package/src/app/accordeons/new-hit-design-campaign-accordeon.ts +3 -67
  72. package/src/app/accordeons/new-pep-triage-template-accordeon.ts +39 -41
  73. package/src/app/accordeons/new-template-accordeon.ts +41 -24
  74. package/src/app/ai/view-functions.ts +22 -19
  75. package/src/app/base-view.ts +99 -8
  76. package/src/app/consts.ts +8 -5
  77. package/src/app/dialogs/functions-dialog.ts +14 -9
  78. package/src/app/dialogs/merge-table-dialog.ts +181 -325
  79. package/src/app/hit-app-base.ts +61 -90
  80. package/src/app/hit-design-app.ts +481 -886
  81. package/src/app/hit-design-views/info-view.ts +57 -407
  82. package/src/app/hit-design-views/submit-view.ts +216 -111
  83. package/src/app/hit-design-views/tiles-view.ts +168 -123
  84. package/src/app/hit-design-views/utils.css +0 -8
  85. package/src/app/hit-triage-app.ts +69 -38
  86. package/src/app/hit-triage-views/info-view.ts +70 -371
  87. package/src/app/pep-triage-app.ts +2 -2
  88. package/src/app/pep-triage-views/info-view.ts +42 -83
  89. package/src/app/pepti-hit-app.ts +32 -183
  90. package/src/app/pepti-hits-views/info-view.ts +15 -37
  91. package/src/app/shared/campaign-catalog.ts +408 -0
  92. package/src/app/shared/campaign-session.ts +557 -0
  93. package/src/app/shared/compute-editor.ts +274 -0
  94. package/src/app/shared/hit-home.ts +45 -0
  95. package/src/app/shared/new-campaign-form.ts +90 -0
  96. package/src/app/shared/permissions-editor.ts +93 -0
  97. package/src/app/shared/template-editor.ts +331 -0
  98. package/src/app/shared/template-picker.ts +154 -0
  99. package/src/app/utils/merge-table.ts +183 -78
  100. package/src/app/utils.ts +34 -325
  101. package/src/package-api.ts +29 -8
  102. package/src/package-test.ts +17 -2
  103. package/src/package.g.ts +12 -8
  104. package/src/package.ts +19 -7
  105. package/src/tests/ai.ts +244 -0
  106. package/src/tests/campaign-layout.ts +82 -0
  107. package/src/tests/campaign-session.ts +168 -0
  108. package/src/tests/campaigns.ts +23 -0
  109. package/src/tests/catalog.ts +156 -0
  110. package/src/tests/compat.ts +482 -0
  111. package/src/tests/compute.ts +165 -0
  112. package/src/tests/fixtures.ts +359 -0
  113. package/src/tests/merge.ts +149 -0
  114. package/src/tests/owners.ts +11 -0
  115. package/src/tests/save-lock.ts +932 -0
  116. package/src/tests/storage.ts +106 -0
  117. package/src/tests/template-editor.ts +538 -0
  118. package/src/tests/templates.ts +143 -0
  119. package/src/tests/triage-start.ts +81 -0
  120. package/src/tests/u2-guards.ts +384 -0
  121. package/src/tests/vid.ts +77 -0
  122. package/src/app/accordeons/new-hit-design-template-accordeon.ts +0 -238
  123. package/src/app/dialogs/permissions-dialog.ts +0 -66
@@ -0,0 +1,244 @@
1
+ /* eslint-disable max-len */
2
+ import * as grok from 'datagrok-api/grok';
3
+ import * as DG from 'datagrok-api/dg';
4
+ import {after, before, category, expect, expectFloat, test, waitUntil} from '@datagrok-libraries/test/src/test';
5
+ import {_package} from '../package';
6
+ import * as api from '../package-api';
7
+ import {HitDesignApp} from '../app/hit-design-app';
8
+ import {HitDesignTemplate} from '../app/types';
9
+ import {allUsers, designCampaign, designCsv, expectSame, noComputeTemplate, Sandbox, triageTemplate} from './fixtures';
10
+
11
+ const infoNames = ['getHitAppInfo', 'listHitCampaigns', 'getHitCampaignDetails', 'openHitCampaign', 'listHitTemplates',
12
+ 'getHitTemplateDetails', 'createHitCampaign', 'deleteHitCampaign'];
13
+ const sharedNames = ['getHitCampaignState', 'saveHitCampaign', 'setHitCampaignStatus', 'submitHitCampaign',
14
+ 'searchHitTableFunctions', 'callHitTableFunction'];
15
+ const designNames = [...sharedNames, 'setHitMolecule', 'setHitStage', 'setHitStages', 'recalculateHitRow'];
16
+
17
+ const names = (v: DG.ViewBase) => v.getFunctions().map((f) => f.name).sort();
18
+
19
+ /** Calls a view function as the assistant does: found in the current view's getFunctions(), that view injected. */
20
+ async function ai(name: string, params: {[key: string]: unknown} = {}): Promise<any> {
21
+ const v = grok.shell.v;
22
+ const f = v.getFunctions().find((x) => x.name === name);
23
+ if (!f)
24
+ throw new Error(`the view "${v.name}" does not report ${name}; it reports ${names(v).join(', ')}`);
25
+ return await f.apply({view: v, ...params});
26
+ }
27
+
28
+ function expectFailure(res: any, contains: string, what: string): void {
29
+ expect(res?.success === false && String(res?.error).includes(contains), true, `${what}: ${JSON.stringify(res)}`);
30
+ }
31
+
32
+ let sb: Sandbox;
33
+ let app: HitDesignApp;
34
+ const template: HitDesignTemplate = {...noComputeTemplate('ZZB3 AI Template', 'ZZB3'), compute: {
35
+ descriptors: {enabled: false, args: []}, scripts: [], queries: [],
36
+ functions: [{name: 'addChemPropertiesColumns', package: 'Chem', args: {MW: true, HBA: false, HBD: false, logP: false,
37
+ logS: false, PSA: false, rotatableBonds: false, stereoCenters: false, moleculeCharge: false, molecularFormula: false}}],
38
+ }};
39
+
40
+ const design = () => grok.shell.v as DG.TableView;
41
+ function closeDialogs(): void {
42
+ for (const d of DG.Dialog.getOpenDialogs())
43
+ d.close();
44
+ }
45
+
46
+ // One landing and one campaign session for the whole category, as the assistant meets them: the tests run in order.
47
+ category('AI', () => {
48
+ before(async () => {
49
+ sb = await Sandbox.create('ai');
50
+ await sb.writeTemplate(template);
51
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-1', template), designCsv);
52
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-2', template, {campaignFields: {Chemist: 'Bo'}, status: 'Approved'}), designCsv);
53
+ app = await sb.hitDesign();
54
+ });
55
+
56
+ after(async () => {
57
+ await sb.dispose();
58
+ });
59
+
60
+ test('the landing reports the info functions to the assistant', async () => {
61
+ expect(grok.shell.v === app.multiView, true, 'the landing is the current view');
62
+ expectSame(names(grok.shell.v), [...infoNames].sort(), 'getFunctions() of the landing');
63
+ expect(String((grok.shell.v as unknown as {aiDescription?: string}).aiDescription).includes('getHitAppInfo'), true, 'aiDescription');
64
+ });
65
+
66
+ test('getHitAppInfo', async () => {
67
+ expectSame(await ai('getHitAppInfo'), {app: sb.appName, campaigns: 2, templates: [template.name],
68
+ currentCampaign: null, canCreateCampaignsHere: true}, 'getHitAppInfo');
69
+ });
70
+
71
+ test('listHitCampaigns', async () => {
72
+ const res = await ai('listHitCampaigns');
73
+ expect(res.total, 2, 'total');
74
+ const one = res.campaigns.find((c: any) => c.code === 'ZZB3-1');
75
+ expectSame(one, {code: 'ZZB3-1', name: 'Friendly ZZB3-1', template: template.name, status: 'In Progress',
76
+ author: DG.User.current().friendlyName, created: '2024/9/4', rows: 2}, 'the brief of ZZB3-1');
77
+ });
78
+
79
+ test('getHitCampaignDetails: by code, by friendly name in any case, and an unknown code', async () => {
80
+ const res = await ai('getHitCampaignDetails', {campaignCode: 'ZZB3-1'});
81
+ expect(res.code, 'ZZB3-1', 'code');
82
+ expectSame(res.campaignFields, designCampaign(sb, 'ZZB3-1', template).campaignFields, 'campaignFields');
83
+ expectSame(res.stages, template.stages, 'stages');
84
+ expectSame(res.compute, {descriptors: [], functions: ['Chem:addChemPropertiesColumns'], scripts: [], queries: []}, 'compute');
85
+ expect(res.canEdit, true, 'canEdit');
86
+ expect(res.lastModifiedBy, 'Someone Else', 'lastModifiedBy');
87
+ expect((await ai('getHitCampaignDetails', {campaignCode: 'friendly zzb3-2'})).code, 'ZZB3-2', 'by friendly name');
88
+ expectFailure(await ai('getHitCampaignDetails', {campaignCode: 'ZZB3-99'}), 'listHitCampaigns', 'an unknown code');
89
+ });
90
+
91
+ test('listHitTemplates and getHitTemplateDetails', async () => {
92
+ expectSame(await ai('listHitTemplates'), {templates: [template.name]}, 'listHitTemplates');
93
+ const res = await ai('getHitTemplateDetails', {templateName: template.name});
94
+ expectSame(res, {name: template.name, key: 'ZZB3',
95
+ campaignFields: template.campaignFields.map((f) => ({name: f.name, type: f.type, required: !!f.required})),
96
+ stages: template.stages, compute: {descriptors: [], functions: ['Chem:addChemPropertiesColumns'], scripts: [], queries: []},
97
+ submitFunction: 'HitTriage:demoFileSubmit'}, 'getHitTemplateDetails');
98
+ expectFailure(await ai('getHitTemplateDetails', {templateName: 'No such template'}), 'listHitTemplates', 'an unknown template');
99
+ });
100
+
101
+ test('createHitCampaign: refuses a missing required field, then creates and opens the campaign', async () => {
102
+ expectFailure(await ai('createHitCampaign', {templateName: template.name, campaignName: 'AI Three', campaignFields: {}}),
103
+ 'Missing required campaign fields: Chemist', 'without Chemist');
104
+ const res = await ai('createHitCampaign', {templateName: template.name, campaignName: 'AI Three', campaignFields: {Chemist: 'Eve'}});
105
+ expectSame(res, {success: true, campaign: 'ZZB3-3', note: 'The campaign is created and its design view is open'}, 'createHitCampaign');
106
+ const saved = await sb.readCampaign('ZZB3-3');
107
+ expect(saved.friendlyName, 'AI Three', 'friendlyName');
108
+ expectSame(saved.campaignFields, {Chemist: 'Eve'}, 'campaignFields');
109
+ expect(design() === app.designView && design().name === 'AI Three', true, 'its design view is current');
110
+ await waitUntil(() => DG.Dialog.getOpenDialogs().length > 0, 'the sketcher did not open for the empty first row', 15000);
111
+ closeDialogs();
112
+ grok.shell.v = app.multiView;
113
+ });
114
+
115
+ test('openHitCampaign', async () => {
116
+ expectFailure(await ai('openHitCampaign', {campaignCode: 'ZZB3-99'}), 'listHitCampaigns', 'an unknown code');
117
+ expectSame(await ai('openHitCampaign', {campaignCode: 'ZZB3-1'}), {success: true, campaign: 'ZZB3-1',
118
+ note: 'The campaign view is now open'}, 'openHitCampaign');
119
+ expect(app.campaignId, 'ZZB3-1', 'the app\'s campaign');
120
+ expect(design() === app.designView && design().name === 'Friendly ZZB3-1', true, 'its design view is current');
121
+ });
122
+
123
+ test('Q4: grok.shell.v of the campaign view reports the campaign functions', async () => {
124
+ expectSame(names(grok.shell.v), [...designNames].sort(), 'getFunctions() of grok.shell.v');
125
+ expect(String((grok.shell.v as unknown as {aiDescription?: string}).aiDescription).includes('getHitCampaignState'), true, 'aiDescription');
126
+ });
127
+
128
+ test('getHitCampaignState', async () => {
129
+ const res = await ai('getHitCampaignState');
130
+ expect(res.app, sb.appName, 'app');
131
+ expect(res.code, 'ZZB3-1', 'code');
132
+ expect(res.campaign?.code, 'ZZB3-1', 'campaign brief');
133
+ expect(res.moleculeColumn, 'Molecule', 'moleculeColumn');
134
+ expectSame(res.stages, template.stages, 'stages');
135
+ expect(res.rows, 2, 'rows');
136
+ expect(res.filteredRows, 2, 'filteredRows');
137
+ expect(['Molecule', 'Stage', 'V-iD', 'Note'].every((c) => res.columns.some((x: any) => x.name === c)), true,
138
+ `columns: ${JSON.stringify(res.columns)}`);
139
+ expect(res.canEdit, true, 'canEdit');
140
+ expect(res.submitFunction, 'HitTriage:demoFileSubmit', 'submitFunction');
141
+ expectSame(res.compute.functions, ['Chem:addChemPropertiesColumns'], 'compute');
142
+ });
143
+
144
+ test('saveHitCampaign', async () => {
145
+ const version = (await sb.readCampaign('ZZB3-1')).version;
146
+ expectSame(await ai('saveHitCampaign'), {success: true, campaign: 'ZZB3-1'}, 'saveHitCampaign');
147
+ expect((await sb.readCampaign('ZZB3-1')).version, version + 1, 'saved');
148
+ });
149
+
150
+ test('setHitCampaignStatus', async () => {
151
+ expectFailure(await ai('setHitCampaignStatus', {status: ' '}), 'status is required', 'an empty status');
152
+ expectSame(await ai('setHitCampaignStatus', {status: 'Approved'}), {success: true, status: 'Approved'}, 'setHitCampaignStatus');
153
+ expect((await sb.readCampaign('ZZB3-1')).status, 'Approved', 'saved status');
154
+ });
155
+
156
+ test('setHitMolecule: a new row and an existing row get the molecule, a V-iD and the computed MW', async () => {
157
+ const df = app.dataFrame!;
158
+ const added = await ai('setHitMolecule', {molecule: 'CCN'});
159
+ await sb.savesDone();
160
+ closeDialogs();
161
+ expect(added.success === true && added.row === 2 && /^V\d{6,}$/.test(added.vId), true, `a new row: ${JSON.stringify(added)}`);
162
+ expect(df.get('Molecule', 2), 'CCN', 'the new row\'s molecule');
163
+ expectFloat(df.get('MW', 2), 45.085, 0.01, 'the new row\'s MW');
164
+ const campaigns = await api.queries.getCampaignsByVid(added.vId, sb.appName);
165
+ expect(campaigns.rowCount === 1 && campaigns.get('campaign_id', 0) === 'ZZB3-1', true, 'the V-iD is registered to the campaign');
166
+ const existing = await ai('setHitMolecule', {molecule: 'Oc1ccccc1', row: 0});
167
+ await sb.savesDone();
168
+ expect(existing.success === true && existing.row === 0 && /^V\d{6,}$/.test(existing.vId), true, `row 0: ${JSON.stringify(existing)}`);
169
+ expectFloat(df.get('MW', 0), 94.113, 0.01, 'row 0 MW');
170
+ expect((await grok.dapi.files.readCsv(sb.savePath('ZZB3-1'))).rowCount, 3, 'the rows saved');
171
+ expectFailure(await ai('setHitMolecule', {molecule: 'CCO', row: 99}), 'row must be between 0 and 2', 'a row out of range');
172
+ });
173
+
174
+ test('setHitStage', async () => {
175
+ expectSame(await ai('setHitStage', {row: 1, stage: 'Tested'}), {success: true, row: 1, stage: 'Tested'}, 'setHitStage');
176
+ expect((await grok.dapi.files.readCsv(sb.savePath('ZZB3-1'))).get('Stage', 1), 'Tested', 'saved stage');
177
+ expectFailure(await ai('setHitStage', {row: 1, stage: 'Nope'}), 'the stages are: Idea, Made, Tested', 'an unknown stage');
178
+ });
179
+
180
+ test('setHitStages', async () => {
181
+ const stages = ['Idea', 'Made', 'Tested', 'Shipped'];
182
+ expectSame(await ai('setHitStages', {stages}), {success: true, stages}, 'setHitStages');
183
+ expectSame((await sb.readCampaign('ZZB3-1')).template.stages, stages, 'saved stages');
184
+ expectFailure(await ai('setHitStages', {stages: []}), 'non-empty list', 'no stages');
185
+ });
186
+
187
+ test('recalculateHitRow', async () => {
188
+ app.dataFrame!.set('MW', 1, null);
189
+ expectSame(await ai('recalculateHitRow', {row: 1}), {success: true, row: 1}, 'recalculateHitRow');
190
+ await sb.savesDone();
191
+ expectFloat(app.dataFrame!.get('MW', 1), 78.114, 0.01, 'benzene MW recalculated');
192
+ expectFailure(await ai('recalculateHitRow', {row: 5}), 'row must be between 0 and 2', 'a row out of range');
193
+ });
194
+
195
+ test('searchHitTableFunctions and callHitTableFunction reach the table view\'s own commands', async () => {
196
+ const found = await ai('searchHitTableFunctions', {query: 'select all', limit: 50});
197
+ expect(found.functions.some((f: any) => f.name === 'Select all'), true, `found: ${found.functions.map((f: any) => f.name).join(', ')}`);
198
+ const df = app.dataFrame!;
199
+ df.selection.setAll(false);
200
+ expect((await ai('callHitTableFunction', {name: 'Select all', parameters: {}})).success, true, 'Select all ran');
201
+ expect(df.selection.trueCount, df.rowCount, 'every row selected');
202
+ df.selection.setAll(false);
203
+ expectFailure(await ai('callHitTableFunction', {name: 'No such command', parameters: {}}), 'searchHitTableFunctions', 'an unknown command');
204
+ });
205
+
206
+ test('submitHitCampaign', async () => {
207
+ expectSame(await ai('submitHitCampaign', {status: 'Submitted by the assistant'}),
208
+ {success: true, submittedTo: 'HitTriage:demoFileSubmit'}, 'submitHitCampaign');
209
+ expect((await sb.readCampaign('ZZB3-1')).status, 'Submitted by the assistant', 'saved status');
210
+ });
211
+
212
+ test('deleteHitCampaign', async () => {
213
+ grok.shell.v = app.multiView;
214
+ expectFailure(await ai('deleteHitCampaign', {campaignCode: 'ZZB3-99'}), 'listHitCampaigns', 'an unknown code');
215
+ expectSame(await ai('deleteHitCampaign', {campaignCode: 'ZZB3-2'}), {success: true, deleted: 'ZZB3-2'}, 'deleteHitCampaign');
216
+ expect(await _package.files.exists(`${sb.appName}/campaigns/ZZB3-2`), false, 'the folder is gone');
217
+ expectSame((await ai('listHitCampaigns')).campaigns.map((c: any) => c.code).sort(), ['ZZB3-1', 'ZZB3-3'], 'the list after the delete');
218
+ });
219
+
220
+ test('Hit Triage: the pick view reports the shared campaign functions', async () => {
221
+ const ht = await Sandbox.create('ai');
222
+ try {
223
+ const t = triageTemplate('ZZB3 AI Triage', 'ZZB3');
224
+ await ht.writeTemplate(t);
225
+ await ht.writeCampaign({name: 'ZZB3-1', templateName: t.name, filters: [],
226
+ ingest: {type: 'File', query: ht.ingestPath('ZZB3-1'), molColName: 'smiles'}, status: 'In Progress',
227
+ createDate: '2024/10/17', campaignFields: {Chemist: 'Ann'}, columnSemTypes: {smiles: 'Molecule'},
228
+ columnTypes: {smiles: 'string'}, rowCount: 1, filteredRowCount: 1, authorUserId: DG.User.current().id,
229
+ permissions: {view: [allUsers], edit: [allUsers]}} as {name: string}, 'smiles\nCCO\n');
230
+ const triage = await ht.hitTriage();
231
+ expectSame(names(grok.shell.v), [...infoNames].sort(), 'getFunctions() of the Hit Triage landing');
232
+ const pick = await ht.openTriage(triage, 'ZZB3-1');
233
+ grok.shell.v = pick;
234
+ expectSame(names(grok.shell.v), [...sharedNames].sort(), 'getFunctions() of the pick view');
235
+ const state = await ai('getHitCampaignState');
236
+ expect(state.code === 'ZZB3-1' && state.moleculeColumn === 'smiles' && state.canEdit === true, true, JSON.stringify(state));
237
+ expectSame(await ai('saveHitCampaign'), {success: true, campaign: 'ZZB3-1'}, 'saveHitCampaign');
238
+ expect((await ht.readCampaign('ZZB3-1')).lastModifiedUserName, DG.User.current().friendlyName, 'saved');
239
+ } finally {
240
+ await ht.dispose();
241
+ grok.shell.v = app.multiView;
242
+ }
243
+ }, {timeout: 120000});
244
+ }, {clear: false});
@@ -0,0 +1,82 @@
1
+ /* eslint-disable max-len */
2
+ import * as grok from 'datagrok-api/grok';
3
+ import * as DG from 'datagrok-api/dg';
4
+ import {category, expect, test, waitUntil} from '@datagrok-libraries/test/src/test';
5
+ import {layoutObjects} from '../app/shared/campaign-session';
6
+ import {designCampaign, designCsv, expectSame, hasBalloon, noComputeTemplate, Sandbox, startDesignCampaign} from './fixtures';
7
+
8
+ /** The columns the Filters viewers of a layout filter on. */
9
+ function filterColumns(viewState: string): string[] {
10
+ return layoutObjects(viewState).filter((o) => o['#type'] === 'FiltersLook')
11
+ .flatMap((o) => ((o.filters ?? []) as {column?: string}[]).map((f) => f.column as string));
12
+ }
13
+
14
+ /** A layout whose Filters viewer filters on Stage and on two descriptors a new campaign calculates later. */
15
+ async function filtersLayout(): Promise<string> {
16
+ const df = DG.DataFrame.fromCsv('Molecule,Stage,V-iD,HeavyAtomCount,qed\nCCO,Idea,,3,0.4\n');
17
+ const tv = grok.shell.addTableView(df);
18
+ try {
19
+ const filters = tv.getFiltersGroup({createDefaultFilters: false});
20
+ filters.updateOrAdd({type: DG.FILTER_TYPE.CATEGORICAL, column: 'Stage'});
21
+ filters.updateOrAdd({type: DG.FILTER_TYPE.HISTOGRAM, column: 'HeavyAtomCount'});
22
+ filters.updateOrAdd({type: DG.FILTER_TYPE.HISTOGRAM, column: 'qed'});
23
+ let state = '';
24
+ await waitUntil(() => filterColumns(state = tv.saveLayout().viewState).length === 3,
25
+ 'the filters never reached the layout', 10000);
26
+ return state;
27
+ } finally {
28
+ tv.close();
29
+ grok.shell.closeTable(df);
30
+ }
31
+ }
32
+
33
+ category('Campaign view: layout', () => {
34
+ test('a new campaign whose template layout filters on columns it calculates later opens without errors and keeps those filters', async () => {
35
+ const sb = await Sandbox.create('layout');
36
+ try {
37
+ const t = {...noComputeTemplate('ZZB3 Layout', 'ZZB3'), layoutViewState: await filtersLayout(),
38
+ compute: {descriptors: {enabled: true, args: ['HeavyAtomCount', 'qed']}, functions: [], scripts: [], queries: []}};
39
+ await sb.writeTemplate(t);
40
+ const app = await sb.hitDesign();
41
+ const id = await startDesignCampaign(app, t, {Chemist: 'Ann'});
42
+ expect(hasBalloon('Error adding filter'), false, 'an "Error adding filter" balloon');
43
+ expect(document.querySelector('[data-u2-item^="Apply template layout"] i')?.classList.contains('svg-view-layout'), true,
44
+ 'Apply template layout shows the platform\'s view-layout picture');
45
+ expectSame(filterColumns((await sb.readCampaign(id)).layout).sort(), ['HeavyAtomCount', 'Stage', 'qed'],
46
+ 'the filters the created campaign keeps');
47
+ await app.performSingleCellCalculations(0, 'CCO');
48
+ await waitUntil(() => app.campaign?.version === 2 && !app.isSaving, 'the calculated row was not saved', 60000);
49
+ expect(app.dataFrame!.get('HeavyAtomCount', 0), 3, 'the calculated HeavyAtomCount');
50
+ expectSame(filterColumns((await sb.readCampaign(id)).layout).sort(), ['HeavyAtomCount', 'Stage', 'qed'],
51
+ 'the filters kept through the first calculation');
52
+ } finally {
53
+ await sb.dispose();
54
+ }
55
+ }, {timeout: 180000});
56
+
57
+ test('Add new row in the ribbon adds a row and logs no error', async () => {
58
+ const sb = await Sandbox.create('layout');
59
+ const logged: string[] = [];
60
+ const error = console.error;
61
+ try {
62
+ const t = noComputeTemplate('ZZB3 Layout', 'ZZB3');
63
+ await sb.writeTemplate(t);
64
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-1', t, {version: 1}), designCsv);
65
+ const app = await sb.hitDesign();
66
+ const view = await sb.openDesign(app, 'ZZB3-1');
67
+ const add = view.root.querySelector<HTMLElement>('[data-u2-item="Add new row"]') ??
68
+ document.querySelector<HTMLElement>('[data-u2-item="Add new row"]');
69
+ expect(add != null, true, 'the ribbon\'s Add new row');
70
+ console.error = (...args: unknown[]) => {
71
+ logged.push(args.map(String).join(' '));
72
+ error(...args);
73
+ };
74
+ add!.click();
75
+ await waitUntil(() => app.dataFrame!.rowCount === 3, 'no row was added', 10000);
76
+ } finally {
77
+ console.error = error;
78
+ await sb.dispose();
79
+ }
80
+ expectSame(logged.filter((l) => l.includes('No such column')), [], 'errors logged by the click');
81
+ }, {timeout: 120000});
82
+ });
@@ -0,0 +1,168 @@
1
+ import * as grok from 'datagrok-api/grok';
2
+ import * as DG from 'datagrok-api/dg';
3
+ import {category, expect, test, waitUntil} from '@datagrok-libraries/test/src/test';
4
+ import * as api from '../package-api';
5
+ import {HitDesignApp} from '../app/hit-design-app';
6
+ import {CampaignJsonName} from '../app/consts';
7
+ import {designCampaign, designCsv, noComputeTemplate, Sandbox} from './fixtures';
8
+
9
+ type Query = (name: string, ...args: unknown[]) => Promise<DG.DataFrame>;
10
+ type SessionInternals = {_session?: {host: {scope: {isDisposed: boolean}}, needsRefresh: {peek(): boolean}}};
11
+
12
+ const session = (app: HitDesignApp) => (app as unknown as SessionInternals)._session!;
13
+
14
+ /** The next GetLastModified call of the sandbox — a campaign view's first read of the last save — runs [first]
15
+ * instead, given the real call; the calls after it run as they are. Answers the undo. */
16
+ function replaceFirstLastModified(sb: Sandbox,
17
+ first: (query: () => Promise<DG.DataFrame>) => Promise<DG.DataFrame>): () => void {
18
+ const data = Object.getPrototypeOf(grok.data) as {query: Query};
19
+ const query = data.query;
20
+ let replaced = false;
21
+ data.query = function(this: unknown, name: string, ...args: unknown[]) {
22
+ if (replaced || name !== 'HitTriage:GetLastModified' || (args[0] as {appName?: string})?.appName !== sb.appName)
23
+ return query.call(this, name, ...args);
24
+ replaced = true;
25
+ return first(() => query.call(this, name, ...args));
26
+ };
27
+ return () => data.query = query;
28
+ }
29
+
30
+ /** A campaign of the sandbox on {@link designCsv}, open in a new Hit Design app. */
31
+ async function openCampaign(sb: Sandbox): Promise<HitDesignApp> {
32
+ const t = noComputeTemplate('ZZB3 Shared', 'ZZB3');
33
+ await sb.writeTemplate(t);
34
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-1', t, {version: 1}), designCsv);
35
+ const app = await sb.hitDesign();
36
+ await sb.openDesign(app, 'ZZB3-1');
37
+ return app;
38
+ }
39
+
40
+ /** Another session's save as the campaign view sees it: the lock taken and let go, which logs the save time. */
41
+ async function anotherSessionSaves(sb: Sandbox): Promise<void> {
42
+ await api.queries.acquireCampaignLock(sb.appName, 'ZZB3-1', 'another session');
43
+ await api.queries.releaseCampaignLock(sb.appName, 'ZZB3-1');
44
+ }
45
+
46
+ const ownerDisposedReports = () => DG.U2.Usage.reports().filter((r) => r.code === 'owner-disposed')
47
+ .reduce((n, r) => n + r.count, 0);
48
+
49
+ category('Campaign view: other sessions', () => {
50
+ test('a failed first read of the last save still starts the check for other sessions\' saves', async () => {
51
+ const sb = await Sandbox.create('poll');
52
+ let failed = false;
53
+ const restore = replaceFirstLastModified(sb, async () => {
54
+ failed = true;
55
+ throw new Error('ZZB3 refused the first read');
56
+ });
57
+ try {
58
+ const app = await openCampaign(sb);
59
+ await waitUntil(() => failed, 'the campaign view never read the last save', 10000);
60
+ restore();
61
+ await anotherSessionSaves(sb);
62
+ await waitUntil(() => session(app).needsRefresh.peek(),
63
+ 'the view never noticed another session\'s save', 10000);
64
+ } finally {
65
+ restore();
66
+ await sb.dispose();
67
+ }
68
+ }, {timeout: 120000});
69
+
70
+ test('a view closed while it reads the last save starts no check; the next view notices other saves', async () => {
71
+ const sb = await Sandbox.create('poll');
72
+ let letGo!: () => void;
73
+ const gate = new Promise<void>((resolve) => letGo = resolve);
74
+ let reading = false;
75
+ let read = false;
76
+ const restore = replaceFirstLastModified(sb, async (query) => {
77
+ reading = true;
78
+ await gate;
79
+ const df = await query();
80
+ read = true;
81
+ return df;
82
+ });
83
+ try {
84
+ const app = await openCampaign(sb);
85
+ await waitUntil(() => reading, 'the campaign view never read the last save', 10000);
86
+ const closed = session(app);
87
+ await sb.openDesign(app, 'ZZB3-1');
88
+ await waitUntil(() => closed.host.scope.isDisposed, 'the first view\'s session did not end with its view', 10000);
89
+ const disposedBefore = ownerDisposedReports();
90
+ letGo();
91
+ await waitUntil(() => read, 'the closed view\'s read never ended', 10000);
92
+ await anotherSessionSaves(sb);
93
+ await waitUntil(() => session(app).needsRefresh.peek(),
94
+ 'the open view never noticed another session\'s save', 10000);
95
+ expect(ownerDisposedReports(), disposedBefore,
96
+ 'u2 owner-disposed reports: the closed view\'s session started no check');
97
+ } finally {
98
+ letGo();
99
+ restore();
100
+ await sb.dispose();
101
+ }
102
+ }, {timeout: 120000});
103
+ });
104
+
105
+ type FileRead = (file: unknown, ...rest: unknown[]) => Promise<unknown>;
106
+
107
+ /** ZZB3-1 is asked for first, and its `read` of the file at `path` waits until ZZB3-2 is open: the app must end on
108
+ * ZZB3-2, whichever read of the open holds ZZB3-1 back. */
109
+ async function openWhileFirstReads(read: 'readAsText' | 'readCsv', path: (sb: Sandbox) => string): Promise<void> {
110
+ const sb = await Sandbox.create('open');
111
+ const files = Object.getPrototypeOf(grok.dapi.files) as {[name: string]: FileRead};
112
+ const original = files[read];
113
+ let release!: () => void;
114
+ const held = new Promise<void>((resolve) => release = resolve);
115
+ try {
116
+ const t = noComputeTemplate('ZZB3 Open', 'ZZB3');
117
+ await sb.writeTemplate(t);
118
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-1', t), designCsv);
119
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-2', t), designCsv);
120
+ const app = await sb.hitDesign();
121
+ let holding = false;
122
+ files[read] = async function(this: unknown, file: unknown, ...rest: unknown[]) {
123
+ if (String(file) === path(sb)) {
124
+ holding = true;
125
+ await held;
126
+ }
127
+ return original.call(this, file, ...rest);
128
+ };
129
+ const first = app.infoView.setCampaign('ZZB3-1');
130
+ await waitUntil(() => holding, `ZZB3-1's ${read} of ${path(sb)} was not reached`, 30000);
131
+ await sb.openDesign(app, 'ZZB3-2');
132
+ release();
133
+ await first;
134
+ expect(app.campaignId, 'ZZB3-2', 'the campaign the app has open');
135
+ expect(app.designView?.name, 'Friendly ZZB3-2', 'the campaign view shown');
136
+ } finally {
137
+ files[read] = original;
138
+ release();
139
+ await sb.dispose();
140
+ }
141
+ }
142
+
143
+ category('Campaign view: opening', () => {
144
+ test('of two campaigns opened in quick succession the one opened last is shown, though the first reads its table ' +
145
+ 'slower', () => openWhileFirstReads('readCsv', (sb) => sb.savePath('ZZB3-1')), {timeout: 120000});
146
+
147
+ test('of two campaigns opened in quick succession the one opened last is shown, though the first reads its ' +
148
+ 'campaign.json slower', () => openWhileFirstReads('readAsText',
149
+ (sb) => `${sb.appName}/campaigns/ZZB3-1/${CampaignJsonName}`), {timeout: 120000});
150
+
151
+ test('a campaign link opens its campaign though the address no longer names it when the landing starts', async () => {
152
+ const sb = await Sandbox.create('link');
153
+ try {
154
+ const t = noComputeTemplate('ZZB3 Link', 'ZZB3');
155
+ await sb.writeTemplate(t);
156
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-1', t), designCsv);
157
+ // a view that took the address while the app started leaves no ?campaignId= in it
158
+ history.replaceState(history.state, '', location.pathname);
159
+ const app = await sb.hitDesign('ZZB3-1');
160
+ await waitUntil(() => app.campaignId === 'ZZB3-1' && app.designView != null,
161
+ 'the campaign of the link did not open', 30000);
162
+ expect(app.designView?.name, 'Friendly ZZB3-1', 'the campaign view shown');
163
+ expect(new URLSearchParams(location.search).get('campaignId'), 'ZZB3-1', 'the campaign the address names again');
164
+ } finally {
165
+ await sb.dispose();
166
+ }
167
+ }, {timeout: 120000});
168
+ });
@@ -0,0 +1,23 @@
1
+ import * as DG from 'datagrok-api/dg';
2
+ import {category, expect, test} from '@datagrok-libraries/test/src/test';
3
+ import {_package} from '../package';
4
+ import {loadCampaigns} from '../app/utils';
5
+ import {AppName} from '../app/types';
6
+ import {CampaignJsonName} from '../app/consts';
7
+ import {defaultPermissions} from '../app/shared/permissions-editor';
8
+
9
+ category('Campaigns', () => {
10
+ test('List skips unreadable campaigns and shows those shared with All users', async () => {
11
+ const appName = `Tests ${DG.Utils.randomString(8)}` as AppName;
12
+ const otherAuthorId = '00000000-0000-0000-0000-000000000001';
13
+ try {
14
+ await _package.files.writeAsText(`${appName}/campaigns/GOOD-1/${CampaignJsonName}`,
15
+ JSON.stringify({name: 'GOOD-1', authorUserId: otherAuthorId, permissions: defaultPermissions}));
16
+ await _package.files.writeAsText(`${appName}/campaigns/BAD-1/${CampaignJsonName}`, '{not json');
17
+ const campaigns = await loadCampaigns(appName, []);
18
+ expect(Object.keys(campaigns).join(','), 'GOOD-1');
19
+ } finally {
20
+ await _package.files.delete(appName);
21
+ }
22
+ });
23
+ });