-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Fluidifier la navigation de l'utilisateur (PIX-6705)
- Loading branch information
Showing
11 changed files
with
123 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>`) | ||
}) | ||
}) | ||
}) |