@playpilot/tpi 8.14.0-beta.4 → 8.15.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.
- package/dist/editorial.mount.js +9 -9
- package/dist/link-injections.js +1 -1
- package/dist/mount.js +9 -9
- package/events.md +5 -0
- package/package.json +2 -2
- package/src/lib/api/externalPages.ts +0 -7
- package/src/lib/data/translations.ts +10 -0
- package/src/lib/enums/TrackingEvent.ts +3 -0
- package/src/lib/fakeData.ts +3 -3
- package/src/lib/inTextWidgets.ts +43 -0
- package/src/lib/injection.ts +4 -0
- package/src/lib/routes.ts +1 -5
- package/src/lib/types/explore.d.ts +1 -0
- package/src/routes/+layout.svelte +2 -0
- package/src/routes/components/Debugger.svelte +0 -5
- package/src/routes/components/Explore/ExploreLayout.svelte +19 -2
- package/src/routes/components/Explore/ExploreRouter.svelte +11 -28
- package/src/routes/components/Explore/Routes/ExploreModal.svelte +38 -0
- package/src/routes/components/Modals/Modal.svelte +3 -1
- package/src/routes/components/Modals/RailModal.svelte +2 -2
- package/src/routes/components/Modals/TitlesRailModal.svelte +5 -4
- package/src/routes/components/Rails/Rail.svelte +4 -4
- package/src/routes/components/Widgets/InjectionsWidgetRail.svelte +51 -0
- package/src/routes/explore/+page.svelte +4 -0
- package/src/tests/lib/inTextWidgets.test.js +160 -0
- package/src/tests/routes/components/Widgets/InjectionsWidgetRail.test.js +28 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { mount, unmount } from 'svelte'
|
|
3
|
+
import { generateInjection } from '../helpers'
|
|
4
|
+
import { insertInTextWidgets, clearInTextWidgets, inTextWidgetInsertedComponents } from '$lib/inTextWidgets'
|
|
5
|
+
|
|
6
|
+
vi.mock('svelte', () => ({
|
|
7
|
+
mount: vi.fn(),
|
|
8
|
+
unmount: vi.fn(),
|
|
9
|
+
}))
|
|
10
|
+
|
|
11
|
+
describe('inTextWidgets.ts', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
vi.resetAllMocks()
|
|
14
|
+
document.body.innerHTML = ''
|
|
15
|
+
|
|
16
|
+
clearInTextWidgets()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
describe('insertInTextWidgets', () => {
|
|
20
|
+
it('Should not mount any component if no linkInjections are given', () => {
|
|
21
|
+
document.body.innerHTML = '<div data-playpilot-widget="tpi-rail"></div>'
|
|
22
|
+
|
|
23
|
+
insertInTextWidgets([])
|
|
24
|
+
|
|
25
|
+
expect(mount).not.toHaveBeenCalled()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('Should not mount any component if no widget targets exist', () => {
|
|
29
|
+
document.body.innerHTML = '<div>No widgets here</div>'
|
|
30
|
+
|
|
31
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
32
|
+
|
|
33
|
+
insertInTextWidgets([injection])
|
|
34
|
+
|
|
35
|
+
expect(mount).not.toHaveBeenCalled()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('Should mount a component for a known widget type', () => {
|
|
39
|
+
document.body.innerHTML = '<div data-playpilot-widget="tpi-rail"></div>'
|
|
40
|
+
|
|
41
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
42
|
+
|
|
43
|
+
insertInTextWidgets([injection])
|
|
44
|
+
|
|
45
|
+
expect(mount).toHaveBeenCalledOnce()
|
|
46
|
+
expect(mount).toHaveBeenCalledWith(
|
|
47
|
+
expect.anything(),
|
|
48
|
+
expect.objectContaining({
|
|
49
|
+
target: document.querySelector('[data-playpilot-widget="tpi-rail"]'),
|
|
50
|
+
props: { linkInjections: [injection] },
|
|
51
|
+
}),
|
|
52
|
+
)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('Should not mount a component for an unknown widget type', () => {
|
|
56
|
+
document.body.innerHTML = '<div data-playpilot-widget="unknown-widget"></div>'
|
|
57
|
+
|
|
58
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
59
|
+
|
|
60
|
+
insertInTextWidgets([injection])
|
|
61
|
+
|
|
62
|
+
expect(mount).not.toHaveBeenCalled()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('Should mount components for multiple widget targets on the same page', () => {
|
|
66
|
+
document.body.innerHTML = `
|
|
67
|
+
<div data-playpilot-widget="tpi-rail"></div>
|
|
68
|
+
<div data-playpilot-widget="tpi-rail"></div>
|
|
69
|
+
`
|
|
70
|
+
|
|
71
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
72
|
+
|
|
73
|
+
insertInTextWidgets([injection])
|
|
74
|
+
|
|
75
|
+
expect(mount).toHaveBeenCalledTimes(2)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('Should skip unknown widget targets and mount known ones', () => {
|
|
79
|
+
document.body.innerHTML = `
|
|
80
|
+
<div data-playpilot-widget="tpi-rail"></div>
|
|
81
|
+
<div data-playpilot-widget="unknown-widget"></div>
|
|
82
|
+
`
|
|
83
|
+
|
|
84
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
85
|
+
|
|
86
|
+
insertInTextWidgets([injection])
|
|
87
|
+
|
|
88
|
+
expect(mount).toHaveBeenCalledOnce()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('Should track inserted components', () => {
|
|
92
|
+
document.body.innerHTML = `
|
|
93
|
+
<div data-playpilot-widget="tpi-rail"></div>
|
|
94
|
+
<div data-playpilot-widget="tpi-rail"></div>
|
|
95
|
+
`
|
|
96
|
+
|
|
97
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
98
|
+
|
|
99
|
+
insertInTextWidgets([injection])
|
|
100
|
+
|
|
101
|
+
expect(inTextWidgetInsertedComponents).toHaveLength(2)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('Should clear previously inserted widgets before inserting new ones', () => {
|
|
105
|
+
document.body.innerHTML = '<div data-playpilot-widget="tpi-rail"></div>'
|
|
106
|
+
|
|
107
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
108
|
+
|
|
109
|
+
insertInTextWidgets([injection])
|
|
110
|
+
insertInTextWidgets([injection])
|
|
111
|
+
|
|
112
|
+
expect(unmount).toHaveBeenCalled()
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
describe('clearInTextWidgets', () => {
|
|
117
|
+
it('Should unmount all inserted components', () => {
|
|
118
|
+
document.body.innerHTML = `
|
|
119
|
+
<div data-playpilot-widget="tpi-rail"></div>
|
|
120
|
+
<div data-playpilot-widget="tpi-rail"></div>
|
|
121
|
+
`
|
|
122
|
+
|
|
123
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
124
|
+
insertInTextWidgets([injection])
|
|
125
|
+
|
|
126
|
+
clearInTextWidgets()
|
|
127
|
+
|
|
128
|
+
expect(unmount).toHaveBeenCalled()
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('Should clear innerHTML of all widget elements', () => {
|
|
132
|
+
document.body.innerHTML = `
|
|
133
|
+
<div data-playpilot-widget="tpi-rail"><span>leftover content</span></div>
|
|
134
|
+
`
|
|
135
|
+
|
|
136
|
+
clearInTextWidgets()
|
|
137
|
+
|
|
138
|
+
expect(/** @type {HTMLElement} */ (document.querySelector('[data-playpilot-widget]')).innerHTML).toBe('')
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
it('Should reset inTextWidgetInsertedComponents to empty array', () => {
|
|
142
|
+
document.body.innerHTML = '<div data-playpilot-widget="tpi-rail"></div>'
|
|
143
|
+
|
|
144
|
+
const injection = generateInjection('This is a sentence with an injection.', 'an injection')
|
|
145
|
+
insertInTextWidgets([injection])
|
|
146
|
+
|
|
147
|
+
expect(inTextWidgetInsertedComponents.length).toBe(1)
|
|
148
|
+
|
|
149
|
+
clearInTextWidgets()
|
|
150
|
+
|
|
151
|
+
expect(inTextWidgetInsertedComponents.length).toBe(0)
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('Should do nothing if no components are present', () => {
|
|
155
|
+
clearInTextWidgets()
|
|
156
|
+
|
|
157
|
+
expect(unmount).not.toHaveBeenCalled()
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { render } from '@testing-library/svelte'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import InjectionsWidgetRail from '../../../../routes/components/Widgets/InjectionsWidgetRail.svelte'
|
|
5
|
+
import { linkInjections } from '$lib/fakeData'
|
|
6
|
+
|
|
7
|
+
describe('InjectionsWidgetRail.svelte', () => {
|
|
8
|
+
it('Should render unique titles for given injections', () => {
|
|
9
|
+
const injections = [linkInjections[0], linkInjections[0], linkInjections[1], linkInjections[2], linkInjections[2]]
|
|
10
|
+
|
|
11
|
+
const { getAllByTestId } = render(InjectionsWidgetRail, { linkInjections: injections })
|
|
12
|
+
|
|
13
|
+
expect(getAllByTestId('title')).toHaveLength(3)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('Should not render if no injections were given', () => {
|
|
17
|
+
const { queryByTestId } = render(InjectionsWidgetRail, { linkInjections: [] })
|
|
18
|
+
|
|
19
|
+
expect(queryByTestId('widget')).not.toBeTruthy()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('Should not render if injections contained no valid titles', () => {
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
const { queryByTestId } = render(InjectionsWidgetRail, { linkInjections: [{ ...linkInjections, title_details: null }] })
|
|
25
|
+
|
|
26
|
+
expect(queryByTestId('widget')).not.toBeTruthy()
|
|
27
|
+
})
|
|
28
|
+
})
|