Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Fluidifier la navigation de l'utilisateur (PIX-6705) #456

Merged
merged 6 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/FooterSliceZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default {
data() {
return {
socialMediasHoverMap: {},
usedMainFooter: null,
usedMainFooter: [],
}
},
async fetch() {
Expand All @@ -75,6 +75,9 @@ export default {
)
},
},
watch: {
'$i18n.locale': '$fetch',
},
}
</script>

Expand Down
3 changes: 3 additions & 0 deletions components/HotNewsBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export default {

this.hotNews = hotNews?.data?.description
},
watch: {
'$i18n.locale': '$fetch',
},
methods: {
closeBanner() {
this.isOpen = false
Expand Down
12 changes: 6 additions & 6 deletions components/LanguageSwitcher/LanguageSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
:selected-menu="selectedMenu"
/>
</template>
<a v-else-if="!option.children" :href="getIndexUrl(option)">
<pix-link v-else-if="!option.children" :href="getIndexUrl(option)">
<img
class="language-switcher__img"
:src="'/images/' + option.icon"
Expand All @@ -65,7 +65,7 @@
{{ $t(option.subtitle) }}
</div>
</div>
</a>
</pix-link>
</div>
</li>
</ul>
Expand All @@ -84,9 +84,9 @@
child.lang === currentLocaleCode,
}"
>
<a :href="getIndexUrl(child)">
<pix-link :href="getIndexUrl(child)">
{{ $t(option.name) }} - {{ $t(child.name) }}
</a>
</pix-link>
<br />
</span>
</template>
Expand All @@ -98,9 +98,9 @@
option.lang === currentLocaleCode,
}"
>
<a :href="getIndexUrl(option)">
<pix-link :href="getIndexUrl(option)">
{{ $t(option.name) }}
</a>
</pix-link>
</span>
</template>
</li>
Expand Down
4 changes: 2 additions & 2 deletions components/LanguageSwitcher/LanguageSwitcherSubMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
}"
>
<div class="language-switcher__lang">
<a :href="getIndexUrl(availableLanguage)">
<pix-link :href="getIndexUrl(availableLanguage)">
{{ $t(availableLanguage.name) }}
</a>
</pix-link>
</div>
</li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions components/LocaleLink.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<a class="locale-link" :href="indexForGivenLocale()">
<pix-link class="locale-link" :href="indexForGivenLocale()">
<img :src="'/images/' + locale.icon" alt="" />
<span class="locale-link__text">{{ locale.name }}</span>
</a>
</pix-link>
</template>

<script>
Expand Down
9 changes: 6 additions & 3 deletions components/NavigationSliceZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
name: 'NavigationSliceZone',
data() {
return {
usedMainNavigation: null,
usedMainNavigation: [],
}
},
async fetch() {
Expand Down Expand Up @@ -67,16 +67,19 @@ export default {
burgerMenuLinks() {
const navigationZone = this.usedMainNavigation.find(
(slice) => slice.slice_type === 'navigation_zone'
)
) || { items: [] }
const actionsZone = this.usedMainNavigation.find(
(slice) => slice.slice_type === 'actions_zone'
)
) || { items: [] }
return {
navigationZone: navigationZone.items,
actionsZone: actionsZone.items,
}
},
},
watch: {
'$i18n.locale': '$fetch',
},
}
</script>

Expand Down
42 changes: 42 additions & 0 deletions components/PixLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<template>
<component :is="linkComponent">
<slot />
</component>
</template>

<script>
export default {
name: 'PixLink',
props: {
href: {
required: true,
type: String,
default: '',
},
},
computed: {
linkComponent() {
let template = ''
if (this.isOnCurrentDomain(this.href)) {
template = `
<nuxt-link to="${this.href}">
<slot />
</nuxt-link>
`
} else {
template = `
<a href="${this.href}">
<slot />
</a>
`
}
return { template }
},
},
methods: {
isOnCurrentDomain(targetDomain) {
return targetDomain.startsWith('/') && !targetDomain.startsWith('//')
},
},
}
</script>
6 changes: 5 additions & 1 deletion components/slices/NavigationZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default {
props: {
navigationZoneItems: {
type: Array,
default: null,
default: () => [],
},
},
data() {
Expand All @@ -62,6 +62,10 @@ export default {
},
computed: {
navigationLinks() {
if (this.navigationZoneItems.length === 0) {
return null
}

return this.navigationZoneItems
.map(({ items: navItems }) =>
navItems.reduce((navGroup, navItem) => {
Expand Down
3 changes: 1 addition & 2 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const i18nConfigurationForInternationalDomain = {
vueI18n: {
fallbackLocale: 'fr',
},
rootRedirect:
config.isPixSite && !config.isFrenchDomain ? 'locale-choice' : undefined,
rootRedirect: config.isPixSite && !config.isFrenchDomain && 'locale-choice',
}

const nuxtConfig = {
Expand Down
7 changes: 5 additions & 2 deletions tests/components/LanguageSwitcher.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { shallowMount, mount } from '@vue/test-utils'
import { config } from '~/config/environment'
import PixLink from '~/components/PixLink'
import LanguageSwitcher from '~/components/LanguageSwitcher/LanguageSwitcher'
import LanguageSwitcherSubMenu from '~/components/LanguageSwitcher/LanguageSwitcherSubMenu.vue'

Expand All @@ -14,6 +15,8 @@ jest.mock('~/config/environment', () => ({
},
}))

LanguageSwitcherSubMenu.components = { 'pix-link': PixLink }

describe('Component: LanguageSwitcher', () => {
describe('when site is pix-pro', () => {
beforeEach(() => {
Expand Down Expand Up @@ -51,7 +54,7 @@ describe('Component: LanguageSwitcher', () => {

// when
const wrapper = mount(LanguageSwitcher, {
components: { LanguageSwitcherSubMenu },
components: { LanguageSwitcherSubMenu, PixLink },
mocks: { $t, $i18n },
stubs: { fa: true },
})
Expand All @@ -76,7 +79,7 @@ describe('Component: LanguageSwitcher', () => {

// when
const wrapper = mount(LanguageSwitcher, {
components: { LanguageSwitcherSubMenu },
components: { LanguageSwitcherSubMenu, PixLink },
mocks: { $t, $i18n },
stubs: { fa: true },
})
Expand Down
47 changes: 47 additions & 0 deletions tests/components/PixLink.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { mount } from '@vue/test-utils'
import PixLink from '~/components/PixLink'

describe('Component: PixLink', () => {
let component

beforeEach(() => {
component = mount(PixLink, {
shallow: true,
propsData: { href: '' },
slots: { default: '<h1>Dummy</h1>' },
stubs: ['nuxt-link'],
})
})

describe('href is in domain', () => {
it('displays the component', async () => {
// given
await component.setProps({ href: '/fr-be' })

// when
const result = component.html()

// then
expect(result).toEqual(
`<nuxt-link-stub to="/fr-be">
<h1>Dummy</h1>
</nuxt-link-stub>`
)
})
})

describe('href is not in domain', () => {
it('displays the component', async () => {
// given
await component.setProps({ href: 'https://example.net/' })

// when
const result = component.html()

// then
expect(result).toEqual(`<a href="https://example.net/">
<h1>Dummy</h1>
</a>`)
})
})
})