@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.
- package/.grokignore +2 -0
- package/.turbo/turbo-build.log +24 -6
- package/.vscode/settings.json +16 -0
- package/CHANGELOG.md +80 -1
- 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 -0
- package/bdd/bindings/campaign.ts +626 -0
- package/bdd/bindings/hit-design.ts +93 -0
- 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/hit-design/campaign-column-metadata.feature +61 -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 +76 -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/bdd/package.json +1 -0
- package/bdd/tsconfig.json +13 -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 +15 -8
- 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 +492 -882
- 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/types.ts +2 -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/tsconfig.json +3 -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,626 @@
|
|
|
1
|
+
/* The campaign view of Hit Design and PeptiHit, as its features use it. A campaign is two files on the AppData share
|
|
2
|
+
(campaign.json and its table) and rows in the hitdesign database: every save logs the campaign's update, a save
|
|
3
|
+
holds its lock, and a molecule written into the table registers its V-iD (a dictionary row, and a row tying it to
|
|
4
|
+
the campaign). A feature's campaign is made through the JS API, its template embedded the way a saved campaign
|
|
5
|
+
carries it (no template file), and removed at feature end and swept before it is made: its folder, its rows, and
|
|
6
|
+
the dictionary rows it registered that nothing else uses. Which dictionary rows are its own is told by the highest
|
|
7
|
+
dictionary id when the campaign was made, kept in the campaign's folder for a sweep after a killed run.
|
|
8
|
+
|
|
9
|
+
A campaign is opened by its link (`?campaignId=`), not from the landing's list: the package lists the campaigns
|
|
10
|
+
once per page, so a list read by an earlier feature on the same page does not hold a campaign made since. */
|
|
11
|
+
import {resolve} from 'path';
|
|
12
|
+
import {Page} from '@playwright/test';
|
|
13
|
+
import {Given, Then, When} from '@datagrok-libraries/bdd';
|
|
14
|
+
import {type ElementRef, atFeatureEnd, expect, gestures, locate, pollMs} from '@datagrok-libraries/bdd/runtime';
|
|
15
|
+
import {sharingLogin, sharingShownName} from '@datagrok-libraries/bdd/bindings/platform/steps';
|
|
16
|
+
|
|
17
|
+
declare const grok: any;
|
|
18
|
+
declare const DG: any;
|
|
19
|
+
|
|
20
|
+
export type App = 'Hit Design' | 'PeptiHit';
|
|
21
|
+
const ROOTS: Record<App, string> = {
|
|
22
|
+
'Hit Design': 'System:AppData/HitTriage/Hit Design',
|
|
23
|
+
'PeptiHit': 'System:AppData/HitTriage/PeptiHit',
|
|
24
|
+
};
|
|
25
|
+
const APP_PATHS: Record<App, string> = {'Hit Design': 'HitDesign', 'PeptiHit': 'PeptiHit'};
|
|
26
|
+
const FLOOR_FILE = 'bdd-vid-floor.txt';
|
|
27
|
+
const LAYOUT = 'System:AppData/HitTriage/Hit Design/HD-template-layout.layout';
|
|
28
|
+
|
|
29
|
+
interface Campaign {app: App; name: string; key: string; id: string}
|
|
30
|
+
const campaigns = new WeakMap<Page, Map<string, Campaign>>();
|
|
31
|
+
|
|
32
|
+
export const keyOf = (name: string): string => 'BDD' + name.replace(/[^A-Za-z]/g, '').toUpperCase();
|
|
33
|
+
|
|
34
|
+
export function campaignOf(page: Page, name: string): Campaign {
|
|
35
|
+
const c = campaigns.get(page)?.get(name);
|
|
36
|
+
if (!c)
|
|
37
|
+
throw new Error(`no campaign "${name}" was made by this feature`);
|
|
38
|
+
return c;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Removes every campaign of the key in the app — its folder, its rows in the hitdesign database, and the dictionary
|
|
42
|
+
* rows above the floor its folder kept that no campaign refers to any more — and returns what is still there. */
|
|
43
|
+
function removeCampaigns(page: Page, app: App, key: string): Promise<string> {
|
|
44
|
+
return page.evaluate(async ([root, a, k, floorFile]) => {
|
|
45
|
+
const folders: string[] = (await grok.dapi.files.list(`${root}/campaigns`))
|
|
46
|
+
.filter((f: any) => f.isDirectory && f.name.startsWith(`${k}-`)).map((f: any) => f.name);
|
|
47
|
+
let floor: number | null = null;
|
|
48
|
+
for (const id of folders) {
|
|
49
|
+
const path = `${root}/campaigns/${id}/${floorFile}`;
|
|
50
|
+
if (await grok.dapi.files.exists(path)) {
|
|
51
|
+
const n = parseInt(await grok.dapi.files.readAsText(path), 10);
|
|
52
|
+
if (Number.isFinite(n))
|
|
53
|
+
floor = floor === null ? n : Math.min(floor, n);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const conn = (await grok.dapi.connections.filter('name = "hitdesign"').list())
|
|
57
|
+
.find((c: any) => c.nqName === 'HitTriage:hitdesign');
|
|
58
|
+
const where = `app_name = '${a}' and campaign_id like '${k}-%'`;
|
|
59
|
+
const vids: string[] = ((await conn.query('bdd-campaign-cleanup', `select vid from hitdesign.campaign_vids where ${where}`)
|
|
60
|
+
.apply()).col('vid')?.toList() ?? []).filter((v: string) => /^V\d+$/.test(v));
|
|
61
|
+
for (const table of ['update_logs', 'campaign_locks', 'campaign_vids'])
|
|
62
|
+
await conn.query('bdd-campaign-cleanup', `delete from hitdesign.${table} where ${where} returning campaign_id`).apply();
|
|
63
|
+
const own = floor !== null && vids.length > 0 ?
|
|
64
|
+
`vid in (${vids.map((v) => `'${v}'`).join(', ')}) and id > ${floor} and ` +
|
|
65
|
+
'not exists (select 1 from hitdesign.campaign_vids c where c.vid = vid_dictionary.vid)' : null;
|
|
66
|
+
if (own)
|
|
67
|
+
await conn.query('bdd-campaign-cleanup', `delete from hitdesign.vid_dictionary where ${own} returning vid`).apply();
|
|
68
|
+
for (const id of folders)
|
|
69
|
+
await grok.dapi.files.delete(`${root}/campaigns/${id}`);
|
|
70
|
+
const left: string[] = [];
|
|
71
|
+
for (const id of folders) {
|
|
72
|
+
if (await grok.dapi.files.exists(`${root}/campaigns/${id}`))
|
|
73
|
+
left.push(`folder ${id}`);
|
|
74
|
+
}
|
|
75
|
+
for (const table of ['update_logs', 'campaign_locks', 'campaign_vids']) {
|
|
76
|
+
const rows = (await conn.query('bdd-campaign-cleanup', `select campaign_id from hitdesign.${table} where ${where}`)
|
|
77
|
+
.apply()).rowCount;
|
|
78
|
+
if (rows > 0)
|
|
79
|
+
left.push(`${rows} row(s) in hitdesign.${table}`);
|
|
80
|
+
}
|
|
81
|
+
if (own) {
|
|
82
|
+
const rows = (await conn.query('bdd-campaign-cleanup', `select vid from hitdesign.vid_dictionary where ${own}`).apply()).rowCount;
|
|
83
|
+
if (rows > 0)
|
|
84
|
+
left.push(`${rows} row(s) in hitdesign.vid_dictionary`);
|
|
85
|
+
}
|
|
86
|
+
return left.join(', ');
|
|
87
|
+
}, [ROOTS[app], app, key, FLOOR_FILE] as [string, App, string, string]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function removedAndReadBack(page: Page, app: App, name: string, key: string): Promise<void> {
|
|
91
|
+
// a publish of the package re-creates its connection: a feature running meanwhile waits for it
|
|
92
|
+
await expect.poll(() => page.evaluate(async () => (await grok.dapi.connections.filter('name = "hitdesign"').list())
|
|
93
|
+
.some((c: any) => c.nqName === 'HitTriage:hitdesign')), {message: 'the package\'s hitdesign connection', timeout: pollMs(120000)})
|
|
94
|
+
.toBe(true);
|
|
95
|
+
let left = '';
|
|
96
|
+
await expect.poll(async () => left = await removeCampaigns(page, app, key),
|
|
97
|
+
{message: `the ${app} campaign "${name}" removed from the share and the hitdesign database`, timeout: pollMs(30000)})
|
|
98
|
+
.toBe('').catch((e) => {
|
|
99
|
+
throw new Error(`the ${app} campaign "${name}" is still on the server: ${left || e?.message}`);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface CampaignOptions {
|
|
104
|
+
/** the second account is the campaign's author and its only editor; everyone may view it */
|
|
105
|
+
sharingUserEdits?: boolean;
|
|
106
|
+
/** a Molecule field after Chemist, set to the SMILES */
|
|
107
|
+
molecule?: {field: string, smiles: string};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A campaign of that friendly name, its id the key and "-1": its table the rows given (the first one the header), its
|
|
111
|
+
* template embedded with the stages given, a "Chemist" field (and the molecule field asked for), the JS-only Chemical
|
|
112
|
+
* Properties compute (MW), the Demo File Submit preset and, for Hit Design, the package's shipped layout file. */
|
|
113
|
+
export async function makeCampaign(page: Page, app: App, name: string, stages: string[], table: string[][],
|
|
114
|
+
options: CampaignOptions = {}): Promise<Campaign> {
|
|
115
|
+
const key = keyOf(name);
|
|
116
|
+
await removedAndReadBack(page, app, name, key);
|
|
117
|
+
atFeatureEnd(page, () => removedAndReadBack(page, app, name, key));
|
|
118
|
+
const sharing = options.sharingUserEdits ? sharingLogin() : '';
|
|
119
|
+
await page.evaluate(async ([root, a, n, k, rows, st, layout, floorFile, second, [molField, smiles]]) => {
|
|
120
|
+
const id = `${k}-1`;
|
|
121
|
+
const csv = rows.map((r) => r.map((v) => /[",\n]/.test(v) ? `"${v.replace(/"/g, '""')}"` : v).join(',')).join('\n') + '\n';
|
|
122
|
+
const types: {[_: string]: string} = {};
|
|
123
|
+
const semTypes: {[_: string]: string | null} = {};
|
|
124
|
+
const df = DG.DataFrame.fromCsv(csv);
|
|
125
|
+
for (const c of df.columns.toList()) {
|
|
126
|
+
types[c.name] = c.type;
|
|
127
|
+
semTypes[c.name] = c.name === 'Molecule' ? 'Molecule' : c.name === 'Helm' ? 'Macromolecule' : null;
|
|
128
|
+
}
|
|
129
|
+
const conn = (await grok.dapi.connections.filter('name = "hitdesign"').list())
|
|
130
|
+
.find((c: any) => c.nqName === 'HitTriage:hitdesign');
|
|
131
|
+
const floor = (await conn.query('bdd-campaign-floor', 'select coalesce(max(id), 0) as floor from hitdesign.vid_dictionary')
|
|
132
|
+
.apply()).get('floor', 0);
|
|
133
|
+
const allUsers = DG.Group.defaultGroupsIds['All users'];
|
|
134
|
+
let owner: {[_: string]: any} = {};
|
|
135
|
+
if (second) {
|
|
136
|
+
const user = await grok.dapi.users.filter(`login = ${JSON.stringify(second)}`).first();
|
|
137
|
+
if (!user)
|
|
138
|
+
throw new Error(`no user "${second}" on the server`);
|
|
139
|
+
owner = {authorUserId: user.id, authorUserFriendlyName: user.friendlyName,
|
|
140
|
+
permissions: {view: [allUsers], edit: [user.group.id]}};
|
|
141
|
+
}
|
|
142
|
+
const folder = `${root}/campaigns/${id}`;
|
|
143
|
+
await grok.dapi.files.writeAsText(`${folder}/${floorFile}`, String(floor));
|
|
144
|
+
await grok.dapi.files.writeAsText(`${folder}/enriched_table.csv`, csv);
|
|
145
|
+
await grok.dapi.files.writeAsText(`${folder}/campaign.json`, JSON.stringify({
|
|
146
|
+
name: id, friendlyName: n, templateName: n, status: 'In Progress', createDate: '2026/10/15',
|
|
147
|
+
campaignFields: {Chemist: 'BDD chemist', ...molField ? {[molField]: smiles} : {}}, columnSemTypes: semTypes, columnTypes: types, rowCount: df.rowCount,
|
|
148
|
+
filteredRowCount: df.rowCount, savePath: `${root.replace('System:AppData', 'System.AppData')}/campaigns/${id}/enriched_table.csv`,
|
|
149
|
+
version: 1, ...owner,
|
|
150
|
+
template: {name: n, key: k, campaignFields: [{name: 'Chemist', type: 'String', required: false},
|
|
151
|
+
...molField ? [{name: molField, type: 'Molecule', required: false}] : []], stages: st,
|
|
152
|
+
submit: {fName: 'demoFileSubmit', package: 'HitTriage'}, ...(a === 'Hit Design' ? {localLayoutPath: layout} : {}),
|
|
153
|
+
compute: {descriptors: {enabled: false, args: []}, scripts: [], queries: [],
|
|
154
|
+
functions: [{name: 'addChemPropertiesColumns', package: 'Chem', args: {MW: true, HBA: false, HBD: false, logP: false,
|
|
155
|
+
logS: false, PSA: false, rotatableBonds: false, stereoCenters: false, moleculeCharge: false, molecularFormula: false}}]}},
|
|
156
|
+
}));
|
|
157
|
+
}, [ROOTS[app], app, name, key, table, stages, LAYOUT, FLOOR_FILE, sharing,
|
|
158
|
+
[options.molecule?.field ?? '', options.molecule?.smiles ?? '']] as
|
|
159
|
+
[string, App, string, string, string[][], string[], string, string, string, [string, string]]);
|
|
160
|
+
const campaign = {app, name, key, id: `${key}-1`};
|
|
161
|
+
if (!campaigns.has(page))
|
|
162
|
+
campaigns.set(page, new Map());
|
|
163
|
+
campaigns.get(page)!.set(name, campaign);
|
|
164
|
+
return campaign;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const stagesOf = (list: string): string[] => list.split(',').map((s) => s.trim()).filter((s) => s.length > 0);
|
|
168
|
+
|
|
169
|
+
export const hitDesignCampaign = Given('the Hit Design campaign {string} with the stages {string} and a table of:',
|
|
170
|
+
async (page: Page, name: string, stages: string, table: string[][]) => {
|
|
171
|
+
await makeCampaign(page, 'Hit Design', name, stagesOf(stages), table);
|
|
172
|
+
}, {tier: 'api', description: 'made through the JS API, its id "BDD" + the name\'s letters + "-1": the rows given (the first one the header), the template embedded (the stages given, a Chemist field set to "BDD chemist", the Chemical Properties compute with MW, the Demo File Submit preset, the package\'s HD-template-layout.layout); removed at feature end with its hitdesign rows and the V-iDs it registered, read back, and swept before it is made'});
|
|
173
|
+
|
|
174
|
+
export const hitDesignCampaignWithMolecule = Given(
|
|
175
|
+
'the Hit Design campaign {string} with the stages {string}, the molecule field {string} set to {string} and a table of:',
|
|
176
|
+
async (page: Page, name: string, stages: string, field: string, smiles: string, table: string[][]) => {
|
|
177
|
+
await makeCampaign(page, 'Hit Design', name, stagesOf(stages), table, {molecule: {field, smiles}});
|
|
178
|
+
}, {tier: 'api', description: 'as "the Hit Design campaign … with the stages …", its template also holding a Molecule field of that name after Chemist, set to the SMILES'});
|
|
179
|
+
|
|
180
|
+
export const viewOnlyCampaign = Given('the Hit Design campaign {string}, which only the sharing user may edit, with a table of:',
|
|
181
|
+
async (page: Page, name: string, table: string[][]) => {
|
|
182
|
+
await makeCampaign(page, 'Hit Design', name, ['Idea', 'Design'], table, {sharingUserEdits: true});
|
|
183
|
+
}, {tier: 'api', description: 'as "the Hit Design campaign … with the stages …", the stages Idea and Design; its author is the second account (DATAGROK_SHARING_LOGIN, bddsecond), whose personal group alone may edit it, and All users may view it'});
|
|
184
|
+
|
|
185
|
+
/* The card layout a closed tracker keeps with the campaign names the table it was made over — "Table" while the
|
|
186
|
+
campaign was the only one open. */
|
|
187
|
+
export const cardLayoutOver = Given('the card layout of the campaign {string} was made over a table named {string}',
|
|
188
|
+
async (page: Page, name: string, table: string) => {
|
|
189
|
+
const c = campaignOf(page, name);
|
|
190
|
+
await page.evaluate(async ([root, id, t]) => {
|
|
191
|
+
const path = `${root}/campaigns/${id}/campaign.json`;
|
|
192
|
+
const campaign = JSON.parse(await grok.dapi.files.readAsText(path));
|
|
193
|
+
const field = (column: string, inputType: string, top: number) => ({left: 83, top, width: 100, height: 20,
|
|
194
|
+
type: 'field', viewerSettings: {column, format: null, inputType}});
|
|
195
|
+
campaign.tilesViewerFormSketch = JSON.stringify({'#type': 'SketchState', table: t, formDesigned: false,
|
|
196
|
+
elementStates: [field('V-iD', 'Text', 20), field('Stage', 'Text', 44), field('MW', 'Float', 68)]});
|
|
197
|
+
await grok.dapi.files.writeAsText(path, JSON.stringify(campaign));
|
|
198
|
+
}, [ROOTS[c.app], c.id, table] as [string, string, string]);
|
|
199
|
+
}, {tier: 'api', description: 'writes into the campaign\'s campaign.json the card layout a tracker keeps (`tilesViewerFormSketch`): the V-iD, Stage and MW fields, over a table of the name given'});
|
|
200
|
+
|
|
201
|
+
export const openByLink = When('user opens the campaign {string} by its link', async (page: Page, name: string) => {
|
|
202
|
+
const c = campaignOf(page, name);
|
|
203
|
+
await page.evaluate((path) => {
|
|
204
|
+
grok.shell.route(path);
|
|
205
|
+
}, `/apps/HitTriage/${APP_PATHS[c.app]}?campaignId=${c.id}`);
|
|
206
|
+
const wanted = `TableView: ${c.name}`;
|
|
207
|
+
let current = '';
|
|
208
|
+
await expect.poll(async () => (current = await page.evaluate(() => `${grok.shell.v?.type}: ${grok.shell.v?.name}`)) === wanted,
|
|
209
|
+
{message: `the campaign view of "${name}"`, timeout: pollMs(60000)}).toBe(true).catch(() => {
|
|
210
|
+
throw new Error(`the campaign view of "${name}" (${wanted}) is not current; current: ${current}`);
|
|
211
|
+
});
|
|
212
|
+
}, {tier: 'api', description: 'the app\'s address with ?campaignId=<id> (a deep link); done when the campaign\'s table view, named after the campaign, is current'});
|
|
213
|
+
|
|
214
|
+
/* The shell renders the crumbs of the current view ("Hit Design › <campaign>") from its parent view: the parent's
|
|
215
|
+
crumb is there with the view, so the crumb of this campaign is the one shown while its view is current. */
|
|
216
|
+
export const backByCrumb = When('user goes back by the {string} crumb of the campaign {string}', async (page: Page, crumb: string, name: string) => {
|
|
217
|
+
await expect.poll(() => page.evaluate(() => grok.shell.v?.name), {message: `the campaign view of "${name}" current`})
|
|
218
|
+
.toBe(name);
|
|
219
|
+
const link = page.locator('.d4-view-ribbon > .d4-ribbon-name:not(.grok-ns-entity-name)', {hasText: crumb})
|
|
220
|
+
.filter({visible: true}).first();
|
|
221
|
+
await expect(link, `the "${crumb}" crumb of "${name}"`).toBeVisible();
|
|
222
|
+
await link.click();
|
|
223
|
+
}, {tier: 'ui', description: 'clicks the parent crumb the shell shows before the campaign\'s name in its view\'s ribbon, once that view is current'});
|
|
224
|
+
|
|
225
|
+
/* ---------------------------------------------------------------- what a save put on the server */
|
|
226
|
+
|
|
227
|
+
interface Saved {rows: number; version: number; status: string; name: string; edit: string[];
|
|
228
|
+
values: {[col: string]: string[]}}
|
|
229
|
+
|
|
230
|
+
function savedCampaign(page: Page, c: Campaign): Promise<Saved | string> {
|
|
231
|
+
return page.evaluate(async ([root, id]) => {
|
|
232
|
+
const folder = `${root}/campaigns/${id}`;
|
|
233
|
+
if (!await grok.dapi.files.exists(`${folder}/campaign.json`))
|
|
234
|
+
return `no ${folder}/campaign.json`;
|
|
235
|
+
const text = await grok.dapi.files.readAsText(`${folder}/campaign.json`);
|
|
236
|
+
let json: any;
|
|
237
|
+
try {
|
|
238
|
+
json = JSON.parse(text);
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
// read while a save rewrites it: a throw would end the poll
|
|
242
|
+
return `${folder}/campaign.json is being written (${text.length} characters read)`;
|
|
243
|
+
}
|
|
244
|
+
const df = DG.DataFrame.fromCsv(await grok.dapi.files.readAsText(`${folder}/enriched_table.csv`));
|
|
245
|
+
const values: {[col: string]: string[]} = {};
|
|
246
|
+
for (const col of df.columns.toList())
|
|
247
|
+
values[col.name] = Array.from({length: df.rowCount}, (_, i) => col.isNone(i) ? '' : String(col.get(i)));
|
|
248
|
+
return {rows: df.rowCount, version: json.version ?? 0, status: json.status ?? '', name: json.friendlyName ?? '',
|
|
249
|
+
edit: json.permissions?.edit ?? [], values};
|
|
250
|
+
}, [ROOTS[c.app], c.id] as [string, string]);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async function pollSaved(page: Page, name: string, what: string, test: (s: Saved) => string): Promise<void> {
|
|
254
|
+
const c = campaignOf(page, name);
|
|
255
|
+
let seen = '';
|
|
256
|
+
await expect.poll(async () => {
|
|
257
|
+
const s = await savedCampaign(page, c);
|
|
258
|
+
seen = typeof s === 'string' ? s : test(s);
|
|
259
|
+
return seen;
|
|
260
|
+
}, {message: `the campaign "${name}" as saved on the server: ${what}`, timeout: pollMs(30000)}).toBe('').catch(() => {
|
|
261
|
+
throw new Error(`the campaign "${name}" on the server is not ${what}: ${seen}`);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const cellOf = (s: Saved, column: string, row: number): string | null =>
|
|
266
|
+
s.values[column] === undefined ? null : s.values[column][row - 1] ?? null;
|
|
267
|
+
|
|
268
|
+
export const savedRows = Then('the campaign {string} should be saved with {int} rows', (page: Page, name: string, rows: number) =>
|
|
269
|
+
pollSaved(page, name, `${rows} rows`, (s) => s.rows === rows ? '' : `${s.rows} rows`),
|
|
270
|
+
{tier: 'api', description: 'its table on the share, read back until the save has written it'});
|
|
271
|
+
|
|
272
|
+
export const savedCell = Then('the campaign {string} should be saved with {string} in row {int} of the {string} column',
|
|
273
|
+
(page: Page, name: string, value: string, row: number, column: string) =>
|
|
274
|
+
pollSaved(page, name, `"${value}" in row ${row} of ${column}`, (s) => {
|
|
275
|
+
const v = cellOf(s, column, row);
|
|
276
|
+
return v === value ? '' : v === null ? `no ${column} column or no row ${row} (${s.rows} rows; ${Object.keys(s.values).join(', ')})` : `"${v}"`;
|
|
277
|
+
}),
|
|
278
|
+
{tier: 'api', description: 'its table on the share, row counted from 1, the value as the CSV holds it; read back until the save has written it'});
|
|
279
|
+
|
|
280
|
+
export const savedCellMatching = Then('the campaign {string} should be saved with a value matching {string} in row {int} of the {string} column',
|
|
281
|
+
(page: Page, name: string, pattern: string, row: number, column: string) =>
|
|
282
|
+
pollSaved(page, name, `/${pattern}/ in row ${row} of ${column}`, (s) => {
|
|
283
|
+
const v = cellOf(s, column, row);
|
|
284
|
+
return v !== null && new RegExp(pattern).test(v) ? '' : v === null ? `no ${column} column or no row ${row} (${s.rows} rows)` : `"${v}"`;
|
|
285
|
+
}),
|
|
286
|
+
{tier: 'api', description: 'as the step above, the value matched by the regular expression'});
|
|
287
|
+
|
|
288
|
+
export const savedStatus = Then('the campaign {string} should be saved with the status {string}', (page: Page, name: string, status: string) =>
|
|
289
|
+
pollSaved(page, name, `status "${status}"`, (s) => s.status === status ? '' : `status "${s.status}"`),
|
|
290
|
+
{tier: 'api', description: 'campaign.json on the share, read back until the save has written it'});
|
|
291
|
+
|
|
292
|
+
export const savedName = Then('the campaign {string} should be saved with the name {string}', (page: Page, name: string, shown: string) =>
|
|
293
|
+
pollSaved(page, name, `named "${shown}"`, (s) => s.name === shown ? '' : `named "${s.name}"`),
|
|
294
|
+
{tier: 'api', description: 'the friendly name campaign.json carries, read back until the save has written it'});
|
|
295
|
+
|
|
296
|
+
export const savedVersion = Then('the campaign {string} should be at version {int} on the server', (page: Page, name: string, version: number) =>
|
|
297
|
+
pollSaved(page, name, `version ${version}`, (s) => s.version === version ? '' : `version ${s.version}`),
|
|
298
|
+
{tier: 'api', description: 'the version campaign.json carries (a save adds one)'});
|
|
299
|
+
|
|
300
|
+
export const sharingUserMayEdit = Then('the campaign {string} should let the sharing user edit it on the server', async (page: Page, name: string) => {
|
|
301
|
+
const group = await page.evaluate(async (login) => (await grok.dapi.users.filter(`login = ${JSON.stringify(login)}`).first())?.group?.id ?? '',
|
|
302
|
+
sharingLogin());
|
|
303
|
+
if (!group)
|
|
304
|
+
throw new Error(`no personal group of "${sharingLogin()}" on the server`);
|
|
305
|
+
await pollSaved(page, name, `editable by ${sharingLogin()}`, (s) => s.edit.includes(group) ? '' : `edit groups ${s.edit.join(', ')}`);
|
|
306
|
+
}, {tier: 'api', description: 'the edit permissions of campaign.json hold the personal group of DATAGROK_SHARING_LOGIN (bddsecond)'});
|
|
307
|
+
|
|
308
|
+
/* ---------------------------------------------------------------- the update log (what the refresh poll reads) */
|
|
309
|
+
|
|
310
|
+
const updateLogs = new WeakMap<Page, Map<string, string>>();
|
|
311
|
+
|
|
312
|
+
function updateLogOf(page: Page, c: Campaign): Promise<string> {
|
|
313
|
+
return page.evaluate(async ([a, id]) => {
|
|
314
|
+
const conn = (await grok.dapi.connections.filter('name = "hitdesign"').list())
|
|
315
|
+
.find((x: any) => x.nqName === 'HitTriage:hitdesign');
|
|
316
|
+
const df = await conn.query('bdd-campaign-log', `select updated_at from hitdesign.update_logs where app_name = '${a}' and campaign_id = '${id}'`).apply();
|
|
317
|
+
return df.rowCount > 0 ? df.col('updated_at').getString(0) : '';
|
|
318
|
+
}, [c.app, c.id] as [string, string]);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export const rememberUpdateLog = When('user remembers the update log of the campaign {string}', async (page: Page, name: string) => {
|
|
322
|
+
if (!updateLogs.has(page))
|
|
323
|
+
updateLogs.set(page, new Map());
|
|
324
|
+
updateLogs.get(page)!.set(name, await updateLogOf(page, campaignOf(page, name)));
|
|
325
|
+
}, {tier: 'api', description: 'the last update the hitdesign database logged for it (none before its first save), which the campaign view polls every 3 s'});
|
|
326
|
+
|
|
327
|
+
/* A save takes the campaign's lock before anything else and lets it go last (the release is what logs an update), so
|
|
328
|
+
a lock gone after the save's balloon is the end of that save: the update log is read after it, never before. */
|
|
329
|
+
export const noLockHeld = Then('the campaign {string} should hold no lock on the server', async (page: Page, name: string) => {
|
|
330
|
+
const c = campaignOf(page, name);
|
|
331
|
+
await expect.poll(() => page.evaluate(async ([a, id]) => {
|
|
332
|
+
const conn = (await grok.dapi.connections.filter('name = "hitdesign"').list())
|
|
333
|
+
.find((x: any) => x.nqName === 'HitTriage:hitdesign');
|
|
334
|
+
return (await conn.query('bdd-campaign-lock', `select campaign_id from hitdesign.campaign_locks where app_name = '${a}' and campaign_id = '${id}'`)
|
|
335
|
+
.apply()).rowCount;
|
|
336
|
+
}, [c.app, c.id] as [string, string]), {message: `the save lock of "${name}" let go`, timeout: pollMs(35000)}).toBe(0);
|
|
337
|
+
}, {tier: 'api', description: 'no row of the campaign in hitdesign.campaign_locks, polled: the save that took the lock has ended'});
|
|
338
|
+
|
|
339
|
+
export const updateLogAsRemembered = Then('the update log of the campaign {string} should be as remembered', async (page: Page, name: string) => {
|
|
340
|
+
const before = updateLogs.get(page)?.get(name);
|
|
341
|
+
if (before === undefined)
|
|
342
|
+
throw new Error(`the update log of "${name}" was not remembered`);
|
|
343
|
+
expect(await updateLogOf(page, campaignOf(page, name)), `the update log of "${name}" (remembered: "${before}")`).toBe(before);
|
|
344
|
+
}, {tier: 'api', description: 'read once, after an end signal the step before gave (the refused save\'s balloon)'});
|
|
345
|
+
|
|
346
|
+
/* ---------------------------------------------------------------- a save from another session */
|
|
347
|
+
|
|
348
|
+
export const otherSessionSaves = When('another session saves the campaign {string} with a new row of {string}', async (page: Page, name: string, smiles: string) => {
|
|
349
|
+
const c = campaignOf(page, name);
|
|
350
|
+
const error = await page.evaluate(async ([root, a, id, mol]) => {
|
|
351
|
+
const lock = await grok.data.query('HitTriage:AcquireCampaignLock', {appName: a, campaignId: id, lockedBy: 'bdd second session'});
|
|
352
|
+
if (!lock || lock.rowCount === 0)
|
|
353
|
+
return 'the campaign lock was not acquired';
|
|
354
|
+
const folder = `${root}/campaigns/${id}`;
|
|
355
|
+
const json = JSON.parse(await grok.dapi.files.readAsText(`${folder}/campaign.json`));
|
|
356
|
+
const df = DG.DataFrame.fromCsv(await grok.dapi.files.readAsText(`${folder}/enriched_table.csv`));
|
|
357
|
+
df.rows.addNew(null, false);
|
|
358
|
+
df.set('Molecule', df.rowCount - 1, mol);
|
|
359
|
+
if (df.col('Stage') && json.template?.stages?.length)
|
|
360
|
+
df.set('Stage', df.rowCount - 1, json.template.stages[0]);
|
|
361
|
+
await grok.dapi.files.writeAsText(`${folder}/enriched_table.csv`, df.toCsv());
|
|
362
|
+
json.version = (json.version ?? 0) + 1;
|
|
363
|
+
json.rowCount = df.rowCount;
|
|
364
|
+
json.filteredRowCount = df.rowCount;
|
|
365
|
+
await grok.dapi.files.writeAsText(`${folder}/campaign.json`, JSON.stringify(json));
|
|
366
|
+
const released = await grok.data.query('HitTriage:ReleaseCampaignLock', {appName: a, campaignId: id});
|
|
367
|
+
return released?.rowCount > 0 ? '' : 'the campaign lock was not released';
|
|
368
|
+
}, [ROOTS[c.app], c.app, c.id, smiles] as [string, App, string, string]);
|
|
369
|
+
if (error)
|
|
370
|
+
throw new Error(`another session's save of "${name}" failed: ${error}`);
|
|
371
|
+
}, {tier: 'api', description: 'what a save in another browser does, through the package\'s own lock queries and the files API: the lock taken, the row appended (the first stage) to the table, the version raised, the lock released, which logs the update the campaign view polls for'});
|
|
372
|
+
|
|
373
|
+
/* ---------------------------------------------------------------- files in the user's home */
|
|
374
|
+
|
|
375
|
+
const homePath = (page: Page, file: string): Promise<string> =>
|
|
376
|
+
page.evaluate((f) => `${grok.shell.user.project.name}:Home/${f}`, file);
|
|
377
|
+
|
|
378
|
+
export const userFileHolds = Given('the user\'s file {string} holds the table:', async (page: Page, file: string, table: string[][]) => {
|
|
379
|
+
const path = await homePath(page, file);
|
|
380
|
+
const remove = async () => {
|
|
381
|
+
await page.evaluate(async (p) => {
|
|
382
|
+
if (await grok.dapi.files.exists(p))
|
|
383
|
+
await grok.dapi.files.delete(p);
|
|
384
|
+
}, path);
|
|
385
|
+
await expect.poll(() => page.evaluate((p) => grok.dapi.files.exists(p), path),
|
|
386
|
+
{message: `${path} deleted`, timeout: pollMs(30000)}).toBe(false);
|
|
387
|
+
};
|
|
388
|
+
await remove();
|
|
389
|
+
atFeatureEnd(page, remove);
|
|
390
|
+
await page.evaluate(([p, rows]) => grok.dapi.files.writeAsText(p, rows.map((r) => r.join(',')).join('\n') + '\n'),
|
|
391
|
+
[path, table] as [string, string[][]]);
|
|
392
|
+
}, {tier: 'api', description: 'a CSV of the rows given (the first one the header) in the account\'s home folder, written through the files API; deleted at feature end, read back'});
|
|
393
|
+
|
|
394
|
+
export const holdsUserFilePath = Then('{element} should hold the path of the user\'s file {string}',
|
|
395
|
+
async (page: Page, target: ElementRef, file: string) => {
|
|
396
|
+
const path = await homePath(page, file);
|
|
397
|
+
await expect((await locate(page, target)).locator('input[type="text"]').first(), `the share path ${path}`).toHaveValue(path);
|
|
398
|
+
}, {tier: 'ui', description: 'the text of the file input\'s box: the file\'s share path (<home project>:Home/<file>)'});
|
|
399
|
+
|
|
400
|
+
export const chooseProjectFile = When('user clicks on {element} and chooses the {string} file of the project',
|
|
401
|
+
async (page: Page, target: ElementRef, file: string) => {
|
|
402
|
+
const chooser = page.waitForEvent('filechooser', {timeout: pollMs(15000)});
|
|
403
|
+
await gestures.click(page, target);
|
|
404
|
+
await (await chooser).setFiles(resolve(process.env.BDD_ROOT ?? process.cwd(), file));
|
|
405
|
+
}, {tier: 'ui', description: 'the click opens the browser\'s file chooser, which is answered with a file of the bdd project'});
|
|
406
|
+
|
|
407
|
+
type MergeKept = {filePath?: string; autoMergeOnOpen?: boolean} | null;
|
|
408
|
+
|
|
409
|
+
const mergeConfigOf = (page: Page, c: Campaign): Promise<MergeKept> =>
|
|
410
|
+
page.evaluate(async ([root, id]) => JSON.parse(await grok.dapi.files.readAsText(`${root}/campaigns/${id}/campaign.json`))
|
|
411
|
+
.mergeConfig ?? null, [ROOTS[c.app], c.id] as [string, string]);
|
|
412
|
+
|
|
413
|
+
async function pollMergeConfig(page: Page, name: string, what: string, test: (cfg: MergeKept) => boolean): Promise<void> {
|
|
414
|
+
const c = campaignOf(page, name);
|
|
415
|
+
let seen: MergeKept = null;
|
|
416
|
+
await expect.poll(async () => {
|
|
417
|
+
seen = await mergeConfigOf(page, c);
|
|
418
|
+
return test(seen);
|
|
419
|
+
}, {message: `the merge kept with the campaign "${name}": ${what}`, timeout: pollMs(30000)}).toBe(true).catch(() => {
|
|
420
|
+
throw new Error(`the campaign "${name}" on the server does not ${what}: its mergeConfig is ${JSON.stringify(seen)}`);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export const savedToMergeUserFile = Then('the campaign {string} should be saved to merge the user\'s file {string} on every open',
|
|
425
|
+
async (page: Page, name: string, file: string) => {
|
|
426
|
+
const path = await homePath(page, file);
|
|
427
|
+
await pollMergeConfig(page, name, `merge ${path} on every open`, (cfg) => cfg?.filePath === path && cfg.autoMergeOnOpen === true);
|
|
428
|
+
}, {tier: 'api', description: 'its campaign.json\'s mergeConfig names the file\'s share path with Auto-merge on campaign open, read back until the save wrote it'});
|
|
429
|
+
|
|
430
|
+
export const savedToMergeNoFile = Then('the campaign {string} should be saved to merge no file on open', (page: Page, name: string) =>
|
|
431
|
+
pollMergeConfig(page, name, 'keep a merge with no file to read on open',
|
|
432
|
+
(cfg) => cfg !== null && cfg.filePath === undefined && cfg.autoMergeOnOpen === false),
|
|
433
|
+
{tier: 'api', description: 'its campaign.json keeps the merge\'s choices but no file path, and Auto-merge on campaign open off'});
|
|
434
|
+
|
|
435
|
+
export const enterUserFilePath = When('user enters the path of the user\'s file {string} into {element}',
|
|
436
|
+
async (page: Page, file: string, target: ElementRef) => gestures.typeInto(page, target, await homePath(page, file), true),
|
|
437
|
+
{tier: 'ui', description: 'types the file\'s share path (<home project>:Home/<file>) and presses Enter, as a person pastes it'});
|
|
438
|
+
|
|
439
|
+
/* ---------------------------------------------------------------- reads of the page */
|
|
440
|
+
|
|
441
|
+
export const valueMatching = Then('the value of {string} column in row {int} should match {string}',
|
|
442
|
+
async (page: Page, column: string, row: number, pattern: string) => {
|
|
443
|
+
await expect.poll(() => page.evaluate(([c, r]) => {
|
|
444
|
+
const col = grok.shell.t?.col(c);
|
|
445
|
+
return col ? r <= col.length ? col.isNone(r - 1) ? '' : String(col.get(r - 1)) : `(the table has ${col.length} rows)` : `(no ${c} column)`;
|
|
446
|
+
}, [column, row] as [string, number]), {message: `"${column}" in row ${row} of the current table`}).toMatch(new RegExp(pattern));
|
|
447
|
+
}, {description: 'the current table\'s cell, rows from 1, matched by the regular expression; polled'});
|
|
448
|
+
|
|
449
|
+
/* The sketcher applies a typed molecule on its own time (OpenChemLib loads it into its editor after the Enter), and
|
|
450
|
+
OK writes what it holds then: an OK right after the Enter wrote the old molecule. The step ends on the sketcher's
|
|
451
|
+
own state. */
|
|
452
|
+
export const enterMoleculeInSketcher = When('user enters the molecule {string} into sketcher dialog', async (page: Page, smiles: string) => {
|
|
453
|
+
const dialog = page.locator('.d4-dialog:has(input[placeholder^="SMILES"])').filter({visible: true}).last();
|
|
454
|
+
const input = dialog.locator('input[placeholder^="SMILES"]');
|
|
455
|
+
await input.click();
|
|
456
|
+
await input.fill(smiles);
|
|
457
|
+
await input.press('Enter');
|
|
458
|
+
await expect.poll(() => dialog.evaluate((d, s) => {
|
|
459
|
+
for (const e of Array.from(d.querySelectorAll('[data-widget]'))) {
|
|
460
|
+
const w = DG.Widget.find(e);
|
|
461
|
+
if (w && typeof w.getSmiles === 'function') {
|
|
462
|
+
const now = String(w.getSmiles() ?? '');
|
|
463
|
+
return now === '' ? '(empty)' : grok.chem.convert(now, DG.chem.Notation.Unknown, DG.chem.Notation.Smiles) ===
|
|
464
|
+
grok.chem.convert(s, DG.chem.Notation.Unknown, DG.chem.Notation.Smiles) ? '' : now;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return '(no sketcher in the dialog)';
|
|
468
|
+
}, smiles), {message: `the sketcher holding ${smiles}`}).toBe('');
|
|
469
|
+
}, {tier: 'ui', description: 'types the SMILES into the molecule field of the open sketcher dialog and presses Enter; done when the sketcher holds that molecule (DG.chem.Sketcher.getSmiles, compared canonically), so OK writes it'});
|
|
470
|
+
|
|
471
|
+
/* The summary, read-only form rows or a key-value table (ui.tableFromMap), is read as label → shown text, the editable
|
|
472
|
+
inputs below it left out. */
|
|
473
|
+
export const summaryIs = Then('the summary in {element} should be:', async (page: Page, target: ElementRef, rows: string[][]) => {
|
|
474
|
+
const root = (await locate(page, target)).filter({visible: true}).first();
|
|
475
|
+
const read = (): Promise<[string, string][]> => root.evaluate((r) => {
|
|
476
|
+
const table = r.querySelector('table.d4-item-table');
|
|
477
|
+
if (table) {
|
|
478
|
+
return Array.from(table.querySelectorAll(':scope > tbody > tr'))
|
|
479
|
+
.map((tr) => Array.from(tr.children).map((td) => (td.textContent ?? '').trim()))
|
|
480
|
+
.map((cells) => [cells[0] ?? '', cells[1] ?? ''] as [string, string]);
|
|
481
|
+
}
|
|
482
|
+
return Array.from(r.querySelectorAll('label')).filter((l) => (l as HTMLElement).offsetWidth > 0)
|
|
483
|
+
.map((l) => {
|
|
484
|
+
const field = (l.htmlFor ? document.getElementById(l.htmlFor) : null) as HTMLInputElement | null;
|
|
485
|
+
const text = field && !field.readOnly && 'value' in field ? null :
|
|
486
|
+
field ? String(field.value ?? field.textContent ?? '') : (l.parentElement?.textContent ?? '').replace(l.textContent ?? '', '');
|
|
487
|
+
return text === null ? null : [(l.textContent ?? '').trim(), text.trim()] as [string, string];
|
|
488
|
+
}).filter((x): x is [string, string] => x !== null);
|
|
489
|
+
});
|
|
490
|
+
// a value "*" is not compared (it changes by design), one ending in "…" is a beginning
|
|
491
|
+
const holds = (got: [string, string][]): boolean => got.length === rows.length && rows.every(([k, v], i) =>
|
|
492
|
+
got[i][0] === k && (v === '*' || (v.endsWith('…') ? got[i][1].startsWith(v.slice(0, -1)) : got[i][1] === v)));
|
|
493
|
+
let got: [string, string][] = [];
|
|
494
|
+
await expect.poll(async () => holds(got = await read()), {message: `the summary of ${target.phrase}`}).toBe(true).catch(() => {
|
|
495
|
+
throw new Error(`the summary of ${target.phrase} is not ${rows.map(([k, v]) => `${k} = ${v}`).join('; ')}: ` +
|
|
496
|
+
`it shows ${got.map(([k, v]) => `${k} = ${v}`).join('; ')}`);
|
|
497
|
+
});
|
|
498
|
+
}, {tier: 'ui', description: 'the read-only summary in the element (a key-value table, or read-only form rows): exactly these keys, in this order, each showing that text — "*" any text, a value ending in "…" the text\'s beginning'});
|
|
499
|
+
|
|
500
|
+
/* A Molecule field's structure is the row's value: inside its row, which is as tall as the picture, starting where the
|
|
501
|
+
text values start, clear of the next row (it hung over the next row from a 28 px row before). */
|
|
502
|
+
export const structureInRow = Then('the structure of the {string} row in {element} should sit in the value column of its row',
|
|
503
|
+
async (page: Page, caption: string, target: ElementRef) => {
|
|
504
|
+
const root = (await locate(page, target)).filter({visible: true}).first();
|
|
505
|
+
let seen = '';
|
|
506
|
+
await expect.poll(async () => seen = await root.evaluate((r, c) => {
|
|
507
|
+
const rows = Array.from(r.querySelectorAll<HTMLElement>('.u2-input-root')).filter((x) => x.getClientRects().length > 0);
|
|
508
|
+
const at = rows.findIndex((x) => x.querySelector(':scope > .u2-input-label')?.textContent?.trim() === c);
|
|
509
|
+
if (at < 0)
|
|
510
|
+
return `no "${c}" row`;
|
|
511
|
+
const box = (el: Element | null | undefined) => el?.getBoundingClientRect() ?? null;
|
|
512
|
+
const row = box(rows[at])!;
|
|
513
|
+
const picture = box(rows[at].querySelector('canvas, svg, img'));
|
|
514
|
+
const next = box(rows[at + 1]);
|
|
515
|
+
const value = box(rows.find((x) => x.dataset.u2 === 'text-input')?.querySelector('[data-u2-part="editor"]'));
|
|
516
|
+
if (picture === null || picture.height < 2)
|
|
517
|
+
return 'no structure drawn';
|
|
518
|
+
const problems: string[] = [];
|
|
519
|
+
if (picture.top < row.top - 1 || picture.bottom > row.bottom + 1 || picture.right > row.right + 1)
|
|
520
|
+
problems.push(`the structure ${Math.round(picture.top)}–${Math.round(picture.bottom)} is outside its row ${Math.round(row.top)}–${Math.round(row.bottom)}`);
|
|
521
|
+
if (next !== null && picture.bottom > next.top + 1)
|
|
522
|
+
problems.push('it covers the next row');
|
|
523
|
+
if (value !== null && Math.abs(picture.left - value.left) > 8)
|
|
524
|
+
problems.push(`it starts at x ${Math.round(picture.left)}, the values at ${Math.round(value.left)}`);
|
|
525
|
+
return problems.join('; ');
|
|
526
|
+
}, caption), {message: `the structure of the "${caption}" row in ${target.phrase}`, timeout: pollMs(15000)}).toBe('')
|
|
527
|
+
.catch(() => {
|
|
528
|
+
throw new Error(`the structure of the "${caption}" row in ${target.phrase} is misplaced: ${seen}`);
|
|
529
|
+
});
|
|
530
|
+
}, {tier: 'ui', description: 'the drawn structure lies inside its form row (the row grew to it), clear of the next row, and starts within 8 px of where the text values start'});
|
|
531
|
+
|
|
532
|
+
/* Status suggestions, a u2 suggest input's list or a platform popup menu, are read and picked by the text of their
|
|
533
|
+
items. */
|
|
534
|
+
const SUGGESTIONS = '.d4-menu-popup .d4-menu-item-label, .u2-overlay [data-u2-part="popup"] [role="option"]';
|
|
535
|
+
|
|
536
|
+
export const suggests = Then('{element} should suggest {string}', async (page: Page, target: ElementRef, text: string) => {
|
|
537
|
+
await locate(page, target);
|
|
538
|
+
await expect.poll(() => page.evaluate((sel) => Array.from(document.querySelectorAll(sel))
|
|
539
|
+
.filter((e) => (e as HTMLElement).offsetWidth > 0).map((e) => (e.textContent ?? '').trim()), SUGGESTIONS),
|
|
540
|
+
{message: `the suggestions shown for ${target.phrase}`}).toContain(text);
|
|
541
|
+
}, {tier: 'ui', description: 'the suggestions open under the input (a popup menu, or a suggest input\'s list) hold an item of exactly that text'});
|
|
542
|
+
|
|
543
|
+
export const takeSuggestion = When('user takes the suggestion {string} of {element}', async (page: Page, text: string, target: ElementRef) => {
|
|
544
|
+
await locate(page, target);
|
|
545
|
+
await page.locator(SUGGESTIONS).filter({visible: true}).filter({hasText: new RegExp(`^\\s*${text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*$`)})
|
|
546
|
+
.first().click();
|
|
547
|
+
}, {tier: 'ui', description: 'clicks the suggestion of exactly that text shown for the input'});
|
|
548
|
+
|
|
549
|
+
/* Edit Permissions is an access grid: a user or group is added from the picker under its rows, then
|
|
550
|
+
given its capabilities in its row. The feature names the outcome; this step is the one place that knows the form. */
|
|
551
|
+
export const grantSharingUserEdit = When('user lets the sharing user edit in {element}', async (page: Page, target: ElementRef) => {
|
|
552
|
+
const dialog = (await locate(page, target)).filter({visible: true}).first();
|
|
553
|
+
const grid = dialog.locator('[data-u2="access-grid"]');
|
|
554
|
+
await expect(grid, `the access grid of ${target.phrase}`).toBeVisible({timeout: pollMs(15000)});
|
|
555
|
+
const shown = new RegExp(sharingShownName(), 'i');
|
|
556
|
+
await gestures.typeVerified(grid.locator('input.u2-typeahead-input'), sharingLogin().split('@')[0],
|
|
557
|
+
`the add picker of ${target.phrase}`);
|
|
558
|
+
const option = page.locator('[role="option"]').filter({has: page.locator('.u2-typeahead-user-name', {hasText: shown})}).first();
|
|
559
|
+
await expect(option, `the "${sharingLogin()}" suggestion of the add picker`).toBeVisible({timeout: pollMs(15000)});
|
|
560
|
+
await option.click();
|
|
561
|
+
const canEdit = grid.locator('tr.u2-access-grid-row').filter({hasText: shown}).locator('input[data-u2-key="edit"]');
|
|
562
|
+
await expect(canEdit, 'the Can Edit box of the second account\'s row').toBeVisible({timeout: pollMs(15000)});
|
|
563
|
+
await canEdit.check();
|
|
564
|
+
await expect(canEdit, 'the Can Edit box of the second account\'s row').toBeChecked();
|
|
565
|
+
}, {tier: 'ui', description: 'gives the second account (DATAGROK_SHARING_LOGIN) edit access in the Edit Permissions grid: adds it from the picker\'s suggestions, then checks Can Edit in its row'});
|
|
566
|
+
|
|
567
|
+
/* Modify Stages is a records input: a row per stage, "Add stage" under them. */
|
|
568
|
+
export const addStage = When('user adds the stage {string} in {element}', async (page: Page, stage: string, target: ElementRef) => {
|
|
569
|
+
const dialog = (await locate(page, target)).filter({visible: true}).first();
|
|
570
|
+
const records = dialog.locator('[data-u2="records-input"]');
|
|
571
|
+
const cells = records.locator('[role="row"] input');
|
|
572
|
+
const before = await cells.count();
|
|
573
|
+
await records.getByText('Add stage', {exact: true}).click();
|
|
574
|
+
await expect(cells, `a new row in ${target.phrase}`).toHaveCount(before + 1);
|
|
575
|
+
await gestures.typeVerified(cells.last(), stage, `the new row of ${target.phrase}`);
|
|
576
|
+
}, {tier: 'ui', description: 'adds a row with "Add stage" and types the stage into it'});
|
|
577
|
+
|
|
578
|
+
export const namesSharingUser = Then('{element} should name the sharing user', async (page: Page, target: ElementRef) => {
|
|
579
|
+
await expect((await locate(page, target)).filter({visible: true}).first(), `${target.phrase}, naming the second account`)
|
|
580
|
+
.toContainText(new RegExp(sharingShownName(), 'i'));
|
|
581
|
+
}, {tier: 'ui', description: 'the element shows the second account (DATAGROK_SHARING_LOGIN) as the platform names it'});
|
|
582
|
+
|
|
583
|
+
/* A row of the Edit Permissions grid starts with who it is: a group's two-person icon, a user's picture or initials. */
|
|
584
|
+
async function principalPicture(page: Page, target: ElementRef, who: RegExp, kind: 'group' | 'user'): Promise<void> {
|
|
585
|
+
const row = (await locate(page, target)).filter({visible: true}).first()
|
|
586
|
+
.locator('[data-u2="access-grid"] tr.u2-access-grid-row')
|
|
587
|
+
.filter({has: page.locator('.u2-access-grid-principal', {hasText: who})}).first();
|
|
588
|
+
await expect(row.locator(`.u2-access-grid-icon > .u2-avatar${kind === 'group' ? '.u2-avatar-group' : ':not(.u2-avatar-group)'}`),
|
|
589
|
+
`the ${kind} picture in the ${who} row of ${target.phrase}`).toBeVisible({timeout: pollMs(15000)});
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
export const groupPicture = Then('the {string} row of {element} should show a group icon',
|
|
593
|
+
(page: Page, name: string, target: ElementRef) =>
|
|
594
|
+
principalPicture(page, target, new RegExp(`^${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`), 'group'),
|
|
595
|
+
{tier: 'ui', description: 'the access grid row of that group starts with the group icon'});
|
|
596
|
+
|
|
597
|
+
export const sharingUserPicture = Then('the sharing user\'s row of {element} should show the user\'s picture',
|
|
598
|
+
(page: Page, target: ElementRef) => principalPicture(page, target, new RegExp(sharingShownName(), 'i'), 'user'),
|
|
599
|
+
{tier: 'ui', description: 'the access grid row of the second account (DATAGROK_SHARING_LOGIN) starts with its picture or initials'});
|
|
600
|
+
|
|
601
|
+
export const ribbonLastGroup = Then('the last group of the ribbon should list {string}', async (page: Page, list: string) => {
|
|
602
|
+
const want = list.split(/\s*,\s*/).filter((s) => s.length > 0);
|
|
603
|
+
await expect.poll(() => page.evaluate(() => {
|
|
604
|
+
const panels = Array.from(document.querySelectorAll('.d4-ribbon-panel')).filter((p) => (p as HTMLElement).offsetWidth > 0);
|
|
605
|
+
const last = panels[panels.length - 1];
|
|
606
|
+
const group = last?.querySelector('[data-u2="ribbon-group"]');
|
|
607
|
+
// a package with a designer function (Reinvent4) adds its action to the group, on the stands it is published to
|
|
608
|
+
const designers = DG.Func.find({meta: {role: 'HitDesignerFunction'}})
|
|
609
|
+
.map((f: {description: string, friendlyName: string}) => f.description || f.friendlyName);
|
|
610
|
+
const names = group ? (DG.U2.Control.forElement(group).getItems().list as {key: string}[]).map((i) => i.key) :
|
|
611
|
+
last ? Array.from(last.querySelectorAll(':scope > .d4-ribbon-item > *'))
|
|
612
|
+
.map((e) => (e.getAttribute('aria-label') ?? e.textContent ?? '').trim()).filter((s) => s.length > 0) : [];
|
|
613
|
+
return names.filter((name) => !designers.includes(name));
|
|
614
|
+
}), {message: 'the items of the ribbon\'s last group, by their names'}).toEqual(want);
|
|
615
|
+
}, {tier: 'ui', description: 'the shown ribbon\'s last panel, item by item in order: a u2 ribbon group\'s items by their keys (an icon\'s name or tooltip, a button\'s text, folded ones included), else each element by its aria-label or text; an item with no name (a separator) is left out'});
|
|
616
|
+
|
|
617
|
+
export const closeViewByName = When('user closes the {string} view', async (page: Page, name: string) => {
|
|
618
|
+
await page.evaluate((n) => {
|
|
619
|
+
const view = Array.from(grok.shell.views as Iterable<any>).find((v) => v.name === n);
|
|
620
|
+
if (!view)
|
|
621
|
+
throw new Error(`no "${n}" view; open: ${Array.from(grok.shell.views as Iterable<any>).map((v) => v.name).join(', ')}`);
|
|
622
|
+
view.close();
|
|
623
|
+
}, name);
|
|
624
|
+
await expect.poll(() => page.evaluate((n) => Array.from(grok.shell.views as Iterable<any>).some((v) => v.name === n), name),
|
|
625
|
+
{message: `the "${name}" view closed`}).toBe(false);
|
|
626
|
+
}, {tier: 'api', description: 'an open view by its name, current or not — what the ✕ of its tab does where the tabs are shown'});
|