From 5b1348e6fbd398657aad7e200a3b29deb6c79133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Tue, 9 Apr 2019 19:17:47 +0200 Subject: [PATCH] Refactor: Notification as a root component --- .../notifications/NotificationList.spec.js | 74 +++++++-------- .../notifications/NotificationList.vue | 49 ++-------- .../notifications/NotificationMenu.vue | 92 +++++++++++++++++++ webapp/layouts/default.vue | 33 +------ 4 files changed, 138 insertions(+), 110 deletions(-) create mode 100644 webapp/components/notifications/NotificationMenu.vue diff --git a/webapp/components/notifications/NotificationList.spec.js b/webapp/components/notifications/NotificationList.spec.js index 1b4355c08..94da7869d 100644 --- a/webapp/components/notifications/NotificationList.spec.js +++ b/webapp/components/notifications/NotificationList.spec.js @@ -27,9 +27,8 @@ describe('NotificationList.vue', () => { let mocks let stubs let user - let data let store - let markAsRead + let propsData beforeEach(() => { store = new Vuex.Store({ @@ -45,47 +44,44 @@ describe('NotificationList.vue', () => { stubs = { NuxtLink: RouterLinkStub } - markAsRead = jest.fn() - data = () => { - return { - notifications: [ - { - id: 'notification-41', - read: false, - post: { - id: 'post-1', - title: 'some post title', - contentExcerpt: 'this is a post content', - author: { - id: 'john-1', - slug: 'john-doe', - name: 'John Doe' - } - } - }, - { - id: 'notification-42', - read: false, - post: { - id: 'post-2', - title: 'another post title', - contentExcerpt: 'this is yet another post content', - author: { - id: 'john-1', - slug: 'john-doe', - name: 'John Doe' - } + propsData = { + notifications: [ + { + id: 'notification-41', + read: false, + post: { + id: 'post-1', + title: 'some post title', + contentExcerpt: 'this is a post content', + author: { + id: 'john-1', + slug: 'john-doe', + name: 'John Doe' } } - ] - } + }, + { + id: 'notification-42', + read: false, + post: { + id: 'post-2', + title: 'another post title', + contentExcerpt: 'this is yet another post content', + author: { + id: 'john-1', + slug: 'john-doe', + name: 'John Doe' + } + } + } + ] } }) describe('shallowMount', () => { const Wrapper = () => { return shallowMount(NotificationList, { - data, + propsData, mocks, store, localVue @@ -104,7 +100,7 @@ describe('NotificationList.vue', () => { describe('mount', () => { const Wrapper = () => { return mount(NotificationList, { - data, + propsData, mocks, stubs, store, @@ -118,15 +114,15 @@ describe('NotificationList.vue', () => { describe('click on a notification', () => { beforeEach(() => { - wrapper.setMethods({ markAsRead }) wrapper .findAll(Notification) .at(1) .trigger('click') }) - it('marks notification as read', () => { - expect(markAsRead).toBeCalledWith('notification-42') + it("emits 'markAsRead' with the notificationId", () => { + expect(wrapper.emitted('markAsRead')).toBeTruthy() + expect(wrapper.emitted('markAsRead')[0]).toEqual(['notification-42']) }) }) }) diff --git a/webapp/components/notifications/NotificationList.vue b/webapp/components/notifications/NotificationList.vue index ec76e8530..2d6cd3828 100644 --- a/webapp/components/notifications/NotificationList.vue +++ b/webapp/components/notifications/NotificationList.vue @@ -11,56 +11,21 @@ + + diff --git a/webapp/layouts/default.vue b/webapp/layouts/default.vue index 44219a319..dd518e213 100644 --- a/webapp/layouts/default.vue +++ b/webapp/layouts/default.vue @@ -32,27 +32,7 @@