@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.
- package/.grokignore +2 -0
- package/.turbo/turbo-build.log +25 -3
- package/CHANGELOG.md +78 -0
- package/CLAUDE.md +87 -10
- package/README_HD.md +14 -14
- package/README_HT.md +6 -6
- package/README_PH.md +110 -0
- package/bdd/bdd.config.json +3 -1
- package/bdd/bindings/campaign.ts +626 -0
- package/bdd/bindings/hit-design.ts +36 -42
- package/bdd/bindings/landing.ts +839 -0
- package/bdd/bindings/pepti-hit.ts +35 -0
- package/bdd/features/campaign/crumbs.feature +22 -0
- package/bdd/features/campaign/grid.feature +56 -0
- package/bdd/features/campaign/merge.feature +105 -0
- package/bdd/features/campaign/molecule-vid.feature +40 -0
- package/bdd/features/campaign/permissions.feature +46 -0
- package/bdd/features/campaign/progress-tracker.feature +89 -0
- package/bdd/features/campaign/refresh-hint.feature +33 -0
- package/bdd/features/campaign/ribbon.feature +49 -0
- package/bdd/features/campaign/stage-choices.feature +39 -0
- package/bdd/features/campaign/submit.feature +135 -0
- package/bdd/features/campaign/tracker-cards.feature +46 -0
- package/bdd/features/campaign/view-only.feature +37 -0
- package/bdd/features/landing/campaign-deep-links.feature +61 -0
- package/bdd/features/landing/hit-design-campaigns-fixes.feature +116 -0
- package/bdd/features/landing/hit-design-campaigns.feature +153 -0
- package/bdd/features/landing/hit-triage-campaigns.feature +99 -0
- package/bdd/features/landing/new-campaign.feature +69 -0
- package/bdd/features/landing/pep-triage-campaigns.feature +41 -0
- package/bdd/features/landing/pepti-hit-landing.feature +132 -0
- package/bdd/features/pepti-hit/helm-edit.feature +47 -0
- package/bdd/features/templates/template-editor.feature +130 -0
- package/bdd/features/templates/template-picker.feature +112 -0
- package/bdd/features/templates/triage-forms.feature +59 -0
- package/bdd/fixtures/bar-chart.layout +1 -0
- package/bdd/fixtures/merge-local.csv +2 -0
- package/bdd/generated/campaign/crumbs.test.ts +33 -0
- package/bdd/generated/campaign/grid.test.ts +79 -0
- package/bdd/generated/campaign/merge.test.ts +134 -0
- package/bdd/generated/campaign/molecule-vid.test.ts +52 -0
- package/bdd/generated/campaign/permissions.test.ts +58 -0
- package/bdd/generated/campaign/progress-tracker.test.ts +129 -0
- package/bdd/generated/campaign/refresh-hint.test.ts +44 -0
- package/bdd/generated/campaign/ribbon.test.ts +65 -0
- package/bdd/generated/campaign/stage-choices.test.ts +55 -0
- package/bdd/generated/campaign/submit.test.ts +167 -0
- package/bdd/generated/campaign/tracker-cards.test.ts +49 -0
- package/bdd/generated/campaign/view-only.test.ts +51 -0
- package/bdd/generated/hit-design/campaign-column-metadata.test.ts +1 -0
- package/bdd/generated/landing/campaign-deep-links.test.ts +68 -0
- package/bdd/generated/landing/hit-design-campaigns-fixes.test.ts +99 -0
- package/bdd/generated/landing/hit-design-campaigns.test.ts +160 -0
- package/bdd/generated/landing/hit-triage-campaigns.test.ts +107 -0
- package/bdd/generated/landing/new-campaign.test.ts +78 -0
- package/bdd/generated/landing/pep-triage-campaigns.test.ts +52 -0
- package/bdd/generated/landing/pepti-hit-landing.test.ts +130 -0
- package/bdd/generated/pepti-hit/helm-edit.test.ts +64 -0
- package/bdd/generated/templates/template-editor.test.ts +137 -0
- package/bdd/generated/templates/template-picker.test.ts +119 -0
- package/bdd/generated/templates/triage-forms.test.ts +68 -0
- package/css/hit-triage.css +27 -23
- package/dist/package-test.js +690 -4
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +318 -73
- package/dist/package.js.map +1 -1
- package/package.json +11 -7
- package/queries/locks.sql +37 -0
- package/src/app/accordeons/layout-input.ts +52 -44
- package/src/app/accordeons/new-campaign-accordeon.ts +91 -54
- package/src/app/accordeons/new-hit-design-campaign-accordeon.ts +3 -67
- package/src/app/accordeons/new-pep-triage-template-accordeon.ts +39 -41
- package/src/app/accordeons/new-template-accordeon.ts +41 -24
- package/src/app/ai/view-functions.ts +22 -19
- package/src/app/base-view.ts +99 -8
- package/src/app/consts.ts +8 -5
- package/src/app/dialogs/functions-dialog.ts +14 -9
- package/src/app/dialogs/merge-table-dialog.ts +181 -325
- package/src/app/hit-app-base.ts +61 -90
- package/src/app/hit-design-app.ts +481 -886
- package/src/app/hit-design-views/info-view.ts +57 -407
- package/src/app/hit-design-views/submit-view.ts +216 -111
- package/src/app/hit-design-views/tiles-view.ts +168 -123
- package/src/app/hit-design-views/utils.css +0 -8
- package/src/app/hit-triage-app.ts +69 -38
- package/src/app/hit-triage-views/info-view.ts +70 -371
- package/src/app/pep-triage-app.ts +2 -2
- package/src/app/pep-triage-views/info-view.ts +42 -83
- package/src/app/pepti-hit-app.ts +32 -183
- package/src/app/pepti-hits-views/info-view.ts +15 -37
- package/src/app/shared/campaign-catalog.ts +408 -0
- package/src/app/shared/campaign-session.ts +557 -0
- package/src/app/shared/compute-editor.ts +274 -0
- package/src/app/shared/hit-home.ts +45 -0
- package/src/app/shared/new-campaign-form.ts +90 -0
- package/src/app/shared/permissions-editor.ts +93 -0
- package/src/app/shared/template-editor.ts +331 -0
- package/src/app/shared/template-picker.ts +154 -0
- package/src/app/utils/merge-table.ts +183 -78
- package/src/app/utils.ts +34 -325
- package/src/package-api.ts +29 -8
- package/src/package-test.ts +17 -2
- package/src/package.g.ts +12 -8
- package/src/package.ts +19 -7
- package/src/tests/ai.ts +244 -0
- package/src/tests/campaign-layout.ts +82 -0
- package/src/tests/campaign-session.ts +168 -0
- package/src/tests/campaigns.ts +23 -0
- package/src/tests/catalog.ts +156 -0
- package/src/tests/compat.ts +482 -0
- package/src/tests/compute.ts +165 -0
- package/src/tests/fixtures.ts +359 -0
- package/src/tests/merge.ts +149 -0
- package/src/tests/owners.ts +11 -0
- package/src/tests/save-lock.ts +932 -0
- package/src/tests/storage.ts +106 -0
- package/src/tests/template-editor.ts +538 -0
- package/src/tests/templates.ts +143 -0
- package/src/tests/triage-start.ts +81 -0
- package/src/tests/u2-guards.ts +384 -0
- package/src/tests/vid.ts +77 -0
- package/src/app/accordeons/new-hit-design-template-accordeon.ts +0 -238
- package/src/app/dialogs/permissions-dialog.ts +0 -66
|
@@ -0,0 +1,839 @@
|
|
|
1
|
+
/* The landings of the four HitTriage apps (Hit Design, PeptiHit, Hit Triage, PepTriage) as the landing and template
|
|
2
|
+
features use them: the campaigns table (its rows, the icons above it, its groups, the row actions), the template
|
|
3
|
+
editor's own inputs, and the fixtures these features stand on.
|
|
4
|
+
|
|
5
|
+
A campaign is two files on the AppData share, campaign.json and enriched_table.csv, written here in the shape the
|
|
6
|
+
app writes them; Hit Design and PeptiHit also keep the time of the last save in the hitdesign database
|
|
7
|
+
(update_logs), which a fixture writes when its row says how long ago it was modified. A template is one file,
|
|
8
|
+
<app>/templates/<name>.json.
|
|
9
|
+
|
|
10
|
+
Every fixture carries the feature's {time}: a campaign code is a family in capitals, the time and a number
|
|
11
|
+
("BDDLND1761512345678-1"), a template name ends in the time, a template key is the family and the time. It goes
|
|
12
|
+
at feature end with what the feature made from it (the campaigns a template's key started through the UI, their
|
|
13
|
+
rows in the hitdesign database), read back until gone; the same family left by a run older than an hour is swept
|
|
14
|
+
when the next one starts, so a second run of the feature at the same time keeps its own.
|
|
15
|
+
|
|
16
|
+
The app keeps the campaign list it read for the life of the page (HTPackage.campaignsCache): campaigns
|
|
17
|
+
put on the server before the app opens drop that copy, as a fresh page would not have it; campaigns saved "from
|
|
18
|
+
elsewhere" leave it alone, which is what the refresh claims are about. */
|
|
19
|
+
import {Page} from '@playwright/test';
|
|
20
|
+
import {Given, Then, When, element, kind} from '@datagrok-libraries/bdd';
|
|
21
|
+
import {type ElementRef, atFeatureEnd, exactText, expect, gestures, locate, pollMs, STALE_AFTER_MS}
|
|
22
|
+
from '@datagrok-libraries/bdd/runtime';
|
|
23
|
+
|
|
24
|
+
declare const grok: any;
|
|
25
|
+
declare const DG: any;
|
|
26
|
+
|
|
27
|
+
type App = 'Hit Design' | 'PeptiHit' | 'Hit Triage' | 'PepTriage';
|
|
28
|
+
const APPS: App[] = ['Hit Design', 'PeptiHit', 'Hit Triage', 'PepTriage'];
|
|
29
|
+
const isDesign = (app: App): boolean => app === 'Hit Design' || app === 'PeptiHit';
|
|
30
|
+
const share = (app: App): string => `System:AppData/HitTriage/${app}`;
|
|
31
|
+
|
|
32
|
+
function appOf(name: string): App {
|
|
33
|
+
if (!APPS.includes(name as App))
|
|
34
|
+
throw new Error(`"${name}" is not a HitTriage app; the apps are ${APPS.join(', ')}`);
|
|
35
|
+
return name as App;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ---- the nouns -------------------------------------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
const TABLE = '[data-u2="catalog-table"][data-u2-name="campaigns"]';
|
|
41
|
+
|
|
42
|
+
element('campaigns table', {selector: TABLE,
|
|
43
|
+
description: 'the table under "Continue Campaign" on an app\'s landing'});
|
|
44
|
+
element('campaign columns icon', {selector: '[data-u2-name="campaigns-columns"]',
|
|
45
|
+
description: 'the eye above the campaigns table ("Edit visible columns in campaigns table"): a menu of the columns to show'});
|
|
46
|
+
element('campaign grouping icon', {selector: '[data-u2-name="campaigns-group"]',
|
|
47
|
+
description: 'the layer-group icon above the campaigns table ("Group Campaigns. Current: …"): a menu of the groupings'});
|
|
48
|
+
element('campaigns refresh icon', {selector: '[data-u2-name="campaigns-refresh"]',
|
|
49
|
+
description: 'the sync icon above the campaigns table ("Refresh campaigns table")'});
|
|
50
|
+
kind('campaign row', {
|
|
51
|
+
selector: `${TABLE} tr.u2-table-row`,
|
|
52
|
+
match: ['label'],
|
|
53
|
+
labelSelector: ':scope > td:first-child',
|
|
54
|
+
parts: {'permissions icon': '[aria-label="Manage campaign permissions"]', 'delete icon': '[aria-label="Delete campaign"]',
|
|
55
|
+
'name link': 'a'},
|
|
56
|
+
description: 'a row of the campaigns table by the campaign\'s name ("BDD Alpha" campaign row); "permissions icon of …" and "delete icon of …" are its row actions',
|
|
57
|
+
});
|
|
58
|
+
kind('campaign group', {
|
|
59
|
+
selector: `${TABLE} tr.u2-table-section`,
|
|
60
|
+
match: ['label'],
|
|
61
|
+
labelSelector: '[data-u2-part="item-label"]',
|
|
62
|
+
description: 'the header of a group of the campaigns table by its label ("In Progress" campaign group); expanded or collapsed',
|
|
63
|
+
});
|
|
64
|
+
element('HELM editor dialog', {selector: '.d4-dialog-full-screen:has([data-testid="app-root"])',
|
|
65
|
+
description: 'the full-screen HELM editor (Helm:editMoleculeCell) a new PeptiHit campaign opens on its first row; no title, CANCEL and OK'});
|
|
66
|
+
const TEMPLATE_EDITOR = '[data-u2-name="template-editor"]';
|
|
67
|
+
element('template name input', {selector: `${TEMPLATE_EDITOR} [data-u2-name="name"], .ui-form [name="input-host-Name"]:not(.ui-items-grid *)`,
|
|
68
|
+
description: 'the Name input of the template editor\'s Details (Hit Design and PeptiHit: u2; Hit Triage and PepTriage: the platform form, where a field row has a Name input too)'});
|
|
69
|
+
element('template key input', {selector: `${TEMPLATE_EDITOR} [data-u2-name="key"], .ui-form [name="input-host-Key"]`,
|
|
70
|
+
description: 'the Key input of the template editor\'s Details: the prefix of the campaign codes'});
|
|
71
|
+
|
|
72
|
+
// ---- the accounts ----------------------------------------------------------------------------------------------
|
|
73
|
+
|
|
74
|
+
interface Account {id: string; name: string; group: string}
|
|
75
|
+
|
|
76
|
+
function accounts(page: Page): Promise<{me: Account, second: Account | null}> {
|
|
77
|
+
return page.evaluate(async (login) => {
|
|
78
|
+
const me = DG.User.current();
|
|
79
|
+
const second = login ? await grok.dapi.users.filter(`login = "${login}"`).first() : null;
|
|
80
|
+
return {me: {id: me.id, name: me.friendlyName, group: me.group.id},
|
|
81
|
+
second: second ? {id: second.id, name: second.friendlyName, group: second.group.id} : null};
|
|
82
|
+
}, process.env.DATAGROK_SHARING_LOGIN ?? null);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ---- the fixtures: names, families, sweeps ---------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
const CODE = /^([A-Z]+)(\d{13})-(\d+)$/;
|
|
88
|
+
const KEY = /^([A-Z]+)(\d{13})$/;
|
|
89
|
+
const TEMPLATE_NAME = /^(.*\S)\s+(\d{13})$/;
|
|
90
|
+
const stale = (time: string | number): boolean => Date.now() - Number(time) > STALE_AFTER_MS;
|
|
91
|
+
|
|
92
|
+
function codeParts(code: string): {family: string, prefix: string} {
|
|
93
|
+
const m = CODE.exec(code);
|
|
94
|
+
if (!m)
|
|
95
|
+
throw new Error(`a fixture campaign's code is a family in capitals, the feature's {time} and a number ("BDDLND{time}-1"), not "${code}"`);
|
|
96
|
+
return {family: m[1], prefix: m[1] + m[2]};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function keyParts(key: string): {family: string, prefix: string} {
|
|
100
|
+
const m = KEY.exec(key);
|
|
101
|
+
if (!m)
|
|
102
|
+
throw new Error(`a fixture template's key is a family in capitals and the feature's {time} ("BDDNEW{time}"), not "${key}"`);
|
|
103
|
+
return {family: m[1], prefix: key};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function templateFamily(name: string): string {
|
|
107
|
+
const m = TEMPLATE_NAME.exec(name);
|
|
108
|
+
if (!m)
|
|
109
|
+
throw new Error(`a fixture template's name ends in the feature's {time} ("BDD Picker {time}"), not "${name}"`);
|
|
110
|
+
return m[1];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** What a sweep removes: the campaign folders of this run's prefixes, the stale ones of the families, and their rows in
|
|
114
|
+
* the hitdesign database. Returns what is left ('' when all of it is gone). */
|
|
115
|
+
async function sweepCampaigns(page: Page, app: App, families: string[], prefixes: string[]): Promise<string> {
|
|
116
|
+
const root = `${share(app)}/campaigns`;
|
|
117
|
+
const names: string[] = await page.evaluate(async (r) => (await grok.dapi.files.list(r))
|
|
118
|
+
.filter((f: any) => f.isDirectory).map((f: any) => f.name), root);
|
|
119
|
+
const doomed = names.filter((n) => prefixes.some((p) => n.startsWith(`${p}-`)) ||
|
|
120
|
+
(CODE.test(n) && families.includes(CODE.exec(n)![1]) && stale(CODE.exec(n)![2])));
|
|
121
|
+
const cutoff = Date.now() - STALE_AFTER_MS;
|
|
122
|
+
const where = [...prefixes.map((p) => `campaign_id like '${p}-%'`),
|
|
123
|
+
...families.map((f) => `(campaign_id ~ '^${f}[0-9]{13}-' and substring(campaign_id from '^${f}([0-9]{13})')::bigint < ${cutoff})`)];
|
|
124
|
+
return page.evaluate(async ([r, ids, a, w, design]) => {
|
|
125
|
+
for (const id of ids)
|
|
126
|
+
await grok.dapi.files.delete(`${r}/${id}`);
|
|
127
|
+
const left: string[] = [];
|
|
128
|
+
for (const id of ids) {
|
|
129
|
+
if (await grok.dapi.files.exists(`${r}/${id}`))
|
|
130
|
+
left.push(`folder ${id}`);
|
|
131
|
+
}
|
|
132
|
+
if (design && w.length > 0) {
|
|
133
|
+
const conn = (await grok.dapi.connections.filter('name = "hitdesign"').list())
|
|
134
|
+
.find((c: any) => c.nqName === 'HitTriage:hitdesign');
|
|
135
|
+
const cond = `app_name = '${a}' and (${w.join(' or ')})`;
|
|
136
|
+
for (const table of ['update_logs', 'campaign_locks', 'campaign_vids'])
|
|
137
|
+
await conn.query('bdd-landing-cleanup', `delete from hitdesign.${table} where ${cond} returning campaign_id`).apply();
|
|
138
|
+
for (const table of ['update_logs', 'campaign_locks', 'campaign_vids']) {
|
|
139
|
+
const rows = (await conn.query('bdd-landing-cleanup', `select campaign_id from hitdesign.${table} where ${cond}`).apply()).rowCount;
|
|
140
|
+
if (rows > 0)
|
|
141
|
+
left.push(`${rows} row(s) in hitdesign.${table}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return left.join(', ');
|
|
145
|
+
}, [root, doomed, app, where, isDesign(app)] as [string, string[], string, string[], boolean]);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function sweepTemplates(page: Page, app: App, families: string[], names: string[]): Promise<{left: string, keys: string[]}> {
|
|
149
|
+
const root = `${share(app)}/templates`;
|
|
150
|
+
const files: string[] = await page.evaluate(async (r) => (await grok.dapi.files.list(r))
|
|
151
|
+
.filter((f: any) => !f.isDirectory && f.name.endsWith('.json')).map((f: any) => f.name.slice(0, -5)), root);
|
|
152
|
+
const doomed = files.filter((n) => names.includes(n) ||
|
|
153
|
+
(TEMPLATE_NAME.test(n) && families.includes(TEMPLATE_NAME.exec(n)![1]) && stale(TEMPLATE_NAME.exec(n)![2])));
|
|
154
|
+
return page.evaluate(async ([r, ds]) => {
|
|
155
|
+
const keys: string[] = [];
|
|
156
|
+
for (const n of ds) {
|
|
157
|
+
try {
|
|
158
|
+
keys.push(String(JSON.parse(await grok.dapi.files.readAsText(`${r}/${n}.json`)).key ?? ''));
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// a file that no longer parses goes all the same
|
|
162
|
+
}
|
|
163
|
+
await grok.dapi.files.delete(`${r}/${n}.json`);
|
|
164
|
+
}
|
|
165
|
+
const left: string[] = [];
|
|
166
|
+
for (const n of ds) {
|
|
167
|
+
if (await grok.dapi.files.exists(`${r}/${n}.json`))
|
|
168
|
+
left.push(`template ${n}`);
|
|
169
|
+
}
|
|
170
|
+
return {left: left.join(', '), keys: keys.filter((k) => k !== '')};
|
|
171
|
+
}, [root, doomed] as [string, string[]]);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The list of campaigns the page read is the app's own cache for the life of the page: after a feature removes its
|
|
175
|
+
* campaigns, a later feature on the same page would still see them listed. */
|
|
176
|
+
function dropPageCopy(page: Page, app: App): Promise<void> {
|
|
177
|
+
return page.evaluate((a) => {
|
|
178
|
+
const cache = (window as any).hittriage?._package?.campaignsCache;
|
|
179
|
+
if (cache)
|
|
180
|
+
delete cache[a];
|
|
181
|
+
}, app);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function readBack(what: string, sweep: () => Promise<string>): Promise<void> {
|
|
185
|
+
let left = '';
|
|
186
|
+
await expect.poll(async () => left = await sweep(), {message: `${what} removed from the server`, timeout: pollMs(30000)})
|
|
187
|
+
.toBe('').catch((e) => {
|
|
188
|
+
throw new Error(`${what} is still on the server: ${left || e?.message}`);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The campaigns of a template key that a feature started through the UI go with the template. */
|
|
193
|
+
function campaignPrefixesOf(keys: string[]): {families: string[], prefixes: string[]} {
|
|
194
|
+
const parts = keys.filter((k) => KEY.test(k)).map(keyParts);
|
|
195
|
+
return {families: [...new Set(parts.map((p) => p.family))], prefixes: parts.map((p) => p.prefix)};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ---- the fixtures: campaigns -----------------------------------------------------------------------------------
|
|
199
|
+
|
|
200
|
+
const SMILES = ['CCO', 'c1ccccc1', 'CC(=O)O', 'CCN', 'CCCC', 'c1ccncc1', 'CC(C)O', 'OCCO', 'CS(C)=O', 'C1CCCCC1'];
|
|
201
|
+
const HELMS = ['PEPTIDE1{A.G}$$$$V2.0', 'PEPTIDE1{G.A.K}$$$$V2.0', 'PEPTIDE1{L.A}$$$$V2.0', 'PEPTIDE1{K.K.G}$$$$V2.0'];
|
|
202
|
+
const NO_COMPUTE = {descriptors: {enabled: false, args: []}, functions: [], scripts: [], queries: []};
|
|
203
|
+
const COLUMNS = ['code', 'name', 'status', 'created', 'molecules', 'author', 'can view', 'can edit', 'template', 'fields', 'modified'];
|
|
204
|
+
|
|
205
|
+
interface CampaignFile {code: string, json: any, csv: string, modified: number | null}
|
|
206
|
+
|
|
207
|
+
/** "Owner = Ann; Due = date 2026-11-15": a Date field is stored the way the new-campaign form stores it. */
|
|
208
|
+
function parseFields(text: string): {values: {[k: string]: any}, defs: {name: string, type: string, required: boolean}[]} {
|
|
209
|
+
const values: {[k: string]: any} = {};
|
|
210
|
+
const defs: {name: string, type: string, required: boolean}[] = [];
|
|
211
|
+
for (const part of text.split(';').map((p) => p.trim()).filter((p) => p !== '')) {
|
|
212
|
+
const [name, ...rest] = part.split('=');
|
|
213
|
+
const value = rest.join('=').trim();
|
|
214
|
+
const date = /^date\s+(\d{4}-\d{2}-\d{2})$/.exec(value);
|
|
215
|
+
if (date) {
|
|
216
|
+
const d = new Date(`${date[1]}T12:00:00Z`);
|
|
217
|
+
values[name.trim()] = {_value: d.getTime(), isUtc: false, date: d.toISOString()};
|
|
218
|
+
}
|
|
219
|
+
else
|
|
220
|
+
values[name.trim()] = value;
|
|
221
|
+
defs.push({name: name.trim(), type: date ? 'Date' : 'String', required: false});
|
|
222
|
+
}
|
|
223
|
+
return {values, defs};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function campaignFiles(app: App, table: string[][], who: {me: Account, second: Account | null}): CampaignFile[] {
|
|
227
|
+
const [header, ...rows] = table;
|
|
228
|
+
const unknown = header.filter((h) => !COLUMNS.includes(h));
|
|
229
|
+
if (unknown.length > 0 || !header.includes('code'))
|
|
230
|
+
throw new Error(`the campaigns table takes the columns ${COLUMNS.join(', ')} (code required); it has ${unknown.join(', ')}`);
|
|
231
|
+
const today = new Date();
|
|
232
|
+
return rows.map((cells) => {
|
|
233
|
+
const r: {[k: string]: string} = {};
|
|
234
|
+
header.forEach((h, i) => r[h] = cells[i]?.trim() ?? '');
|
|
235
|
+
const code = r['code'];
|
|
236
|
+
const {prefix} = codeParts(code);
|
|
237
|
+
const author = (r['author'] || 'me') === 'me' ? who.me : who.second;
|
|
238
|
+
if (!author)
|
|
239
|
+
throw new Error(`"${code}" is authored by the sharing user, and the run has no second account (DATAGROK_SHARING_LOGIN)`);
|
|
240
|
+
const groups = (v: string) => (v || 'everyone') === 'everyone' ? [DG_ALL_USERS] : [author.group];
|
|
241
|
+
const n = Number(r['molecules'] || '1');
|
|
242
|
+
const gone = /^gone:\s*/.test(r['template'] ?? '');
|
|
243
|
+
const templateName = (r['template'] ?? '').replace(/^gone:\s*/, '') || prefix;
|
|
244
|
+
const {values, defs} = parseFields(r['fields'] ?? '');
|
|
245
|
+
const template: any = {name: templateName, key: prefix, campaignFields: defs, compute: NO_COMPUTE};
|
|
246
|
+
const createDate = r['created'] || `${today.getFullYear()}/${today.getMonth() + 1}/${today.getDate()}`;
|
|
247
|
+
const common: any = {
|
|
248
|
+
name: code, ...(r['name'] ? {friendlyName: r['name']} : {}), templateName, status: r['status'] || 'In Progress',
|
|
249
|
+
createDate, campaignFields: values, rowCount: n, filteredRowCount: n,
|
|
250
|
+
authorUserId: author.id, authorUserFriendlyName: author.name, lastModifiedUserName: author.name,
|
|
251
|
+
permissions: {view: groups(r['can view']), edit: groups(r['can edit'])},
|
|
252
|
+
};
|
|
253
|
+
const modified = r['modified'] ? Number(r['modified']) : null;
|
|
254
|
+
if (isDesign(app)) {
|
|
255
|
+
const helm = app === 'PeptiHit';
|
|
256
|
+
template.stages = ['Design'];
|
|
257
|
+
const cols = [...(helm ? ['Helm'] : []), 'Molecule', 'Stage', 'V-iD'];
|
|
258
|
+
const csv = [cols.join(','), ...Array.from({length: n}, (_, i) =>
|
|
259
|
+
[...(helm ? [HELMS[i % HELMS.length]] : []), SMILES[i % SMILES.length], 'Design', ''].join(','))].join('\n') + '\n';
|
|
260
|
+
const json = {...common,
|
|
261
|
+
columnSemTypes: {...(helm ? {Helm: 'Macromolecule'} : {}), Molecule: 'Molecule', Stage: null, 'V-iD': null},
|
|
262
|
+
savePath: `System.AppData/HitTriage/${app}/campaigns/${code}/enriched_table.csv`,
|
|
263
|
+
columnTypes: {...(helm ? {Helm: 'string'} : {}), Molecule: 'string', Stage: 'string', 'V-iD': 'string'},
|
|
264
|
+
columnTags: helm ? {Helm: {'units': 'helm', 'cell.renderer': 'helm', '.alphabetIsMultichar': 'true'}} : {},
|
|
265
|
+
version: 1, ...(gone ? {} : {template})};
|
|
266
|
+
return {code, json, csv, modified};
|
|
267
|
+
}
|
|
268
|
+
const pep = app === 'PepTriage';
|
|
269
|
+
const cols = [...(pep ? ['Helm'] : []), 'Molecule', 'Selected hits'];
|
|
270
|
+
const csv = [cols.join(','), ...Array.from({length: n}, (_, i) =>
|
|
271
|
+
[...(pep ? [HELMS[i % HELMS.length]] : []), SMILES[i % SMILES.length], 'false'].join(','))].join('\n') + '\n';
|
|
272
|
+
const json = {...common, filters: [],
|
|
273
|
+
ingest: {type: 'File', query: `${share(app)}/campaigns/${code}/enriched_table.csv`, molColName: 'Molecule'},
|
|
274
|
+
columnSemTypes: {...(pep ? {Helm: 'Macromolecule'} : {}), Molecule: 'Molecule', 'Selected hits': null},
|
|
275
|
+
columnTypes: {...(pep ? {Helm: 'string'} : {}), Molecule: 'string', 'Selected hits': 'bool'},
|
|
276
|
+
...(gone ? {} : {template: {...template, dataSourceType: 'File', ...(pep ? {sequenceColumnName: 'Helm'} : {})}})};
|
|
277
|
+
return {code, json, csv, modified};
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const DG_ALL_USERS = 'a4b45840-9a50-11e6-9cc9-8546b8bf62e6';
|
|
282
|
+
|
|
283
|
+
async function writeCampaigns(page: Page, app: App, files: CampaignFile[], freshList: boolean): Promise<void> {
|
|
284
|
+
// written oldest first, so the share's own times agree with the "modified" column
|
|
285
|
+
const ordered = [...files].sort((a, b) => (b.modified ?? 0) - (a.modified ?? 0));
|
|
286
|
+
await page.evaluate(async ([r, a, fs, design, drop]) => {
|
|
287
|
+
let conn: any = null;
|
|
288
|
+
for (const f of fs) {
|
|
289
|
+
await grok.dapi.files.writeAsText(`${r}/${f.code}/enriched_table.csv`, f.csv);
|
|
290
|
+
await grok.dapi.files.writeAsText(`${r}/${f.code}/campaign.json`, JSON.stringify(f.json));
|
|
291
|
+
if (design && f.modified !== null) {
|
|
292
|
+
conn ??= (await grok.dapi.connections.filter('name = "hitdesign"').list()).find((c: any) => c.nqName === 'HitTriage:hitdesign');
|
|
293
|
+
await conn.query('bdd-landing-fixture', `insert into hitdesign.update_logs (app_name, campaign_id, updated_at) ` +
|
|
294
|
+
`values ('${a}', '${f.code}', now() - interval '${Number(f.modified)} minutes') on conflict (app_name, campaign_id) ` +
|
|
295
|
+
`do update set updated_at = excluded.updated_at returning campaign_id`).apply();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const cache = (window as any).hittriage?._package?.campaignsCache;
|
|
299
|
+
if (drop && cache)
|
|
300
|
+
delete cache[a];
|
|
301
|
+
}, [`${share(app)}/campaigns`, app, ordered, isDesign(app), freshList] as [string, string, CampaignFile[], boolean, boolean]);
|
|
302
|
+
const missing: string[] = await page.evaluate(async ([r, codes]) => {
|
|
303
|
+
const out: string[] = [];
|
|
304
|
+
for (const c of codes) {
|
|
305
|
+
if (!await grok.dapi.files.exists(`${r}/${c}/campaign.json`))
|
|
306
|
+
out.push(c);
|
|
307
|
+
}
|
|
308
|
+
return out;
|
|
309
|
+
}, [`${share(app)}/campaigns`, files.map((f) => f.code)] as [string, string[]]);
|
|
310
|
+
if (missing.length > 0)
|
|
311
|
+
throw new Error(`the ${app} campaigns ${missing.join(', ')} did not reach the server`);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async function putCampaigns(page: Page, appName: string, table: string[][], freshList: boolean): Promise<void> {
|
|
315
|
+
const app = appOf(appName);
|
|
316
|
+
const files = campaignFiles(app, table, await accounts(page));
|
|
317
|
+
const parts = files.map((f) => codeParts(f.code));
|
|
318
|
+
const families = [...new Set(parts.map((p) => p.family))];
|
|
319
|
+
const prefixes = [...new Set(parts.map((p) => p.prefix))];
|
|
320
|
+
// a campaign saved from elsewhere joins the ones the feature put there: a sweep of the prefix would remove them
|
|
321
|
+
if (freshList)
|
|
322
|
+
await readBack(`the ${app} campaigns of ${prefixes.join(', ')}`, () => sweepCampaigns(page, app, families, prefixes));
|
|
323
|
+
atFeatureEnd(page, async () => {
|
|
324
|
+
await readBack(`the ${app} campaigns of ${prefixes.join(', ')}`, () => sweepCampaigns(page, app, families, prefixes));
|
|
325
|
+
await dropPageCopy(page, app);
|
|
326
|
+
});
|
|
327
|
+
await writeCampaigns(page, app, files, freshList);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export const campaignsOnServer = Given('the {string} campaigns are on the server:',
|
|
331
|
+
(page: Page, app: string, table: string[][]) => putCampaigns(page, app, table, true),
|
|
332
|
+
{tier: 'api', description: 'campaign folders written through the JS API in the shape the app writes (columns: code, name, status, created, molecules, author me|sharing user, can view / can edit everyone|author, template <name> or "gone: <name>" for a legacy campaign with no snapshot, fields "Owner = Ann; Due = date 2026-11-15", modified = minutes ago, also written to hitdesign.update_logs); the page drops its cached list, as a fresh page would; removed at feature end with every campaign of their prefixes and their hitdesign rows, read back'});
|
|
333
|
+
|
|
334
|
+
export const campaignsFromElsewhere = When('the {string} campaigns are saved on the server from elsewhere:',
|
|
335
|
+
(page: Page, app: string, table: string[][]) => putCampaigns(page, app, table, false),
|
|
336
|
+
{tier: 'api', description: 'the same files as "… campaigns are on the server", written while the landing is open, as another session would save them, beside the campaigns already there: the page keeps the list it read'});
|
|
337
|
+
|
|
338
|
+
// ---- the fixtures: templates ------------------------------------------------------------------------------------
|
|
339
|
+
|
|
340
|
+
const TEMPLATE_COLUMNS = ['name', 'key', 'fields', 'stages', 'submit', 'layout'];
|
|
341
|
+
const SUBMIT_FUNCTIONS: {[friendly: string]: {fName: string, package: string}} =
|
|
342
|
+
{'Demo File Submit': {fName: 'demoFileSubmit', package: 'HitTriage'}};
|
|
343
|
+
const FIELD_TYPES = ['String', 'Number', 'Boolean', 'Date', 'Molecule'];
|
|
344
|
+
|
|
345
|
+
/** "Owner: String required; Budget: Number" */
|
|
346
|
+
function parseFieldDefs(text: string): {name: string, type: string, required: boolean}[] {
|
|
347
|
+
return text.split(';').map((p) => p.trim()).filter((p) => p !== '').map((p) => {
|
|
348
|
+
const m = /^(.+?):\s*(\w+)(\s+required)?$/.exec(p);
|
|
349
|
+
if (!m || !FIELD_TYPES.includes(m[2]))
|
|
350
|
+
throw new Error(`a template field is "<name>: <${FIELD_TYPES.join('|')}>[ required]", not "${p}"`);
|
|
351
|
+
return {name: m[1].trim(), type: m[2], required: !!m[3]};
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** "bar chart of Stage" or "scatter plot of MolWt": the layout a table view saves with that one viewer next to its grid. */
|
|
356
|
+
function layoutViewState(page: Page, text: string): Promise<string> {
|
|
357
|
+
const m = /^(bar chart|scatter plot) of (\S+)$/.exec(text);
|
|
358
|
+
if (!m)
|
|
359
|
+
throw new Error(`a fixture template's layout is "bar chart of <column>" or "scatter plot of <column>", not "${text}"`);
|
|
360
|
+
return page.evaluate(async ([viewer, col]) => {
|
|
361
|
+
const extra = ['Molecule', 'Stage', 'V-iD'].includes(col) ? '' : `,${col}`;
|
|
362
|
+
const df = DG.DataFrame.fromCsv(`Molecule,Stage,V-iD${extra}\nCCO,Design,${extra ? ',1.5' : ''}\nc1ccccc1,Design,${extra ? ',2.5' : ''}\n`);
|
|
363
|
+
df.name = 'bdd-layout-fixture';
|
|
364
|
+
const tv = grok.shell.addTableView(df);
|
|
365
|
+
tv.addViewer(viewer === 'bar chart' ? 'Bar chart' : 'Scatter plot',
|
|
366
|
+
viewer === 'bar chart' ? {splitColumnName: col} : {xColumnName: col, yColumnName: col});
|
|
367
|
+
const state = tv.saveLayout().viewState;
|
|
368
|
+
tv.close();
|
|
369
|
+
grok.shell.closeTable(df);
|
|
370
|
+
return state;
|
|
371
|
+
}, [m[1], m[2]] as [string, string]);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
async function templateJson(page: Page, app: App, r: {[k: string]: string}): Promise<any> {
|
|
375
|
+
keyParts(r['key']);
|
|
376
|
+
templateFamily(r['name']);
|
|
377
|
+
const submit = r['submit'] ? SUBMIT_FUNCTIONS[r['submit']] : undefined;
|
|
378
|
+
if (r['submit'] && !submit)
|
|
379
|
+
throw new Error(`the fixture submit functions are ${Object.keys(SUBMIT_FUNCTIONS).join(', ')}, not "${r['submit']}"`);
|
|
380
|
+
const out: any = {name: r['name'], key: r['key'], campaignFields: parseFieldDefs(r['fields'] ?? '')};
|
|
381
|
+
if (isDesign(app))
|
|
382
|
+
out.stages = (r['stages'] ?? '').split(',').map((s) => s.trim()).filter((s) => s !== '');
|
|
383
|
+
else
|
|
384
|
+
out.dataSourceType = 'File';
|
|
385
|
+
if (app === 'PepTriage')
|
|
386
|
+
out.sequenceColumnName = 'Helm';
|
|
387
|
+
if (r['layout'])
|
|
388
|
+
out.layoutViewState = await layoutViewState(page, r['layout']);
|
|
389
|
+
out.compute = NO_COMPUTE;
|
|
390
|
+
if (submit)
|
|
391
|
+
out.submit = submit;
|
|
392
|
+
return out;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
async function templatesAtEnd(page: Page, app: App, names: string[], keys: string[]): Promise<void> {
|
|
396
|
+
const families = [...new Set(names.map(templateFamily))];
|
|
397
|
+
const what = `the ${app} templates ${names.join(', ')}`;
|
|
398
|
+
const sweep = async (): Promise<string> => {
|
|
399
|
+
const {left, keys: found} = await sweepTemplates(page, app, families, names);
|
|
400
|
+
const c = campaignPrefixesOf([...keys, ...found]);
|
|
401
|
+
const campaignsLeft = c.prefixes.length > 0 ? await sweepCampaigns(page, app, c.families, c.prefixes) : '';
|
|
402
|
+
return [left, campaignsLeft].filter((s) => s !== '').join(', ');
|
|
403
|
+
};
|
|
404
|
+
await readBack(what, sweep);
|
|
405
|
+
atFeatureEnd(page, async () => {
|
|
406
|
+
await readBack(what, sweep);
|
|
407
|
+
await dropPageCopy(page, app);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export const templatesOnServer = Given('the {string} templates are on the server:',
|
|
412
|
+
async (page: Page, appName: string, table: string[][]) => {
|
|
413
|
+
const app = appOf(appName);
|
|
414
|
+
const [header, ...rows] = table;
|
|
415
|
+
const unknown = header.filter((h) => !TEMPLATE_COLUMNS.includes(h));
|
|
416
|
+
if (unknown.length > 0 || !header.includes('name') || !header.includes('key'))
|
|
417
|
+
throw new Error(`the templates table takes the columns ${TEMPLATE_COLUMNS.join(', ')} (name and key required); it has ${unknown.join(', ')}`);
|
|
418
|
+
const specs = rows.map((cells) => {
|
|
419
|
+
const r: {[k: string]: string} = {};
|
|
420
|
+
header.forEach((h, i) => r[h] = cells[i]?.trim() ?? '');
|
|
421
|
+
return r;
|
|
422
|
+
});
|
|
423
|
+
await templatesAtEnd(page, app, specs.map((r) => r['name']), specs.map((r) => r['key']));
|
|
424
|
+
const jsons = [];
|
|
425
|
+
for (const r of specs)
|
|
426
|
+
jsons.push(await templateJson(page, app, r));
|
|
427
|
+
await page.evaluate(async ([root, ts]) => {
|
|
428
|
+
for (const t of ts)
|
|
429
|
+
await grok.dapi.files.writeAsText(`${root}/${t.name}.json`, JSON.stringify(t));
|
|
430
|
+
}, [`${share(app)}/templates`, jsons] as [string, any[]]);
|
|
431
|
+
}, {tier: 'api', description: 'template files written through the JS API as the template editor writes them (columns: name, key, fields "Owner: String required; Due: Date", stages "Design, Make", submit "Demo File Submit", layout "bar chart of Stage" / "scatter plot of MolWt"; no compute); removed at feature end with the campaigns their keys started and those campaigns\' hitdesign rows, read back'});
|
|
432
|
+
|
|
433
|
+
export const templatesRemoved = Given('the {string} templates named {string} are removed now and at feature end',
|
|
434
|
+
(page: Page, appName: string, names: string) =>
|
|
435
|
+
templatesAtEnd(page, appOf(appName), names.split(',').map((n) => n.trim()).filter((n) => n !== ''), []),
|
|
436
|
+
{tier: 'api', description: 'for the templates a feature makes through the UI (names ending in {time}): their files, and the campaigns their keys started, go now and at feature end'});
|
|
437
|
+
|
|
438
|
+
/* The descriptors the Compute section lists come from Chem, which on an RDKit stand asks its container: a feature
|
|
439
|
+
never waits on that service, so the editor opens while the list cannot be read. */
|
|
440
|
+
export const descriptorsUnlisted = Given('the descriptors cannot be listed, put back at feature end', async (page: Page) => {
|
|
441
|
+
await page.evaluate(() => {
|
|
442
|
+
const chem = grok.chem;
|
|
443
|
+
chem.bddDescriptorsTree ??= chem.descriptorsTree;
|
|
444
|
+
chem.descriptorsTree = () => Promise.reject(new Error('the descriptors are not available'));
|
|
445
|
+
});
|
|
446
|
+
atFeatureEnd(page, () => page.evaluate(() => {
|
|
447
|
+
const chem = grok.chem;
|
|
448
|
+
if (chem.bddDescriptorsTree) {
|
|
449
|
+
chem.descriptorsTree = chem.bddDescriptorsTree;
|
|
450
|
+
delete chem.bddDescriptorsTree;
|
|
451
|
+
}
|
|
452
|
+
}));
|
|
453
|
+
}, {tier: 'api', description: 'grok.chem.descriptorsTree answers "the descriptors are not available" in the page, as when Chem\'s descriptor service is down; put back at feature end'});
|
|
454
|
+
|
|
455
|
+
// ---- the per-viewer settings of the landings --------------------------------------------------------------------
|
|
456
|
+
|
|
457
|
+
const SETTINGS = /^(HD|HT)Campaign|^Accordion:Hit-Design-campaigns-group-/;
|
|
458
|
+
|
|
459
|
+
export const settingsDefaults = Given('the campaigns tables start from their defaults, put back at feature end',
|
|
460
|
+
async (page: Page) => {
|
|
461
|
+
const saved: [string, string][] = await page.evaluate((re) => {
|
|
462
|
+
const keys = Object.keys(localStorage).filter((k) => new RegExp(re).test(k));
|
|
463
|
+
const out = keys.map((k) => [k, localStorage.getItem(k) ?? ''] as [string, string]);
|
|
464
|
+
for (const k of keys)
|
|
465
|
+
localStorage.removeItem(k);
|
|
466
|
+
return out;
|
|
467
|
+
}, SETTINGS.source);
|
|
468
|
+
atFeatureEnd(page, () => page.evaluate(([re, back]) => {
|
|
469
|
+
for (const k of Object.keys(localStorage).filter((k) => new RegExp(re).test(k)))
|
|
470
|
+
localStorage.removeItem(k);
|
|
471
|
+
for (const [k, v] of back)
|
|
472
|
+
localStorage.setItem(k, v);
|
|
473
|
+
}, [SETTINGS.source, saved] as [string, [string, string][]]));
|
|
474
|
+
}, {tier: 'api', description: 'the columns, grouping and sorting the landings keep in the browser (HDCampaign*, HTCampaign*) and the groups\' expanded state (Accordion:Hit-Design-campaigns-group-*) are cleared now and put back as they were at feature end'});
|
|
475
|
+
|
|
476
|
+
export const sortedBy = Given('the campaigns table of {string} is sorted by {string} {word}',
|
|
477
|
+
async (page: Page, appName: string, column: string, direction: string) => {
|
|
478
|
+
const app = appOf(appName);
|
|
479
|
+
if (direction !== 'ascending' && direction !== 'descending')
|
|
480
|
+
throw new Error(`a sort is ascending or descending, not "${direction}"`);
|
|
481
|
+
await page.evaluate(([key, value]) => localStorage.setItem(key, value),
|
|
482
|
+
[isDesign(app) ? 'HDCampaignsTableSorting' : 'HTCampaignsTableSorting',
|
|
483
|
+
JSON.stringify({columnName: column, ascending: direction === 'ascending'})] as [string, string]);
|
|
484
|
+
}, {tier: 'api', description: 'the sort a double-click on the header leaves in the browser (HDCampaignsTableSorting for Hit Design and PeptiHit, HTCampaignsTableSorting for Hit Triage and PepTriage), set before the landing opens; with "the campaigns tables start from their defaults" it is put back at feature end'});
|
|
485
|
+
|
|
486
|
+
// ---- the campaigns table: reading it ------------------------------------------------------------------------------
|
|
487
|
+
|
|
488
|
+
interface TableRead {headers: string[], arrows: string[], rows: string[][], names: string[]}
|
|
489
|
+
|
|
490
|
+
/** The campaigns table of the view shown: its header captions and sort arrows (`aria-sort`), the cells of every row
|
|
491
|
+
* it rendered, and the names of all its campaigns in order (the rows of a folded group, which it does not render,
|
|
492
|
+
* included). */
|
|
493
|
+
function readTable(page: Page): Promise<TableRead | null> {
|
|
494
|
+
return page.evaluate((selector) => {
|
|
495
|
+
const table = Array.from(document.querySelectorAll(selector)).find((t) => (t as HTMLElement).offsetParent !== null);
|
|
496
|
+
if (!table)
|
|
497
|
+
return null;
|
|
498
|
+
const heads = Array.from(table.querySelectorAll('th[data-u2="column-header"]'));
|
|
499
|
+
const control = (window as any).DG.U2.Control.forElement(table);
|
|
500
|
+
return {
|
|
501
|
+
headers: heads.map((th) => (th.textContent ?? '').trim()),
|
|
502
|
+
arrows: heads.map((th) => ({ascending: 'ascending', descending: 'descending'} as {[k: string]: string})[th.getAttribute('aria-sort') ?? ''] ?? ''),
|
|
503
|
+
rows: Array.from(table.querySelectorAll('tr.u2-table-row'))
|
|
504
|
+
.map((tr) => Array.from(tr.children).map((td) => (td.textContent ?? '').trim())),
|
|
505
|
+
names: control.getItems({all: true}).list.filter((i: any) => !i.key.startsWith('section:')).map((i: any) => i.label),
|
|
506
|
+
};
|
|
507
|
+
}, TABLE);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
async function pollTable<T>(page: Page, what: string, read: (t: TableRead) => T, want: T): Promise<void> {
|
|
511
|
+
let last: TableRead | null = null;
|
|
512
|
+
let got: unknown = null;
|
|
513
|
+
await expect.poll(async () => {
|
|
514
|
+
last = await readTable(page);
|
|
515
|
+
return got = last ? read(last) : '(no campaigns table is shown)';
|
|
516
|
+
}, {message: what}).toEqual(want).catch(() => {
|
|
517
|
+
const t = last as TableRead | null;
|
|
518
|
+
throw new Error(`${what}: expected ${JSON.stringify(want)}, read ${JSON.stringify(got)}` +
|
|
519
|
+
(t ? `; the table shows the columns "${t.headers.filter((h) => h).join(', ')}" and ${t.rows.length} row(s): ` +
|
|
520
|
+
t.rows.slice(0, 25).map((r) => r[0]).join(' | ') : ''));
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export const tableColumns = Then('the campaigns table should have the columns {string}', (page: Page, list: string) =>
|
|
525
|
+
pollTable(page, `the columns of the campaigns table`, (t) => t.headers.filter((h) => h !== '').join(', '),
|
|
526
|
+
list.split(',').map((s) => s.trim()).join(', ')),
|
|
527
|
+
{description: 'the header captions in order, the sort arrow and the unlabeled row-action columns apart'});
|
|
528
|
+
|
|
529
|
+
/** The order the table sorts the shown values in (u2 CatalogTable): numbers when every value reads as one, else dates
|
|
530
|
+
* when every value parses as one, else text in natural order (KHL-2 before KHL-12); empty values go last both ways
|
|
531
|
+
* and are left to `sortProblem`. */
|
|
532
|
+
function compareValues(values: string[]): (a: string, b: string) => number {
|
|
533
|
+
const filled = values.filter((v) => v !== '');
|
|
534
|
+
const numbers = filled.every((v) => !isNaN(Number(v)));
|
|
535
|
+
const dates = !numbers && filled.every((v) => !isNaN(Date.parse(v)));
|
|
536
|
+
const text = new Intl.Collator(undefined, {numeric: true});
|
|
537
|
+
return (a, b) => numbers ? Number(a) - Number(b) : dates ? Date.parse(a) - Date.parse(b) : text.compare(a, b);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function sortProblem(t: TableRead, column: string, direction: string): string {
|
|
541
|
+
const i = t.headers.indexOf(column);
|
|
542
|
+
if (i < 0)
|
|
543
|
+
return `no "${column}" column`;
|
|
544
|
+
if (t.arrows[i] !== direction)
|
|
545
|
+
return `the "${column}" header shows ${t.arrows[i] ? `the ${t.arrows[i]} arrow` : 'no arrow'}`;
|
|
546
|
+
if (t.rows.length < 2)
|
|
547
|
+
return `${t.rows.length} row(s): no order to see`;
|
|
548
|
+
const values = t.rows.map((r) => r[i] ?? '');
|
|
549
|
+
const cmp = compareValues(values);
|
|
550
|
+
for (let k = 1; k < values.length; k++) {
|
|
551
|
+
const [a, b] = [values[k - 1], values[k]];
|
|
552
|
+
if (b === '')
|
|
553
|
+
continue;
|
|
554
|
+
if (a === '' || (direction === 'ascending' ? cmp(a, b) > 0 : cmp(a, b) < 0))
|
|
555
|
+
return `row ${k} ("${t.rows[k - 1][0]}": "${a}") comes before row ${k + 1} ("${t.rows[k][0]}": "${b}")`;
|
|
556
|
+
}
|
|
557
|
+
return '';
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export const tableSorted = Then('the campaigns table should be sorted by {string} {word}',
|
|
561
|
+
(page: Page, column: string, direction: string) =>
|
|
562
|
+
pollTable(page, `the campaigns table sorted by ${column} ${direction}`, (t) => sortProblem(t, column, direction), ''),
|
|
563
|
+
{description: 'the header shows the arrow of that direction, and the values of the column go that way down every row the table rendered — as numbers when all are numbers, else as dates, else as text in natural order (KHL-2 before KHL-12); empty values last either way'});
|
|
564
|
+
|
|
565
|
+
export const tableNotSorted = Then('the campaigns table should not be sorted', (page: Page) =>
|
|
566
|
+
pollTable(page, 'the sort arrows of the campaigns table', (t) => t.arrows.filter((a) => a !== '').length, 0),
|
|
567
|
+
{description: 'no header shows a sort arrow'});
|
|
568
|
+
|
|
569
|
+
function cellOf(t: TableRead, column: string, row: string): string | null {
|
|
570
|
+
const i = t.headers.indexOf(column);
|
|
571
|
+
const r = t.rows.find((cells) => cells[0] === row);
|
|
572
|
+
return i < 0 || !r ? null : r[i] ?? '';
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
export const cellIs = Then('the {string} column of the {string} campaign row should be {string}',
|
|
576
|
+
(page: Page, column: string, row: string, value: string) =>
|
|
577
|
+
pollTable(page, `the ${column} of "${row}" in the campaigns table`, (t) => cellOf(t, column, row), value),
|
|
578
|
+
{description: 'the text of that cell, exactly'});
|
|
579
|
+
|
|
580
|
+
export const cellContains = Then('the {string} column of the {string} campaign row should contain {string}',
|
|
581
|
+
(page: Page, column: string, row: string, text: string) =>
|
|
582
|
+
pollTable(page, `the ${column} of "${row}" in the campaigns table, containing "${text}"`,
|
|
583
|
+
(t) => (cellOf(t, column, row) ?? '(no such cell)').includes(text) ? text : cellOf(t, column, row) ?? '(no such cell)', text),
|
|
584
|
+
{description: 'the text of that cell holds the text (case-sensitive)'});
|
|
585
|
+
|
|
586
|
+
const namesOf = (list: string): string[] => list.split(',').map((s) => s.trim()).filter((s) => s !== '');
|
|
587
|
+
|
|
588
|
+
export const listed = Then('the campaigns table should list {string}', (page: Page, list: string) =>
|
|
589
|
+
pollTable(page, `the campaigns ${list} in the table`,
|
|
590
|
+
(t) => namesOf(list).filter((n) => !t.names.includes(n)).join(', ') || 'all listed', 'all listed'),
|
|
591
|
+
{description: 'each of the names (a comma-separated list) is a row of the table — in a folded group too'});
|
|
592
|
+
|
|
593
|
+
export const notListed = Then('the campaigns table should not list {string}', (page: Page, list: string) =>
|
|
594
|
+
pollTable(page, `the campaigns ${list} not in the table`,
|
|
595
|
+
(t) => namesOf(list).filter((n) => t.names.includes(n)).join(', ') || 'none listed', 'none listed'),
|
|
596
|
+
{description: 'none of the names is a row of the table'});
|
|
597
|
+
|
|
598
|
+
export const groupCount = Then('the {string} campaign group should count {int} campaigns', async (page: Page, label: string, count: number) => {
|
|
599
|
+
let text = '';
|
|
600
|
+
await expect.poll(async () => {
|
|
601
|
+
text = await page.evaluate(([selector, l]) => {
|
|
602
|
+
const header = Array.from(document.querySelectorAll(`${selector} tr.u2-table-section`))
|
|
603
|
+
.find((h) => (h as HTMLElement).offsetParent !== null &&
|
|
604
|
+
(h.querySelector('[data-u2-part="item-label"]')?.textContent ?? '') === l);
|
|
605
|
+
return header ? (header.textContent ?? '').trim() : '(no such group)';
|
|
606
|
+
}, [TABLE, label] as [string, string]);
|
|
607
|
+
return (text.replace(label, '').match(/\d+/g) ?? []).map(Number);
|
|
608
|
+
}, {message: `the count in the header of the "${label}" group`}).toContain(count).catch(() => {
|
|
609
|
+
throw new Error(`the header of the "${label}" group reads "${text}": no count ${count} beside its label`);
|
|
610
|
+
});
|
|
611
|
+
}, {description: 'the header of the group shows the number of campaigns it holds beside its label (the label\'s own digits apart)'});
|
|
612
|
+
|
|
613
|
+
export const listedInOrder = Then('the campaigns table should list {string} in this order', (page: Page, list: string) => {
|
|
614
|
+
const names = list.split(',').map((s) => s.trim());
|
|
615
|
+
return pollTable(page, `the campaigns ${names.join(', ')} in this order`, (t) => {
|
|
616
|
+
const order = t.names;
|
|
617
|
+
const missing = names.filter((n) => !order.includes(n));
|
|
618
|
+
if (missing.length > 0)
|
|
619
|
+
return `not listed: ${missing.join(', ')}`;
|
|
620
|
+
return names.slice().sort((a, b) => order.indexOf(a) - order.indexOf(b)).join(', ');
|
|
621
|
+
}, names.join(', '));
|
|
622
|
+
}, {description: 'each of them is a row the table rendered, and they come in that order (other rows may lie between)'});
|
|
623
|
+
|
|
624
|
+
// ---- the campaigns table: gestures ------------------------------------------------------------------------------
|
|
625
|
+
|
|
626
|
+
export const doubleClickHeader = When('user double-clicks the {string} header of the campaigns table',
|
|
627
|
+
async (page: Page, column: string) => {
|
|
628
|
+
const header = page.locator(`${TABLE} th[data-u2="column-header"]`).filter({visible: true})
|
|
629
|
+
.filter({hasText: exactText(column)});
|
|
630
|
+
await expect(header, {message: `the "${column}" header of the campaigns table`}).toHaveCount(1);
|
|
631
|
+
await header.dblclick();
|
|
632
|
+
}, {tier: 'ui', description: 'a double click on the header cell of that column (a single click does nothing)'});
|
|
633
|
+
|
|
634
|
+
// ---- menus ---------------------------------------------------------------------------------------------------------
|
|
635
|
+
|
|
636
|
+
function menuCheck(page: Page, item: string): Promise<string> {
|
|
637
|
+
return page.evaluate((label) => {
|
|
638
|
+
const items = Array.from(document.querySelectorAll('.d4-menu-popup [role="menuitem"], .u2-menu-item'))
|
|
639
|
+
.filter((i) => (i as HTMLElement).offsetParent !== null &&
|
|
640
|
+
(i.querySelector(':scope > .d4-menu-item-label, :scope > .u2-menu-label')?.textContent ?? '').trim() === label);
|
|
641
|
+
if (items.length !== 1)
|
|
642
|
+
return `${items.length} "${label}" items in the open menu`;
|
|
643
|
+
return items[0].getAttribute('aria-checked') === 'true' ? 'checked' : 'unchecked';
|
|
644
|
+
}, item);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
export const menuItemChecked = Then('the open menu should show {string} as {word}', async (page: Page, item: string, state: string) => {
|
|
648
|
+
if (state !== 'checked' && state !== 'unchecked')
|
|
649
|
+
throw new Error(`a menu item shows as checked or unchecked, not "${state}"`);
|
|
650
|
+
await expect.poll(() => menuCheck(page, item), {message: `"${item}" in the open menu`}).toBe(state);
|
|
651
|
+
}, {description: 'the check mark of a popup menu item (aria-checked) — a Dart menu\'s or a u2 one\'s, a submenu\'s items included'});
|
|
652
|
+
|
|
653
|
+
/** A confirmation's button says what it does ("DELETE"); a platform dialog's is OK. Either is the dialog's confirming
|
|
654
|
+
* button. */
|
|
655
|
+
export const confirmDialog = When('user confirms {element}', async (page: Page, target: ElementRef) => {
|
|
656
|
+
const dialog = (await locate(page, target)).filter({visible: true}).first();
|
|
657
|
+
const button = dialog.locator('button').filter({visible: true}).filter({hasText: /^\s*(OK|DELETE)\s*$/i});
|
|
658
|
+
await expect(button, {message: `the OK or DELETE button of ${target.phrase}`}).toHaveCount(1);
|
|
659
|
+
await button.click();
|
|
660
|
+
}, {tier: 'ui', description: 'clicks the button that confirms the dialog: OK, or DELETE where the dialog names what it does'});
|
|
661
|
+
|
|
662
|
+
export const campaignViewsOpen = Then('{int} campaign view(s) should be open', async (page: Page, count: number) => {
|
|
663
|
+
await expect.poll(() => page.evaluate(() => Array.from(grok.shell.views).filter((v: any) => v.type === 'TableView').length),
|
|
664
|
+
{message: 'the table views open in the shell (a campaign is one)'}).toBe(count);
|
|
665
|
+
}, {description: 'the open table views, whatever they are named: an app\'s campaigns open as table views'});
|
|
666
|
+
|
|
667
|
+
// ---- the server -------------------------------------------------------------------------------------------------
|
|
668
|
+
|
|
669
|
+
function campaignJson(page: Page, app: App, code: string): Promise<any | null> {
|
|
670
|
+
return page.evaluate(async (p) => await grok.dapi.files.exists(p) ? JSON.parse(await grok.dapi.files.readAsText(p)) : null,
|
|
671
|
+
`${share(app)}/campaigns/${code}/campaign.json`);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
export const campaignOnServerClaim = Then('the {string} campaign {string} should be on the server',
|
|
675
|
+
async (page: Page, appName: string, code: string) => {
|
|
676
|
+
const app = appOf(appName);
|
|
677
|
+
await expect.poll(async () => (await campaignJson(page, app, code)) !== null,
|
|
678
|
+
{message: `${app} campaign ${code} on the server`, timeout: pollMs(20000)}).toBe(true);
|
|
679
|
+
}, {tier: 'api', description: 'its campaign.json is on the share'});
|
|
680
|
+
|
|
681
|
+
export const campaignNotOnServer = Then('the {string} campaign {string} should not be on the server',
|
|
682
|
+
async (page: Page, appName: string, code: string) => {
|
|
683
|
+
const app = appOf(appName);
|
|
684
|
+
await expect.poll(() => page.evaluate((p) => grok.dapi.files.exists(p), `${share(app)}/campaigns/${code}`),
|
|
685
|
+
{message: `${app} campaign ${code} gone from the server`, timeout: pollMs(20000)}).toBe(false);
|
|
686
|
+
}, {tier: 'api', description: 'its folder is gone from the share'});
|
|
687
|
+
|
|
688
|
+
const CAMPAIGN_KEYS: {[word: string]: (c: any) => string} = {
|
|
689
|
+
name: (c) => String(c.friendlyName ?? ''), status: (c) => String(c.status ?? ''),
|
|
690
|
+
author: (c) => String(c.authorUserFriendlyName ?? ''), template: (c) => String(c.templateName ?? ''),
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
export const campaignHas = Then('the {string} campaign {string} on the server should have the {word} {string}',
|
|
694
|
+
async (page: Page, appName: string, code: string, word: string, value: string) => {
|
|
695
|
+
const app = appOf(appName);
|
|
696
|
+
const read = CAMPAIGN_KEYS[word];
|
|
697
|
+
if (!read)
|
|
698
|
+
throw new Error(`a campaign's ${word} is not claimed; the claims are ${Object.keys(CAMPAIGN_KEYS).join(', ')}`);
|
|
699
|
+
await expect.poll(async () => {
|
|
700
|
+
const c = await campaignJson(page, app, code);
|
|
701
|
+
return c ? read(c) : '(no such campaign)';
|
|
702
|
+
}, {message: `the ${word} of ${app} campaign ${code} on the server`, timeout: pollMs(20000)}).toBe(value);
|
|
703
|
+
}, {tier: 'api', description: 'read from its campaign.json: name (the friendly name), status, author (friendly name), template (its name)'});
|
|
704
|
+
|
|
705
|
+
function templateJsonOnServer(page: Page, app: App, name: string): Promise<any | null> {
|
|
706
|
+
return page.evaluate(async (p) => await grok.dapi.files.exists(p) ? JSON.parse(await grok.dapi.files.readAsText(p)) : null,
|
|
707
|
+
`${share(app)}/templates/${name}.json`);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
export const templateOnServer = Then('the {string} template {string} should be on the server',
|
|
711
|
+
async (page: Page, appName: string, name: string) => {
|
|
712
|
+
const app = appOf(appName);
|
|
713
|
+
await expect.poll(async () => (await templateJsonOnServer(page, app, name)) !== null,
|
|
714
|
+
{message: `${app} template ${name} on the server`, timeout: pollMs(20000)}).toBe(true);
|
|
715
|
+
}, {tier: 'api', description: 'its <name>.json is in the app\'s templates folder'});
|
|
716
|
+
|
|
717
|
+
export const templateNotOnServer = Then('the {string} template {string} should not be on the server',
|
|
718
|
+
async (page: Page, appName: string, name: string) => {
|
|
719
|
+
const app = appOf(appName);
|
|
720
|
+
await expect.poll(async () => (await templateJsonOnServer(page, app, name)) !== null,
|
|
721
|
+
{message: `${app} template ${name} gone from the server`, timeout: pollMs(20000)}).toBe(false);
|
|
722
|
+
}, {tier: 'api', description: 'no <name>.json in the app\'s templates folder'});
|
|
723
|
+
|
|
724
|
+
const TEMPLATE_KEYS: {[word: string]: (t: any) => string} = {
|
|
725
|
+
key: (t) => String(t.key ?? ''),
|
|
726
|
+
fields: (t) => (t.campaignFields ?? []).map((f: any) => `${f.name} (${f.type}${f.required ? ', required' : ''})`).join(', '),
|
|
727
|
+
stages: (t) => (t.stages ?? []).join(', '),
|
|
728
|
+
submit: (t) => t.submit ? `${t.submit.package}:${t.submit.fName}` : '',
|
|
729
|
+
layout: (t) => t.layoutViewState ? 'a layout' : 'no layout',
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
export const templateHas = Then('the {string} template {string} on the server should have the {word} {string}',
|
|
733
|
+
async (page: Page, appName: string, name: string, word: string, value: string) => {
|
|
734
|
+
const app = appOf(appName);
|
|
735
|
+
const read = TEMPLATE_KEYS[word];
|
|
736
|
+
if (!read)
|
|
737
|
+
throw new Error(`a template's ${word} is not claimed; the claims are ${Object.keys(TEMPLATE_KEYS).join(', ')}`);
|
|
738
|
+
await expect.poll(async () => {
|
|
739
|
+
const t = await templateJsonOnServer(page, app, name);
|
|
740
|
+
return t ? read(t) : '(no such template)';
|
|
741
|
+
}, {message: `the ${word} of ${app} template ${name} on the server`, timeout: pollMs(20000)}).toBe(value);
|
|
742
|
+
}, {tier: 'api', description: 'read from its JSON: key; fields "Owner (String, required), Due (Date)"; stages "Design, Make"; submit "HitTriage:demoFileSubmit"; layout "a layout" or "no layout"'});
|
|
743
|
+
|
|
744
|
+
// ---- the template editor ------------------------------------------------------------------------------------------
|
|
745
|
+
|
|
746
|
+
/** The two RecordsInputs of the Hit Design / PeptiHit editor: the Additional fields (Name, Type, Required per row) and
|
|
747
|
+
* the Stages (Name). "Add field" / "Add stage" under the rows adds an empty row; a row typed into is a row, saved
|
|
748
|
+
* without leaving it. */
|
|
749
|
+
const FIELDS = `${TEMPLATE_EDITOR} [data-u2-name="fields"]`;
|
|
750
|
+
const STAGES = `${TEMPLATE_EDITOR} [data-u2-name="stages"]`;
|
|
751
|
+
|
|
752
|
+
async function newRow(page: Page, records: string) {
|
|
753
|
+
await page.locator(`${records} [data-u2-part="add"]`).click();
|
|
754
|
+
const row = page.locator(`${records} .u2-records-body > .u2-records-row`).last();
|
|
755
|
+
await expect(row, {message: `the new row of the ${records === FIELDS ? 'Additional fields' : 'Stages'}`}).toBeVisible();
|
|
756
|
+
return row;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
async function typeField(page: Page, name: string, type: string, required: boolean, leave: boolean): Promise<void> {
|
|
760
|
+
const row = await newRow(page, FIELDS);
|
|
761
|
+
const nameEditor = row.locator('[data-u2="text-input"] input');
|
|
762
|
+
await gestures.typeVerified(nameEditor, name, 'the name of the new field');
|
|
763
|
+
await row.locator('select').selectOption(type);
|
|
764
|
+
const box = row.locator('input[type="checkbox"]');
|
|
765
|
+
if (await box.isChecked() !== required)
|
|
766
|
+
await box.click();
|
|
767
|
+
await expect(box, {message: 'the Required box of the new field'}).toBeChecked({checked: required});
|
|
768
|
+
if (leave)
|
|
769
|
+
await box.press('Tab');
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
export const addField = When('user adds the field {string} of type {string} in the template editor',
|
|
773
|
+
(page: Page, name: string, type: string) => typeField(page, name, type, false, true),
|
|
774
|
+
{tier: 'ui', description: 'clicks "Add field", fills the new row of Additional fields and leaves it'});
|
|
775
|
+
export const addRequiredField = When('user adds the required field {string} of type {string} in the template editor',
|
|
776
|
+
(page: Page, name: string, type: string) => typeField(page, name, type, true, true),
|
|
777
|
+
{tier: 'ui', description: 'clicks "Add field", fills the new row of Additional fields, ticks Required and leaves the row'});
|
|
778
|
+
export const typePendingField = When('user types the field {string} of type {string} in the template editor without adding it',
|
|
779
|
+
(page: Page, name: string, type: string) => typeField(page, name, type, false, false),
|
|
780
|
+
{tier: 'ui', description: 'clicks "Add field" and fills the new row of Additional fields, the focus left in it (CREATE takes it)'});
|
|
781
|
+
|
|
782
|
+
async function typeStage(page: Page, name: string, leave: boolean): Promise<void> {
|
|
783
|
+
const editor = (await newRow(page, STAGES)).locator('[data-u2="text-input"] input');
|
|
784
|
+
await gestures.typeVerified(editor, name, 'the name of the new stage');
|
|
785
|
+
if (leave)
|
|
786
|
+
await editor.press('Tab');
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
export const addStage = When('user adds the stage {string} in the template editor', (page: Page, name: string) => typeStage(page, name, true),
|
|
790
|
+
{tier: 'ui', description: 'clicks "Add stage", types the name into the new row of Stages and leaves it'});
|
|
791
|
+
export const typePendingStage = When('user types the stage {string} in the template editor without adding it',
|
|
792
|
+
(page: Page, name: string) => typeStage(page, name, false),
|
|
793
|
+
{tier: 'ui', description: 'clicks "Add stage" and types the name into the new row of Stages, the focus left in it'});
|
|
794
|
+
|
|
795
|
+
/** The rows of a RecordsInput as its value holds them, the ones with no name apart (CREATE leaves them out). */
|
|
796
|
+
function readRecords(page: Page, records: string): Promise<string> {
|
|
797
|
+
return page.evaluate((sel) => {
|
|
798
|
+
const el = Array.from(document.querySelectorAll(sel)).find((e) => (e as HTMLElement).offsetParent !== null);
|
|
799
|
+
if (!el)
|
|
800
|
+
return '(not shown)';
|
|
801
|
+
const rows: {name: string, type?: string, required?: boolean}[] = DG.U2.control(el).peek() ?? [];
|
|
802
|
+
return rows.filter((r) => r.name).map((r) => r.type === undefined ? r.name :
|
|
803
|
+
`${r.name} (${r.type}${r.required ? ', required' : ''})`).join(', ');
|
|
804
|
+
}, records);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
export const editorFields = Then('the template editor should list the fields {string}', async (page: Page, list: string) => {
|
|
808
|
+
await expect.poll(() => readRecords(page, FIELDS), {message: 'the rows of Additional fields'}).toBe(list);
|
|
809
|
+
}, {description: 'the named rows of Additional fields as "Owner (String, required), Due (Date)"'});
|
|
810
|
+
|
|
811
|
+
export const editorStages = Then('the template editor should list the stages {string}', async (page: Page, list: string) => {
|
|
812
|
+
await expect.poll(() => readRecords(page, STAGES), {message: 'the rows of Stages'}).toBe(list);
|
|
813
|
+
}, {description: 'the named rows of Stages as "Design, Make"'});
|
|
814
|
+
|
|
815
|
+
/** The messages under the editor's inputs: u2's error lines (Hit Design, PeptiHit), and the Hit Triage / PepTriage
|
|
816
|
+
* error divs, always in the DOM and shown by their opacity, which Playwright's visibility ignores. */
|
|
817
|
+
function shownErrors(page: Page): Promise<string[]> {
|
|
818
|
+
return page.evaluate(() => {
|
|
819
|
+
const root = grok.shell.v?.root as HTMLElement | undefined;
|
|
820
|
+
const legacy = Array.from(root?.querySelectorAll('.hit-triage-error-div') ?? [])
|
|
821
|
+
.filter((e) => (e as HTMLElement).offsetParent !== null && Number(getComputedStyle(e).opacity) > 0);
|
|
822
|
+
const u2 = Array.from(root?.querySelectorAll('[data-u2-name="template-editor"] [data-u2-part="error"]') ?? [])
|
|
823
|
+
.filter((e) => (e as HTMLElement).offsetParent !== null);
|
|
824
|
+
return [...legacy, ...u2].map((e) => (e.textContent ?? '').trim()).filter((t) => t !== '');
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
export const editorShowsError = Then('the template editor should show the error {string}', async (page: Page, text: string) => {
|
|
829
|
+
await expect.poll(async () => (await shownErrors(page)).includes(text), {message: `the error "${text}" under the template editor's inputs`}).toBe(true);
|
|
830
|
+
}, {description: 'an error line of the editor\'s Details shown (not transparent)'});
|
|
831
|
+
|
|
832
|
+
export const editorShowsNoError = Then('the template editor should not show the error {string}', async (page: Page, text: string) => {
|
|
833
|
+
await expect.poll(async () => (await shownErrors(page)).includes(text), {message: `the error "${text}" under the template editor's inputs`}).toBe(false);
|
|
834
|
+
}, {description: 'no error line of the editor\'s Details shows that text'});
|
|
835
|
+
|
|
836
|
+
export const viewNotOpen = Then('the {string} view should not be open', async (page: Page, name: string) => {
|
|
837
|
+
await expect.poll(() => page.evaluate((n) => Array.from(grok.shell.views).some((v: any) => v.name === n), name),
|
|
838
|
+
{message: `a view named "${name}" open`}).toBe(false);
|
|
839
|
+
}, {description: 'no open view has that name (closed, not only behind another)'});
|