From 19f374759c702c2f559e4e62bdd2df668ab2bb1f Mon Sep 17 00:00:00 2001 From: Vincent Hardouin Date: Thu, 15 Dec 2022 15:28:29 +0100 Subject: [PATCH] sr: add snapshot test for language switcher --- tests/components/LanguageSwitcher.test.js | 143 +++++--- .../LanguageSwitcher.test.js.snap | 313 ++++++++++++++++++ 2 files changed, 403 insertions(+), 53 deletions(-) create mode 100644 tests/components/__snapshots__/LanguageSwitcher.test.js.snap diff --git a/tests/components/LanguageSwitcher.test.js b/tests/components/LanguageSwitcher.test.js index 203cb57b2..737dd3fb8 100644 --- a/tests/components/LanguageSwitcher.test.js +++ b/tests/components/LanguageSwitcher.test.js @@ -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: '
', - } - - 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() + }) }) }) diff --git a/tests/components/__snapshots__/LanguageSwitcher.test.js.snap b/tests/components/__snapshots__/LanguageSwitcher.test.js.snap new file mode 100644 index 000000000..8d4628350 --- /dev/null +++ b/tests/components/__snapshots__/LanguageSwitcher.test.js.snap @@ -0,0 +1,313 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Component: LanguageSwitcher when site is pix-pro should render the language switcher correctly for pix-pro 1`] = ` +
+ + + + + +
+`; + +exports[`Component: LanguageSwitcher when site is pix-site should render the language switcher correctly for pix-site 1`] = ` +
+ + + + + +
+`;