Skip to content

Commit

Permalink
Add tests to LogosZone
Browse files Browse the repository at this point in the history
  • Loading branch information
sbedeau committed Oct 6, 2020
1 parent a19ec32 commit 3ab19d8
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions tests/components/slices/LogosZone.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
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 = {
isPixSite: true,
isPixPro: false,
}
})

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 = {
isPixSite: false,
isPixPro: true,
}
})

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 3ab19d8

Please sign in to comment.