From fb7868344aaf8745cd441ccf6995f2f852dfbce7 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 24 Nov 2021 17:29:53 +0100 Subject: [PATCH] test user search --- admin/src/views/UserSearch.spec.js | 59 ++++++++++++++++++++++++++++++ admin/src/views/UserSearch.vue | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 admin/src/views/UserSearch.spec.js diff --git a/admin/src/views/UserSearch.spec.js b/admin/src/views/UserSearch.spec.js new file mode 100644 index 000000000..37ba4f5ec --- /dev/null +++ b/admin/src/views/UserSearch.spec.js @@ -0,0 +1,59 @@ +import { mount } from '@vue/test-utils' +import UserSearch from './UserSearch.vue' + +const localVue = global.localVue + +const apolloQueryMock = jest.fn().mockResolvedValue({ + data: { + searchUsers: [ + { + firstName: 'Bibi', + lastName: 'Bloxberg', + email: 'bibi@bloxberg.de', + creation: [200, 400, 600], + }, + ], + }, +}) + +const toastErrorMock = jest.fn() + +const mocks = { + $apollo: { + query: apolloQueryMock, + }, + $toasted: { + error: toastErrorMock, + }, +} + +describe('UserSearch', () => { + let wrapper + + const Wrapper = () => { + return mount(UserSearch, { localVue, mocks }) + } + + describe('mount', () => { + beforeEach(() => { + wrapper = Wrapper() + }) + + it('has a DIV element with the class.user-search', () => { + expect(wrapper.find('div.user-search').exists()).toBeTruthy() + }) + + describe('apollo returns error', () => { + beforeEach(() => { + apolloQueryMock.mockRejectedValue({ + message: 'Ouch', + }) + wrapper = Wrapper() + }) + + it('toasts an error message', () => { + expect(toastErrorMock).toBeCalledWith('Ouch') + }) + }) + }) +}) diff --git a/admin/src/views/UserSearch.vue b/admin/src/views/UserSearch.vue index 0172d6a23..6606d8063 100644 --- a/admin/src/views/UserSearch.vue +++ b/admin/src/views/UserSearch.vue @@ -1,5 +1,5 @@