@gcorevideo/player 2.22.31 → 2.23.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.
@@ -0,0 +1,72 @@
1
+ import { describe, it, expect, beforeEach, vi } from 'vitest'
2
+
3
+ import { Events } from '@clappr/core'
4
+
5
+
6
+ import { createMockCore, createMockMediaControl } from '../../../testUtils'
7
+
8
+ import { Thumbnails } from '../Thumbnails'
9
+ import { loadImageDimensions } from '../utils'
10
+
11
+ import { Logger, LogTracer, setTracer } from '@gcorevideo/utils'
12
+
13
+ // Logger.enable('*')
14
+ // setTracer(new LogTracer('Thumbnails.test'))
15
+
16
+ vi.mock('../utils.ts', () => ({
17
+ loadImageDimensions: vi.fn().mockResolvedValue({ width: 600, height: 900 }),
18
+ }))
19
+
20
+ describe('Thumbnails', () => {
21
+ let core: any
22
+ let mediaControl: any
23
+ let thumbnails: Thumbnails
24
+ beforeEach(() => {
25
+ core = createMockCore({
26
+ thumbnails: {
27
+ backdropHeight: 100,
28
+ spotlightHeight: 100,
29
+ sprite: 'https://example.com/sprite.png',
30
+ vtt: `
31
+ 1
32
+ 00:00:00.000 --> 00:00:01.000
33
+ sprite.png#xywh=100,100,100,100
34
+
35
+ 2
36
+ 00:00:01.000 --> 00:00:02.000
37
+ sprite.png#xywh=200,200,100,100
38
+ `,
39
+ },
40
+ })
41
+ mediaControl = createMockMediaControl(core)
42
+ core.getPlugin.mockImplementation((name) => {
43
+ switch (name) {
44
+ case 'media_control':
45
+ return mediaControl
46
+ }
47
+ });
48
+ thumbnails = new Thumbnails(core)
49
+ })
50
+ describe('loading', () => {
51
+ beforeEach(async () => {
52
+ core.emit(Events.CORE_READY)
53
+ await new Promise(resolve => setTimeout(resolve, 1))
54
+ })
55
+ it('should render', () => {
56
+ expect(thumbnails.$el.html()).toMatchSnapshot()
57
+ })
58
+ it('should mount to media controls', () => {
59
+ expect(mediaControl.$el.find('.scrub-thumbnails')).toHaveLength(1)
60
+ })
61
+ it('should load image dimensions', () => {
62
+ expect(loadImageDimensions).toHaveBeenCalledWith('https://example.com/sprite.png')
63
+ })
64
+ it('should parse sprite sheet and create thumbnails', () => {
65
+ const thumbs = mediaControl.$el.find('#thumbnails-carousel .thumbnail-container')
66
+ expect(thumbs).toHaveLength(2)
67
+ })
68
+ it('should hide', () => {
69
+ expect(thumbnails.$el.hasClass('hidden')).toBe(true)
70
+ })
71
+ })
72
+ })
@@ -0,0 +1,10 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`Thumbnails > loading > should render 1`] = `
4
+ "<div class="thumbnails-text" id="thumbnails-text"></div>
5
+ <div class="backdrop" id="thumbnails-backdrop" style="height: 100px;">
6
+ <div class="carousel" id="thumbnails-carousel"><div class="thumbnail-container" style="width: 100px; height: 100px; background-image: url(&quot;https://example.com/sprite.png&quot;); background-size: 600px 900px; background-position: -100px -100px;"></div><div class="thumbnail-container" style="width: 100px; height: 100px; background-image: url(&quot;https://example.com/sprite.png&quot;); background-size: 600px 900px; background-position: -200px -200px;"></div></div>
7
+ </div>
8
+ <div class="spotlight" id="thumbnails-spotlight" style="height: 100px;"></div>
9
+ "
10
+ `;
@@ -0,0 +1,12 @@
1
+ export function loadImageDimensions(url: string): Promise<{ width: number, height: number }> {
2
+ return new Promise((resolve, reject) => {
3
+ const img = new Image()
4
+ img.src = url
5
+ img.onload = () => {
6
+ resolve({ width: img.width, height: img.height })
7
+ }
8
+ img.onerror = () => {
9
+ reject(new Error('Failed to load image'))
10
+ }
11
+ })
12
+ }
package/src/testUtils.ts CHANGED
@@ -112,14 +112,13 @@ export function createMockContainer(
112
112
 
113
113
  export function createMockMediaControl(core: any) {
114
114
  const mediaControl = new UICorePlugin(core)
115
+ // TODO <div class="media-control-layer">
115
116
  mediaControl.$el.html(
116
117
  `<div class="media-control-left-panel" data-media-control></div>
117
118
  <div class="media-control-right-panel" data-media-control></div>
118
119
  <div class="media-control-center-panel" data-media-control></div>`,
119
120
  )
120
121
  // @ts-ignore
121
- mediaControl.putElement = vi.fn()
122
- // @ts-ignore
123
122
  mediaControl.mount = vi.fn()
124
123
  // @ts-ignore
125
124
  mediaControl.toggleElement = vi.fn()