@datagrok/hit-triage 1.10.8 → 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 (129) hide show
  1. package/.grokignore +2 -0
  2. package/.turbo/turbo-build.log +24 -6
  3. package/.vscode/settings.json +16 -0
  4. package/CHANGELOG.md +80 -1
  5. package/CLAUDE.md +87 -10
  6. package/README_HD.md +14 -14
  7. package/README_HT.md +6 -6
  8. package/README_PH.md +110 -0
  9. package/bdd/bdd.config.json +3 -0
  10. package/bdd/bindings/campaign.ts +626 -0
  11. package/bdd/bindings/hit-design.ts +93 -0
  12. package/bdd/bindings/landing.ts +839 -0
  13. package/bdd/bindings/pepti-hit.ts +35 -0
  14. package/bdd/features/campaign/crumbs.feature +22 -0
  15. package/bdd/features/campaign/grid.feature +56 -0
  16. package/bdd/features/campaign/merge.feature +105 -0
  17. package/bdd/features/campaign/molecule-vid.feature +40 -0
  18. package/bdd/features/campaign/permissions.feature +46 -0
  19. package/bdd/features/campaign/progress-tracker.feature +89 -0
  20. package/bdd/features/campaign/refresh-hint.feature +33 -0
  21. package/bdd/features/campaign/ribbon.feature +49 -0
  22. package/bdd/features/campaign/stage-choices.feature +39 -0
  23. package/bdd/features/campaign/submit.feature +135 -0
  24. package/bdd/features/campaign/tracker-cards.feature +46 -0
  25. package/bdd/features/campaign/view-only.feature +37 -0
  26. package/bdd/features/hit-design/campaign-column-metadata.feature +61 -0
  27. package/bdd/features/landing/campaign-deep-links.feature +61 -0
  28. package/bdd/features/landing/hit-design-campaigns-fixes.feature +116 -0
  29. package/bdd/features/landing/hit-design-campaigns.feature +153 -0
  30. package/bdd/features/landing/hit-triage-campaigns.feature +99 -0
  31. package/bdd/features/landing/new-campaign.feature +69 -0
  32. package/bdd/features/landing/pep-triage-campaigns.feature +41 -0
  33. package/bdd/features/landing/pepti-hit-landing.feature +132 -0
  34. package/bdd/features/pepti-hit/helm-edit.feature +47 -0
  35. package/bdd/features/templates/template-editor.feature +130 -0
  36. package/bdd/features/templates/template-picker.feature +112 -0
  37. package/bdd/features/templates/triage-forms.feature +59 -0
  38. package/bdd/fixtures/bar-chart.layout +1 -0
  39. package/bdd/fixtures/merge-local.csv +2 -0
  40. package/bdd/generated/campaign/crumbs.test.ts +33 -0
  41. package/bdd/generated/campaign/grid.test.ts +79 -0
  42. package/bdd/generated/campaign/merge.test.ts +134 -0
  43. package/bdd/generated/campaign/molecule-vid.test.ts +52 -0
  44. package/bdd/generated/campaign/permissions.test.ts +58 -0
  45. package/bdd/generated/campaign/progress-tracker.test.ts +129 -0
  46. package/bdd/generated/campaign/refresh-hint.test.ts +44 -0
  47. package/bdd/generated/campaign/ribbon.test.ts +65 -0
  48. package/bdd/generated/campaign/stage-choices.test.ts +55 -0
  49. package/bdd/generated/campaign/submit.test.ts +167 -0
  50. package/bdd/generated/campaign/tracker-cards.test.ts +49 -0
  51. package/bdd/generated/campaign/view-only.test.ts +51 -0
  52. package/bdd/generated/hit-design/campaign-column-metadata.test.ts +76 -0
  53. package/bdd/generated/landing/campaign-deep-links.test.ts +68 -0
  54. package/bdd/generated/landing/hit-design-campaigns-fixes.test.ts +99 -0
  55. package/bdd/generated/landing/hit-design-campaigns.test.ts +160 -0
  56. package/bdd/generated/landing/hit-triage-campaigns.test.ts +107 -0
  57. package/bdd/generated/landing/new-campaign.test.ts +78 -0
  58. package/bdd/generated/landing/pep-triage-campaigns.test.ts +52 -0
  59. package/bdd/generated/landing/pepti-hit-landing.test.ts +130 -0
  60. package/bdd/generated/pepti-hit/helm-edit.test.ts +64 -0
  61. package/bdd/generated/templates/template-editor.test.ts +137 -0
  62. package/bdd/generated/templates/template-picker.test.ts +119 -0
  63. package/bdd/generated/templates/triage-forms.test.ts +68 -0
  64. package/bdd/package.json +1 -0
  65. package/bdd/tsconfig.json +13 -0
  66. package/css/hit-triage.css +27 -23
  67. package/dist/package-test.js +690 -4
  68. package/dist/package-test.js.map +1 -1
  69. package/dist/package.js +318 -73
  70. package/dist/package.js.map +1 -1
  71. package/package.json +15 -8
  72. package/queries/locks.sql +37 -0
  73. package/src/app/accordeons/layout-input.ts +52 -44
  74. package/src/app/accordeons/new-campaign-accordeon.ts +91 -54
  75. package/src/app/accordeons/new-hit-design-campaign-accordeon.ts +3 -67
  76. package/src/app/accordeons/new-pep-triage-template-accordeon.ts +39 -41
  77. package/src/app/accordeons/new-template-accordeon.ts +41 -24
  78. package/src/app/ai/view-functions.ts +22 -19
  79. package/src/app/base-view.ts +99 -8
  80. package/src/app/consts.ts +8 -5
  81. package/src/app/dialogs/functions-dialog.ts +14 -9
  82. package/src/app/dialogs/merge-table-dialog.ts +181 -325
  83. package/src/app/hit-app-base.ts +61 -90
  84. package/src/app/hit-design-app.ts +492 -882
  85. package/src/app/hit-design-views/info-view.ts +57 -407
  86. package/src/app/hit-design-views/submit-view.ts +216 -111
  87. package/src/app/hit-design-views/tiles-view.ts +168 -123
  88. package/src/app/hit-design-views/utils.css +0 -8
  89. package/src/app/hit-triage-app.ts +69 -38
  90. package/src/app/hit-triage-views/info-view.ts +70 -371
  91. package/src/app/pep-triage-app.ts +2 -2
  92. package/src/app/pep-triage-views/info-view.ts +42 -83
  93. package/src/app/pepti-hit-app.ts +32 -183
  94. package/src/app/pepti-hits-views/info-view.ts +15 -37
  95. package/src/app/shared/campaign-catalog.ts +408 -0
  96. package/src/app/shared/campaign-session.ts +557 -0
  97. package/src/app/shared/compute-editor.ts +274 -0
  98. package/src/app/shared/hit-home.ts +45 -0
  99. package/src/app/shared/new-campaign-form.ts +90 -0
  100. package/src/app/shared/permissions-editor.ts +93 -0
  101. package/src/app/shared/template-editor.ts +331 -0
  102. package/src/app/shared/template-picker.ts +154 -0
  103. package/src/app/types.ts +2 -0
  104. package/src/app/utils/merge-table.ts +183 -78
  105. package/src/app/utils.ts +34 -325
  106. package/src/package-api.ts +29 -8
  107. package/src/package-test.ts +17 -2
  108. package/src/package.g.ts +12 -8
  109. package/src/package.ts +19 -7
  110. package/src/tests/ai.ts +244 -0
  111. package/src/tests/campaign-layout.ts +82 -0
  112. package/src/tests/campaign-session.ts +168 -0
  113. package/src/tests/campaigns.ts +23 -0
  114. package/src/tests/catalog.ts +156 -0
  115. package/src/tests/compat.ts +482 -0
  116. package/src/tests/compute.ts +165 -0
  117. package/src/tests/fixtures.ts +359 -0
  118. package/src/tests/merge.ts +149 -0
  119. package/src/tests/owners.ts +11 -0
  120. package/src/tests/save-lock.ts +932 -0
  121. package/src/tests/storage.ts +106 -0
  122. package/src/tests/template-editor.ts +538 -0
  123. package/src/tests/templates.ts +143 -0
  124. package/src/tests/triage-start.ts +81 -0
  125. package/src/tests/u2-guards.ts +384 -0
  126. package/src/tests/vid.ts +77 -0
  127. package/tsconfig.json +3 -0
  128. package/src/app/accordeons/new-hit-design-template-accordeon.ts +0 -238
  129. package/src/app/dialogs/permissions-dialog.ts +0 -66
