Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbertrand authored and VincentHardouin committed Jan 6, 2023
1 parent c35a05e commit 6a9e0cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pages/pix-site/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:field="{ url: '/images/logo-pix-blanc.svg', alt: 'Pix' }"
/>
</h1>
<LocaleLink
<locale-link
v-for="locale in locales"
:key="locale.code"
class="locale-choice__link"
Expand Down
33 changes: 26 additions & 7 deletions tests/pages/pix-site/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { shallowMount } from '@vue/test-utils'
import { nextTick } from 'vue'
import Index from '@/pages/pix-site/index.vue'

describe('Index Page', () => {
Expand All @@ -19,15 +20,21 @@ describe('Index Page', () => {

describe('#mounted', () => {
describe('when there is no cookie', () => {
test('redirects to /locale-choice page', () => {
test('do not redirect', async () => {
// given
document.cookie = ''

// when
shallowMount(Index, { mocks: { $router } })
const wrapper = shallowMount(Index, {
mocks: { $router },
stubs: ['client-only', 'pix-image', 'locale-link'],
})
await nextTick()

// then
expect($router.push).toHaveBeenCalledWith('/locale-choice')
expect($router.push).not.toHaveBeenCalled()
const localeLinks = wrapper.findAll('locale-link-stub')
expect(localeLinks.length).toBe(4)
})
})

Expand All @@ -37,7 +44,10 @@ describe('Index Page', () => {
document.cookie = 'foo=bar; locale=fr'

// when
shallowMount(Index, { mocks: { $router } })
shallowMount(Index, {
mocks: { $router },
stubs: ['client-only', 'pix-image', 'locale-link'],
})

// then
expect($router.push).toHaveBeenCalledWith('/fr/')
Expand All @@ -51,7 +61,10 @@ describe('Index Page', () => {
test('returns no locale', () => {
// given
document.cookie = ''
const wrapper = shallowMount(Index, { mocks: { $router } })
const wrapper = shallowMount(Index, {
mocks: { $router },
stubs: ['client-only', 'pix-image', 'locale-link'],
})

// when
const chosenLocale = wrapper.vm.getLocaleFromCookie()
Expand All @@ -65,7 +78,10 @@ describe('Index Page', () => {
test('returns the proper locale', () => {
// given
document.cookie = 'foo=bar; locale=fr'
const wrapper = shallowMount(Index, { mocks: { $router } })
const wrapper = shallowMount(Index, {
mocks: { $router },
stubs: ['client-only', 'pix-image', 'locale-link'],
})

// when
const chosenLocale = wrapper.vm.getLocaleFromCookie()
Expand All @@ -79,7 +95,10 @@ describe('Index Page', () => {
test('cookie value is ignored', () => {
// given
document.cookie = 'foo=bar; locale=1234-crafted-cookie'
const wrapper = shallowMount(Index, { mocks: { $router } })
const wrapper = shallowMount(Index, {
mocks: { $router },
stubs: ['client-only', 'pix-image', 'locale-link'],
})

// when
const chosenLocale = wrapper.vm.getLocaleFromCookie()
Expand Down

0 comments on commit 6a9e0cc

Please sign in to comment.