Skip to content

Commit

Permalink
simple tests on sign in button
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogge committed Mar 13, 2024
1 parent 2d423e9 commit 6e3014c
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ exports[`TextButtonInput > TextButtonInput renders 1`] = `
<div
class="v-input__details"
>
<transition-stub
<transition-group-stub
appear="false"
aria-live="polite"
class="v-messages"
Expand All @@ -165,7 +165,7 @@ exports[`TextButtonInput > TextButtonInput renders 1`] = `
tag="div"
>
<!---->
</transition-stub>
</transition-group-stub>
<!---->
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ exports[`ContactForm > renders form 1`] = `
<div
class="v-input__details"
>
<transition-stub
<transition-group-stub
appear="false"
aria-live="polite"
class="v-messages"
Expand All @@ -518,7 +518,7 @@ exports[`ContactForm > renders form 1`] = `
tag="div"
>
<!---->
</transition-stub>
</transition-group-stub>
<!---->
</div>
</div>
Expand Down
84 changes: 84 additions & 0 deletions presenter/src/components/menu/#HeaderMenu.test.ts#
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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<typeof Wrapper>

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', () => {
})
})
})
79 changes: 72 additions & 7 deletions presenter/src/components/menu/HeaderMenu.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,83 @@
import { mount } from '@vue/test-utils'
import { describe, it, expect } from 'vitest'
import { navigate } from 'vike/client/router'
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 HeaderMenu from './HeaderMenu.vue'

describe('HeaderMenu', () => {
const wrapper = mount(VApp, {
slots: {
default: h(HeaderMenu as Component),
},
})
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<typeof Wrapper>

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(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('/')
})
})

/*
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', () => {})
*/
})
})
20 changes: 16 additions & 4 deletions presenter/src/components/menu/HeaderMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,29 @@
size="small"
@click="queryProtectedBackend"
/>-->
<MainButton variant="third" label="Sign Out" size="small" @click="signOut" />
<MainButton
class="sign-out"
variant="third"
label="Sign Out"
size="small"
@click="signOut"
/>
</div>
<div v-else>
<MainButton
variant="third-inverse"
class="mr-1"
class="mr-1 sign-in"
label="Sign in"
size="small"
@click="signIn"
/>
<MainButton variant="third" label="Sign up" size="small" @click="signUp" />
<MainButton
class="sign-up"
variant="third"
label="Sign up"
size="small"
@click="signUp"
/>
</div>
</div>
<div class="d-flex d-md-none align-center justify-end mr-8 mobile-column">
Expand Down Expand Up @@ -117,7 +129,7 @@ async function signIn() {
}
function signUp() {
navigate(AUTH.AUTHORITY_SIGNUP_URI)
window.location.href = AUTH.AUTHORITY_SIGNUP_URI
}
async function signOut() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ exports[`FooterMenu > renders 1`] = `
<div
class="v-input__details"
>
<transition-stub
<transition-group-stub
appear="false"
aria-live="polite"
class="v-messages"
Expand All @@ -785,7 +785,7 @@ exports[`FooterMenu > renders 1`] = `
tag="div"
>
<!---->
</transition-stub>
</transition-group-stub>
<!---->
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ exports[`HeaderMenu > renders 1`] = `
data-v-5e2a2776=""
>
<header
class="v-toolbar v-toolbar--flat v-toolbar--density-default v-theme--light v-locale--is-ltr v-app-bar"
class="v-toolbar v-toolbar--flat v-toolbar--density-default bg-transparent v-theme--light v-locale--is-ltr v-app-bar"
data-v-5e2a2776=""
style="top: 0px; z-index: 1006; transform: translateY(0%); position: fixed; background-color: #f5f5f5; color: #000; caret-color: #000; left: 0px; width: calc(100% - 0px - 0px);"
style="top: 0px; z-index: 1004; transform: translateY(0%); position: fixed; transition: none !important;"
>
<!---->
Expand Down Expand Up @@ -175,9 +175,6 @@ exports[`HeaderMenu > renders 1`] = `
>
<div
aria-expanded="false"
aria-haspopup="listbox"
aria-owns="v-menu-6"
class="v-field v-field--active v-field--appended v-field--center-affix v-field--dirty v-field--flat v-field--has-background v-field--no-label v-field--variant-solo v-theme--light bg-transparent v-locale--is-ltr"
role="combobox"
>
Expand Down Expand Up @@ -361,7 +358,7 @@ exports[`HeaderMenu > renders 1`] = `
<nav
class="v-navigation-drawer v-navigation-drawer--right v-navigation-drawer--temporary v-theme--light v-navigation-drawer--mobile nav-drawer d-flex d-md-none"
data-v-5e2a2776=""
style="background-color: #f5f5f5; color: #000; caret-color: #000; right: 0px; z-index: 1004; transform: translateX(110%); position: fixed; height: calc(100% - 64px - 0px); top: 64px; bottom: 0px; width: 256px;"
style="background-color: #d8d8d8; color: #000; caret-color: #000; right: 0px; z-index: 1004; transform: translateX(110%); position: fixed; transition: none !important;"
>
<!---->
<!---->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ exports[`DefaultLayout > renders 1`] = `
<div
class="v-input__details"
>
<transition-stub
<transition-group-stub
appear="false"
aria-live="polite"
class="v-messages"
Expand All @@ -1276,7 +1276,7 @@ exports[`DefaultLayout > renders 1`] = `
tag="div"
>
<!---->
</transition-stub>
</transition-group-stub>
<!---->
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions presenter/src/pages/auth/__snapshots__/Page.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ exports[`AuthPage > renders 1`] = `
<div
class="v-input__details"
>
<transition-stub
<transition-group-stub
appear="false"
aria-live="polite"
class="v-messages"
Expand All @@ -1283,7 +1283,7 @@ exports[`AuthPage > renders 1`] = `
tag="div"
>
<!---->
</transition-stub>
</transition-group-stub>
<!---->
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ exports[`DataPrivacyPage > renders 1`] = `
<div
class="v-input__details"
>
<transition-stub
<transition-group-stub
appear="false"
aria-live="polite"
class="v-messages"
Expand All @@ -1652,7 +1652,7 @@ exports[`DataPrivacyPage > renders 1`] = `
tag="div"
>
<!---->
</transition-stub>
</transition-group-stub>
<!---->
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions presenter/src/pages/impressum/__snapshots__/Page.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,7 @@ exports[`ImpressumPage > renders 1`] = `
<div
class="v-input__details"
>
<transition-stub
<transition-group-stub
appear="false"
aria-live="polite"
class="v-messages"
Expand All @@ -1929,7 +1929,7 @@ exports[`ImpressumPage > renders 1`] = `
tag="div"
>
<!---->
</transition-stub>
</transition-group-stub>
<!---->
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions presenter/src/pages/index/__snapshots__/Page.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3199,7 +3199,7 @@ exports[`IndexPage > renders 1`] = `
<div
class="v-input__details"
>
<transition-stub
<transition-group-stub
appear="false"
aria-live="polite"
class="v-messages"
Expand All @@ -3211,7 +3211,7 @@ exports[`IndexPage > renders 1`] = `
tag="div"
>
<!---->
</transition-stub>
</transition-group-stub>
<!---->
</div>
</div>
Expand Down
Loading

0 comments on commit 6e3014c

Please sign in to comment.