@internetarchive/radio-player 0.0.3 → 0.1.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.
Files changed (34) hide show
  1. package/package.json +2 -2
  2. package/.eslintrc +0 -37
  3. package/.gitignore +0 -11
  4. package/.storybook/.babelrc +0 -15
  5. package/.storybook/addons.js +0 -7
  6. package/.storybook/config.js +0 -11
  7. package/.storybook/webpack.config.js +0 -5
  8. package/demo/full-text-search-service.ts +0 -32
  9. package/demo/index.html +0 -53
  10. package/demo/radio-player-controller.ts +0 -237
  11. package/karma.bs.config.js +0 -16
  12. package/karma.conf.js +0 -66
  13. package/package-lock.json +0 -51719
  14. package/stories/index.stories.js +0 -40
  15. package/stories/transcript.js +0 -683
  16. package/test/assets/arrow.mp3 +0 -0
  17. package/test/music-zone.test.js +0 -13
  18. package/test/promised-sleep.js +0 -3
  19. package/test/radio-player-config.test.js +0 -42
  20. package/test/radio-player.test.js +0 -1072
  21. package/test/sample_transcript.js +0 -1493
  22. package/test/search-handler/search-backends/full-text-sample-response-brackets.js +0 -60
  23. package/test/search-handler/search-backends/full-text-sample-response-em.js +0 -60
  24. package/test/search-handler/search-backends/full-text-search-backend.test.js +0 -74
  25. package/test/search-handler/search-backends/full-text-search-response.test.js +0 -14
  26. package/test/search-handler/search-backends/local-search-backend.test.js +0 -39
  27. package/test/search-handler/search-handler.test.js +0 -550
  28. package/test/search-handler/search-helper.test.js +0 -63
  29. package/test/search-handler/search-model.test.js +0 -56
  30. package/test/search-handler/transcript-index.test.js +0 -66
  31. package/test/search-results-switcher.test.js +0 -97
  32. package/tsconfig.build.json +0 -7
  33. package/tsconfig.json +0 -21
  34. package/yarn.lock +0 -14450
