@playpilot/tpi 8.30.0 → 8.31.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 +8 -8
- package/dist/link-injections.js +1 -1
- package/dist/mount.js +5 -5
- package/package.json +1 -1
- package/src/lib/api/externalPages.ts +1 -0
- package/src/lib/api/participants.ts +1 -1
- package/src/lib/api/providers.ts +1 -1
- package/src/lib/api/search.ts +9 -0
- package/src/lib/api/titles.ts +1 -1
- package/src/routes/components/Editorial/Editor.svelte +0 -2
- package/src/routes/components/Editorial/EditorItem.svelte +2 -2
- package/src/routes/components/Editorial/ManualInjection.svelte +26 -19
- package/src/routes/components/Editorial/Search/ParticipantSearchItem.svelte +86 -0
- package/src/routes/components/Editorial/Search/TypeSearch.svelte +120 -0
- package/src/routes/components/Tabs.svelte +12 -23
- package/src/tests/lib/api/externalPages.test.js +134 -1
- package/src/tests/routes/components/Editorial/EditorItem.test.js +1 -2
- package/src/tests/routes/components/Editorial/ManualInjection.test.js +43 -6
- package/src/tests/routes/components/Editorial/Search/{TitleSearch.test.js → TypeSearch.test.js} +21 -9
- package/src/routes/components/Editorial/Search/TitleSearch.svelte +0 -96
|
@@ -2,9 +2,10 @@ import { fireEvent, render, waitFor } from '@testing-library/svelte'
|
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
import ManualInjection from '../../../../routes/components/Editorial/ManualInjection.svelte'
|
|
5
|
-
import { searchTitles } from '$lib/api/search'
|
|
6
|
-
import { title } from '$lib/fakeData'
|
|
5
|
+
import { searchParticipants, searchTitles } from '$lib/api/search'
|
|
6
|
+
import { participants, title } from '$lib/fakeData'
|
|
7
7
|
import { getIndexOfSelection } from '$lib/selection'
|
|
8
|
+
import { participantUrl, titleUrl } from '$lib/routes'
|
|
8
9
|
|
|
9
10
|
function createSelectionMock() {
|
|
10
11
|
const container = document.querySelector('div')
|
|
@@ -26,6 +27,7 @@ function createSelectionMock() {
|
|
|
26
27
|
|
|
27
28
|
vi.mock('$lib/api/search', () => ({
|
|
28
29
|
searchTitles: vi.fn(),
|
|
30
|
+
searchParticipants: vi.fn(),
|
|
29
31
|
}))
|
|
30
32
|
|
|
31
33
|
vi.mock('$lib/selection', () => ({
|
|
@@ -93,7 +95,7 @@ describe('ManualInjection.svelte', () => {
|
|
|
93
95
|
sid: title.sid,
|
|
94
96
|
title: 'text',
|
|
95
97
|
sentence: 'Some text in a sentence',
|
|
96
|
-
playpilot_url:
|
|
98
|
+
playpilot_url: titleUrl(title),
|
|
97
99
|
key: expect.any(String),
|
|
98
100
|
title_details: title,
|
|
99
101
|
manual: true,
|
|
@@ -136,7 +138,7 @@ describe('ManualInjection.svelte', () => {
|
|
|
136
138
|
sid: title.sid,
|
|
137
139
|
title: 'text',
|
|
138
140
|
sentence: 'Some text in a sentence',
|
|
139
|
-
playpilot_url:
|
|
141
|
+
playpilot_url: titleUrl(title),
|
|
140
142
|
key: expect.any(String),
|
|
141
143
|
title_details: title,
|
|
142
144
|
manual: true,
|
|
@@ -179,7 +181,7 @@ describe('ManualInjection.svelte', () => {
|
|
|
179
181
|
sid: title.sid,
|
|
180
182
|
title: 'Some title',
|
|
181
183
|
sentence: 'Some title',
|
|
182
|
-
playpilot_url:
|
|
184
|
+
playpilot_url: titleUrl(title),
|
|
183
185
|
key: expect.any(String),
|
|
184
186
|
title_details: title,
|
|
185
187
|
manual: true,
|
|
@@ -222,7 +224,7 @@ describe('ManualInjection.svelte', () => {
|
|
|
222
224
|
sid: title.sid,
|
|
223
225
|
title: 'Some other paragraph',
|
|
224
226
|
sentence: 'Some other paragraph',
|
|
225
|
-
playpilot_url:
|
|
227
|
+
playpilot_url: titleUrl(title),
|
|
226
228
|
key: expect.any(String),
|
|
227
229
|
title_details: title,
|
|
228
230
|
manual: true,
|
|
@@ -285,4 +287,39 @@ describe('ManualInjection.svelte', () => {
|
|
|
285
287
|
|
|
286
288
|
await waitFor(() => expect(searchTitles).toHaveBeenCalled())
|
|
287
289
|
})
|
|
290
|
+
|
|
291
|
+
it('Should save participants when selected', async () => {
|
|
292
|
+
createSelectionMock()
|
|
293
|
+
|
|
294
|
+
const participant = participants[0]
|
|
295
|
+
|
|
296
|
+
vi.mocked(searchParticipants).mockResolvedValueOnce([participant])
|
|
297
|
+
vi.mocked(getIndexOfSelection).mockReturnValueOnce({ start: 5, end: 10 })
|
|
298
|
+
|
|
299
|
+
const onsave = vi.fn()
|
|
300
|
+
const { getByText, getByLabelText } = render(ManualInjection, { onsave })
|
|
301
|
+
|
|
302
|
+
await fireEvent.mouseUp(window)
|
|
303
|
+
await fireEvent.click(getByText('Cast & Crew'))
|
|
304
|
+
|
|
305
|
+
await waitFor(async () => {
|
|
306
|
+
await fireEvent.input(getByLabelText('Search...'), { target: { value: 'test' } })
|
|
307
|
+
await fireEvent.click(getByText(participants[0].name))
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
await fireEvent.click(getByText('Add playlink'))
|
|
311
|
+
|
|
312
|
+
expect(onsave).toHaveBeenCalledWith({
|
|
313
|
+
sid: participants[0].sid,
|
|
314
|
+
title: 'text',
|
|
315
|
+
sentence: 'Some text in a sentence',
|
|
316
|
+
playpilot_url: participantUrl(participant),
|
|
317
|
+
key: expect.any(String),
|
|
318
|
+
participant_details: participant,
|
|
319
|
+
manual: true,
|
|
320
|
+
phrase_before: 'Some',
|
|
321
|
+
phrase_after: 'in a',
|
|
322
|
+
type: 'participant',
|
|
323
|
+
})
|
|
324
|
+
})
|
|
288
325
|
})
|
package/src/tests/routes/components/Editorial/Search/{TitleSearch.test.js → TypeSearch.test.js}
RENAMED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { fireEvent, render, waitFor } from '@testing-library/svelte'
|
|
2
2
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import { searchTitles } from '$lib/api/search'
|
|
4
|
+
import TypeSearch from '../../../../../routes/components/Editorial/Search/TypeSearch.svelte'
|
|
5
|
+
import { searchTitles, searchParticipants } from '$lib/api/search'
|
|
6
6
|
import { title } from '$lib/fakeData'
|
|
7
7
|
|
|
8
8
|
vi.mock('$lib/api/search', () => ({
|
|
9
9
|
searchTitles: vi.fn(),
|
|
10
|
+
searchParticipants: vi.fn(),
|
|
10
11
|
}))
|
|
11
12
|
|
|
12
|
-
describe('
|
|
13
|
+
describe('TypeSearch.svelte', () => {
|
|
13
14
|
beforeEach(() => {
|
|
14
15
|
vi.resetAllMocks()
|
|
15
16
|
})
|
|
16
17
|
|
|
17
18
|
it('Should search for titles when inputting text', async () => {
|
|
18
|
-
const { getByRole } = render(
|
|
19
|
+
const { getByRole } = render(TypeSearch)
|
|
19
20
|
|
|
20
21
|
await fireEvent.input(getByRole('textbox'), { target: { value: 'test' } })
|
|
21
22
|
|
|
@@ -25,7 +26,7 @@ describe('TitleSearch.svelte', () => {
|
|
|
25
26
|
it('Should show empty state when no results are returned', async () => {
|
|
26
27
|
vi.mocked(searchTitles).mockResolvedValueOnce([])
|
|
27
28
|
|
|
28
|
-
const { getByRole, getByText } = render(
|
|
29
|
+
const { getByRole, getByText } = render(TypeSearch)
|
|
29
30
|
|
|
30
31
|
await fireEvent.input(getByRole('textbox'), { target: { value: 'test' } })
|
|
31
32
|
|
|
@@ -37,7 +38,7 @@ describe('TitleSearch.svelte', () => {
|
|
|
37
38
|
it('Should show results when given', async () => {
|
|
38
39
|
vi.mocked(searchTitles).mockResolvedValueOnce([title])
|
|
39
40
|
|
|
40
|
-
const { getByRole, getByText, getByTestId } = render(
|
|
41
|
+
const { getByRole, getByText, getByTestId } = render(TypeSearch)
|
|
41
42
|
|
|
42
43
|
await fireEvent.input(getByRole('textbox'), { target: { value: 'test' } })
|
|
43
44
|
|
|
@@ -52,15 +53,26 @@ describe('TitleSearch.svelte', () => {
|
|
|
52
53
|
vi.mocked(searchTitles).mockResolvedValueOnce([title])
|
|
53
54
|
|
|
54
55
|
const onselect = vi.fn()
|
|
55
|
-
const { getByRole, getByText, queryByTestId } = render(
|
|
56
|
+
const { getByRole, getByText, queryByTestId } = render(TypeSearch, { onselect, query: '' })
|
|
56
57
|
|
|
57
58
|
await fireEvent.input(getByRole('textbox'), { target: { value: 'test' } })
|
|
58
59
|
|
|
59
60
|
await waitFor(async () => {
|
|
60
|
-
await fireEvent.click(
|
|
61
|
-
|
|
61
|
+
await fireEvent.click(getByText(title.title))
|
|
62
|
+
|
|
63
|
+
expect(onselect).toHaveBeenCalledWith(title, 'title')
|
|
62
64
|
expect(queryByTestId('search-results')).not.toBeTruthy()
|
|
63
65
|
expect(getByText(title.title)).toBeTruthy()
|
|
64
66
|
})
|
|
65
67
|
})
|
|
68
|
+
|
|
69
|
+
it('Should search for participants after changing tab when inputting text', async () => {
|
|
70
|
+
const { getByRole, getByText } = render(TypeSearch)
|
|
71
|
+
|
|
72
|
+
await fireEvent.click(getByText('Cast & Crew'))
|
|
73
|
+
await fireEvent.input(getByRole('textbox'), { target: { value: 'test' } })
|
|
74
|
+
|
|
75
|
+
expect(searchTitles).not.toHaveBeenCalled()
|
|
76
|
+
expect(searchParticipants).toHaveBeenCalled()
|
|
77
|
+
})
|
|
66
78
|
})
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { searchTitles } from '$lib/api/search'
|
|
3
|
-
import type { TitleData } from '$lib/types/title'
|
|
4
|
-
import TextInput from '../TextInput.svelte'
|
|
5
|
-
import TitleSearchItem from './TitleSearchItem.svelte'
|
|
6
|
-
|
|
7
|
-
interface Props {
|
|
8
|
-
onselect?: (title: TitleData) => void
|
|
9
|
-
query: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
let { onselect = () => null, query = $bindable() }: Props = $props()
|
|
13
|
-
|
|
14
|
-
let results: TitleData[] = $state([])
|
|
15
|
-
let selectedResult: TitleData | null = $state(null)
|
|
16
|
-
let loading = $state(false)
|
|
17
|
-
|
|
18
|
-
$effect(() => {
|
|
19
|
-
if (query) search(query)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
async function search(query: string): Promise<void> {
|
|
23
|
-
loading = true
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
results = await searchTitles(query)
|
|
27
|
-
} finally {
|
|
28
|
-
loading = false
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function select(title: TitleData): void {
|
|
33
|
-
query = title.title
|
|
34
|
-
selectedResult = title
|
|
35
|
-
|
|
36
|
-
onselect(title)
|
|
37
|
-
}
|
|
38
|
-
</script>
|
|
39
|
-
|
|
40
|
-
<div class="search">
|
|
41
|
-
<TextInput
|
|
42
|
-
bind:value={query}
|
|
43
|
-
oninput={() => selectedResult = null}
|
|
44
|
-
name="search"
|
|
45
|
-
label="Search..." />
|
|
46
|
-
|
|
47
|
-
{#if query && !selectedResult}
|
|
48
|
-
<div class="results" data-testid="search-results">
|
|
49
|
-
{#each results as title (title.sid)}
|
|
50
|
-
<TitleSearchItem {title} onclick={() => select(title)} />
|
|
51
|
-
{:else}
|
|
52
|
-
{#if !loading}
|
|
53
|
-
<em class="empty">No results found</em>
|
|
54
|
-
{/if}
|
|
55
|
-
{/each}
|
|
56
|
-
</div>
|
|
57
|
-
{/if}
|
|
58
|
-
|
|
59
|
-
{#if selectedResult}
|
|
60
|
-
<div class="selected">
|
|
61
|
-
<TitleSearchItem title={selectedResult} hoverable={false} />
|
|
62
|
-
</div>
|
|
63
|
-
{/if}
|
|
64
|
-
</div>
|
|
65
|
-
|
|
66
|
-
<style lang="scss">
|
|
67
|
-
.search {
|
|
68
|
-
position: relative;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
.results {
|
|
72
|
-
z-index: 1;
|
|
73
|
-
position: absolute;
|
|
74
|
-
top: calc(100% + margin(0.5));
|
|
75
|
-
left: 0;
|
|
76
|
-
right: 0;
|
|
77
|
-
height: 30vh;
|
|
78
|
-
max-height: margin(10);
|
|
79
|
-
border-radius: margin(0.5);
|
|
80
|
-
background: theme(lighter);
|
|
81
|
-
scrollbar-width: thin;
|
|
82
|
-
overflow: auto;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.empty {
|
|
86
|
-
padding: margin(0.5);
|
|
87
|
-
font-size: margin(0.75);
|
|
88
|
-
color: theme(text-color-alt);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
.selected {
|
|
92
|
-
margin: margin(0.5) 0;
|
|
93
|
-
border-radius: 0.5rem;
|
|
94
|
-
border: 2px solid theme(green);
|
|
95
|
-
}
|
|
96
|
-
</style>
|