summaryrefslogtreecommitdiffstats
path: root/tests/javascript/unit/components/App.spec.ts
blob: 135b41d40f362b5ad515f64c1efa5183331286dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils'

import App from '../../../../src/App.vue'
import { MUTATIONS } from '../../../../src/store'

describe('FeedItemDisplay.vue', () => {
	'use strict'
	const localVue = createLocalVue()
	let wrapper: Wrapper<App>

	const dispatchStub = jest.fn()
	const commitStub = jest.fn()
	beforeAll(() => {
		wrapper = shallowMount(App, {
			localVue,
			mocks: {
				$store: {
					state: {
						items: {
							playingItem: undefined,
						},
					},
					dispatch: dispatchStub,
					commit: commitStub,
				},
			},
		})
	})

	beforeEach(() => {
		dispatchStub.mockReset()
		commitStub.mockReset()
	})

	it('should send SET_PLAYING_ITEM with undefined to stop playback', () => {
		(wrapper.vm as any).stopPlaying()

		expect(commitStub).toBeCalledWith(MUTATIONS.SET_PLAYING_ITEM, undefined)
	})

	it('should stop all video elements in page when playing video', () => {
		const pauseStub = jest.fn()
		document.getElementsByTagName = jest.fn().mockReturnValue([{ pause: pauseStub }]);

		(wrapper.vm as any).stopVideo()

		expect(pauseStub).toBeCalled()
	})
})