diff options
author | Devlin Junker <devlin.junker@gmail.com> | 2023-09-28 15:46:35 -0700 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2023-10-05 09:46:36 +0200 |
commit | b6a42935399bb14afd06201034b3828a888e1d79 (patch) | |
tree | 78c3adcd0f11669ed2a7f50993fd814dd1be3abd /tests | |
parent | ed69499a160b310f24a67e0cee9d318dcf26e46b (diff) |
add unit tests
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/javascript/unit/components/App.spec.ts | 49 | ||||
-rw-r--r-- | tests/javascript/unit/components/feed-display/FeedItemDisplay.spec.ts | 18 | ||||
-rw-r--r-- | tests/javascript/unit/store/item.spec.ts | 10 |
3 files changed, 75 insertions, 2 deletions
diff --git a/tests/javascript/unit/components/App.spec.ts b/tests/javascript/unit/components/App.spec.ts new file mode 100644 index 000000000..135b41d40 --- /dev/null +++ b/tests/javascript/unit/components/App.spec.ts @@ -0,0 +1,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() + }) +}) diff --git a/tests/javascript/unit/components/feed-display/FeedItemDisplay.spec.ts b/tests/javascript/unit/components/feed-display/FeedItemDisplay.spec.ts index a75119414..7d60d4a01 100644 --- a/tests/javascript/unit/components/feed-display/FeedItemDisplay.spec.ts +++ b/tests/javascript/unit/components/feed-display/FeedItemDisplay.spec.ts @@ -72,7 +72,7 @@ describe('FeedItemDisplay.vue', () => { expect(feed).toEqual(mockFeed) }) - it('toggles starred state', () => { + it('should toggle starred state', () => { wrapper.vm.$props.item.starred = true; (wrapper.vm as any).toggleStarred(wrapper.vm.$props.item) @@ -88,5 +88,19 @@ describe('FeedItemDisplay.vue', () => { }) }) - // TODO: Audio/Video tests + it('should send SET_PLAYING_ITEM with item', () => { + const item = { id: 123 }; + (wrapper.vm as any).playAudio(item) + + expect(commitStub).toBeCalledWith(MUTATIONS.SET_PLAYING_ITEM, item) + }) + + it('should stop all audio elements in page when playing video', () => { + const pauseStub = jest.fn() + document.getElementsByTagName = jest.fn().mockReturnValue([{ pause: pauseStub }]); + + (wrapper.vm as any).stopAudio() + + expect(pauseStub).toBeCalled() + }) }) diff --git a/tests/javascript/unit/store/item.spec.ts b/tests/javascript/unit/store/item.spec.ts index b0c5fa412..f194ad223 100644 --- a/tests/javascript/unit/store/item.spec.ts +++ b/tests/javascript/unit/store/item.spec.ts @@ -129,6 +129,16 @@ describe('item.ts', () => { expect(state.selectedId).toEqual(123) }) }) + + describe('SET_PLAYING_ITEM', () => { + it('should update selectedId on state', async () => { + const state = { playingItem: undefined } as any + const item = { id: 123 } as any + mutations[FEED_ITEM_MUTATION_TYPES.SET_PLAYING_ITEM](state, item as any) + expect(state.playingItem).toEqual(item) + }) + }) + describe('SET_ITEMS', () => { it('should add feeds to state', () => { const state = { allItems: [] as any } as any |