Skip to content

Commit 05094fe

Browse files
Reif TauatiReif Tauati
authored andcommitted
[test] scope verse selectors to #ch-* blocks when multiple chapters are in DOM
Made-with: Cursor
1 parent 73b8894 commit 05094fe

1 file changed

Lines changed: 38 additions & 33 deletions

File tree

test-library-sources.js

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,11 @@ async function run() {
412412
'scripture breadcrumbs did not recover after source view'
413413
);
414414

415-
await page.waitForSelector('#v1 span.w', { timeout: 20000 });
416-
await page.$eval('#v1', (el) => el.scrollIntoView({ block: 'center' }));
415+
await page.waitForSelector('#ch-john_3 #v1 span.w', { timeout: 20000 });
416+
await page.$eval('#ch-john_3 #v1', (el) => el.scrollIntoView({ block: 'center' }));
417417
await new Promise(function(r) { setTimeout(r, 400); });
418418
await page.evaluate(() => {
419-
const spans = Array.from(document.querySelectorAll('#v1 span.w'));
419+
const spans = Array.from(document.querySelectorAll('#ch-john_3 #v1 span.w'));
420420
const target = spans.find((el) => /pharisees?/i.test(el.textContent || '')) || spans[0];
421421
if (target) target.dispatchEvent(new MouseEvent('click', { bubbles: true }));
422422
});
@@ -518,11 +518,11 @@ async function run() {
518518
});
519519
await page.waitForSelector('#ch-john_3', { timeout: 20000 });
520520
await page.waitForFunction(() => !document.querySelector('.source-doc'), { timeout: 20000 });
521-
await page.waitForSelector('#v1 span.w', { timeout: 20000 });
522-
await page.$eval('#v1', (el) => el.scrollIntoView({ block: 'center' }));
521+
await page.waitForSelector('#ch-john_3 #v1 span.w', { timeout: 20000 });
522+
await page.$eval('#ch-john_3 #v1', (el) => el.scrollIntoView({ block: 'center' }));
523523
await new Promise(function(r) { setTimeout(r, 400); });
524524
await page.evaluate(() => {
525-
const spans = Array.from(document.querySelectorAll('#v1 span.w'));
525+
const spans = Array.from(document.querySelectorAll('#ch-john_3 #v1 span.w'));
526526
const target = spans.find((el) => /pharisees?/i.test(el.textContent || '')) || spans[0];
527527
if (target) target.dispatchEvent(new MouseEvent('click', { bubbles: true }));
528528
});
@@ -542,10 +542,10 @@ async function run() {
542542
assert(rankingState.morsels.every((m) => m.src === 'Standard Works'), 'scripture-first ranking no longer pins the first scripture tranche');
543543

544544
await page.$eval('#ch-close', (el) => el.click());
545-
await page.click('#v16');
546-
await page.waitForSelector('#v16 span.w', { timeout: 20000 });
545+
await page.click('#ch-john_3 #v16');
546+
await page.waitForSelector('#ch-john_3 #v16 span.w', { timeout: 20000 });
547547
await page.evaluate(() => {
548-
const target = Array.from(document.querySelectorAll('#v16 span.w')).find((el) => /god/i.test(el.textContent || ''));
548+
const target = Array.from(document.querySelectorAll('#ch-john_3 #v16 span.w')).find((el) => /god/i.test(el.textContent || ''));
549549
if (target) target.dispatchEvent(new MouseEvent('click', { bubbles: true }));
550550
});
551551
await page.waitForFunction(() => document.querySelector('#channel')?.classList.contains('open'), { timeout: 25000 });
@@ -572,9 +572,10 @@ async function run() {
572572
await page.waitForFunction(() => !document.querySelector('#channel')?.classList.contains('open'));
573573

574574
await page.evaluate(() => jumpTo('genesis_2'));
575-
await page.waitForSelector('#v6 .verse-text .w', { timeout: 20000 });
575+
await page.waitForSelector('#ch-genesis_2', { timeout: 20000 });
576+
await page.waitForSelector('#ch-genesis_2 #v6 .verse-text .w', { timeout: 20000 });
576577
await page.evaluate(() => {
577-
const target = Array.from(document.querySelectorAll('#v6 .verse-text .w')).find((el) => /mist/i.test(el.textContent || ''));
578+
const target = Array.from(document.querySelectorAll('#ch-genesis_2 #v6 .verse-text .w')).find((el) => /mist/i.test(el.textContent || ''));
578579
if (target) target.dispatchEvent(new MouseEvent('click', { bubbles: true }));
579580
});
580581
await page.waitForFunction(() => document.querySelector('#channel')?.classList.contains('open'), { timeout: 15000 });
@@ -588,18 +589,19 @@ async function run() {
588589
await page.waitForFunction(() => !document.querySelector('#channel')?.classList.contains('open'));
589590

590591
const genesisCleanState = await page.evaluate(() => ({
591-
v6: document.querySelector('#v6 .verse-text')?.innerText || '',
592-
v7: document.querySelector('#v7 .verse-text')?.innerText || '',
593-
v7Html: document.querySelector('#v7 .verse-text')?.innerHTML || '',
592+
v6: document.querySelector('#ch-genesis_2 #v6 .verse-text')?.innerText || '',
593+
v7: document.querySelector('#ch-genesis_2 #v7 .verse-text')?.innerText || '',
594+
v7Html: document.querySelector('#ch-genesis_2 #v7 .verse-text')?.innerHTML || '',
594595
}));
595596
assert(/there went up a mist from the earth/i.test(genesisCleanState.v6), 'Genesis 2:6 did not restore full canonical verse text');
596597
assert(/breath of life; and man became a living soul/i.test(genesisCleanState.v7), 'Genesis 2:7 did not restore full canonical verse text');
597598
assert(!/<span class=|"cw/i.test(genesisCleanState.v7Html), 'Genesis 2 still leaks escaped critical-word wrappers');
598599

599600
await page.evaluate(() => jumpTo('john_3'));
600-
await page.waitForSelector('#v16 .verse-text .w', { timeout: 20000 });
601+
await page.waitForSelector('#ch-john_3', { timeout: 20000 });
602+
await page.waitForSelector('#ch-john_3 #v16 .verse-text .w', { timeout: 20000 });
601603
await page.evaluate(() => {
602-
const target = Array.from(document.querySelectorAll('#v16 .verse-text .w')).find((el) => /loved/i.test(el.textContent || ''));
604+
const target = Array.from(document.querySelectorAll('#ch-john_3 #v16 .verse-text .w')).find((el) => /loved/i.test(el.textContent || ''));
603605
if (target) target.dispatchEvent(new MouseEvent('click', { bubbles: true }));
604606
});
605607
await page.waitForFunction(() => document.querySelector('#channel')?.classList.contains('open'), { timeout: 15000 });
@@ -613,31 +615,34 @@ async function run() {
613615
await page.waitForFunction(() => !document.querySelector('#channel')?.classList.contains('open'));
614616

615617
await page.evaluate(() => jumpTo('john_1'));
616-
await page.waitForSelector('#v1 .verse-text', { timeout: 20000 });
618+
await page.waitForSelector('#ch-john_1', { timeout: 20000 });
619+
await page.waitForSelector('#ch-john_1 #v1 .verse-text', { timeout: 20000 });
617620
const johnCleanState = await page.evaluate(() => ({
618-
v1: document.querySelector('#v1 .verse-text')?.innerText || '',
619-
v17: document.querySelector('#v17 .verse-text')?.innerText || '',
620-
v1Html: document.querySelector('#v1 .verse-text')?.innerHTML || '',
621+
v1: document.querySelector('#ch-john_1 #v1 .verse-text')?.innerText || '',
622+
v17: document.querySelector('#ch-john_1 #v17 .verse-text')?.innerText || '',
623+
v1Html: document.querySelector('#ch-john_1 #v1 .verse-text')?.innerHTML || '',
621624
}));
622625
assert(/In the beginning was the Word/i.test(johnCleanState.v1), 'John 1:1 did not restore full canonical verse text');
623626
assert(/grace and truth came by Jesus Christ/i.test(johnCleanState.v17), 'John 1:17 did not restore full canonical verse text');
624627
assert(!/<span class=|"cw/i.test(johnCleanState.v1Html), 'John 1 still leaks escaped critical-word wrappers');
625628

626629
await page.evaluate(() => jumpTo('2_thessalonians_2'));
627-
await page.waitForSelector('#v1 .verse-text', { timeout: 20000 });
630+
await page.waitForSelector('#ch-2_thessalonians_2', { timeout: 20000 });
631+
await page.waitForSelector('#ch-2_thessalonians_2 #v1 .verse-text', { timeout: 20000 });
628632
const secondThessCleanState = await page.evaluate(() => ({
629-
v1: document.querySelector('#v1 .verse-text')?.innerText || '',
630-
v3: document.querySelector('#v3 .verse-text')?.innerText || '',
631-
v3Html: document.querySelector('#v3 .verse-text')?.innerHTML || '',
633+
v1: document.querySelector('#ch-2_thessalonians_2 #v1 .verse-text')?.innerText || '',
634+
v3: document.querySelector('#ch-2_thessalonians_2 #v3 .verse-text')?.innerText || '',
635+
v3Html: document.querySelector('#ch-2_thessalonians_2 #v3 .verse-text')?.innerHTML || '',
632636
}));
633637
assert(/Now we beseech you, brethren/i.test(secondThessCleanState.v1), '2 Thessalonians 2:1 did not restore full canonical verse text');
634638
assert(/that man of sin be revealed, the son of perdition/i.test(secondThessCleanState.v3), '2 Thessalonians 2:3 did not restore full canonical verse text');
635639
assert(!/<span class=|"cw/i.test(secondThessCleanState.v3Html), '2 Thessalonians still leaks escaped critical-word wrappers');
636640

637641
await page.evaluate(() => jumpTo('1_nephi_8'));
638-
await page.waitForSelector('#v23 .verse-text .w', { timeout: 20000 });
642+
await page.waitForSelector('#ch-1_nephi_8', { timeout: 20000 });
643+
await page.waitForSelector('#ch-1_nephi_8 #v23 .verse-text .w', { timeout: 20000 });
639644
await page.evaluate(() => {
640-
const target = Array.from(document.querySelectorAll('#v23 .verse-text .w')).find((el) => /mist/i.test(el.textContent || ''));
645+
const target = Array.from(document.querySelectorAll('#ch-1_nephi_8 #v23 .verse-text .w')).find((el) => /mist/i.test(el.textContent || ''));
641646
if (target) target.dispatchEvent(new MouseEvent('click', { bubbles: true }));
642647
});
643648
await page.waitForFunction(() => document.querySelector('#channel')?.classList.contains('open'), { timeout: 15000 });
@@ -654,11 +659,11 @@ async function run() {
654659

655660
await page.evaluate(() => jumpTo('doctrine_and_covenants_121'));
656661
await page.waitForSelector('#ch-doctrine_and_covenants_121', { timeout: 20000 });
657-
await page.waitForSelector('#v41 .verse-text .w', { timeout: 20000 });
658-
await page.$eval('#v41', (el) => el.scrollIntoView({ block: 'center' }));
662+
await page.waitForSelector('#ch-doctrine_and_covenants_121 #v41 .verse-text .w', { timeout: 20000 });
663+
await page.$eval('#ch-doctrine_and_covenants_121 #v41', (el) => el.scrollIntoView({ block: 'center' }));
659664
await new Promise(function(r) { setTimeout(r, 400); });
660665
await page.evaluate(() => {
661-
const target = Array.from(document.querySelectorAll('#v41 .verse-text .w')).find((el) => /priesthood/i.test(el.textContent || ''));
666+
const target = Array.from(document.querySelectorAll('#ch-doctrine_and_covenants_121 #v41 .verse-text .w')).find((el) => /priesthood/i.test(el.textContent || ''));
662667
if (target) target.dispatchEvent(new MouseEvent('click', { bubbles: true }));
663668
});
664669
await page.waitForFunction(() => document.querySelector('#channel')?.classList.contains('open'), { timeout: 25000 });
@@ -673,18 +678,18 @@ async function run() {
673678
await page.$eval('#ch-close', (el) => el.click());
674679
await page.waitForFunction(() => !document.querySelector('#channel')?.classList.contains('open'));
675680

676-
await page.$eval('#v41', (el) => el.scrollIntoView({ block: 'center' }));
681+
await page.$eval('#ch-doctrine_and_covenants_121 #v41', (el) => el.scrollIntoView({ block: 'center' }));
677682
await new Promise(function(r) { setTimeout(r, 400); });
678683
await page.evaluate(() => {
679-
const target = Array.from(document.querySelectorAll('#v41 .verse-text .w')).find((el) => /^love$/i.test((el.textContent || '').trim()));
684+
const target = Array.from(document.querySelectorAll('#ch-doctrine_and_covenants_121 #v41 .verse-text .w')).find((el) => /^love$/i.test((el.textContent || '').trim()));
680685
if (target) target.dispatchEvent(new MouseEvent('click', { bubbles: true }));
681686
});
682687
await page.waitForFunction(() => document.querySelector('#channel')?.classList.contains('open'), { timeout: 25000 });
683688
const dcLoveCleanState = await page.evaluate(() => ({
684689
word: document.querySelector('#ch-word')?.textContent.trim(),
685690
sources: Array.from(document.querySelectorAll('#panel-body .ch-morsel .ch-src-name')).slice(0, 3).map((el) => el.textContent.trim()),
686-
verseText: document.querySelector('#v41 .verse-text')?.innerText || '',
687-
verseHtml: document.querySelector('#v41 .verse-text')?.innerHTML || '',
691+
verseText: document.querySelector('#ch-doctrine_and_covenants_121 #v41 .verse-text')?.innerText || '',
692+
verseHtml: document.querySelector('#ch-doctrine_and_covenants_121 #v41 .verse-text')?.innerHTML || '',
688693
}));
689694
assert(/love/i.test(dcLoveCleanState.word), 'D&C clean re-annotation did not make love clickable');
690695
assert(dcLoveCleanState.sources[0] === 'Standard Works', 'Doctrine and Covenants love did not rank standard works first after re-annotation');

0 commit comments

Comments
 (0)