@playpilot/tpi 3.3.0 → 3.3.1
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/dist/link-injections.js +8 -8
- package/package.json +1 -1
- package/src/lib/linkInjection.ts +29 -13
- package/src/lib/scss/_mixins.scss +13 -0
- package/src/routes/+page.svelte +1 -23
- package/src/routes/components/AfterArticlePlaylinks.svelte +5 -6
- package/src/routes/components/Editorial/Editor.svelte +1 -0
- package/src/routes/components/Modal.svelte +1 -0
- package/src/routes/components/Popover.svelte +1 -0
- package/src/tests/lib/linkInjection.test.js +51 -56
- package/src/tests/routes/components/Editorial/EditorItem.test.js +7 -7
|
@@ -3,7 +3,7 @@ import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
|
|
|
3
3
|
|
|
4
4
|
import { injectLinksInDocument, clearLinkInjections, clearLinkInjection, getLinkInjectionElements, insertAfterArticlePlaylinks, getLinkInjectionsParentElement, isAvailableAsManualInjection, filterRemovedAndInactiveInjections, isEquivalentInjection, filterInvalidInTextInjections, filterInvalidAfterArticleInjections, isValidInjection, isValidPlaylinkType } from '$lib/linkInjection'
|
|
5
5
|
import { mount, unmount } from 'svelte'
|
|
6
|
-
import { generateInjection } from '../helpers'
|
|
6
|
+
import { fakeFetch, generateInjection } from '../helpers'
|
|
7
7
|
|
|
8
8
|
vi.mock('svelte', () => ({
|
|
9
9
|
mount: vi.fn(),
|
|
@@ -23,7 +23,11 @@ function mockMatchMedia(matches = false) {
|
|
|
23
23
|
describe('linkInjection.js', () => {
|
|
24
24
|
beforeEach(() => {
|
|
25
25
|
vi.resetAllMocks()
|
|
26
|
+
clearLinkInjections()
|
|
27
|
+
|
|
26
28
|
mockMatchMedia()
|
|
29
|
+
fakeFetch()
|
|
30
|
+
vi.mocked(mount).mockReturnValueOnce({})
|
|
27
31
|
|
|
28
32
|
// @ts-ignore
|
|
29
33
|
window.PlayPilotLinkInjections = {}
|
|
@@ -42,7 +46,7 @@ describe('linkInjection.js', () => {
|
|
|
42
46
|
|
|
43
47
|
const elements = Array.from(document.querySelectorAll('p'))
|
|
44
48
|
|
|
45
|
-
injectLinksInDocument(elements,
|
|
49
|
+
injectLinksInDocument(elements, { aiInjections: linkInjections, manualInjections: [] })
|
|
46
50
|
|
|
47
51
|
const link = /** @type {HTMLAnchorElement} */ (document.querySelector('a'))
|
|
48
52
|
|
|
@@ -61,7 +65,7 @@ describe('linkInjection.js', () => {
|
|
|
61
65
|
|
|
62
66
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
63
67
|
|
|
64
|
-
injectLinksInDocument(elements,
|
|
68
|
+
injectLinksInDocument(elements, { aiInjections: linkInjections, manualInjections: [] })
|
|
65
69
|
|
|
66
70
|
const links = /** @type {HTMLAnchorElement[]} */ (Array.from(document.querySelectorAll('a')))
|
|
67
71
|
|
|
@@ -85,7 +89,7 @@ describe('linkInjection.js', () => {
|
|
|
85
89
|
|
|
86
90
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
87
91
|
|
|
88
|
-
injectLinksInDocument(elements,
|
|
92
|
+
injectLinksInDocument(elements, { aiInjections: linkInjections, manualInjections: [] })
|
|
89
93
|
|
|
90
94
|
expect(document.body.innerHTML).toBe(`<p>${sentence}</p>`)
|
|
91
95
|
})
|
|
@@ -99,7 +103,7 @@ describe('linkInjection.js', () => {
|
|
|
99
103
|
|
|
100
104
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
101
105
|
|
|
102
|
-
injectLinksInDocument(elements,
|
|
106
|
+
injectLinksInDocument(elements, { aiInjections: linkInjections, manualInjections: [] })
|
|
103
107
|
|
|
104
108
|
expect(document.body.innerHTML).toBe(`<p>${sentence}</p>`)
|
|
105
109
|
})
|
|
@@ -117,7 +121,7 @@ describe('linkInjection.js', () => {
|
|
|
117
121
|
manualInjections: [{ ...injection, manual: true, removed: true }],
|
|
118
122
|
}
|
|
119
123
|
|
|
120
|
-
injectLinksInDocument(elements,
|
|
124
|
+
injectLinksInDocument(elements, injections)
|
|
121
125
|
|
|
122
126
|
expect(document.body.innerHTML).toBe(`<p>${sentence}</p>`)
|
|
123
127
|
})
|
|
@@ -135,7 +139,7 @@ describe('linkInjection.js', () => {
|
|
|
135
139
|
manualInjections: [{ ...injection, manual: true, inactive: true }],
|
|
136
140
|
}
|
|
137
141
|
|
|
138
|
-
injectLinksInDocument(elements,
|
|
142
|
+
injectLinksInDocument(elements, injections)
|
|
139
143
|
|
|
140
144
|
expect(document.body.innerHTML).toBe(`<p>${sentence}</p>`)
|
|
141
145
|
})
|
|
@@ -148,7 +152,7 @@ describe('linkInjection.js', () => {
|
|
|
148
152
|
|
|
149
153
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
150
154
|
|
|
151
|
-
injectLinksInDocument(elements,
|
|
155
|
+
injectLinksInDocument(elements, { aiInjections: linkInjections, manualInjections: [] })
|
|
152
156
|
|
|
153
157
|
const button = /** @type {HTMLButtonElement} */ (document.querySelector('button'))
|
|
154
158
|
|
|
@@ -161,7 +165,7 @@ describe('linkInjection.js', () => {
|
|
|
161
165
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
162
166
|
const injection = generateInjection('I am a title', 'a title')
|
|
163
167
|
|
|
164
|
-
injectLinksInDocument(elements,
|
|
168
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
165
169
|
|
|
166
170
|
expect(document.body.innerHTML.includes(injection.sentence)).toBeTruthy()
|
|
167
171
|
})
|
|
@@ -172,7 +176,7 @@ describe('linkInjection.js', () => {
|
|
|
172
176
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
173
177
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
174
178
|
|
|
175
|
-
injectLinksInDocument(elements,
|
|
179
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
176
180
|
|
|
177
181
|
expect(document.body.innerHTML.includes('an injection')).not.toBeTruthy()
|
|
178
182
|
expect(document.body.innerHTML.includes('an')).toBeTruthy()
|
|
@@ -184,7 +188,7 @@ describe('linkInjection.js', () => {
|
|
|
184
188
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
185
189
|
const injection = generateInjection('This is a sentence & an injection.', 'an injection')
|
|
186
190
|
|
|
187
|
-
injectLinksInDocument(elements,
|
|
191
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
188
192
|
|
|
189
193
|
expect(document.querySelectorAll('a')).toHaveLength(1)
|
|
190
194
|
})
|
|
@@ -195,7 +199,7 @@ describe('linkInjection.js', () => {
|
|
|
195
199
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
196
200
|
const injection = generateInjection('This is a sentence with an injection.', 'a sentence')
|
|
197
201
|
|
|
198
|
-
injectLinksInDocument(elements,
|
|
202
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
199
203
|
|
|
200
204
|
expect(document.querySelector('[data-playpilot-injection-key]')).not.toBeTruthy()
|
|
201
205
|
})
|
|
@@ -206,7 +210,7 @@ describe('linkInjection.js', () => {
|
|
|
206
210
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
207
211
|
const injection = generateInjection('This is a sentence with an injection.', 'some word')
|
|
208
212
|
|
|
209
|
-
injectLinksInDocument(elements,
|
|
213
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
210
214
|
|
|
211
215
|
expect(document.querySelector('[data-playpilot-injection-key]')).not.toBeTruthy()
|
|
212
216
|
})
|
|
@@ -217,7 +221,7 @@ describe('linkInjection.js', () => {
|
|
|
217
221
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
218
222
|
const injection = generateInjection('This is a word with a word.', 'a word')
|
|
219
223
|
|
|
220
|
-
injectLinksInDocument(elements,
|
|
224
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
221
225
|
|
|
222
226
|
expect(document.querySelectorAll('a')).toHaveLength(2)
|
|
223
227
|
expect(Array.from(document.querySelectorAll('a')).filter(a => a.innerText === 'a word')).toHaveLength(2)
|
|
@@ -229,7 +233,7 @@ describe('linkInjection.js', () => {
|
|
|
229
233
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
230
234
|
const injection = generateInjection('This is a word with a word.', 'a word')
|
|
231
235
|
|
|
232
|
-
injectLinksInDocument(elements,
|
|
236
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
233
237
|
|
|
234
238
|
expect(document.querySelectorAll('a')).toHaveLength(2)
|
|
235
239
|
expect(Array.from(document.querySelectorAll('a')).filter(a => a.innerText === 'a word')).toHaveLength(2)
|
|
@@ -241,7 +245,7 @@ describe('linkInjection.js', () => {
|
|
|
241
245
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
242
246
|
const injection = generateInjection('this is a word with a word.', 'a word')
|
|
243
247
|
|
|
244
|
-
injectLinksInDocument(elements,
|
|
248
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
245
249
|
|
|
246
250
|
expect(document.querySelectorAll('a')).toHaveLength(2)
|
|
247
251
|
expect(Array.from(document.querySelectorAll('a')).filter(a => a.innerText === 'a word')).toHaveLength(2)
|
|
@@ -254,7 +258,7 @@ describe('linkInjection.js', () => {
|
|
|
254
258
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
255
259
|
const injection = generateInjection('But this sentence is a match.', 'a match')
|
|
256
260
|
|
|
257
|
-
injectLinksInDocument(elements,
|
|
261
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
258
262
|
|
|
259
263
|
expect(document.body.innerHTML).toContain('This is a match')
|
|
260
264
|
expect(document.querySelectorAll('[data-playpilot-injection-key]')).toHaveLength(1)
|
|
@@ -266,7 +270,7 @@ describe('linkInjection.js', () => {
|
|
|
266
270
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
267
271
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
268
272
|
|
|
269
|
-
injectLinksInDocument(elements,
|
|
273
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
270
274
|
|
|
271
275
|
expect(document.querySelector('[data-playpilot-injection-key]')).toBeTruthy()
|
|
272
276
|
})
|
|
@@ -279,7 +283,7 @@ describe('linkInjection.js', () => {
|
|
|
279
283
|
/** @type {import('$lib/types/injection').LinkInjection[]} */
|
|
280
284
|
const linkInjections = []
|
|
281
285
|
|
|
282
|
-
injectLinksInDocument(elements,
|
|
286
|
+
injectLinksInDocument(elements, { aiInjections: linkInjections, manualInjections: [] })
|
|
283
287
|
|
|
284
288
|
expect(document.body.innerHTML.includes('This is a sentence with an injection.')).toBeTruthy()
|
|
285
289
|
})
|
|
@@ -291,25 +295,24 @@ describe('linkInjection.js', () => {
|
|
|
291
295
|
/** @type {import('$lib/types/injection').LinkInjection[]} */
|
|
292
296
|
const linkInjections = []
|
|
293
297
|
|
|
294
|
-
expect(() => injectLinksInDocument(elements,
|
|
298
|
+
expect(() => injectLinksInDocument(elements, { aiInjections: linkInjections, manualInjections: [] })).not.toThrow()
|
|
295
299
|
})
|
|
296
300
|
|
|
297
|
-
it('Should
|
|
301
|
+
it('Should mount modal when clicked', async () => {
|
|
298
302
|
document.body.innerHTML = '<p>This is a sentence with an injection.</p>'
|
|
299
303
|
|
|
300
304
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
301
305
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
302
306
|
|
|
303
|
-
|
|
304
|
-
injectLinksInDocument(elements, mock, { aiInjections: [injection], manualInjections: [] })
|
|
307
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
305
308
|
|
|
306
309
|
const link = /** @type {HTMLAnchorElement} */ (document.querySelector('a'))
|
|
307
310
|
await fireEvent.click(link)
|
|
308
311
|
|
|
309
|
-
expect(
|
|
312
|
+
expect(mount).toHaveBeenCalled()
|
|
310
313
|
})
|
|
311
314
|
|
|
312
|
-
it('Should
|
|
315
|
+
it('Should not mount modal multiple times if modal is already open', async () => {
|
|
313
316
|
const sentence = 'This is a sentence with an injection.'
|
|
314
317
|
document.body.innerHTML = `<p>${sentence}</p>`
|
|
315
318
|
|
|
@@ -320,14 +323,13 @@ describe('linkInjection.js', () => {
|
|
|
320
323
|
generateInjection(sentence, 'an injection'),
|
|
321
324
|
]
|
|
322
325
|
|
|
323
|
-
|
|
324
|
-
injectLinksInDocument(elements, mock, { aiInjections: linkInjections, manualInjections: [] })
|
|
326
|
+
injectLinksInDocument(elements, { aiInjections: linkInjections, manualInjections: [] })
|
|
325
327
|
|
|
326
328
|
const links = document.querySelectorAll('a')
|
|
327
329
|
await fireEvent.click(links[0])
|
|
328
330
|
await fireEvent.click(links[1])
|
|
329
331
|
|
|
330
|
-
expect(
|
|
332
|
+
expect(mount).toHaveBeenCalledTimes(1)
|
|
331
333
|
})
|
|
332
334
|
|
|
333
335
|
it('Should not fire given onclick function when clicked with modifier keys or not left click', async () => {
|
|
@@ -337,7 +339,7 @@ describe('linkInjection.js', () => {
|
|
|
337
339
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
338
340
|
|
|
339
341
|
const mock = vi.fn()
|
|
340
|
-
injectLinksInDocument(elements,
|
|
342
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
341
343
|
|
|
342
344
|
const link = /** @type {HTMLAnchorElement} */ (document.querySelector('a'))
|
|
343
345
|
|
|
@@ -360,7 +362,7 @@ describe('linkInjection.js', () => {
|
|
|
360
362
|
generateInjection(sentence, 'not an injection'),
|
|
361
363
|
]
|
|
362
364
|
|
|
363
|
-
const results = injectLinksInDocument(elements,
|
|
365
|
+
const results = injectLinksInDocument(elements, { aiInjections: linkInjections, manualInjections: [] })
|
|
364
366
|
|
|
365
367
|
expect(results[0].failed).toBe(false)
|
|
366
368
|
expect(results[1].failed).toBe(true)
|
|
@@ -377,7 +379,7 @@ describe('linkInjection.js', () => {
|
|
|
377
379
|
generateInjection('Some unknown sentence', 'nothing'),
|
|
378
380
|
]
|
|
379
381
|
|
|
380
|
-
const results = injectLinksInDocument(elements,
|
|
382
|
+
const results = injectLinksInDocument(elements, { aiInjections: [], manualInjections: linkInjections })
|
|
381
383
|
|
|
382
384
|
expect(results[0].failed_message).toBe('Given text is already inside of a link.')
|
|
383
385
|
expect(results[1].failed_message).toBe('Given sentence was not found in the article.')
|
|
@@ -389,8 +391,7 @@ describe('linkInjection.js', () => {
|
|
|
389
391
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
390
392
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
391
393
|
|
|
392
|
-
|
|
393
|
-
injectLinksInDocument(elements, mock, { aiInjections: [injection], manualInjections: [] })
|
|
394
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
394
395
|
|
|
395
396
|
const link = /** @type {HTMLAnchorElement} */ (document.querySelector('[data-playpilot-injection-key]'))
|
|
396
397
|
|
|
@@ -410,8 +411,7 @@ describe('linkInjection.js', () => {
|
|
|
410
411
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
411
412
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
412
413
|
|
|
413
|
-
|
|
414
|
-
injectLinksInDocument(elements, mock, { aiInjections: [injection], manualInjections: [] })
|
|
414
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
415
415
|
|
|
416
416
|
const link = /** @type {HTMLAnchorElement} */ (document.querySelector('[data-playpilot-injection-key]'))
|
|
417
417
|
|
|
@@ -432,8 +432,7 @@ describe('linkInjection.js', () => {
|
|
|
432
432
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
433
433
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
434
434
|
|
|
435
|
-
|
|
436
|
-
injectLinksInDocument(elements, mock, { aiInjections: [injection], manualInjections: [] })
|
|
435
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
437
436
|
|
|
438
437
|
const link = /** @type {HTMLAnchorElement} */ (document.querySelector('[data-playpilot-injection-key]'))
|
|
439
438
|
|
|
@@ -453,8 +452,7 @@ describe('linkInjection.js', () => {
|
|
|
453
452
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
454
453
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
455
454
|
|
|
456
|
-
|
|
457
|
-
injectLinksInDocument(elements, mock, { aiInjections: [injection], manualInjections: [] })
|
|
455
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
458
456
|
|
|
459
457
|
const link = /** @type {HTMLAnchorElement} */ (document.querySelector('[data-playpilot-injection-key]'))
|
|
460
458
|
|
|
@@ -481,7 +479,7 @@ describe('linkInjection.js', () => {
|
|
|
481
479
|
generateInjection(sentence, 'injection'),
|
|
482
480
|
]
|
|
483
481
|
|
|
484
|
-
injectLinksInDocument(elements,
|
|
482
|
+
injectLinksInDocument(elements, { aiInjections: linkInjections, manualInjections: [] })
|
|
485
483
|
|
|
486
484
|
const links = /** @type {HTMLAnchorElement[]} */ (Array.from(document.querySelectorAll('[data-playpilot-injection-key]')))
|
|
487
485
|
|
|
@@ -496,7 +494,7 @@ describe('linkInjection.js', () => {
|
|
|
496
494
|
const elements = Array.from(document.querySelectorAll('p'))
|
|
497
495
|
const injection = { ...generateInjection('This is a sentence with an injection.', 'an injection'), in_text: false }
|
|
498
496
|
|
|
499
|
-
injectLinksInDocument(elements,
|
|
497
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
500
498
|
|
|
501
499
|
expect(document.querySelector('a')).not.toBeTruthy()
|
|
502
500
|
})
|
|
@@ -509,8 +507,7 @@ describe('linkInjection.js', () => {
|
|
|
509
507
|
const elements = Array.from(document.body.querySelectorAll('p'))
|
|
510
508
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
511
509
|
|
|
512
|
-
|
|
513
|
-
injectLinksInDocument(elements, mock, { aiInjections: [injection], manualInjections: [] })
|
|
510
|
+
injectLinksInDocument(elements, { aiInjections: [injection], manualInjections: [] })
|
|
514
511
|
|
|
515
512
|
const link = /** @type {HTMLAnchorElement} */ (document.querySelector('a'))
|
|
516
513
|
|
|
@@ -529,8 +526,7 @@ describe('linkInjection.js', () => {
|
|
|
529
526
|
const injection = generateInjection('Some sentence', 'an injection')
|
|
530
527
|
const linkInjections = [{ ...injection, after_article: true, inactive: true }, { ...injection, after_article: true, removed: true }]
|
|
531
528
|
|
|
532
|
-
|
|
533
|
-
injectLinksInDocument(elements, mock, { aiInjections: [], manualInjections: linkInjections })
|
|
529
|
+
injectLinksInDocument(elements, { aiInjections: [], manualInjections: linkInjections })
|
|
534
530
|
|
|
535
531
|
expect(mount).not.toHaveBeenCalled()
|
|
536
532
|
expect(document.querySelector('[data-playpilot-after-article-playlinks]')).not.toBeTruthy()
|
|
@@ -553,8 +549,7 @@ describe('linkInjection.js', () => {
|
|
|
553
549
|
generateInjection('Some fourthtext', 'Some'),
|
|
554
550
|
]
|
|
555
551
|
|
|
556
|
-
|
|
557
|
-
injectLinksInDocument(elements, mock, { aiInjections: [], manualInjections: injections })
|
|
552
|
+
injectLinksInDocument(elements, { aiInjections: [], manualInjections: injections })
|
|
558
553
|
|
|
559
554
|
expect(document.querySelectorAll('a')).toHaveLength(4)
|
|
560
555
|
})
|
|
@@ -574,8 +569,7 @@ describe('linkInjection.js', () => {
|
|
|
574
569
|
generateInjection('Somethird text', 'Some'),
|
|
575
570
|
]
|
|
576
571
|
|
|
577
|
-
|
|
578
|
-
injectLinksInDocument(elements, mock, { aiInjections: [], manualInjections: injections })
|
|
572
|
+
injectLinksInDocument(elements, { aiInjections: [], manualInjections: injections })
|
|
579
573
|
|
|
580
574
|
expect(document.querySelectorAll('a')).toHaveLength(3)
|
|
581
575
|
})
|
|
@@ -599,7 +593,7 @@ describe('linkInjection.js', () => {
|
|
|
599
593
|
generateInjection('First Title Some other title', 'Fourth'),
|
|
600
594
|
]
|
|
601
595
|
|
|
602
|
-
injectLinksInDocument(elements,
|
|
596
|
+
injectLinksInDocument(elements, { aiInjections: [], manualInjections: injections })
|
|
603
597
|
|
|
604
598
|
expect(document.querySelectorAll('a')).toHaveLength(4)
|
|
605
599
|
})
|
|
@@ -702,7 +696,7 @@ describe('linkInjection.js', () => {
|
|
|
702
696
|
expect(getLinkInjectionElements(parent)[1].tagName).toBe('OL')
|
|
703
697
|
})
|
|
704
698
|
|
|
705
|
-
it('Should ignore links, buttons, script tags, style tags, iframes, and
|
|
699
|
+
it('Should ignore links, buttons, script tags, style tags, iframes, headers, and more', () => {
|
|
706
700
|
document.body.innerHTML = `<section>
|
|
707
701
|
<h1>Some header</h1>
|
|
708
702
|
<h4>Some smaller header</h4>
|
|
@@ -714,6 +708,7 @@ describe('linkInjection.js', () => {
|
|
|
714
708
|
<style>I am styling</style>
|
|
715
709
|
<iframe>I am an iframe</iframe>
|
|
716
710
|
<noscript>I am noscript</noscript>
|
|
711
|
+
<figcaption>I am a figcaption</figcaption>
|
|
717
712
|
|
|
718
713
|
<div>
|
|
719
714
|
<a>I am another link</a>
|
|
@@ -822,7 +817,7 @@ describe('linkInjection.js', () => {
|
|
|
822
817
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
823
818
|
|
|
824
819
|
const elements = getLinkInjectionElements(document.body)
|
|
825
|
-
insertAfterArticlePlaylinks(elements, [injection]
|
|
820
|
+
insertAfterArticlePlaylinks(elements, [injection])
|
|
826
821
|
|
|
827
822
|
expect(mount).toHaveBeenCalled()
|
|
828
823
|
expect(document.querySelector('p:last-of-type + [data-playpilot-after-article-playlinks]')).toBeTruthy()
|
|
@@ -836,7 +831,7 @@ describe('linkInjection.js', () => {
|
|
|
836
831
|
`
|
|
837
832
|
|
|
838
833
|
const elements = getLinkInjectionElements(document.body)
|
|
839
|
-
insertAfterArticlePlaylinks(elements, []
|
|
834
|
+
insertAfterArticlePlaylinks(elements, [])
|
|
840
835
|
|
|
841
836
|
expect(mount).not.toHaveBeenCalled()
|
|
842
837
|
expect(document.querySelector('[data-playpilot-after-article-playlinks]')).not.toBeTruthy()
|
|
@@ -854,7 +849,7 @@ describe('linkInjection.js', () => {
|
|
|
854
849
|
|
|
855
850
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
856
851
|
const elements = getLinkInjectionElements(document.body)
|
|
857
|
-
insertAfterArticlePlaylinks(elements, [injection]
|
|
852
|
+
insertAfterArticlePlaylinks(elements, [injection])
|
|
858
853
|
|
|
859
854
|
expect(document.querySelector('hr + [data-playpilot-after-article-playlinks]')).toBeTruthy()
|
|
860
855
|
})
|
|
@@ -871,7 +866,7 @@ describe('linkInjection.js', () => {
|
|
|
871
866
|
|
|
872
867
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
873
868
|
const elements = getLinkInjectionElements(document.body)
|
|
874
|
-
insertAfterArticlePlaylinks(elements, [injection]
|
|
869
|
+
insertAfterArticlePlaylinks(elements, [injection])
|
|
875
870
|
|
|
876
871
|
expect(document.querySelector('hr + [data-playpilot-after-article-playlinks]')).toBeTruthy()
|
|
877
872
|
})
|
|
@@ -889,7 +884,7 @@ describe('linkInjection.js', () => {
|
|
|
889
884
|
|
|
890
885
|
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
891
886
|
const elements = getLinkInjectionElements(document.body)
|
|
892
|
-
insertAfterArticlePlaylinks(elements, [injection]
|
|
887
|
+
insertAfterArticlePlaylinks(elements, [injection])
|
|
893
888
|
|
|
894
889
|
expect(document.querySelector('[data-playpilot-after-article-playlinks] + hr')).toBeTruthy()
|
|
895
890
|
})
|
|
@@ -26,7 +26,7 @@ describe('EditorItem.svelte', () => {
|
|
|
26
26
|
it('Should highlight and unhighlight the matching link when component is hovered', async () => {
|
|
27
27
|
document.body.innerHTML = '<p>This is a sentence with an injection.</p>'
|
|
28
28
|
|
|
29
|
-
injectLinksInDocument(Array.from(document.querySelectorAll('p')),
|
|
29
|
+
injectLinksInDocument(Array.from(document.querySelectorAll('p')), linkInjections)
|
|
30
30
|
|
|
31
31
|
const { getAllByText, container } = render(EditorItem, { linkInjection })
|
|
32
32
|
|
|
@@ -41,7 +41,7 @@ describe('EditorItem.svelte', () => {
|
|
|
41
41
|
document.body.innerHTML = '<p>This is a sentence with an injection.</p>'
|
|
42
42
|
|
|
43
43
|
const linkInjectionWithAfterArticle = { ...linkInjection, in_text: true, after_article: true }
|
|
44
|
-
injectLinksInDocument(Array.from(document.querySelectorAll('p')),
|
|
44
|
+
injectLinksInDocument(Array.from(document.querySelectorAll('p')), { aiInjections: [linkInjectionWithAfterArticle], manualInjections: [] })
|
|
45
45
|
|
|
46
46
|
const { container } = render(EditorItem, { linkInjection })
|
|
47
47
|
|
|
@@ -54,7 +54,7 @@ describe('EditorItem.svelte', () => {
|
|
|
54
54
|
|
|
55
55
|
const failedInjection = generateInjection('This is a sentence', 'fail')
|
|
56
56
|
|
|
57
|
-
injectLinksInDocument(Array.from(document.querySelectorAll('p')),
|
|
57
|
+
injectLinksInDocument(Array.from(document.querySelectorAll('p')), { aiInjections: [], manualInjections: [failedInjection] })
|
|
58
58
|
|
|
59
59
|
const { container } = render(EditorItem, { linkInjection })
|
|
60
60
|
|
|
@@ -65,7 +65,7 @@ describe('EditorItem.svelte', () => {
|
|
|
65
65
|
it('Should scroll matching link into view when component is clicked', async () => {
|
|
66
66
|
document.body.innerHTML = '<p>This is a sentence with an injection.</p>'
|
|
67
67
|
|
|
68
|
-
injectLinksInDocument(Array.from(document.querySelectorAll('p')),
|
|
68
|
+
injectLinksInDocument(Array.from(document.querySelectorAll('p')), linkInjections)
|
|
69
69
|
|
|
70
70
|
const { container } = render(EditorItem, { linkInjection })
|
|
71
71
|
|
|
@@ -76,7 +76,7 @@ describe('EditorItem.svelte', () => {
|
|
|
76
76
|
it('Should not scroll matching link into view when component is clicked but there is no matching injection', async () => {
|
|
77
77
|
document.body.innerHTML = '<main><p>This has no matching injections.</p></main>'
|
|
78
78
|
|
|
79
|
-
injectLinksInDocument(Array.from(document.querySelectorAll('main p')),
|
|
79
|
+
injectLinksInDocument(Array.from(document.querySelectorAll('main p')), linkInjections)
|
|
80
80
|
|
|
81
81
|
const { container } = render(EditorItem, { linkInjection })
|
|
82
82
|
|
|
@@ -87,7 +87,7 @@ describe('EditorItem.svelte', () => {
|
|
|
87
87
|
it('Should not scroll matching link into view when component is clicked on button or input', async () => {
|
|
88
88
|
document.body.innerHTML = '<p>This is a sentence with an injection.</p>'
|
|
89
89
|
|
|
90
|
-
injectLinksInDocument(Array.from(document.querySelectorAll('p')),
|
|
90
|
+
injectLinksInDocument(Array.from(document.querySelectorAll('p')), linkInjections)
|
|
91
91
|
|
|
92
92
|
const { container } = render(EditorItem, { linkInjection })
|
|
93
93
|
|
|
@@ -101,7 +101,7 @@ describe('EditorItem.svelte', () => {
|
|
|
101
101
|
it('Should highlight element in editor when hovering element on page', async () => {
|
|
102
102
|
document.body.innerHTML = '<p>This is a sentence with an injection.</p>'
|
|
103
103
|
|
|
104
|
-
injectLinksInDocument(Array.from(document.querySelectorAll('p')),
|
|
104
|
+
injectLinksInDocument(Array.from(document.querySelectorAll('p')), linkInjections)
|
|
105
105
|
|
|
106
106
|
await new Promise(res => setTimeout(res))
|
|
107
107
|
|