@playpilot/tpi 3.7.2 → 3.8.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.
@@ -369,7 +369,7 @@ describe('linkInjection.js', () => {
369
369
  })
370
370
 
371
371
  it('Should return corresponding messages for failed injections', () => {
372
- const sentence = '<p>This is <a href="/">a sentence</a> with an injection.</p>'
372
+ const sentence = 'This is <a href="/">a sentence</a> with an injection.'
373
373
  document.body.innerHTML = `<p>${sentence}</p>`
374
374
 
375
375
  const elements = Array.from(document.body.querySelectorAll('p'))
@@ -385,6 +385,23 @@ describe('linkInjection.js', () => {
385
385
  expect(results[1].failed_message).toBe('Given sentence was not found in the article.')
386
386
  })
387
387
 
388
+ it('Should disregard spaces and special characters in failed message', () => {
389
+ const sentence = 'This is a &amp; sentence with an injection.'
390
+ document.body.innerHTML = `<p>${sentence}</p>`
391
+
392
+ const elements = Array.from(document.body.querySelectorAll('p'))
393
+
394
+ const linkInjections = [
395
+ generateInjection('This is a&sentence with aninjection.', 'an injection'),
396
+ generateInjection('This is a&sentence with aninjection.', 'nothing'),
397
+ ]
398
+
399
+ const results = injectLinksInDocument(elements, { aiInjections: [], manualInjections: linkInjections })
400
+
401
+ expect(results[0].failed_message).not.toBeTruthy()
402
+ expect(results[1].failed_message).toBe('The link failed to inject for unknown reasons.')
403
+ })
404
+
388
405
  it('Should mount popover component when element other than popover or link is hovered', async () => {
389
406
  document.body.innerHTML = '<p>This is a sentence with an injection.</p>'
390
407
 
@@ -449,6 +466,29 @@ describe('linkInjection.js', () => {
449
466
  expect(mount).not.toHaveBeenCalled()
450
467
  })
451
468
 
469
+ it('Should not mount popover on mouseover again if link is already being hovered', async () => {
470
+ document.body.innerHTML = '<p>This is a sentence with an injection.</p>'
471
+
472
+ const elements = Array.from(document.body.querySelectorAll('p'))
473
+ const injections = [
474
+ generateInjection('This is a sentence with an injection.', 'a sentence'),
475
+ generateInjection('This is a sentence with an injection.', 'an injection'),
476
+ ]
477
+
478
+ injectLinksInDocument(elements, { aiInjections: injections, manualInjections: [] })
479
+
480
+ const [link1, link2] = document.querySelectorAll('[data-playpilot-injection-key]')
481
+
482
+ vi.useFakeTimers()
483
+
484
+ await fireEvent.mouseEnter(link1)
485
+ vi.advanceTimersByTime(200)
486
+ await fireEvent.mouseEnter(link2)
487
+ vi.advanceTimersByTime(500)
488
+
489
+ expect(mount).toHaveBeenCalledTimes(1)
490
+ })
491
+
452
492
  it('Should inject links of the same phrase when multiple are present', () => {
453
493
  document.body.innerHTML = '<p>This is a sentence with an injection and another injection</p>'
454
494
 
@@ -734,10 +774,10 @@ describe('linkInjection.js', () => {
734
774
  it('Should return elements in the same order they were given', () => {
735
775
  document.body.innerHTML = `<section>
736
776
  <div>
737
- <p><span><strong>Some first text</strong></span></p>
777
+ <div><span><strong>Some first text</strong></span></div>
738
778
  <div>
739
779
  <em>Some empasized</em>
740
- <main><p><em><i>Some deeply nested text</i></em></p></main>
780
+ <main><span><em><i>Some deeply nested text</i></em></span></main>
741
781
  <div>Some text</div>
742
782
  </div>
743
783
  </div>
@@ -752,6 +792,33 @@ describe('linkInjection.js', () => {
752
792
  expect(elements[2].nodeName).toBe('I')
753
793
  expect(elements[3].nodeName).toBe('DIV')
754
794
  })
795
+
796
+ it('Should exclude elements that match or are in the given excludeElementsSelector attribute', () => {
797
+ document.body.innerHTML = `<section>
798
+ <p>I am a regular element</p>
799
+ <div data-exclude>I am to be excluded. <span>And so am I!</span></div>
800
+ </section>
801
+ `
802
+ const parent = /** @type {HTMLElement} */ (document.querySelector('section'))
803
+
804
+ const result = getLinkInjectionElements(parent, '[data-exclude]')
805
+ expect(result).toHaveLength(1)
806
+ expect(result[0].innerText).toBe('I am a regular element')
807
+ });
808
+
809
+ it('Should return paragraphs fully even if they contain no direct text nodes, skipping empty paragraphs', () => {
810
+ document.body.innerHTML = `<section>
811
+ <p>Some text</p>
812
+ <p><span>Some text</span> <span>broken up</span></p>
813
+ <p><span>Some text</span> <span>broken up</span> but also contains direct text</p>
814
+ <p></p>
815
+ </section>`
816
+
817
+ const parent = /** @type {HTMLElement} */ (document.querySelector('section'))
818
+ const elements = getLinkInjectionElements(parent)
819
+
820
+ expect(elements).toHaveLength(3)
821
+ })
755
822
  })
756
823
 
757
824
  describe('getLinkInjectionsParentElement', () => {
@@ -418,7 +418,7 @@ describe('$routes/+page.svelte', () => {
418
418
  })
419
419
 
420
420
  describe('custom_style', () => {
421
- it('Should insert custom html tag with returned value for given selector from config', async () => {
421
+ it('Should insert custom html tag with returned value from config', async () => {
422
422
  vi.mocked(fetchConfig).mockResolvedValueOnce({ custom_style: 'some: style' })
423
423
 
424
424
  // @ts-ignore
@@ -427,17 +427,7 @@ describe('$routes/+page.svelte', () => {
427
427
  render(page)
428
428
 
429
429
  await waitFor(() => {
430
- expect(document.querySelector('#playpilot-custom-style')?.textContent).toBe('.some-element, .modal, .popover { some: style }')
431
- })
432
- })
433
-
434
- it('Should insert custom html tag with returned value for body when no selector is given', async () => {
435
- vi.mocked(fetchConfig).mockResolvedValueOnce({ custom_style: 'some: style' })
436
-
437
- render(page)
438
-
439
- await waitFor(() => {
440
- expect(document.querySelector('#playpilot-custom-style')?.textContent).toBe('body, .modal, .popover { some: style }')
430
+ expect(document.querySelector('#playpilot-custom-style')?.textContent).toBe('[data-playpilot-link-injections] { some: style }')
441
431
  })
442
432
  })
443
433
 
Binary file