From 4899be32e3f6065297f95e0ccc42e97efbec545b Mon Sep 17 00:00:00 2001 From: Devlin Junker Date: Sat, 3 Dec 2022 14:34:26 -0800 Subject: add more tests Signed-off-by: Devlin Junker --- tests/javascript/unit/components/Sidebar.spec.ts | 117 +++++++++++++++++------ tests/javascript/unit/setup.ts | 2 +- 2 files changed, 91 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/javascript/unit/components/Sidebar.spec.ts b/tests/javascript/unit/components/Sidebar.spec.ts index 42f826eb8..16affbb3d 100644 --- a/tests/javascript/unit/components/Sidebar.spec.ts +++ b/tests/javascript/unit/components/Sidebar.spec.ts @@ -29,41 +29,104 @@ describe('Sidebar.vue', () => { expect((wrapper.vm as any).$data.showAddFeed).toBeFalsy() }) - it('should dispatch message to store with folder name to create new folder', () => { - (wrapper.vm as any).newFolder('abc') + describe('User Actions', () => { + it('should dispatch message to store with folder name to create new folder', () => { + (wrapper.vm as any).newFolder('abc') - expect((wrapper.vm as any).$store.dispatch).toHaveBeenCalledWith(ACTIONS.ADD_FOLDERS, { folder: { name: 'abc' } }) - }) + expect((wrapper.vm as any).$store.dispatch).toHaveBeenCalledWith(ACTIONS.ADD_FOLDERS, { folder: { name: 'abc' } }) + }) - it('should dispatch message to store with folder object on delete folder', () => { - const folder = {}; - (wrapper.vm as any).deleteFolder(folder) + it('should dispatch message to store with folder object on delete folder', () => { + const folder = {}; + (wrapper.vm as any).deleteFolder(folder) - expect((wrapper.vm as any).$store.dispatch).toHaveBeenCalledWith(ACTIONS.DELETE_FOLDER, { folder }) - }) + expect((wrapper.vm as any).$store.dispatch).toHaveBeenCalledWith(ACTIONS.DELETE_FOLDER, { folder }) + }) - it('should set showAddFeed to true', () => { - (wrapper.vm as any).showShowAddFeed() - expect(wrapper.vm.$data.showAddFeed).toBeTruthy() - }) + it('should set showAddFeed to true', () => { + (wrapper.vm as any).showShowAddFeed() + expect(wrapper.vm.$data.showAddFeed).toBeTruthy() + }) - it('should set showAddFeed to false', () => { - (wrapper.vm as any).closeShowAddFeed() - expect(wrapper.vm.$data.showAddFeed).toBeFalsy() + it('should set showAddFeed to false', () => { + (wrapper.vm as any).closeShowAddFeed() + expect(wrapper.vm.$data.showAddFeed).toBeFalsy() + }) }) - // TODO: A couple more tests here - it('should return top level nav (folders and feeds without folders)', () => { - const topLevelNav = (wrapper.vm.$options.computed?.topLevelNav as any).call({ - $store: { - getters: { - feeds: [], - folders: [], + describe('SideBarState', () => { + it('should return no top level nav when no folders or feeds', () => { + const topLevelNav = (wrapper.vm.$options.computed?.topLevelNav as any).call({ + $store: { + getters: { + feeds: [], + folders: [], + }, }, - }, + }) + + expect(topLevelNav).toEqual([]) + }) + + it('should return top level nav with 1 feed', () => { + const feeds: any[] = [{ name: 'feed1', id: 1 }] + const folders: any[] = [] + const topLevelNav = (wrapper.vm.$options.computed?.topLevelNav as any).call({ + $store: { + getters: { + feeds, + folders, + }, + }, + }) + + expect(topLevelNav).toEqual([feeds[0]]) }) - expect(topLevelNav).toEqual([]) + it('should return top level nav with 1 folder (with feeds)', () => { + const feeds: any[] = [{ name: 'feed2', id: 2, folderId: 123 }] + const folders: any[] = [{ name: 'abc', id: 123 }] + const topLevelNav = (wrapper.vm.$options.computed?.topLevelNav as any).call({ + $store: { + getters: { + feeds, + folders, + }, + }, + }) + + expect(topLevelNav).toEqual(folders) + }) + + it('should return top level nav with 1 folder (without feed)', () => { + const feeds: any[] = [{ name: 'feed1', id: 1 }] + const folders: any[] = [{ name: 'abc', id: 123 }] + const topLevelNav = (wrapper.vm.$options.computed?.topLevelNav as any).call({ + $store: { + getters: { + feeds, + folders, + }, + }, + }) + + expect(topLevelNav).toEqual([feeds[0], ...folders]) + }) + + it('should return top level nav with feeds and folders', () => { + const feeds: any[] = [{ name: 'feed1', id: 1 }, { name: 'feed2', id: 2, folderId: 123 }] + const folders: any[] = [{ name: 'abc', id: 123 }, { name: 'xyz', id: 234 }] + const topLevelNav = (wrapper.vm.$options.computed?.topLevelNav as any).call({ + $store: { + getters: { + feeds, + folders, + }, + }, + }) + + expect(topLevelNav).toEqual([feeds[0], ...folders]) + }) }) // TODO: More Template Testing with https://test-utils.vuejs.org/guide/essentials/a-crash-course.html#adding-a-new-todo @@ -72,7 +135,7 @@ describe('Sidebar.vue', () => { jest.clearAllMocks() }) - describe('SideBar State', () => { - // TODO + afterEach(() => { + jest.clearAllMocks() }) }) diff --git a/tests/javascript/unit/setup.ts b/tests/javascript/unit/setup.ts index f3b734953..380436f8c 100644 --- a/tests/javascript/unit/setup.ts +++ b/tests/javascript/unit/setup.ts @@ -16,5 +16,5 @@ config.mocks.$n = function(app: any, singular: any, plural: any, count: any) { config.mocks.n = config.mocks.$n afterAll(() => { - + // TODO: ? }) -- cgit v1.2.3