summaryrefslogtreecommitdiffstats
path: root/tests/javascript/unit/components/Sidebar.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/javascript/unit/components/Sidebar.spec.ts')
-rw-r--r--tests/javascript/unit/components/Sidebar.spec.ts49
1 files changed, 48 insertions, 1 deletions
diff --git a/tests/javascript/unit/components/Sidebar.spec.ts b/tests/javascript/unit/components/Sidebar.spec.ts
index 1eee5486a..9b28ab8a0 100644
--- a/tests/javascript/unit/components/Sidebar.spec.ts
+++ b/tests/javascript/unit/components/Sidebar.spec.ts
@@ -8,6 +8,12 @@ describe('Sidebar.vue', () => {
let wrapper: Wrapper<AppSidebar>
+ const feeds = [{
+ id: 1, title: 'first',
+ }, {
+ id: 2, title: 'second', folderId: 123,
+ }]
+
beforeAll(() => {
const localVue = createLocalVue()
wrapper = shallowMount(AppSidebar, {
@@ -15,15 +21,22 @@ describe('Sidebar.vue', () => {
mocks: {
$store: {
state: {
- feeds: [],
+ feeds,
folders: [],
},
+ getters: {
+ feeds,
+ },
dispatch: jest.fn(),
},
},
})
})
+ beforeEach(() => {
+ (wrapper.vm as any).$store.dispatch.mockReset()
+ })
+
it('should initialize without showing AddFeed Component', () => {
expect((wrapper.vm as any).$data.showAddFeed).toBeFalsy()
})
@@ -51,6 +64,25 @@ describe('Sidebar.vue', () => {
(wrapper.vm as any).closeShowAddFeed()
expect(wrapper.vm.$data.showAddFeed).toBeFalsy()
})
+
+ it('should call mark feed read for all feeds in state', () => {
+ window.confirm = jest.fn().mockReturnValue(true);
+ (wrapper.vm as any).markAllRead()
+ expect((wrapper.vm as any).$store.dispatch).toHaveBeenCalledTimes(2)
+ })
+
+ it('should call mark feed read for all feeds in state with matching folderId', () => {
+ window.confirm = jest.fn().mockReturnValue(true);
+ (wrapper.vm as any).markFolderRead({ id: 123 })
+ expect((wrapper.vm as any).$store.dispatch).toHaveBeenCalledTimes(1)
+ })
+
+ it('should call disptch rename folder with response from user', () => {
+ const name = 'new name'
+ window.prompt = jest.fn().mockReturnValue(name);
+ (wrapper.vm as any).renameFolder({ id: 123 })
+ expect((wrapper.vm as any).$store.dispatch).toHaveBeenCalledWith(ACTIONS.FOLDER_SET_NAME, { folder: { id: 123 }, name })
+ })
})
describe('SideBarState', () => {
@@ -126,6 +158,21 @@ describe('Sidebar.vue', () => {
expect(topLevelNav).toEqual([feeds[0], ...folders])
})
+
+ it('should set pinned feeds at beginning top level nav with feeds and folders', () => {
+ const feeds: any[] = [{ name: 'feed1', id: 1 }, { name: 'feed2', id: 2, folderId: 123 }, { name: 'feed3', id: 3, pinned: true }]
+ 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[0].name).toEqual('feed3')
+ })
})
// TODO: More Template Testing with https://test-utils.vuejs.org/guide/essentials/a-crash-course.html#adding-a-new-todo