@@ -1,550 +0,0 @@
1
- /* eslint-disable class-methods-use-this */
2
- import { expect } from '@open-wc/testing';
3
-
4
- import { TranscriptConfig, TranscriptEntryConfig } from '@internetarchive/transcript-view';
5
- import { SearchHandler } from '../../lib/src/search-handler/search-handler';
6
- import { LocalSearchBackend } from '../../lib/src/search-handler/search-backends/local-search-backend/local-search-backend';
7
- import { TranscriptIndex } from '../../lib/src/search-handler/transcript-index';
8
- import { Range } from '../../lib/src/search-handler/search-models';
9
-
10
- class MockSearchIndex {
11
- async getSearchRanges(query) {
12
- return new Promise(resolve => resolve([]));
13
- }
14
- }
15
-
16
- class MockTranscriptIndex {
17
- mergedTranscript = 'Foo';
18
-
19
- mergedTranscriptLowercased = 'foo';
20
-
21
- transcriptEntryRanges = [];
22
-
23
- getTranscriptEntryAt(overallCharIndex) {
24
- return undefined;
25
- }
26
- }
27
-
28
- describe('Search Handler', () => {
29
- it('can be instantiated', async () => {
30
- const searchBackend = new MockSearchIndex();
31
- const transcriptIndex = new MockTranscriptIndex();
32
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
33
- expect(searchHandler).to.exist;
34
- });
35
-
36
- describe('getSearchSeparatedTranscript(term: string)', () => {
37
- it('returns a promise if there are search results', async () => {
38
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
39
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
40
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump baz boing', false);
41
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3]);
42
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
43
- const searchBackend = new LocalSearchBackend(transcriptIndex);
44
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
45
-
46
- const response = searchHandler.getSearchSeparatedTranscript('ba');
47
-
48
- expect(response instanceof Promise).to.be.true;
49
- });
50
-
51
- it('returns a promise if there are no search results', async () => {
52
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
53
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
54
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump baz boing', false);
55
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3]);
56
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
57
- const searchBackend = new LocalSearchBackend(transcriptIndex);
58
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
59
-
60
- const response = searchHandler.getSearchSeparatedTranscript('zip');
61
-
62
- expect(response instanceof Promise).to.be.true;
63
- });
64
-
65
- it('returns a single result, the entire transcript, if there are no search results', async () => {
66
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
67
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
68
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump baz boing', false);
69
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3]);
70
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
71
- const searchBackend = new LocalSearchBackend(transcriptIndex);
72
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
73
-
74
- const results = await searchHandler.getSearchSeparatedTranscript('zip');
75
-
76
- expect(results.length).to.equal(1);
77
-
78
- const entry = results[0];
79
- expect(entry.range.startIndex).to.equal(0);
80
- expect(entry.range.endIndex).to.equal(36);
81
- expect(entry.text).to.equal('foo bar baz boop blop bump baz boing');
82
- expect(entry.isSearchMatch).to.equal(false);
83
- });
84
-
85
- it('returns the correct results if the results are returned in-order', async () => {
86
- class MockInOrderSearchBackend {
87
- getSearchRanges() {
88
- const range1 = new Range(8, 11);
89
- const range2 = new Range(27, 30);
90
- const range3 = new Range(52, 55);
91
- return [range1, range2, range3];
92
- }
93
- }
94
-
95
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
96
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
97
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump baz boing', false);
98
- const entry4 = new TranscriptEntryConfig(4, 14, 19, 'snip snap', false);
99
- const entry5 = new TranscriptEntryConfig(5, 20, 24, 'ooga baz booga', false);
100
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3, entry4, entry5]);
101
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
102
- const searchBackend = new MockInOrderSearchBackend();
103
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
104
-
105
- const results = await searchHandler.getSearchSeparatedTranscript('baz');
106
-
107
- const result0 = results[0];
108
- expect(result0.range.startIndex).to.equal(0);
109
- expect(result0.range.endIndex).to.equal(8);
110
- expect(result0.text).to.equal('foo bar ');
111
- expect(result0.isSearchMatch).to.equal(false);
112
-
113
- const result1 = results[1];
114
- expect(result1.range.startIndex).to.equal(8);
115
- expect(result1.range.endIndex).to.equal(11);
116
- expect(result1.text).to.equal('baz');
117
- expect(result1.isSearchMatch).to.equal(true);
118
-
119
- const result2 = results[2];
120
- expect(result2.range.startIndex).to.equal(11);
121
- expect(result2.range.endIndex).to.equal(27);
122
- expect(result2.text).to.equal(' boop blop bump ');
123
- expect(result2.isSearchMatch).to.equal(false);
124
-
125
- const result3 = results[3];
126
- expect(result3.range.startIndex).to.equal(27);
127
- expect(result3.range.endIndex).to.equal(30);
128
- expect(result3.text).to.equal('baz');
129
- expect(result3.isSearchMatch).to.equal(true);
130
-
131
- const result4 = results[4];
132
- expect(result4.range.startIndex).to.equal(30);
133
- expect(result4.range.endIndex).to.equal(52);
134
- expect(result4.text).to.equal(' boing snip snap ooga ');
135
- expect(result4.isSearchMatch).to.equal(false);
136
-
137
- const result5 = results[5];
138
- expect(result5.range.startIndex).to.equal(52);
139
- expect(result5.range.endIndex).to.equal(55);
140
- expect(result5.text).to.equal('baz');
141
- expect(result5.isSearchMatch).to.equal(true);
142
-
143
- const result6 = results[6];
144
- expect(result6.range.startIndex).to.equal(55);
145
- expect(result6.range.endIndex).to.equal(61);
146
- expect(result6.text).to.equal(' booga');
147
- expect(result6.isSearchMatch).to.equal(false);
148
- });
149
-
150
- it('returns the correct results if the results are out of order', async () => {
151
- class MockOutOfOrderSearchBackend {
152
- getSearchRanges() {
153
- const range3 = new Range(52, 55);
154
- const range1 = new Range(8, 11);
155
- const range2 = new Range(27, 30);
156
- return [range3, range1, range2];
157
- }
158
- }
159
-
160
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
161
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
162
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump baz boing', false);
163
- const entry4 = new TranscriptEntryConfig(4, 14, 19, 'snip snap', false);
164
- const entry5 = new TranscriptEntryConfig(5, 20, 24, 'ooga baz booga', false);
165
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3, entry4, entry5]);
166
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
167
- const searchBackend = new MockOutOfOrderSearchBackend();
168
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
169
-
170
- const results = await searchHandler.getSearchSeparatedTranscript('baz');
171
-
172
- const result0 = results[0];
173
- expect(result0.range.startIndex).to.equal(0);
174
- expect(result0.range.endIndex).to.equal(8);
175
- expect(result0.text).to.equal('foo bar ');
176
- expect(result0.isSearchMatch).to.equal(false);
177
-
178
- const result1 = results[1];
179
- expect(result1.range.startIndex).to.equal(8);
180
- expect(result1.range.endIndex).to.equal(11);
181
- expect(result1.text).to.equal('baz');
182
- expect(result1.isSearchMatch).to.equal(true);
183
-
184
- const result2 = results[2];
185
- expect(result2.range.startIndex).to.equal(11);
186
- expect(result2.range.endIndex).to.equal(27);
187
- expect(result2.text).to.equal(' boop blop bump ');
188
- expect(result2.isSearchMatch).to.equal(false);
189
-
190
- const result3 = results[3];
191
- expect(result3.range.startIndex).to.equal(27);
192
- expect(result3.range.endIndex).to.equal(30);
193
- expect(result3.text).to.equal('baz');
194
- expect(result3.isSearchMatch).to.equal(true);
195
-
196
- const result4 = results[4];
197
- expect(result4.range.startIndex).to.equal(30);
198
- expect(result4.range.endIndex).to.equal(52);
199
- expect(result4.text).to.equal(' boing snip snap ooga ');
200
- expect(result4.isSearchMatch).to.equal(false);
201
-
202
- const result5 = results[5];
203
- expect(result5.range.startIndex).to.equal(52);
204
- expect(result5.range.endIndex).to.equal(55);
205
- expect(result5.text).to.equal('baz');
206
- expect(result5.isSearchMatch).to.equal(true);
207
-
208
- const result6 = results[6];
209
- expect(result6.range.startIndex).to.equal(55);
210
- expect(result6.range.endIndex).to.equal(61);
211
- expect(result6.text).to.equal(' booga');
212
- expect(result6.isSearchMatch).to.equal(false);
213
- });
214
-
215
- it('correctly splits up transcript search results', async () => {
216
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
217
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
218
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump baz boing', false);
219
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3]);
220
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
221
- const searchBackend = new LocalSearchBackend(transcriptIndex);
222
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
223
-
224
- const transcriptSearchResults = await searchHandler.getSearchSeparatedTranscript('ba');
225
-
226
- expect(transcriptSearchResults.length).to.equal(7);
227
-
228
- const firstEntry = transcriptSearchResults[0];
229
- const secondEntry = transcriptSearchResults[1];
230
- const thirdEntry = transcriptSearchResults[2];
231
- const fourthEntry = transcriptSearchResults[3];
232
- const fifthEntry = transcriptSearchResults[4];
233
- const sixthEntry = transcriptSearchResults[5];
234
- const seventhEntry = transcriptSearchResults[6];
235
-
236
- expect(firstEntry.range.startIndex).to.equal(0);
237
- expect(firstEntry.range.endIndex).to.equal(4);
238
- expect(firstEntry.text).to.equal('foo ');
239
- expect(firstEntry.isSearchMatch).to.equal(false);
240
-
241
- expect(secondEntry.range.startIndex).to.equal(4);
242
- expect(secondEntry.range.endIndex).to.equal(6);
243
- expect(secondEntry.text).to.equal('ba');
244
- expect(secondEntry.isSearchMatch).to.equal(true);
245
-
246
- expect(thirdEntry.range.startIndex).to.equal(6);
247
- expect(thirdEntry.range.endIndex).to.equal(8);
248
- expect(thirdEntry.text).to.equal('r ');
249
- expect(thirdEntry.isSearchMatch).to.equal(false);
250
-
251
- expect(fourthEntry.range.startIndex).to.equal(8);
252
- expect(fourthEntry.range.endIndex).to.equal(10);
253
- expect(fourthEntry.text).to.equal('ba');
254
- expect(fourthEntry.isSearchMatch).to.equal(true);
255
-
256
- expect(fifthEntry.range.startIndex).to.equal(10);
257
- expect(fifthEntry.range.endIndex).to.equal(27);
258
- expect(fifthEntry.text).to.equal('z boop blop bump ');
259
- expect(fifthEntry.isSearchMatch).to.equal(false);
260
-
261
- expect(sixthEntry.range.startIndex).to.equal(27);
262
- expect(sixthEntry.range.endIndex).to.equal(29);
263
- expect(sixthEntry.text).to.equal('ba');
264
- expect(sixthEntry.isSearchMatch).to.equal(true);
265
-
266
- expect(seventhEntry.range.startIndex).to.equal(29);
267
- expect(seventhEntry.range.endIndex).to.equal(36);
268
- expect(seventhEntry.text).to.equal('z boing');
269
- expect(seventhEntry.isSearchMatch).to.equal(false);
270
- });
271
- });
272
-
273
- describe('search(term: string)', () => {
274
- it('correctly generates a new transcript with search results at beginning of transcript entry', async () => {
275
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
276
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
277
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump boing', false);
278
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3]);
279
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
280
- const searchBackend = new LocalSearchBackend(transcriptIndex);
281
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
282
-
283
- const newTranscript = await searchHandler.search('boop');
284
-
285
- expect(newTranscript.entries.length).to.equal(4);
286
-
287
- const firstEntry = newTranscript.entries[0];
288
- expect(firstEntry.id).to.equal(1);
289
- expect(firstEntry.start).to.equal(0);
290
- expect(firstEntry.end).to.equal(4);
291
- expect(firstEntry.rawText).to.equal('foo bar baz');
292
- expect(firstEntry.searchMatchIndex).to.equal(undefined);
293
-
294
- const secondEntry = newTranscript.entries[1];
295
- expect(secondEntry.id).to.equal(2);
296
- expect(secondEntry.start).to.equal(5);
297
- expect(secondEntry.end).to.equal(9);
298
- expect(secondEntry.rawText).to.equal('boop');
299
- expect(secondEntry.searchMatchIndex).to.equal(0);
300
-
301
- const thirdEntry = newTranscript.entries[2];
302
- expect(thirdEntry.id).to.equal(3);
303
- expect(thirdEntry.start).to.equal(5);
304
- expect(thirdEntry.end).to.equal(9);
305
- expect(thirdEntry.rawText).to.equal('blop');
306
- expect(thirdEntry.searchMatchIndex).to.equal(undefined);
307
-
308
- const fourthEntry = newTranscript.entries[3];
309
- expect(fourthEntry.id).to.equal(4);
310
- expect(fourthEntry.start).to.equal(10);
311
- expect(fourthEntry.end).to.equal(13);
312
- expect(fourthEntry.rawText).to.equal('bump boing');
313
- expect(fourthEntry.searchMatchIndex).to.equal(undefined);
314
- });
315
-
316
- it('correctly generates a new transcript with search results at end of transcript entry', async () => {
317
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
318
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
319
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'boing bump', false);
320
- const entry4 = new TranscriptEntryConfig(4, 14, 18, 'snip snap', false);
321
- const entry5 = new TranscriptEntryConfig(5, 19, 23, 'grip grap', false);
322
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3, entry4, entry5]);
323
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
324
- const searchBackend = new LocalSearchBackend(transcriptIndex);
325
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
326
-
327
- const newTranscript = await searchHandler.search('bump');
328
-
329
- expect(newTranscript.entries.length).to.equal(6);
330
-
331
- const entryPriorToSearchMatch = newTranscript.entries[2];
332
- expect(entryPriorToSearchMatch.id).to.equal(3);
333
- expect(entryPriorToSearchMatch.start).to.equal(10);
334
- expect(entryPriorToSearchMatch.end).to.equal(13);
335
- expect(entryPriorToSearchMatch.rawText).to.equal('boing');
336
- expect(entryPriorToSearchMatch.searchMatchIndex).to.equal(undefined);
337
-
338
- const searchMatchEntry = newTranscript.entries[3];
339
- expect(searchMatchEntry.id).to.equal(4);
340
- expect(searchMatchEntry.start).to.equal(10);
341
- expect(searchMatchEntry.end).to.equal(13);
342
- expect(searchMatchEntry.rawText).to.equal('bump');
343
- expect(searchMatchEntry.searchMatchIndex).to.equal(0);
344
-
345
- const entryAfterSearchMatch = newTranscript.entries[4];
346
- expect(entryAfterSearchMatch.id).to.equal(5);
347
- expect(entryAfterSearchMatch.start).to.equal(14);
348
- expect(entryAfterSearchMatch.end).to.equal(18);
349
- expect(entryAfterSearchMatch.rawText).to.equal('snip snap');
350
- expect(entryAfterSearchMatch.searchMatchIndex).to.equal(undefined);
351
- });
352
-
353
- it('correctly generates a new transcript with multiple search result matches', async () => {
354
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
355
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
356
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump boing', false);
357
- const entry4 = new TranscriptEntryConfig(4, 14, 17, 'fizz buzz', false);
358
- const entry5 = new TranscriptEntryConfig(5, 18, 23, 'blammer blommer', false);
359
- const entry6 = new TranscriptEntryConfig(6, 24, 28, 'slop bump snap', false);
360
- const entry7 = new TranscriptEntryConfig(7, 29, 34, 'ooga booga', false);
361
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3, entry4, entry5, entry6, entry7]);
362
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
363
- const searchBackend = new LocalSearchBackend(transcriptIndex);
364
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
365
-
366
- const newTranscript = await searchHandler.search('bump');
367
-
368
- expect(newTranscript.entries.length).to.equal(10);
369
-
370
- const firstSearchMatch = newTranscript.entries[2];
371
- expect(firstSearchMatch.id).to.equal(3);
372
- expect(firstSearchMatch.start).to.equal(10);
373
- expect(firstSearchMatch.end).to.equal(13);
374
- expect(firstSearchMatch.rawText).to.equal('bump');
375
- expect(firstSearchMatch.searchMatchIndex).to.equal(0);
376
-
377
- const secondSearchMatch = newTranscript.entries[7];
378
- expect(secondSearchMatch.id).to.equal(8);
379
- expect(secondSearchMatch.start).to.equal(24);
380
- expect(secondSearchMatch.end).to.equal(28);
381
- expect(secondSearchMatch.rawText).to.equal('bump');
382
- expect(secondSearchMatch.searchMatchIndex).to.equal(1);
383
- });
384
-
385
- it('correctly generates a new transcript with search results that cross over transcript entries', async () => {
386
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
387
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
388
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump boing', false);
389
- const entry4 = new TranscriptEntryConfig(4, 14, 18, 'fizz buzz', false);
390
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3, entry4]);
391
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
392
- const searchBackend = new LocalSearchBackend(transcriptIndex);
393
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
394
-
395
- const newTranscript = await searchHandler.search('blop bump');
396
-
397
- expect(newTranscript.entries.length).to.equal(5);
398
- });
399
-
400
- it('correctly generates a new transcript with search results that completely cross a transcript entry', async () => {
401
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
402
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
403
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump boing', false); // will completely skip over this entry
404
- const entry4 = new TranscriptEntryConfig(4, 14, 18, 'fizz buzz', false);
405
- const entry5 = new TranscriptEntryConfig(5, 19, 23, 'snip snap', false);
406
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3, entry4, entry5]);
407
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
408
- const searchBackend = new LocalSearchBackend(transcriptIndex);
409
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
410
-
411
- const newTranscript = await searchHandler.search('blop bump boing fizz');
412
-
413
- expect(newTranscript.entries.length).to.equal(5);
414
-
415
- const firstEntry = newTranscript.entries[0];
416
- expect(firstEntry.id).to.equal(1);
417
- expect(firstEntry.start).to.equal(0);
418
- expect(firstEntry.end).to.equal(4);
419
- expect(firstEntry.rawText).to.equal('foo bar baz');
420
- expect(firstEntry.searchMatchIndex).to.equal(undefined);
421
-
422
- const secondEntry = newTranscript.entries[1];
423
- expect(secondEntry.id).to.equal(2);
424
- expect(secondEntry.start).to.equal(5);
425
- expect(secondEntry.end).to.equal(9);
426
- expect(secondEntry.rawText).to.equal('boop');
427
- expect(secondEntry.searchMatchIndex).to.equal(undefined);
428
-
429
- const thirdEntry = newTranscript.entries[2];
430
- expect(thirdEntry.id).to.equal(3);
431
- expect(thirdEntry.start).to.equal(5);
432
- expect(thirdEntry.end).to.equal(18);
433
- expect(thirdEntry.rawText).to.equal('blop bump boing fizz');
434
- expect(thirdEntry.searchMatchIndex).to.equal(0);
435
-
436
- const fourthEntry = newTranscript.entries[3];
437
- expect(fourthEntry.id).to.equal(4);
438
- expect(fourthEntry.start).to.equal(14);
439
- expect(fourthEntry.end).to.equal(18);
440
- expect(fourthEntry.rawText).to.equal('buzz');
441
- expect(fourthEntry.searchMatchIndex).to.equal(undefined);
442
-
443
- const fifthEntry = newTranscript.entries[4];
444
- expect(fifthEntry.id).to.equal(5);
445
- expect(fifthEntry.start).to.equal(19);
446
- expect(fifthEntry.end).to.equal(23);
447
- expect(fifthEntry.rawText).to.equal('snip snap');
448
- expect(fifthEntry.searchMatchIndex).to.equal(undefined);
449
- });
450
-
451
- it('correctly generates a new transcript with partial word match', async () => {
452
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
453
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
454
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump boing', false);
455
- const entry4 = new TranscriptEntryConfig(4, 14, 18, 'fizz buzz', false);
456
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3, entry4]);
457
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
458
- const searchBackend = new LocalSearchBackend(transcriptIndex);
459
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
460
-
461
- const newTranscript = await searchHandler.search('bu');
462
-
463
- expect(newTranscript.entries.length).to.equal(7);
464
-
465
- const firstSearchMatch = newTranscript.entries[2];
466
- expect(firstSearchMatch.id).to.equal(3);
467
- expect(firstSearchMatch.start).to.equal(10);
468
- expect(firstSearchMatch.end).to.equal(13);
469
- expect(firstSearchMatch.rawText).to.equal('bu');
470
- expect(firstSearchMatch.searchMatchIndex).to.equal(0);
471
-
472
- const secondSearchMatch = newTranscript.entries[5];
473
- expect(secondSearchMatch.id).to.equal(6);
474
- expect(secondSearchMatch.start).to.equal(14);
475
- expect(secondSearchMatch.end).to.equal(18);
476
- expect(secondSearchMatch.rawText).to.equal('bu');
477
- expect(secondSearchMatch.searchMatchIndex).to.equal(1);
478
- });
479
-
480
- it('correctly generates a new transcript with multiple matches inside single entry', async () => {
481
- const entry1 = new TranscriptEntryConfig(1, 1.031, 6.002, 'He was pressed by reporters but Maryland Congressman Elijah Cummings declined to', false);
482
- const entry2 = new TranscriptEntryConfig(2, 6.003, 11.012, 'add fuel to the ongoing feud between himself and President Trump erupted last', false);
483
- const entry3 = new TranscriptEntryConfig(3, 11.013, 15.044, 'weekend after the president harshly criticized the Democratic lawmaker and his', false);
484
- const entry4 = new TranscriptEntryConfig(4, 15.045, 20.033, 'Baltimore area district which the president called Rat and road and infested', false);
485
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3, entry4]);
486
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
487
- const searchBackend = new LocalSearchBackend(transcriptIndex);
488
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
489
-
490
- const newTranscript = await searchHandler.search('the');
491
-
492
- expect(newTranscript.entries.length).to.equal(12);
493
-
494
- const firstSearchMatch = newTranscript.entries[2];
495
- expect(firstSearchMatch.id).to.equal(3);
496
- expect(firstSearchMatch.start).to.equal(6.003);
497
- expect(firstSearchMatch.end).to.equal(11.012);
498
- expect(firstSearchMatch.rawText).to.equal('the');
499
- expect(firstSearchMatch.searchMatchIndex).to.equal(0);
500
-
501
- const secondSearchMatch = newTranscript.entries[5];
502
- expect(secondSearchMatch.id).to.equal(6);
503
- expect(secondSearchMatch.start).to.equal(11.013);
504
- expect(secondSearchMatch.end).to.equal(15.044);
505
- expect(secondSearchMatch.rawText).to.equal('the');
506
- expect(secondSearchMatch.searchMatchIndex).to.equal(1);
507
-
508
- const afterSecondMatch = newTranscript.entries[6];
509
- expect(afterSecondMatch.id).to.equal(7);
510
- expect(afterSecondMatch.start).to.equal(11.013);
511
- expect(afterSecondMatch.end).to.equal(15.044);
512
- expect(afterSecondMatch.rawText).to.equal('president harshly criticized');
513
- expect(afterSecondMatch.searchMatchIndex).to.equal(undefined);
514
-
515
- const thirdSearchMatch = newTranscript.entries[7];
516
- expect(thirdSearchMatch.id).to.equal(8);
517
- expect(thirdSearchMatch.start).to.equal(11.013);
518
- expect(thirdSearchMatch.end).to.equal(15.044);
519
- expect(thirdSearchMatch.rawText).to.equal('the');
520
- expect(thirdSearchMatch.searchMatchIndex).to.equal(2);
521
-
522
- const afterThirdSearchMatch = newTranscript.entries[8];
523
- expect(afterThirdSearchMatch.id).to.equal(9);
524
- expect(afterThirdSearchMatch.start).to.equal(11.013);
525
- expect(afterThirdSearchMatch.end).to.equal(15.044);
526
- expect(afterThirdSearchMatch.rawText).to.equal('Democratic lawmaker and his');
527
- expect(afterThirdSearchMatch.searchMatchIndex).to.equal(undefined);
528
- });
529
-
530
- it('sets the start and end of search matches correctly', async () => {
531
- const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
532
- const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
533
- const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump boing', false);
534
- const entry4 = new TranscriptEntryConfig(4, 14, 18, 'fizz buzz', false);
535
- const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3, entry4]);
536
- const transcriptIndex = new TranscriptIndex(transcriptConfig);
537
- const searchBackend = new LocalSearchBackend(transcriptIndex);
538
- const searchHandler = new SearchHandler(searchBackend, transcriptIndex);
539
-
540
- const newTranscript = await searchHandler.search('blop bump');
541
-
542
- const thirdSearchMatch = newTranscript.entries[2];
543
- expect(thirdSearchMatch.id).to.equal(3);
544
- expect(thirdSearchMatch.start).to.equal(5);
545
- expect(thirdSearchMatch.end).to.equal(13);
546
- expect(thirdSearchMatch.rawText).to.equal('blop bump');
547
- expect(thirdSearchMatch.searchMatchIndex).to.equal(0);
548
- });
549
- });
550
- });
@@ -1,63 +0,0 @@
1
- import {
2
- html, fixture, expect, oneEvent, elementUpdated
3
- } from '@open-wc/testing';
4
-
5
- import { SearchHelper } from '../../lib/src/search-handler/search-helper';
6
- import { Range } from '../../lib/src/search-handler/search-models';
7
-
8
- describe('Search Helper', () => {
9
- describe('getIntersection()', () => {
10
- it('correctly calculates the intersection of two ranges', async () => {
11
- const range1 = new Range(0, 10);
12
- const range2 = new Range(7, 15);
13
- const intersection = SearchHelper.getIntersection(range1, range2);
14
-
15
- expect(intersection.startIndex).to.equal(7);
16
- expect(intersection.endIndex).to.equal(10);
17
- });
18
-
19
- it('correctly calculates the intersection of two ranges in opposite order', async () => {
20
- const range1 = new Range(0, 10);
21
- const range2 = new Range(7, 15);
22
- const intersection = SearchHelper.getIntersection(range2, range1);
23
-
24
- expect(intersection.startIndex).to.equal(7);
25
- expect(intersection.endIndex).to.equal(10);
26
- });
27
-
28
- it('correctly calculates the intersection when one consumes the other', async () => {
29
- const range1 = new Range(3, 17);
30
- const range2 = new Range(7, 15);
31
- const intersection = SearchHelper.getIntersection(range1, range2);
32
-
33
- expect(intersection.startIndex).to.equal(7);
34
- expect(intersection.endIndex).to.equal(15);
35
- });
36
-
37
- it('correctly calculates the intersection when one consumes the other in other order', async () => {
38
- const range1 = new Range(3, 17);
39
- const range2 = new Range(7, 15);
40
- const intersection = SearchHelper.getIntersection(range2, range1);
41
-
42
- expect(intersection.startIndex).to.equal(7);
43
- expect(intersection.endIndex).to.equal(15);
44
- });
45
-
46
- it('returns `undefined` if the ranges do not intersect', async () => {
47
- const range1 = new Range(0, 10);
48
- const range2 = new Range(11, 15);
49
- const intersection = SearchHelper.getIntersection(range1, range2);
50
- expect(intersection).to.equal(undefined);
51
- });
52
-
53
- it('returns the expected intersection for a given text block', async () => {
54
- const range1 = new Range(0, 11);
55
- const range2 = new Range(8, 15);
56
- const intersection = SearchHelper.getIntersection(range1, range2);
57
- const text = 'foo bar baz boop blop bump snip snap';
58
- const intersected = text.substring(intersection.startIndex, intersection.endIndex);
59
-
60
- expect(intersected).to.equal('baz');
61
- });
62
- });
63
- });
@@ -1,56 +0,0 @@
1
- import {
2
- expect
3
- } from '@open-wc/testing';
4
-
5
- import { TranscriptEntryConfig } from '@internetarchive/transcript-view';
6
- import { Range, SearchResult, TranscriptEntryRange } from '../../lib/src/search-handler/search-models';
7
-
8
- describe('Search Models', () => {
9
- describe('Range', () => {
10
- it('can be initialized properly', async () => {
11
- const range = new Range(9, 13);
12
- expect(range.startIndex).to.equal(9);
13
- expect(range.endIndex).to.equal(13);
14
-
15
- const range2 = new Range(14, 7);
16
- expect(range2.startIndex).to.equal(14);
17
- expect(range2.endIndex).to.equal(7);
18
- });
19
-
20
- it('correctly calculates the length of the range is start is less than end', async () => {
21
- const range = new Range(9, 13);
22
- expect(range.length).to.equal(4);
23
- });
24
-
25
- it('correctly calculates the length of the range is end is less than start', async () => {
26
- const range = new Range(7, 2);
27
- expect(range.length).to.equal(5);
28
- });
29
-
30
- it('can be initialized with the same number', async () => {
31
- const range = new Range(7, 7);
32
- expect(range.length).to.equal(0);
33
- });
34
- });
35
-
36
- describe('SearchResult', () => {
37
- it('can be initialized properly', async () => {
38
- const range = new Range(9, 12);
39
- const result = new SearchResult(range, 'foo', true);
40
- expect(result.range.length).to.equal(3);
41
- expect(result.text).to.equal('foo');
42
- expect(result.isSearchMatch).to.equal(true);
43
- });
44
- });
45
-
46
- describe('TranscriptEntryRange', () => {
47
- it('can be initialized properly', async () => {
48
- const transcript = new TranscriptEntryConfig(1, 17, 23, 'foo bar baz', false);
49
- const range = new Range(34, 44);
50
- const transcriptRange = new TranscriptEntryRange(transcript, range);
51
-
52
- expect(transcriptRange.range.length).to.equal(10);
53
- expect(transcriptRange.entry.rawText).to.equal('foo bar baz');
54
- });
55
- });
56
- });