forked from oncokb/oncokb-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnnotationPages.screenshot.js
581 lines (533 loc) · 20.4 KB
/
AnnotationPages.screenshot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
import puppeteer from 'puppeteer';
import fs from 'fs';
const DATA_DIR = './screenshot-test/data/';
const CLIENT_URL = 'http://localhost:9000/';
const SERVER_URL = 'http://localhost:9095/';
const VIEW_PORT_1080 = {
width: 1920,
height: 1080,
deviceScaleFactor: 1,
}
const MOBILE_VIEW_PORT = {
width: 400,
height: 800,
deviceScaleFactor: 1,
}
const WAITING_TIME = 2000;
const LONG_WAITING_TIME = 10000;
const LATEST_SNAPSHOTS_DIR = './screenshot-test/__latest_snapshots__/';
const browserConfig = { // Docker requires --no-sandbox to be able to run the tests
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox'],
ignoreHTTPSErrors: true,
dumpio: false
}
// Shared API response data
const apiAccount = fs.readFileSync(`${DATA_DIR}api-account.json`).toString();
const apiV1Info = fs.readFileSync(`${DATA_DIR}api-v1-info.json`).toString();
const numbersMain = fs.readFileSync(`${DATA_DIR}private-utils-numbers-main.json`).toString();
const numbersLevels = fs.readFileSync(`${DATA_DIR}private-utils-numbers-levels.json`).toString();
const tumorTypes = fs.readFileSync(`${DATA_DIR}private-utils-tumorTypes.json`).toString();
// ROS1 gene page - API response data
const rose1GeneQuery = fs.readFileSync(`${DATA_DIR}api-v1-genes-ROS1.json`).toString();
const ros1BiologicalVariants = fs.readFileSync(`${DATA_DIR}api-private-search-variants-bio-ROS1.json`).toString();
const rose1EnsemblGenes = fs.readFileSync(`${DATA_DIR}api-private-utils-ensembleGenes-ROS1.json`).toString();
const ros1GeneNumbers = fs.readFileSync(`${DATA_DIR}private-utils-numbers-gene-ROS1.json`).toString();
const ros1EvidenceSummary = fs.readFileSync(`${DATA_DIR}api-v1-evidences-ROS1-summary.json`).toString();
const ros1EvidenceBackground = fs.readFileSync(`${DATA_DIR}api-v1-evidences-ROS1-background.json`).toString();
const ros1ClinicalVariants = fs.readFileSync(`${DATA_DIR}api-private-search-variants-cli-ROS1.json`).toString();
// TP53 Deletion page - API response data
// Mainly test the prognostic data
const tp53GeneQuery = fs.readFileSync(`${DATA_DIR}api-v1-genes-TP53.json`).toString();
const tp53GeneNumbers = fs.readFileSync(`${DATA_DIR}private-utils-numbers-gene-TP53.json`).toString();
const tp53EnsemblGenes = fs.readFileSync(`${DATA_DIR}api-private-utils-ensembleGenes-TP53.json`).toString();
const tp53BiologicalVariants = fs.readFileSync(`${DATA_DIR}api-private-search-variants-bio-TP53.json`).toString();
const tp53ClinicalVariants = fs.readFileSync(`${DATA_DIR}api-private-search-variants-cli-TP53.json`).toString();
const tp53DeletionVariantAnnotation = fs.readFileSync(`${DATA_DIR}api-private-utils-variantAnnotation-TP53-DELETION.json`).toString();
const tp53DeletionQuery = fs.readFileSync(`${DATA_DIR}api-v1-variants-TP53-DELETION.json`).toString();
// BRAF V600E shared API response data
const brafGeneQuery = fs.readFileSync(`${DATA_DIR}api-v1-genes-BRAF.json`).toString();
const brafGeneNumbers = fs.readFileSync(`${DATA_DIR}private-utils-numbers-gene-BRAF.json`).toString();
const brafEnsemblGenes = fs.readFileSync(`${DATA_DIR}api-private-utils-ensembleGenes-BRAF.json`).toString();
const brafBiologicalVariants = fs.readFileSync(`${DATA_DIR}api-private-search-variants-bio-BRAF.json`).toString();
const brafClinicalVariants = fs.readFileSync(`${DATA_DIR}api-private-search-variants-cli-BRAF.json`).toString();
const brafV600eQuery = fs.readFileSync(`${DATA_DIR}api-v1-variants-BRAF-V600E.json`).toString();
const brafV600eRelevantAlterations = fs.readFileSync(`${DATA_DIR}api-private-utils-relevantAlterations-BRAF-V600E.json`).toString();
// BRAF V600E HGVSg page - API response data
// Mainly test the therapeutic/fda data for solid disease
const brafV600eHgvsgVariantAnnotation = fs.readFileSync(`${DATA_DIR}api-private-utils-variantAnnotation-BRAF-V600E-HGVSG.json`).toString();
// BRAF V600E Hairy Cell Leukemia page - API response data
// Mainly test the therapeutic/diagnostic data for heme disease
const brafV600eHairyCellLeukemiaVariantAnnotation = fs.readFileSync(`${DATA_DIR}api-private-utils-variantAnnotation-BRAF-V600E-HCL.json`).toString();
// BRAF V600E Melanoma Leukemia page - API response data
// Mainly test the therapeutic/fda data for solid disease
const brafV600eMelanomaVariantAnnotation = fs.readFileSync(`${DATA_DIR}api-private-utils-variantAnnotation-BRAF-V600E-MEL.json`).toString();
// # Fix the time to expiration date.
function updateTokenExpirationDate(current){
let today = new Date()
today.setDate(today.getDate()+100);
current.forEach(token => {
token.expiration = today.toISOString();
})
return current;
}
let apiAccountToken = fs.readFileSync(`${DATA_DIR}api-account-token.json`).toString();
apiAccountToken = JSON.stringify(updateTokenExpirationDate(JSON.parse(apiAccountToken)));
let userToken = fs.readFileSync(`${DATA_DIR}api-users-tokens.json`).toString();
userToken = JSON.stringify(updateTokenExpirationDate(JSON.parse(userToken)));
let companyUserToken = fs.readFileSync(`${DATA_DIR}api-company-user-tokens.json`).toString();
companyUserToken = JSON.stringify(updateTokenExpirationDate(JSON.parse(companyUserToken)));
function getScreenshotConfig(name){
return{
path: `${LATEST_SNAPSHOTS_DIR}${name}-snap.png`,
fullPage: true
}
}
if (!fs.existsSync(LATEST_SNAPSHOTS_DIR)){
fs.mkdirSync(LATEST_SNAPSHOTS_DIR);
}
function getMockResponse(url){
let res = undefined
switch (url) {
case `${SERVER_URL}api/account`:
res = {
status: 200,
contentType: 'application/json',
body: apiAccount
};
break;
case `${SERVER_URL}api/account/tokens`:
res = {
status: 200,
contentType: 'application/json',
body: apiAccountToken
};
break;
case `${SERVER_URL}api/v1/info`:
res = {
status: 200,
contentType: 'application/json',
body: apiV1Info
};
break;
case `${SERVER_URL}api/private/utils/numbers/main/`:
res = {
status: 200,
contentType: 'application/json',
body: numbersMain
};
break;
case `${SERVER_URL}api/private/utils/numbers/levels/`:
res = {
status: 200,
contentType: 'application/json',
body: numbersLevels
};
break;
case `${SERVER_URL}api/private/utils/tumorTypes`:
res = {
status: 200,
contentType: 'application/json',
body: tumorTypes
};
break;
case `${SERVER_URL}api/users/admin/tokens`:
res = {
status: 200,
contentType: 'application/json',
body: userToken
};
break;
// ROS1
case `${SERVER_URL}api/private/utils/numbers/gene/ROS1`:
res = {
status: 200,
contentType: 'application/json',
body: ros1GeneNumbers
};
break;
case `${SERVER_URL}api/v1/genes/lookup?query=ROS1`:
res = {
status: 200,
contentType: 'application/json',
body: rose1GeneQuery
};
break;
case `${SERVER_URL}api/private/search/variants/biological?hugoSymbol=ROS1`:
res = {
status: 200,
contentType: 'application/json',
body: ros1BiologicalVariants
};
break;
case `${SERVER_URL}api/private/search/variants/clinical?hugoSymbol=ROS1`:
res = {
status: 200,
contentType: 'application/json',
body: ros1ClinicalVariants
};
break;
case `${SERVER_URL}api/private/utils/ensembleGenes?entrezGeneId=6098`:
res = {
status: 200,
contentType: 'application/json',
body: rose1EnsemblGenes
};
break;
case `${SERVER_URL}api/v1/evidences/lookup?hugoSymbol=ROS1&evidenceTypes=GENE_SUMMARY`:
res = {
status: 200,
contentType: 'application/json',
body: ros1EvidenceSummary
};
break;
case `${SERVER_URL}api/v1/evidences/lookup?hugoSymbol=ROS1&evidenceTypes=GENE_BACKGROUND`:
res = {
status: 200,
contentType: 'application/json',
body: ros1EvidenceBackground
};
break;
case `https://www.genomenexus.org//ensembl/transcript`:
res = {
status: 200,
contentType: 'application/json',
body: rose1EnsemblGenes
};
break;
case `${SERVER_URL}api/private/utils/portalAlterationSampleCount`:
res = {
status: 200,
contentType: 'application/json',
body: '[]'
};
break;
case `${SERVER_URL}api/private/utils/mutationMapperData?hugoSymbol=ROS1`:
res = {
status: 200,
contentType: 'application/json',
body: '[]'
};
break;
case `https://www.genomenexus.org//ensembl/canonical-transcript/hgnc/ROS1?isoformOverrideSource=mskcc`:
res = {
status: 200,
contentType: 'application/json',
body: '{}'
};
break;
case `https://www.genomenexus.org//pfam/domain`:
res = {
status: 200,
contentType: 'application/json',
body: '[]'
};
break;
// TP53 Deletion
case `${SERVER_URL}api/private/utils/numbers/gene/TP53`:
res = {
status: 200,
contentType: 'application/json',
body: tp53GeneNumbers
};
break;
case `${SERVER_URL}api/v1/genes/lookup?query=TP53`:
res = {
status: 200,
contentType: 'application/json',
body: tp53GeneQuery
};
break;
case `${SERVER_URL}api/private/search/variants/biological?hugoSymbol=TP53`:
res = {
status: 200,
contentType: 'application/json',
body: tp53BiologicalVariants
};
break;
case `${SERVER_URL}api/private/search/variants/clinical?hugoSymbol=TP53`:
res = {
status: 200,
contentType: 'application/json',
body: tp53ClinicalVariants
};
break;
case `${SERVER_URL}api/private/utils/ensembleGenes?entrezGeneId=7157`:
res = {
status: 200,
contentType: 'application/json',
body: tp53EnsemblGenes
};
break;
case `${SERVER_URL}api/private/utils/variantAnnotation?hugoSymbol=TP53&referenceGenome=GRCh37&alteration=Deletion`:
res = {
status: 200,
contentType: 'application/json',
body: tp53DeletionVariantAnnotation
};
break;
case `${SERVER_URL}api/v1/variants/lookup?hugoSymbol=TP53&variant=Deletion`:
res = {
status: 200,
contentType: 'application/json',
body: tp53DeletionQuery
};
break;
case `${SERVER_URL}api/private/utils/relevantAlterations?referenceGenome=GRCh37&entrezGeneId=7157&alteration=Deletion`:
res = {
status: 200,
contentType: 'application/json',
body: '[]'
};
break;
// BRAF V600E
case `${SERVER_URL}api/private/utils/numbers/gene/BRAF`:
res = {
status: 200,
contentType: 'application/json',
body: brafGeneNumbers
};
break;
case `${SERVER_URL}api/v1/genes/lookup?query=BRAF`:
res = {
status: 200,
contentType: 'application/json',
body: brafGeneQuery
};
break;
case `${SERVER_URL}api/private/search/variants/biological?hugoSymbol=BRAF`:
res = {
status: 200,
contentType: 'application/json',
body: brafBiologicalVariants
};
break;
case `${SERVER_URL}api/private/search/variants/clinical?hugoSymbol=BRAF`:
res = {
status: 200,
contentType: 'application/json',
body: brafClinicalVariants
};
break;
case `${SERVER_URL}api/private/utils/ensembleGenes?entrezGeneId=673`:
res = {
status: 200,
contentType: 'application/json',
body: brafEnsemblGenes
};
break;
case `${SERVER_URL}api/v1/variants/lookup?hugoSymbol=BRAF&variant=V600E`:
res = {
status: 200,
contentType: 'application/json',
body: brafV600eQuery
};
break;
case `${SERVER_URL}api/private/utils/relevantAlterations?referenceGenome=GRCh37&entrezGeneId=673&alteration=V600E`:
res = {
status: 200,
contentType: 'application/json',
body: brafV600eRelevantAlterations
};
break;
case `${SERVER_URL}api/private/utils/variantAnnotation?hugoSymbol=BRAF&referenceGenome=GRCh37&alteration=V600E&tumorType=MEL`:
res = {
status: 200,
contentType: 'application/json',
body: brafV600eMelanomaVariantAnnotation
};
break;
case `${SERVER_URL}api/private/utils/variantAnnotation?hugoSymbol=BRAF&referenceGenome=GRCh37&alteration=V600E&tumorType=HCL`:
res = {
status: 200,
contentType: 'application/json',
body: brafV600eHairyCellLeukemiaVariantAnnotation
};
break;
case `${SERVER_URL}api/private/utils/variantAnnotation?referenceGenome=GRCh37&hgvsg=7%3Ag.140453136A%3ET`:
res = {
status: 200,
contentType: 'application/json',
body: brafV600eHgvsgVariantAnnotation
};
break;
default:
res = undefined
}
return res;
}
describe('Tests with login', () => {
let browser;
let page;
beforeAll(async () => {
browser = await puppeteer.launch(browserConfig);
page = await browser.newPage();
await page.setRequestInterception(true); // Handle UnhandledPromiseRejectionWarning: Error: Request Interception is not enabled!
page.on('request', (request) => {
let url = request.url()
if (getMockResponse(url) !== undefined){
request.respond(
getMockResponse(url)
)
}
else request.continue();
});
await page.goto(`${CLIENT_URL}`);
await page.evaluate(() => {
localStorage.setItem('localdev', 'true');
localStorage.setItem('disablebanner', 'true');
localStorage.setItem('oncokb-user-token', 'oncokb-public-demo-admin-token');
});
})
it('Gene Page', async() => {
await page.goto(`${CLIENT_URL}gene/ROS1`);
await page.setViewport(VIEW_PORT_1080);
await page.waitFor(LONG_WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('Gene Page with Login'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'Gene Page with Login' });
})
it('Alteration Page', async() => {
await page.goto(`${CLIENT_URL}gene/TP53/Deletion`);
await page.setViewport(VIEW_PORT_1080);
await page.waitFor(WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('Alteration Page with Login'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'Alteration Page with Login' });
})
it('Alteration Page with Cancer Type - Solid', async() => {
await page.goto(`${CLIENT_URL}gene/BRAF/V600E/MEL`);
await page.setViewport(VIEW_PORT_1080);
await page.waitFor(WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('Alteration Page with Cancer Type - Solid with Login'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'Alteration Page with Cancer Type - Solid with Login' });
})
it('Alteration Page with Cancer Type - Heme', async() => {
await page.goto(`${CLIENT_URL}gene/BRAF/V600E/HCL`);
await page.setViewport(VIEW_PORT_1080);
await page.waitFor(WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('Alteration Page with Cancer Type - Heme with Login'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'Alteration Page with Cancer Type - Heme with Login' });
})
it('HGVSg Page', async() => {
await page.goto(`${CLIENT_URL}hgvsg/7:g.140453136A>T?refGenome=GRCh37`);
await page.setViewport(VIEW_PORT_1080);
await page.waitFor(WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('HGVSg Page with Login'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'HGVSg Page with Login' });
})
afterAll(async () => {
await browser.close();
})
})
describe('Tests without login', () => {
let browser;
let page;
beforeAll(async () => {
browser = await puppeteer.launch(browserConfig);
page = await browser.newPage();
await page.setRequestInterception(true); // Handle UnhandledPromiseRejectionWarning: Error: Request Interception is not enabled!
page.on('request', (request) => {
let url = request.url()
if (url.includes('recaptcha')){
request.abort();
}
else{
if (getMockResponse(url) !== undefined){
request.respond(
getMockResponse(url)
)
}
else request.continue();
}
});
await page.goto(`${CLIENT_URL}`);
await page.evaluate(() => {
localStorage.setItem('localdev', 'true');
localStorage.setItem('disablebanner', 'true');
});
})
it('Gene Page', async() => {
await page.goto(`${CLIENT_URL}gene/ROS1`);
await page.setViewport(VIEW_PORT_1080);
await page.waitFor(LONG_WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('Gene Page without Login'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'Gene Page without Login' });
})
it('Alteration Page', async() => {
await page.goto(`${CLIENT_URL}gene/TP53/Deletion`);
await page.setViewport(VIEW_PORT_1080);
await page.waitFor(WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('Alteration Page without Login'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'Alteration Page without Login' });
})
it('Alteration Page with Cancer Type - Solid', async() => {
await page.goto(`${CLIENT_URL}gene/BRAF/V600E/MEL`);
await page.setViewport(VIEW_PORT_1080);
await page.waitFor(WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('Alteration Page with Cancer Type - Solid without Login'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'Alteration Page with Cancer Type - Solid without Login' });
})
it('Alteration Page with Cancer Type - Heme', async() => {
await page.goto(`${CLIENT_URL}gene/BRAF/V600E/HCL`);
await page.setViewport(VIEW_PORT_1080);
await page.waitFor(WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('Alteration Page with Cancer Type - Heme without Login'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'Alteration Page with Cancer Type - Heme without Login' });
})
it('HGVSg Page', async() => {
// this is BRAF V600E
await page.goto(`${CLIENT_URL}hgvsg/7:g.140453136A>T?refGenome=GRCh37`);
await page.setViewport(VIEW_PORT_1080);
await page.waitFor(WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('HGVSg Page without Login'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'HGVSg Page without Login' });
})
afterAll(async () => {
await browser.close();
})
})
describe('Tests on mobile view (< large grid)', () => {
let browser;
let page;
beforeAll(async () => {
browser = await puppeteer.launch(browserConfig);
page = await browser.newPage();
await page.setRequestInterception(true); // Handle UnhandledPromiseRejectionWarning: Error: Request Interception is not enabled!
page.on('request', (request) => {
let url = request.url()
if (getMockResponse(url) !== undefined){
request.respond(
getMockResponse(url)
)
}
else request.continue();
});
await page.goto(`${CLIENT_URL}`);
await page.evaluate(() => {
localStorage.setItem('localdev', 'true');
localStorage.setItem('disablebanner', 'true');
});
})
it('Alteration Page with Cancer Type - With login - Mobile', async() => {
await page.evaluate(() => {
localStorage.setItem('oncokb-user-token', 'oncokb-public-demo-admin-token');
});
await page.goto(`${CLIENT_URL}gene/BRAF/V600E/HCL`);
await page.setViewport(MOBILE_VIEW_PORT);
await page.waitFor(WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('Alteration Page with Cancer Type - With login - Mobile'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'Alteration Page with Cancer Type - With login - Mobile' });
})
it('Alteration Page with Cancer Type - Without login - Mobile', async() => {
await page.evaluate(() => {
localStorage.removeItem('oncokb-user-token');
});
await page.goto(`${CLIENT_URL}gene/BRAF/V600E/HCL`);
await page.setViewport(MOBILE_VIEW_PORT);
await page.waitFor(WAITING_TIME);
let image = await page.screenshot(getScreenshotConfig('Alteration Page with Cancer Type - Without login - Mobile'));
expect(image).toMatchImageSnapshot({ customSnapshotIdentifier: 'Alteration Page with Cancer Type - Without login - Mobile' });
})
afterAll(async () => {
await browser.close();
})
})