@@ -0,0 +1,143 @@
1
+ /* eslint-disable max-len */
2
+ import * as grok from 'datagrok-api/grok';
3
+ import {category, expect, test, waitUntil} from '@datagrok-libraries/test/src/test';
4
+ import {_package} from '../package';
5
+ import {loadTemplate} from '../app/utils';
6
+ import {HitDesignApp} from '../app/hit-design-app';
7
+ import {HitTriageApp} from '../app/hit-triage-app';
8
+ import {hitInfoViewFunctions} from '../app/ai/view-functions';
9
+ import {allUsers, expectSame, noComputeTemplate, pepTriageTemplate, Sandbox, startDesignCampaign,
10
+ triageTemplate} from './fixtures';
11
+
12
+ /** The template file name is the template name, spaces included, and every reader takes it back unchanged. */
13
+ async function expectTemplateFile(sb: Sandbox, t: {name: string}): Promise<void> {
14
+ const files = (await _package.files.list(`${sb.appName}/templates`)).map((f) => f.name);
15
+ expect(files.includes(`${t.name}.json`), true, `the templates folder lists "${t.name}.json"; it has ${files.join(', ')}`);
16
+ expectSame(await loadTemplate(`${sb.appName}/templates/${t.name}.json`), t, 'the template read back');
17
+ }
18
+
19
+ function expectPicked(app: HitDesignApp | HitTriageApp, name: string): void {
20
+ const options = Array.from(app.infoView.root.querySelectorAll('select option')).map((o) => o.textContent);
21
+ expect(options.includes(name), true, `the template picker offers "${name}"; it offers ${options.join(', ')}`);
22
+ }
23
+
24
+ async function aiTemplateDetails(app: HitDesignApp | HitTriageApp, name: string): Promise<{[key: string]: any}> {
25
+ const f = hitInfoViewFunctions().find((x) => x.name === 'getHitTemplateDetails')!;
26
+ return await f.apply({view: app.multiView, templateName: name});
27
+ }
28
+
29
+ async function startTriage(sb: Sandbox, app: HitTriageApp, id: string, templateName: string, csv: string,
30
+ columns: {columnSemTypes: {[c: string]: string | null}, columnTypes: {[c: string]: string}}, molColName: string) {
31
+ await sb.writeCampaign({name: id, templateName, filters: [],
32
+ ingest: {type: 'File', query: sb.ingestPath(id), molColName}, status: 'In Progress', createDate: '2026/6/17',
33
+ campaignFields: {Chemist: 'Ann'}, ...columns, rowCount: 1, filteredRowCount: 1,
34
+ permissions: {view: [allUsers], edit: [allUsers]}} as {name: string}, csv);
35
+ await sb.openTriage(app, id);
36
+ await app.saveCampaign(undefined, false);
37
+ return await sb.readCampaign(id);
38
+ }
39
+
40
+ category('Compat: templates', () => {
41
+ test('Hit Design: with no template, the landing offers to create the first one', async () => {
42
+ const sb = await Sandbox.create('tmpl');
43
+ try {
44
+ const app = await sb.hitDesign();
45
+ const empty = app.infoView.root.querySelector<HTMLElement>('[data-u2-name="template-picker"] [data-u2="empty-state"]');
46
+ expect(empty?.textContent?.includes('No templates yet') === true, true, `the picker's empty state; it shows "${empty?.textContent}"`);
47
+ const create = Array.from(empty!.querySelectorAll('button')).find((b) => b.textContent === 'Create template');
48
+ expect(create !== undefined, true, 'the Create template button');
49
+ create!.click();
50
+ await waitUntil(() => grok.shell.v?.name === 'New Template', 'the template editor did not open', 15000);
51
+ grok.shell.v.close();
52
+ } finally {
53
+ await sb.dispose();
54
+ }
55
+ }, {timeout: 120000});
56
+
57
+ test('Hit Design: the template file is listed, offered, and snapshotted by a new campaign', async () => {
58
+ const sb = await Sandbox.create('tmpl');
59
+ try {
60
+ const t = noComputeTemplate('ZZB3 Design Template', 'ZZB3');
61
+ await sb.writeTemplate(t);
62
+ await expectTemplateFile(sb, t);
63
+ const app = await sb.hitDesign();
64
+ expectPicked(app, t.name);
65
+ const details = await aiTemplateDetails(app, t.name);
66
+ expect(details.key, 'ZZB3', 'key');
67
+ expectSame(details.stages, t.stages, 'stages');
68
+ const id = await startDesignCampaign(app, t, {Chemist: 'Ann'}, 'Created from the file');
69
+ expect(id, 'ZZB3-1', 'the first code of the key');
70
+ const after = await sb.readCampaign(id);
71
+ expect(after.templateName, t.name, 'templateName');
72
+ expectSame(after.template, t, 'template snapshot');
73
+ expect(after.friendlyName, 'Created from the file', 'friendlyName');
74
+ expectSame(after.campaignFields, {Chemist: 'Ann'}, 'campaignFields');
75
+ expect(after.version, 1, 'version');
76
+ const df = await grok.dapi.files.readCsv(after.savePath);
77
+ expectSame(df.columns.names(), ['Molecule', 'Stage', 'V-iD'], 'columns of a new campaign');
78
+ expect(df.get('Stage', 0), 'Idea', 'the first stage is the default');
79
+ } finally {
80
+ await sb.dispose();
81
+ }
82
+ }, {timeout: 120000});
83
+
84
+ test('PeptiHit: the template file is listed, offered, and snapshotted by a new campaign', async () => {
85
+ const sb = await Sandbox.create('tmpl');
86
+ try {
87
+ const t = {...noComputeTemplate('ZZB3 Peptide Template', 'ZZB3'), stages: ['Design', 'Consideration']};
88
+ await sb.writeTemplate(t);
89
+ await expectTemplateFile(sb, t);
90
+ const app = await sb.peptiHit();
91
+ expectPicked(app, t.name);
92
+ const id = await startDesignCampaign(app, t, {Chemist: 'Ann'}, undefined, 'PEPTIDE1{A.G.L}$$$$V2.0');
93
+ const after = await sb.readCampaign(id);
94
+ expect(after.templateName, t.name, 'templateName');
95
+ expectSame(after.template, t, 'template snapshot');
96
+ const df = await grok.dapi.files.readCsv(after.savePath);
97
+ expectSame(df.columns.names(), ['Helm', 'Molecule', 'Stage', 'V-iD'], 'columns of a new campaign');
98
+ expect(df.get('Stage', 0), 'Design', 'the first stage is the default');
99
+ } finally {
100
+ await sb.dispose();
101
+ }
102
+ }, {timeout: 150000});
103
+
104
+ test('Hit Triage: the template file opens a campaign without a snapshot and becomes its snapshot', async () => {
105
+ const sb = await Sandbox.create('tmpl');
106
+ try {
107
+ const t = triageTemplate('ZZB3 Triage Template', 'ZZB3');
108
+ await sb.writeTemplate(t);
109
+ await expectTemplateFile(sb, t);
110
+ const app = await sb.hitTriage();
111
+ expectPicked(app, t.name);
112
+ const details = await aiTemplateDetails(app, t.name);
113
+ expect(details.dataSourceType, 'Query', 'dataSourceType');
114
+ expect(details.dataSourceFunction, 'Demo Molecules variable', 'the data source by its friendly name');
115
+ const after = await startTriage(sb, app, 'ZZB3-1', t.name, 'smiles\nCCO\n',
116
+ {columnSemTypes: {smiles: 'Molecule'}, columnTypes: {smiles: 'string'}}, 'smiles');
117
+ expect(after.templateName, t.name, 'templateName');
118
+ expectSame(after.template, t, 'template snapshot');
119
+ } finally {
120
+ await sb.dispose();
121
+ }
122
+ }, {timeout: 120000});
123
+
124
+ test('PepTriage: the template file opens a campaign and becomes its snapshot', async () => {
125
+ const sb = await Sandbox.create('tmpl');
126
+ try {
127
+ const t = pepTriageTemplate('ZZB3 PepTriage Template', 'ZZB3');
128
+ await sb.writeTemplate(t);
129
+ await expectTemplateFile(sb, t);
130
+ const app = await sb.pepTriage();
131
+ expectPicked(app, t.name);
132
+ const details = await aiTemplateDetails(app, t.name);
133
+ expect(details.dataSourceFunction, 'Demo Peptide Sequences', 'the data source by its friendly name');
134
+ const after = await startTriage(sb, app, 'ZZB3-1', t.name, 'Helm,molfile(Helm)\nPEPTIDE1{A.G.L.V.K}$$$$V2.0,CC(N)C(=O)O\n',
135
+ {columnSemTypes: {'Helm': 'Macromolecule', 'molfile(Helm)': 'Molecule'},
136
+ columnTypes: {'Helm': 'string', 'molfile(Helm)': 'string'}}, 'molfile(Helm)');
137
+ expectSame(after.template, t, 'template snapshot, sequence and molecule columns included');
138
+ expect(after.ingest.molColName, 'molfile(Helm)', 'ingest.molColName');
139
+ } finally {
140
+ await sb.dispose();
141
+ }
142
+ }, {timeout: 150000});
143
+ });
@@ -0,0 +1,81 @@
1
+ /* eslint-disable max-len */
2
+ import {Scope} from '@datagrok-libraries/u2';
3
+ import {category, expect, test, waitUntil} from '@datagrok-libraries/test/src/test';
4
+ import {newCampaignAccordeon} from '../app/accordeons/new-campaign-accordeon';
5
+ import {HitTriageDataSourceTag, PepTriageDataSourceTag, i18n} from '../app/consts';
6
+ import {HitTriageTemplate} from '../app/types';
7
+ import {expectSame, hasBalloon, pepTriageTemplate, Sandbox, triageTemplate} from './fixtures';
8
+
9
+ /** The new-campaign form of [template] with the inputs of the given captions typed in, START pressed: what START
10
+ * handed on to create. */
11
+ async function startOver(template: HitTriageTemplate, tag: string, typed: {[caption: string]: string}): Promise<unknown[]> {
12
+ const owner = new Scope();
13
+ const started: unknown[] = [];
14
+ try {
15
+ const form = await newCampaignAccordeon(template, {}, tag, {owner, start: async (c) => {started.push(c);}});
16
+ document.body.append(form);
17
+ for (const [caption, value] of Object.entries(typed)) {
18
+ const root = Array.from(form.querySelectorAll<HTMLElement>('.ui-input-root'))
19
+ .find((r) => r.querySelector('label')?.textContent?.trim().toLowerCase() === caption.toLowerCase());
20
+ const editor = root?.querySelector<HTMLInputElement>('input');
21
+ expect(editor != null, true, `the ${caption} input`);
22
+ editor!.value = value;
23
+ editor!.dispatchEvent(new Event('input', {bubbles: true}));
24
+ editor!.dispatchEvent(new Event('change', {bubbles: true}));
25
+ }
26
+ const start = Array.from(form.querySelectorAll('button')).find((b) => b.textContent?.trim().toLowerCase() === 'start')!;
27
+ await waitUntil(() => !start.disabled, `START stayed disabled: ${start.title}`, 10000);
28
+ start.click();
29
+ await waitUntil(() => start.disabled, 'START never got busy', 5000).catch(() => {});
30
+ await waitUntil(() => !start.disabled, 'START stayed busy', 30000);
31
+ form.remove();
32
+ } finally {
33
+ owner.dispose();
34
+ }
35
+ return started;
36
+ }
37
+
38
+ /** Each caption's right edge in the new-campaign section of a landing, by its text; START's and the form's right edges. */
39
+ function geometry(root: HTMLElement): {labels: {[text: string]: number}, start: number, form: number} {
40
+ const picker = root.querySelector<HTMLElement>('[data-u2-name="template-picker"]')!;
41
+ const labels: {[text: string]: number} = {};
42
+ for (const label of Array.from(picker.querySelectorAll<HTMLElement>('label, .u2-input-label'))) {
43
+ if (label.textContent?.trim() && label.getClientRects().length > 0)
44
+ labels[label.textContent.trim()] = Math.round(label.getBoundingClientRect().right);
45
+ }
46
+ const start = Array.from(picker.querySelectorAll('button')).find((b) => b.textContent?.trim().toLowerCase() === 'start');
47
+ const form = picker.querySelector<HTMLElement>('.ui-form');
48
+ return {labels, start: Math.round(start?.getBoundingClientRect().right ?? 0), form: Math.round(form?.getBoundingClientRect().right ?? 0)};
49
+ }
50
+
51
+ category('New campaign: Hit Triage, PepTriage', () => {
52
+ test('Hit Triage: Template, Campaign Name and the data source share one label column, START at the form\'s end', async () => {
53
+ const sb = await Sandbox.create('htform');
54
+ try {
55
+ await sb.writeTemplate(triageTemplate('ZZB3 HT', 'ZZB3'));
56
+ const app = await sb.hitTriage();
57
+ const root = app.infoView.root;
58
+ let g = geometry(root);
59
+ const near = (a?: number, b?: number) => a !== undefined && b !== undefined && Math.abs(a - b) <= 1;
60
+ await waitUntil(() => (g = geometry(root)).start > 0 && near(g.labels['Template'], g.labels['Campaign Name']),
61
+ () => `Template does not line up with Campaign Name: ${JSON.stringify(g)}`, 10000);
62
+ expect(near(g.labels[i18n.dataSourceFunction], g.labels['Campaign Name']), true, `the data source caption: ${JSON.stringify(g)}`);
63
+ expect(Math.abs(g.start - g.form) <= 2, true, `START ends where the form does: ${JSON.stringify(g)}`);
64
+ } finally {
65
+ await sb.dispose();
66
+ }
67
+ }, {timeout: 60000});
68
+
69
+ test('PepTriage: a data source that answers no rows creates no campaign and says so', async () => {
70
+ const started = await startOver(pepTriageTemplate('ZZB3 PT', 'ZZB3'), PepTriageDataSourceTag, {Chemist: 'Ann'});
71
+ expectSame(started, [], 'the campaigns START created');
72
+ expect(hasBalloon('Demo Peptide Sequences returned no rows, so no campaign was created'), true, 'the warning');
73
+ }, {timeout: 60000});
74
+
75
+ test('Hit Triage: a data source that answers no rows creates no campaign and says so', async () => {
76
+ const started = await startOver(triageTemplate('ZZB3 HT', 'ZZB3'), HitTriageDataSourceTag,
77
+ {'Number Of Molecules': '0', 'Chemist': 'Ann'});
78
+ expectSame(started, [], 'the campaigns START created');
79
+ expect(hasBalloon('Demo Molecules variable returned no rows, so no campaign was created'), true, 'the warning');
80
+ }, {timeout: 60000});
81
+ });
@@ -0,0 +1,384 @@
1
+ import * as grok from 'datagrok-api/grok';
2
+ import * as ui from 'datagrok-api/ui';
3
+ import * as DG from 'datagrok-api/dg';
4
+ import {category, expect, test, waitUntil} from '@datagrok-libraries/test/src/test';
5
+ import {byKind, byName, expectOperable, state, u2test, user} from '@datagrok-libraries/u2/testing';
6
+ import {PermissionsEditor} from '../app/shared/permissions-editor';
7
+ import {openTemplateEditor} from '../app/shared/template-editor';
8
+ import {CampaignGrouping, HDCampaignsGroupingLSKey} from '../app/consts';
9
+ import type {HitDesignApp} from '../app/hit-design-app';
10
+ import type {HitDesignTemplate, TriagePermissions} from '../app/types';
11
+ import {fieldText} from '../app/shared/campaign-catalog';
12
+ import {allUsers, designCampaign, designCsv, expectSame, formDate, noComputeTemplate, Sandbox} from './fixtures';
13
+
14
+ function openDialog(name: string): HTMLElement | undefined {
15
+ try {
16
+ return byKind(document, 'dialog').find((d) => state(d).name === name);
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
22
+
23
+ async function dialogNamed(name: string): Promise<HTMLElement> {
24
+ await waitUntil(() => openDialog(name) !== undefined, `the ${name} dialog did not open`, 15000);
25
+ return openDialog(name)!;
26
+ }
27
+
28
+ async function designApp(sb: Sandbox): Promise<HitDesignApp> {
29
+ const t = noComputeTemplate('ZZB3 Guards', 'ZZB3');
30
+ await sb.writeTemplate(t);
31
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-1', t), designCsv);
32
+ const app = await sb.hitDesign();
33
+ await sb.openDesign(app, 'ZZB3-1');
34
+ return app;
35
+ }
36
+
37
+ /** The Submit dialog of a sandbox Hit Design campaign, opened as its ribbon button opens it. */
38
+ async function submitDialog(sb: Sandbox): Promise<HTMLElement> {
39
+ const app = await designApp(sb);
40
+ app.submitView!.render();
41
+ return await dialogNamed('submit');
42
+ }
43
+
44
+ const openTracker = (app: HitDesignApp) =>
45
+ (app as unknown as {_session: {openTracker(): unknown}})._session.openTracker();
46
+
47
+ const HOVER_MARK = 'data-zzb3-hover';
48
+
49
+ // no script sets :hover: each :hover rule is copied right after itself onto a marker attribute (same specificity, same
50
+ // place in the cascade), so the element carrying the marker is styled as under the pointer
51
+ function hovered<T>(el: Element, read: () => T): T {
52
+ const added: [CSSStyleSheet | CSSGroupingRule, CSSRule][] = [];
53
+ const copy = (owner: CSSStyleSheet | CSSGroupingRule) => {
54
+ for (let i = owner.cssRules.length - 1; i >= 0; i--) {
55
+ const rule = owner.cssRules[i];
56
+ if (rule instanceof CSSGroupingRule)
57
+ copy(rule);
58
+ else if (rule instanceof CSSStyleRule && rule.selectorText.includes(':hover')) {
59
+ owner.insertRule(`${rule.selectorText.replace(/:hover/g, `[${HOVER_MARK}]`)} {${rule.style.cssText}}`, i + 1);
60
+ added.push([owner, owner.cssRules[i + 1]]);
61
+ }
62
+ }
63
+ };
64
+ try {
65
+ for (const sheet of Array.from(document.styleSheets)) {
66
+ try {
67
+ copy(sheet);
68
+ }
69
+ catch {
70
+ // another origin's sheet keeps its rules to itself
71
+ }
72
+ }
73
+ el.setAttribute(HOVER_MARK, '');
74
+ return read();
75
+ } finally {
76
+ el.removeAttribute(HOVER_MARK);
77
+ for (const [owner, rule] of added)
78
+ owner.deleteRule(Array.from(owner.cssRules).indexOf(rule));
79
+ }
80
+ }
81
+
82
+ type Rgba = [number, number, number, number];
83
+
84
+ function rgba(color: string): Rgba {
85
+ const srgb = /color\(srgb ([\d.]+) ([\d.]+) ([\d.]+)(?: \/ ([\d.]+))?\)/.exec(color);
86
+ if (srgb)
87
+ return [+srgb[1] * 255, +srgb[2] * 255, +srgb[3] * 255, srgb[4] === undefined ? 1 : +srgb[4]];
88
+ const [r, g, b, a] = (/rgba?\(([^)]*)\)/.exec(color)?.[1] ?? '0, 0, 0, 0').split(/[\s,/]+/).map(Number);
89
+ return [r, g, b, a ?? 1];
90
+ }
91
+
92
+ const over = (top: Rgba, under: Rgba): Rgba =>
93
+ [0, 1, 2].map((i) => top[i] * top[3] + under[i] * (1 - top[3])).concat(1) as Rgba;
94
+
95
+ function painted(el: Element): string {
96
+ let color: Rgba = [255, 255, 255, 1];
97
+ const chain: Element[] = [];
98
+ for (let at: Element | null = el; at !== null; at = at.parentElement)
99
+ chain.unshift(at);
100
+ for (const at of chain) {
101
+ const style = getComputedStyle(at);
102
+ color = over(rgba(style.backgroundColor), color);
103
+ const layers = Array.from(style.backgroundImage.matchAll(/gradient\((?:[^,(]*,\s*)?((?:rgba?|color)\([^)]*\))/g));
104
+ for (const layer of layers.reverse())
105
+ color = over(rgba(layer[1]), color);
106
+ }
107
+ return `rgb(${color.slice(0, 3).map(Math.round).join(', ')})`;
108
+ }
109
+
110
+ const textLook = (e: Element): string => `${getComputedStyle(e).color} ${getComputedStyle(e).fontWeight}`;
111
+
112
+ function breadcrumbsLinkLook(): string {
113
+ const host = ui.div([ui.breadcrumbs(['ZZB3 app', 'ZZB3 campaign']).root], 'd4-ribbon-name');
114
+ document.body.append(host);
115
+ try {
116
+ return textLook(host.querySelector('.ui-breadcrumbs-element a')!);
117
+ } finally {
118
+ host.remove();
119
+ }
120
+ }
121
+
122
+ const isOpen = (v: DG.ViewBase) => Array.from(grok.shell.views).some((x) => x.dart === v.dart);
123
+
124
+ /** What stopped `gesture`, or '' when nothing did. */
125
+ function refusal(gesture: () => void): string {
126
+ try {
127
+ gesture();
128
+ return '';
129
+ }
130
+ catch (e) {
131
+ return (e as Error).message;
132
+ }
133
+ }
134
+
135
+ async function closeWithCancel(dialog: HTMLElement): Promise<void> {
136
+ user.click(byName(dialog, 'Cancel'));
137
+ await waitUntil(() => !dialog.isConnected, 'CANCEL left the dialog open');
138
+ }
139
+
140
+ category('u2 guards', () => {
141
+ test('Submit: every control the dialog offers can be operated, the read-only rows\' pencils and download included',
142
+ u2test(async () => {
143
+ const sb = await Sandbox.create('guards');
144
+ try {
145
+ const dialog = await submitDialog(sb);
146
+ expectOperable(dialog);
147
+ await closeWithCancel(dialog);
148
+ } finally {
149
+ await sb.dispose();
150
+ }
151
+ }), {timeout: 120000});
152
+
153
+ test('Submit: the Name and File Path pencils edit in place, Escape gives the row back and keeps the dialog',
154
+ u2test(async () => {
155
+ const sb = await Sandbox.create('guards');
156
+ try {
157
+ const dialog = await submitDialog(sb);
158
+ const name = byName(dialog, 'Name');
159
+ expect(refusal(() => user.type(name, 'x')).includes('is read-only'), true,
160
+ 'Name takes no keys before its pencil');
161
+ user.click(byName(dialog, 'Edit Campaign Name'));
162
+ expect(state(name).readOnly, false, 'Name after its pencil');
163
+ user.type(name, 'ZZB3 renamed', {replace: true});
164
+ expect(state(name).value, 'ZZB3 renamed', 'Name while editing');
165
+ user.press(name, 'Escape');
166
+ expect(state(name).readOnly, true, 'Name after Escape');
167
+ expect(state(name).value, 'Friendly ZZB3-1', 'Escape keeps the saved name');
168
+ expect(dialog.isConnected, true, 'Escape in the row leaves the dialog open');
169
+ const path = byName(dialog, 'File Path');
170
+ user.click(byName(dialog, 'Edit file path'));
171
+ expect(state(path).readOnly, false, 'File Path after its pencil');
172
+ user.press(path, 'Escape');
173
+ expect(state(path).readOnly, true, 'File Path after Escape');
174
+ await closeWithCancel(dialog);
175
+ } finally {
176
+ await sb.dispose();
177
+ }
178
+ }), {timeout: 120000});
179
+
180
+ test('Submit: a Date field reads as the campaigns table shows it', u2test(async () => {
181
+ const sb = await Sandbox.create('guards');
182
+ try {
183
+ const dialog = await submitDialog(sb);
184
+ expect(state(byName(dialog, 'Deadline')).value, fieldText(formDate), 'the Deadline row');
185
+ await closeWithCancel(dialog);
186
+ } finally {
187
+ await sb.dispose();
188
+ }
189
+ }), {timeout: 120000});
190
+
191
+ test('Edit Permissions: every row control works; Can Edit checks Can View; OK saves both', u2test(async () => {
192
+ const saved: TriagePermissions[] = [];
193
+ void PermissionsEditor.show({view: [allUsers], edit: []}, {subject: 'ZZB3-1', save: (p) => saved.push(p)});
194
+ const dialog = await dialogNamed('edit-permissions');
195
+ expectOperable(dialog);
196
+ const [grid] = byKind(dialog, 'access-grid');
197
+ const view = byName(grid, 'Can View for All users') as HTMLInputElement;
198
+ const edit = byName(grid, 'Can Edit for All users') as HTMLInputElement;
199
+ expectSame([view.checked, edit.checked], [true, false], 'Can View, Can Edit as stored');
200
+ user.click(edit);
201
+ expectSame([view.checked, edit.checked], [true, true], 'Can View, Can Edit after checking Can Edit');
202
+ user.click(byName(dialog, 'OK'));
203
+ await waitUntil(() => !dialog.isConnected, 'OK left Edit Permissions open', 10000);
204
+ expectSame(saved, [{edit: [allUsers], view: [allUsers]}], 'what OK saved');
205
+ }), {timeout: 60000});
206
+
207
+ test('Edit Permissions of a campaign view closes with the view when another campaign opens',
208
+ u2test(async () => {
209
+ const sb = await Sandbox.create('guards');
210
+ try {
211
+ const t = noComputeTemplate('ZZB3 Guards', 'ZZB3');
212
+ await sb.writeTemplate(t);
213
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-1', t), designCsv);
214
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-2', t), designCsv);
215
+ const app = await sb.hitDesign();
216
+ await sb.openDesign(app, 'ZZB3-1');
217
+ const icon = document.querySelector<HTMLElement>('[data-u2-item="Edit campaign permissions"]');
218
+ expect(icon !== null, true, 'the ribbon\'s Edit campaign permissions');
219
+ icon!.click();
220
+ const dialog = await dialogNamed('edit-permissions');
221
+ await sb.openDesign(app, 'ZZB3-2');
222
+ await waitUntil(() => !dialog.isConnected, 'Edit Permissions of ZZB3-1 stayed open over ZZB3-2', 10000);
223
+ } finally {
224
+ await sb.dispose();
225
+ }
226
+ }), {timeout: 120000});
227
+
228
+ test('Submit: Enter in the edited Name saves it and keeps the dialog; Download gives the campaign\'s table',
229
+ u2test(async () => {
230
+ const sb = await Sandbox.create('guards');
231
+ const click = HTMLAnchorElement.prototype.click;
232
+ const downloads: string[] = [];
233
+ HTMLAnchorElement.prototype.click = function(this: HTMLAnchorElement) {
234
+ if (this.hasAttribute('download'))
235
+ downloads.push(this.download);
236
+ else
237
+ click.call(this);
238
+ };
239
+ try {
240
+ const dialog = await submitDialog(sb);
241
+ const name = byName(dialog, 'Name');
242
+ user.click(byName(dialog, 'Edit Campaign Name'));
243
+ user.type(name, 'ZZB3 renamed', {replace: true});
244
+ user.press(name, 'Enter');
245
+ await waitUntil(() => !dialog.isConnected || state(name).readOnly === true, 'Enter left the Name editing',
246
+ 30000);
247
+ expect(dialog.isConnected, true, 'Enter in the row leaves the dialog open');
248
+ await sb.savesDone();
249
+ expect((await sb.readCampaign('ZZB3-1')).friendlyName, 'ZZB3 renamed', 'the name Enter saved');
250
+ user.click(byName(dialog, 'Download'));
251
+ expectSame(downloads, ['ZZB3-1.csv'], 'what Download saved');
252
+ await closeWithCancel(dialog);
253
+ } finally {
254
+ HTMLAnchorElement.prototype.click = click;
255
+ await sb.dispose();
256
+ }
257
+ }), {timeout: 120000});
258
+
259
+ test('Edit Permissions: each row starts with its user\'s picture or its group\'s icon', u2test(async () => {
260
+ const me = DG.User.current().group;
261
+ void PermissionsEditor.show({view: [allUsers, me.id], edit: [me.id]}, {subject: 'ZZB3-1', save: () => true});
262
+ const dialog = await dialogNamed('edit-permissions');
263
+ const [grid] = byKind(dialog, 'access-grid');
264
+ const pictureOf = (principal: string): Element | null => {
265
+ const cell = Array.from(grid.querySelectorAll<HTMLTableRowElement>('tbody tr'))
266
+ .find((r) => r.dataset.u2Key === principal)?.cells[0];
267
+ const first = cell?.firstElementChild ?? null;
268
+ return first !== null && first !== cell!.lastElementChild ? first : null;
269
+ };
270
+ const icons = (el: Element | null) => {
271
+ try {
272
+ return el === null ? 0 : byKind(el, 'icon').length;
273
+ }
274
+ catch {
275
+ return 0;
276
+ }
277
+ };
278
+ const group = pictureOf(allUsers);
279
+ expect(group !== null && icons(group) === 1, true, 'the All users row starts with the group icon');
280
+ const person = pictureOf(me.id);
281
+ expect(person !== null && person.firstElementChild !== null && icons(person) === 0, true,
282
+ `the ${me.friendlyName} row starts with the user's picture or initials`);
283
+ await closeWithCancel(dialog);
284
+ }), {timeout: 60000});
285
+
286
+ test('Progress tracker: Escape and the close button keep the moves, and save them', u2test(async () => {
287
+ const sb = await Sandbox.create('guards');
288
+ try {
289
+ const app = await designApp(sb);
290
+ const df = app.dataFrame!;
291
+ for (const [row, how] of [[0, 'Escape'], [1, 'the close button']] as const) {
292
+ openTracker(app);
293
+ const tracker = await dialogNamed('progress-tracker');
294
+ const version = app.campaign!.version ?? 0;
295
+ df.set('Stage', row, 'Tested');
296
+ if (how === 'Escape')
297
+ user.press(tracker, 'Escape');
298
+ else
299
+ user.click(Array.from(tracker.querySelectorAll('button[aria-label="Close"]')).find((b) => !b.textContent)!);
300
+ await waitUntil(() => !tracker.isConnected, `${how} left the tracker open`, 10000);
301
+ await waitUntil(() => app.campaign?.version === version + 1 && !app.isSaving, `${how}: the move was not saved`,
302
+ 30000);
303
+ expect(df.get('Stage', row), 'Tested', `${how}: the move stays in the table`);
304
+ }
305
+ const saved = await grok.dapi.files.readCsv(sb.savePath('ZZB3-1'));
306
+ expectSame(saved.col('Stage')!.toList(), ['Tested', 'Tested'], 'the saved stages');
307
+ } finally {
308
+ await sb.dispose();
309
+ }
310
+ }), {timeout: 120000});
311
+
312
+ test('Template editor: a stage is free text: one typed in a new row is the template\'s stage', u2test(async () => {
313
+ const sb = await Sandbox.create('guards');
314
+ let created: HitDesignTemplate | undefined;
315
+ try {
316
+ const app = await sb.hitDesign();
317
+ await openTemplateEditor<HitDesignTemplate>({app, onCreated: (t) => created = t});
318
+ await waitUntil(() => grok.shell.v?.name === 'New Template', 'the template editor did not open', 15000);
319
+ const editor = byName(grok.shell.v.root, 'template-editor');
320
+ user.type(byName(editor, 'name'), 'ZZB3 Stages');
321
+ user.type(byName(editor, 'key'), 'ZZBS');
322
+ const stages = byName(editor, 'stages');
323
+ user.click(byName(stages, 'Add stage'));
324
+ user.type(byName(stages, 'Name'), 'ZZB3 assay review');
325
+ const create = byName(editor, 'Create');
326
+ await waitUntil(() => state(create).enabled, () => `CREATE stayed off: ${state(create).disabledReason}`, 30000);
327
+ user.click(create);
328
+ await waitUntil(() => created !== undefined, 'CREATE made no template', 30000);
329
+ expectSame(created!.stages, ['ZZB3 assay review'], 'the stages the template keeps');
330
+ } finally {
331
+ if (grok.shell.v?.name === 'New Template')
332
+ grok.shell.v.close();
333
+ await sb.dispose();
334
+ }
335
+ }), {timeout: 120000});
336
+
337
+ test('Campaigns table: the hovered row is marked, and not as a section header is', u2test(async () => {
338
+ const sb = await Sandbox.create('guards');
339
+ const grouping = localStorage.getItem(HDCampaignsGroupingLSKey);
340
+ try {
341
+ localStorage.setItem(HDCampaignsGroupingLSKey, CampaignGrouping.Status);
342
+ const t = noComputeTemplate('ZZB3 Guards', 'ZZB3');
343
+ await sb.writeTemplate(t);
344
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-1', t), designCsv);
345
+ await sb.writeCampaign(designCampaign(sb, 'ZZB3-2', t, {status: 'Submitted'}), designCsv);
346
+ const app = await sb.hitDesign();
347
+ const table = byName(app.infoView.root, 'campaigns');
348
+ const row = () => table.querySelector('tr[role="row"]');
349
+ const section = () => table.querySelector('th[role="rowheader"]');
350
+ await waitUntil(() => row() !== null && section() !== null,
351
+ 'the campaigns table shows no section with a campaign', 30000);
352
+ const resting = painted(row()!);
353
+ const header = painted(section()!);
354
+ const under = hovered(row()!, () => painted(row()!));
355
+ expect(under !== resting, true, `the row under the pointer looks as it rests: ${under}`);
356
+ expect(under !== header, true, `the row under the pointer looks like a section header: ${under}`);
357
+ } finally {
358
+ grouping === null ? localStorage.removeItem(HDCampaignsGroupingLSKey) :
359
+ localStorage.setItem(HDCampaignsGroupingLSKey, grouping);
360
+ await sb.dispose();
361
+ }
362
+ }), {timeout: 120000});
363
+
364
+ test('Campaign view: the crumb is a breadcrumbs link; a press on it closes the campaign', u2test(async () => {
365
+ const sb = await Sandbox.create('guards');
366
+ try {
367
+ const app = await designApp(sb);
368
+ const view = app.designView!;
369
+ const crumb = () => document.querySelector('.d4-view-ribbon > span.d4-ribbon-name');
370
+ await waitUntil(() => crumb()?.textContent === app.mainView.name,
371
+ 'the campaign view shows no crumb to the landing', 10000);
372
+ // the chrome hears a press on the crumb from the frame after it placed its group in the ribbon
373
+ await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
374
+ const link = crumb()!.querySelector('a');
375
+ expect(link !== null && textLook(link) === breadcrumbsLinkLook(), true,
376
+ `the crumb is not drawn as a ui.breadcrumbs link: ${textLook(link ?? crumb()!)} vs ${breadcrumbsLinkLook()}`);
377
+ user.click(link!);
378
+ await waitUntil(() => !isOpen(view), 'the press on the crumb left the campaign open', 10000);
379
+ expect(isOpen(app.mainView), true, 'the landing stays open');
380
+ } finally {
381
+ await sb.dispose();
382
+ }
383
+ }), {timeout: 120000});
384
+ });