Skip to content

Commit

Permalink
Add tests to LogosZone and refactor site env
Browse files Browse the repository at this point in the history
  • Loading branch information
sbedeau committed Oct 5, 2020
1 parent a39aad4 commit 31aa3a4
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/AppFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default {
data() {
const showUnescoLogo = this.$i18n.locale !== 'fr-fr'
const isFrenchLocale = this.$i18n.locale === 'fr-fr'
const isPixSite = process.env.isPixSite
const isPixSite = process.env.site === 'pix-site'
return {
showUnescoLogo,
showFrenchGovLogo: isFrenchLocale && isPixSite,
Expand Down
2 changes: 1 addition & 1 deletion components/BurgerMenuNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default {
},
computed: {
isPixPro() {
return process.env.isPixPro
return process.env.site === 'pix-pro'
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion components/NavigationSliceZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default {
},
computed: {
isPixPro() {
return process.env.isPixPro
return process.env.site === 'pix-pro'
},
...mapState(['mainNavigation', 'organizationNavItems']),
burgerMenuLinks() {
Expand Down
2 changes: 1 addition & 1 deletion components/slices/LogosZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default {
},
computed: {
filteredLogos() {
if (process.env.isPixSite) {
if (process.env.site === 'pix-site') {
return this.slice.items.filter((item) => item.display_on_pix_site)
}
return this.slice.items.filter((item) => item.display_on_pix_pro)
Expand Down
3 changes: 1 addition & 2 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ export default {
port: process.env.PORT || 5000,
},
env: {
isPixSite: process.env.SITE === 'pix-site',
isPixPro: process.env.SITE === 'pix-pro',
site: process.env.SITE,
},
dir: {
pages: `pages/${process.env.SITE}`,
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
},
"scripts": {
"clean": "rm -rf node_modules .nuxt",

"build": "nuxt build",
"start": "nuxt start",

"dev:site": "SITE=pix-site nuxt",
"build:site": "SITE=pix-site nuxt build",
"start:site": "SITE=pix-site nuxt start",

"test": "SITE=pix-site jest --no-coverage",

"dev:pro": "SITE=pix-pro nuxt",
"build:pro": "SITE=pix-pro nuxt build",
"start:pro": "SITE=pix-pro nuxt start",

"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"test": "SITE=pix-site jest --no-coverage",
"release": "npm run release:minor",
"release:patch": "npm version patch -m \"Release v%s\"",
"release:minor": "npm version minor -m \"Release v%s\"",
Expand Down
2 changes: 1 addition & 1 deletion store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const mutations = {
return response.data.body.filter((body) => body.primary.type === type)
}

if (process.env.isPixPro) {
if (process.env.site === 'pix-pro') {
state.organizationNavItems = navItems(
navigations,
'pix-pro-organizations-nav'
Expand Down
121 changes: 121 additions & 0 deletions tests/components/slices/LogosZone.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { shallowMount } from '@vue/test-utils'
import { documentFetcher } from '~/services/document-fetcher'
import LogosZone from '~/components/slices/LogosZone'

jest.mock('~/services/document-fetcher')

describe('LogosZone slice', () => {
let component
const get = jest.fn()

beforeEach(() => {
documentFetcher.mockReturnValue({
get,
})

get.mockResolvedValueOnce({
data: {
id: '',
meta: '',
page_title: '',
},
})
})

describe('Slice: LogosZone', () => {
let logoGovernment
let logoPix

beforeEach(() => {
logoGovernment = {
display_on_pix_site: true,
display_on_pix_pro: false,
image: {
alt: 'République française',
url: 'logo.png',
},
url: '',
}

logoPix = {
display_on_pix_site: true,
display_on_pix_pro: true,
image: {
alt: 'Pix',
url: 'pix.png',
},
url: '/',
}
})

describe('#filteredLogos', () => {
describe('when is Pix Site', () => {
beforeEach(() => {
jest.resetModules()
process.env.site = 'pix-site'
})

it('should return Pix Site logos', () => {
// given
component = shallowMount(LogosZone, {
stubs: {
fa: true,
'pix-link': true,
'pix-image': true,
},
propsData: {
slice: {
items: [logoGovernment, logoPix],
},
},
computed: {
$prismic() {
return { asText: () => {} }
},
},
})

// when
const result = component.vm.filteredLogos

// then
expect(result).toEqual([logoGovernment, logoPix])
})
})

describe('when is Pix Pro', () => {
beforeEach(() => {
jest.resetModules()
process.env.site = 'pix-pro'
})

it('should return Pix Pro logos', () => {
// given
component = shallowMount(LogosZone, {
stubs: {
fa: true,
'pix-link': true,
'pix-image': true,
},
propsData: {
slice: {
items: [logoGovernment, logoPix],
},
},
computed: {
$prismic() {
return { asText: () => {} }
},
},
})

// when
const result = component.vm.filteredLogos

// then
expect(result).toEqual([logoPix])
})
})
})
})
})

0 comments on commit 31aa3a4

Please sign in to comment.