From 8fd81b6dbc575ced42c8597ceedfb0c6206719e3 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 13 Mar 2024 14:24:29 +0100 Subject: [PATCH] Test error case in sign in --- .../src/components/menu/#HeaderMenu.test.ts# | 84 ------------------- .../src/components/menu/HeaderMenu.test.ts | 32 +++++-- 2 files changed, 24 insertions(+), 92 deletions(-) delete mode 100644 presenter/src/components/menu/#HeaderMenu.test.ts# diff --git a/presenter/src/components/menu/#HeaderMenu.test.ts# b/presenter/src/components/menu/#HeaderMenu.test.ts# deleted file mode 100644 index c5e976a8ff..0000000000 --- a/presenter/src/components/menu/#HeaderMenu.test.ts# +++ /dev/null @@ -1,84 +0,0 @@ -import { mount } from '@vue/test-utils' -import { describe, it, expect, beforeEach, vi } from 'vitest' -import { Component, h } from 'vue' -import { VApp } from 'vuetify/components' -import { AUTH } from '#src/env' -import { authService } from '#tests/mock.authService' -import { navigate } from 'vike/client/router' -import { useAuthStore } from '#stores/authStore' - -import HeaderMenu from './HeaderMenu.vue' - -vi.mock('vike/client/router') -vi.mocked(navigate).mockResolvedValue() - - - -describe('HeaderMenu', () => { - it('renders', () => { - AUTH.AUTHORITY = '' - AUTH.AUTHORITY_SIGNUP_URI = '' - - const wrapper = mount(VApp, { - slots: { - default: h(HeaderMenu as Component), - }, - }) - - expect(wrapper.element).toMatchSnapshot() - }) - - describe('auth service active', () => { - const Wrapper = () => { - return mount(VApp, { - slots: { - default: h(HeaderMenu as Component), - }, - }) - } - - let wrapper: ReturnType - - beforeEach(() => { - AUTH.AUTHORITY = 'authority' - AUTH.AUTHORITY_SIGNUP_URI = 'http://sign-up.uri' - wrapper = Wrapper() - }) - - it('has a sign in button', () => { - expect(wrapper.find('button.sign-in').exists()).toBe(true) - }) - - describe('sign in button', () => { - const authServiceSpy = vi.spyOn(authService, 'signIn') - - beforeEach(() => { - vi.clearAllMocks() - wrapper.find('button.sign-in').trigger('click') - }) - - it('calls sign in from auth service', () => { - expect(authServiceSpy).toBeCalled() - }) - - it('navigates to /', () => { - expect(navigate).toBeCalledWith('/') - }) - }) - - describe('sign up button', () => { - beforeEach(() => { - vi.clearAllMocks() - wrapper.find('button.sign-up').trigger('click') - }) - - // how to redirect correctly (navigate vs recirect)? - it('redirects to sign up url', () => { - expect(true).toBe(true) - }) - }) - - describe('logged in', () => { - }) - }) -}) diff --git a/presenter/src/components/menu/HeaderMenu.test.ts b/presenter/src/components/menu/HeaderMenu.test.ts index 6fc4100d16..e8c8695bf7 100644 --- a/presenter/src/components/menu/HeaderMenu.test.ts +++ b/presenter/src/components/menu/HeaderMenu.test.ts @@ -50,17 +50,33 @@ describe('HeaderMenu', () => { describe('sign in button', () => { const authServiceSpy = vi.spyOn(authService, 'signIn') - beforeEach(async () => { - vi.clearAllMocks() - await wrapper.find('button.sign-in').trigger('click') + describe('without error', () => { + beforeEach(async () => { + vi.clearAllMocks() + await wrapper.find('button.sign-in').trigger('click') + }) + + it('calls sign in from auth service', () => { + expect(authServiceSpy).toBeCalled() + }) + + it('navigates to /', () => { + expect(navigate).toBeCalledWith('/') + }) }) - it('calls sign in from auth service', () => { - expect(authServiceSpy).toBeCalled() - }) + describe('with error', () => { + const consoleSpy = vi.spyOn(global.console, 'log') + + beforeEach(async () => { + vi.clearAllMocks() + authServiceSpy.mockRejectedValue('Ouch!') + await wrapper.find('button.sign-in').trigger('click') + }) - it('navigates to /', () => { - expect(navigate).toBeCalledWith('/') + it('logs the error to console', () => { + expect(consoleSpy).toBeCalledWith('auth error', 'Ouch!') + }) }) })