@internetarchive/radio-player 0.0.3-a4 → 0.0.3

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/.eslintrc +37 -0
  2. package/.gitignore +11 -0
  3. package/.storybook/.babelrc +15 -0
  4. package/.storybook/addons.js +7 -0
  5. package/.storybook/config.js +11 -0
  6. package/.storybook/webpack.config.js +5 -0
  7. package/demo/full-text-search-service.ts +32 -0
  8. package/demo/index.html +53 -0
  9. package/demo/radio-player-controller.ts +237 -0
  10. package/karma.bs.config.js +16 -0
  11. package/karma.conf.js +66 -0
  12. package/package-lock.json +51719 -0
  13. package/package.json +5 -5
  14. package/stories/index.stories.js +40 -0
  15. package/stories/transcript.js +683 -0
  16. package/test/assets/arrow.mp3 +0 -0
  17. package/test/music-zone.test.js +13 -0
  18. package/test/promised-sleep.js +3 -0
  19. package/test/radio-player-config.test.js +42 -0
  20. package/test/radio-player.test.js +1072 -0
  21. package/test/sample_transcript.js +1493 -0
  22. package/test/search-handler/search-backends/full-text-sample-response-brackets.js +60 -0
  23. package/test/search-handler/search-backends/full-text-sample-response-em.js +60 -0
  24. package/test/search-handler/search-backends/full-text-search-backend.test.js +74 -0
  25. package/test/search-handler/search-backends/full-text-search-response.test.js +14 -0
  26. package/test/search-handler/search-backends/local-search-backend.test.js +39 -0
  27. package/test/search-handler/search-handler.test.js +550 -0
  28. package/test/search-handler/search-helper.test.js +63 -0
  29. package/test/search-handler/search-model.test.js +56 -0
  30. package/test/search-handler/transcript-index.test.js +66 -0
  31. package/test/search-results-switcher.test.js +97 -0
  32. package/tsconfig.build.json +7 -0
  33. package/tsconfig.json +21 -0
  34. package/yarn.lock +14450 -0
