@playpilot/tpi 8.29.8 → 8.29.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playpilot/tpi",
3
- "version": "8.29.8",
3
+ "version": "8.29.10",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -191,11 +191,11 @@ export function injectLinksInDocument(elements: HTMLElement[], injections: LinkI
191
191
 
192
192
  const matchingElement = document.querySelector(`[${keyDataAttribute}="${injection.key}"]`)
193
193
  const failed = isValidPlaylinkType(injection) && !injection.inactive && !injection.removed && !injection.after_article && !matchingElement
194
- const containsSentence = foundInjections.find(i => i.key === injection.key)
194
+ const anyElementContainsSentence = failed && elements.some(element => cleanPhrase(element.innerText).includes(cleanPhrase(injection.sentence)))
195
195
  const failedMessage =
196
196
  !failed ? '' :
197
197
  failedMessages[injection.key] ||
198
- (!containsSentence ? 'Given sentence was not found in the article.' : 'The link failed to inject for unknown reasons.')
198
+ (!anyElementContainsSentence ? 'Given sentence was not found in the article.' : 'The link failed to inject for unknown reasons.')
199
199
 
200
200
  return {
201
201
  ...injection,
@@ -468,6 +468,17 @@ describe('injection.ts', () => {
468
468
  expect(results[3].failed_message).toBe('Injection was manually removed.')
469
469
  })
470
470
 
471
+ it('Should return sentence message if text was found in full body text but not in individual elements', () => {
472
+ document.body.innerHTML = `<article><p>Some sentence</p><p>that is broken in two</p></main>`
473
+
474
+ const elements = Array.from(document.body.querySelectorAll('p'))
475
+ const linkInjections = [generateInjection('Some sentence that is broken in two', 'broken'),]
476
+
477
+ const results = injectLinksInDocument(elements, { aiInjections: linkInjections, manualInjections: [] })
478
+
479
+ expect(results[0].failed_message).toBe('Given sentence was not found in the article.')
480
+ })
481
+
471
482
  it('Should disregard spaces and special characters in failed message', () => {
472
483
  const sentence = 'This is a &amp; sentence with an injection.'
473
484
  document.body.innerHTML = `<p>${sentence}</p>`