-
Notifications
You must be signed in to change notification settings - Fork 3
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
[TECH] Ajouter des tests sur le language switcher #442
Merged
pix-service-auto-merge
merged 1 commit into
dev
from
tech-add-snapshot-test-for-language-switcher
Dec 22, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,103 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import { shallowMount, mount } from '@vue/test-utils' | ||
import LanguageSwitcher from '~/components/LanguageSwitcher/LanguageSwitcher' | ||
import LanguageSwitcherSubMenu from '~/components/LanguageSwitcher/LanguageSwitcherSubMenu.vue' | ||
|
||
describe('Component: LanguageSwitcher', () => { | ||
it('should render the language switcher if site is pix-pro.fr', () => { | ||
// given | ||
const $t = () => {} | ||
const $i18n = { locale: 'fr-fr' } | ||
|
||
// when | ||
const wrapper = shallowMount(LanguageSwitcher, { | ||
stubs: { | ||
LanguageSwitcherSubMenu: true, | ||
fa: true, | ||
}, | ||
propsData: { | ||
type: 'with-dropdown', | ||
}, | ||
data: LanguageSwitcher.data, | ||
computed: LanguageSwitcher.computed, | ||
mocks: { $t, $i18n }, | ||
let oldDomainFr | ||
let oldDomainOrg | ||
|
||
beforeEach(() => { | ||
oldDomainFr = process.env.DOMAIN_FR | ||
oldDomainOrg = process.env.DOMAIN_ORG | ||
process.env.DOMAIN_FR = 'example.fr' | ||
process.env.DOMAIN_ORG = 'example.org' | ||
}) | ||
|
||
afterEach(() => { | ||
process.env.DOMAIN_FR = oldDomainFr | ||
process.env.DOMAIN_ORG = oldDomainOrg | ||
}) | ||
|
||
describe('when site is pix-pro', () => { | ||
let oldSite | ||
beforeEach(() => { | ||
oldSite = process.env.SITE | ||
process.env.SITE = 'pix-pro' | ||
}) | ||
|
||
// then | ||
expect(wrapper.find('.language-switcher__button').exists()).toBe(true) | ||
afterEach(() => { | ||
process.env.SITE = oldSite | ||
}) | ||
|
||
it('should render the language switcher', () => { | ||
// given | ||
const $t = () => {} | ||
const $i18n = { locale: 'fr-fr' } | ||
|
||
// when | ||
const wrapper = shallowMount(LanguageSwitcher, { | ||
stubs: { | ||
LanguageSwitcherSubMenu: true, | ||
fa: true, | ||
}, | ||
propsData: { | ||
type: 'with-dropdown', | ||
}, | ||
data: LanguageSwitcher.data, | ||
computed: LanguageSwitcher.computed, | ||
mocks: { $t, $i18n }, | ||
}) | ||
|
||
// then | ||
expect(wrapper.find('.language-switcher__button').exists()).toBe(true) | ||
}) | ||
|
||
it('should render the language switcher correctly for pix-pro', async () => { | ||
// given | ||
const $t = () => {} | ||
const $i18n = { locale: 'fr-fr' } | ||
|
||
// when | ||
const wrapper = mount(LanguageSwitcher, { | ||
components: { LanguageSwitcherSubMenu }, | ||
mocks: { $t, $i18n }, | ||
stubs: { fa: true }, | ||
}) | ||
await wrapper.find('button').trigger('click') | ||
await wrapper.find('.language-switcher-sub-menu-button').trigger('click') | ||
|
||
// then | ||
expect(wrapper.element).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
it('should render the language switcher if site is pix-pro.org', async () => { | ||
// given | ||
const $t = () => {} | ||
const $i18n = { locale: 'fr' } | ||
|
||
const LanguageSwitcherSubMenuStub = { | ||
name: 'language-switcher-burger-menu', | ||
template: '<div class="language-switcher__dropdown-menu child"/>', | ||
} | ||
|
||
const wrapper = shallowMount(LanguageSwitcher, { | ||
stubs: { | ||
LanguageSwitcherSubMenu: LanguageSwitcherSubMenuStub, | ||
fa: true, | ||
}, | ||
propsData: { | ||
type: 'with-dropdown', | ||
}, | ||
data: LanguageSwitcher.data, | ||
computed: LanguageSwitcher.computed, | ||
mocks: { $t, $i18n }, | ||
describe('when site is pix-site', () => { | ||
let oldSite | ||
beforeEach(() => { | ||
oldSite = process.env.SITE | ||
process.env.SITE = 'pix-site' | ||
}) | ||
|
||
afterEach(() => { | ||
process.env.SITE = oldSite | ||
}) | ||
|
||
const languageSwitcher = wrapper.find('.language-switcher__button') | ||
it('should render the language switcher correctly for pix-site', async () => { | ||
// given | ||
const $t = () => {} | ||
const $i18n = { locale: 'fr-fr' } | ||
|
||
// when | ||
await languageSwitcher.trigger('click') | ||
const languageChildrenSubMenuButton = wrapper.find( | ||
'.language-switcher-sub-menu-button' | ||
) | ||
await languageChildrenSubMenuButton.trigger('click') | ||
const languageChildrenSubMenu = wrapper.find( | ||
'.language-switcher__dropdown-menu.child' | ||
) | ||
// when | ||
const wrapper = mount(LanguageSwitcher, { | ||
components: { LanguageSwitcherSubMenu }, | ||
mocks: { $t, $i18n }, | ||
stubs: { fa: true }, | ||
}) | ||
await wrapper.find('button').trigger('click') | ||
await wrapper.find('.language-switcher-sub-menu-button').trigger('click') | ||
|
||
// then | ||
expect(languageChildrenSubMenu.exists()).toBe(true) | ||
// then | ||
expect(wrapper.element).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question : pourquoi passer sur le
mount
plutôt queshallowMount
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mount
permet d'avoir le dom des composants enfants, ce que ne fait passhallowMount