diff --git a/webapp/pages/notifications/index.spec.js b/webapp/pages/notifications/index.spec.js index 14bcf790b..e9cea64a7 100644 --- a/webapp/pages/notifications/index.spec.js +++ b/webapp/pages/notifications/index.spec.js @@ -5,12 +5,13 @@ import DropdownFilter from '~/components/DropdownFilter/DropdownFilter' import NotificationsTable from '~/components/NotificationsTable/NotificationsTable' import PaginationButtons from '~/components/_new/generic/PaginationButtons/PaginationButtons' +import { markAsReadMutation, markAllAsReadMutation } from '~/graphql/User' const localVue = global.localVue config.stubs['client-only'] = '' describe('PostIndex', () => { - let wrapper, Wrapper, mocks, propsData + let wrapper, Wrapper, mocks, propsData, markAllAsReadButton beforeEach(() => { propsData = {} @@ -80,6 +81,9 @@ describe('PostIndex', () => { ] wrapper = Wrapper() wrapper.find(DropdownFilter).vm.$emit('filter', propsData.filterOptions[1]) + + markAllAsReadButton = wrapper.find('[data-test="markAllAsRead-button"]') + expect(markAllAsReadButton).toBeTruthy() }) it('sets `notificationRead` to value of received option', () => { @@ -93,18 +97,25 @@ describe('PostIndex', () => { it('refreshes the notificaitons', () => { expect(mocks.$apollo.queries.notifications.refresh).toHaveBeenCalledTimes(1) }) + it('click on `mark all as read` button', async () => { + await markAllAsReadButton.trigger('click') + expect(mocks.$apollo.mutate).not.toHaveBeenCalled() + }) }) describe('markNotificationAsRead', () => { + let expectedParams beforeEach(() => { wrapper = Wrapper() wrapper.find(NotificationsTable).vm.$emit('markNotificationAsRead', 'notificationSourceId') }) it('calls markNotificationAsRead mutation', () => { - expect(mocks.$apollo.mutate).toHaveBeenCalledWith( - expect.objectContaining({ variables: { id: 'notificationSourceId' } }), - ) + expectedParams = { + mutation: markAsReadMutation(), + variables: { id: 'notificationSourceId' }, + } + expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams)) }) describe('error handling', () => { @@ -122,6 +133,41 @@ describe('PostIndex', () => { }) }) + describe('markAllNotificationAsRead', () => { + let expectedParams + beforeEach(() => { + wrapper = Wrapper() + // FIXME Should I remove next line? + wrapper.find(NotificationsTable).vm.$emit('markNotificationAsRead', 'notificationSourceId') + }) + + // FIXME: I need to discover why this test isn't working =( + it.skip('calls markAllNotificationAsRead mutation', async () => { + expectedParams = { + mutation: markAllAsReadMutation(), + } + // expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams)) + // await wrapper.find('[data-test="markAllAsRead-button"]').trigger('click') + + expect(mocks.$apollo.mutate).toHaveBeenCalledWith(expect.objectContaining(expectedParams)) + }) + + describe('error handling', () => { + beforeEach(() => { + mocks.$apollo.mutate = jest.fn().mockRejectedValueOnce({ message: 'Some error message' }) + wrapper = Wrapper() + // FIXME Should I remove next line? + wrapper + .find(NotificationsTable) + .vm.$emit('markNotificationAsRead', 'notificationSourceId') + }) + + it('shows an error message if there is an error', () => { + expect(mocks.$toast.error).toHaveBeenCalledWith('Some error message') + }) + }) + }) + describe('PaginationButtons', () => { beforeEach(() => { wrapper = Wrapper()