@@ -0,0 +1,66 @@
1
+ import {
2
+ html, fixture, expect, oneEvent, elementUpdated
3
+ } from '@open-wc/testing';
4
+
5
+ import { TranscriptConfig, TranscriptEntryConfig } from '@internetarchive/transcript-view';
6
+ import { TranscriptIndex } from '../../lib/src/search-handler/transcript-index';
7
+
8
+ describe('Transcript Index', () => {
9
+ it('correctly calculates entry start and end index offsets of the source transcript', async () => {
10
+ const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
11
+ const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
12
+ const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bang boing', false);
13
+ const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3]);
14
+ const transcriptIndex = new TranscriptIndex(transcriptConfig);
15
+
16
+ const entryStartEndIndices = transcriptIndex.transcriptEntryRanges;
17
+
18
+ // note a space is added between each transcript entry so it increases each
19
+ // subsequent index by 1
20
+ expect(entryStartEndIndices[0].entry).to.equal(entry1);
21
+ expect(entryStartEndIndices[0].range.startIndex).to.equal(0);
22
+ expect(entryStartEndIndices[0].range.endIndex).to.equal(11);
23
+
24
+ expect(entryStartEndIndices[1].entry).to.equal(entry2);
25
+ expect(entryStartEndIndices[1].range.startIndex).to.equal(12);
26
+ expect(entryStartEndIndices[1].range.endIndex).to.equal(21);
27
+
28
+ expect(entryStartEndIndices[2].entry).to.equal(entry3);
29
+ expect(entryStartEndIndices[2].range.startIndex).to.equal(22);
30
+ expect(entryStartEndIndices[2].range.endIndex).to.equal(32);
31
+ });
32
+
33
+ it('correctly builds the full text blob', async () => {
34
+ const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
35
+ const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
36
+ const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bang boing', false);
37
+ const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3]);
38
+ const transcriptIndex = new TranscriptIndex(transcriptConfig);
39
+
40
+ expect(transcriptIndex.mergedTranscript).to.equal('foo bar baz boop blop bang boing');
41
+ });
42
+
43
+ it('correctly finds the correct entry range for a given index', async () => {
44
+ const entry1 = new TranscriptEntryConfig(1, 0, 4, 'foo bar baz', false);
45
+ const entry2 = new TranscriptEntryConfig(2, 5, 9, 'boop blop', false);
46
+ const entry3 = new TranscriptEntryConfig(3, 10, 13, 'bump baz boing', false);
47
+ const transcriptConfig = new TranscriptConfig([entry1, entry2, entry3]);
48
+ const transcriptIndex = new TranscriptIndex(transcriptConfig);
49
+
50
+ // in second entry
51
+ const transcriptEntryRange = transcriptIndex.getTranscriptEntryAt(14);
52
+ expect(transcriptEntryRange.entry).to.equal(entry2);
53
+
54
+ // in third entry
55
+ const transcriptEntryRange2 = transcriptIndex.getTranscriptEntryAt(23);
56
+ expect(transcriptEntryRange2.entry).to.equal(entry3);
57
+
58
+ // in-between the first and second entry
59
+ const transcriptEntryRange3 = transcriptIndex.getTranscriptEntryAt(11);
60
+ expect(transcriptEntryRange3).to.equal(undefined);
61
+
62
+ // outside of range
63
+ const transcriptEntryRange4 = transcriptIndex.getTranscriptEntryAt(45);
64
+ expect(transcriptEntryRange4).to.equal(undefined);
65
+ });
66
+ });
@@ -0,0 +1,97 @@
1
+ import {
2
+ html, fixture, expect, oneEvent, elementUpdated
3
+ } from '@open-wc/testing';
4
+
5
+ import promisedSleep from './promised-sleep';
6
+
7
+ import '../lib/src/radio-player';
8
+
9
+ describe('Search Results Switcher', () => {
10
+ it('defaults to 0 results', async () => {
11
+ const el = await fixture(html`
12
+ <search-results-switcher></search-results-switcher>
13
+ `);
14
+
15
+ expect(el.numberOfResults).to.equal(0);
16
+ expect(el.currentResultIndex).to.equal(0);
17
+ });
18
+
19
+ it('renders the number of results correctly', async () => {
20
+ const el = await fixture(html`
21
+ <search-results-switcher numberOfResults='7'></search-results-switcher>
22
+ `);
23
+
24
+ const { shadowRoot } = el;
25
+
26
+ expect(shadowRoot.getElementById('current-result').innerText).to.equal('1');
27
+ expect(shadowRoot.getElementById('number-of-results').innerText).to.equal('7');
28
+ });
29
+
30
+ it('increments the values properly and emits event when changed', async () => {
31
+ const el = await fixture(html`
32
+ <search-results-switcher numberOfResults='7'></search-results-switcher>
33
+ `);
34
+
35
+ const { shadowRoot } = el;
36
+
37
+ const clickEvent = new MouseEvent('click');
38
+ const nextButton = shadowRoot.getElementById('next-button');
39
+
40
+ setTimeout(() => { nextButton.dispatchEvent(clickEvent); });
41
+ const response = await oneEvent(el, 'searchResultIndexChanged');
42
+ expect(response.detail.searchResultIndex).to.equal(1);
43
+ expect(el.currentResultIndex).to.equal(1);
44
+ });
45
+
46
+ it('wraps around to the beginning if it reaches the end', async () => {
47
+ const el = await fixture(html`
48
+ <search-results-switcher numberOfResults='7'></search-results-switcher>
49
+ `);
50
+
51
+ el.currentResultIndex = 6;
52
+
53
+ const { shadowRoot } = el;
54
+
55
+ const clickEvent = new MouseEvent('click');
56
+ const nextButton = shadowRoot.getElementById('next-button');
57
+
58
+ setTimeout(() => { nextButton.dispatchEvent(clickEvent); });
59
+ const response = await oneEvent(el, 'searchResultIndexChanged');
60
+ expect(response.detail.searchResultIndex).to.equal(0);
61
+ expect(el.currentResultIndex).to.equal(0);
62
+ });
63
+
64
+ it('decrements the values properly and emits event when changed', async () => {
65
+ const el = await fixture(html`
66
+ <search-results-switcher numberOfResults='7'></search-results-switcher>
67
+ `);
68
+
69
+ el.currentResultIndex = 4;
70
+
71
+ const { shadowRoot } = el;
72
+
73
+ const clickEvent = new MouseEvent('click');
74
+ const nextButton = shadowRoot.getElementById('previous-button');
75
+
76
+ setTimeout(() => { nextButton.dispatchEvent(clickEvent); });
77
+ const response = await oneEvent(el, 'searchResultIndexChanged');
78
+ expect(response.detail.searchResultIndex).to.equal(3);
79
+ expect(el.currentResultIndex).to.equal(3);
80
+ });
81
+
82
+ it('wraps around to the end if it reaches the beginning', async () => {
83
+ const el = await fixture(html`
84
+ <search-results-switcher numberOfResults='7'></search-results-switcher>
85
+ `);
86
+
87
+ const { shadowRoot } = el;
88
+
89
+ const clickEvent = new MouseEvent('click');
90
+ const nextButton = shadowRoot.getElementById('previous-button');
91
+
92
+ setTimeout(() => { nextButton.dispatchEvent(clickEvent); });
93
+ const response = await oneEvent(el, 'searchResultIndexChanged');
94
+ expect(response.detail.searchResultIndex).to.equal(6);
95
+ expect(el.currentResultIndex).to.equal(6);
96
+ });
97
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "allowJs": false,
5
+ "checkJs": false,
6
+ }
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es6", // define the target version of js
4
+ "lib": ["es2016", "dom"], // define the minimum set of libraries needed to build
5
+ "experimentalDecorators": true, // needed for using decorators
6
+ "moduleResolution": "node", // needed to correctly resolve node_modules like `lit-element`
7
+ "sourceMap": true,
8
+ "outDir": "./lib",
9
+ "declaration": true,
10
+ "strict": true
11
+ },
12
+ "include": [
13
+ "src/**/*.ts",
14
+ "dev_tools/**/*.ts",
15
+ "demo/**/*.ts"
16
+ ],
17
+ "exclude": [
18
+ "node_modules/!(@open-wc)",
19
+ "node_modules/!(@types)"
20
+ ]
21
+ }