diff --git a/nuxt.config.js b/nuxt.config.js index bce7c2981..afc368de9 100755 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -30,7 +30,8 @@ export default { { hid: 'description', name: 'description', - content: process.env.npm_package_description || '', + content: + 'Pix est le service public en ligne pour évaluer, développer et certifier ses compétences numériques tout au long de la vie.', }, ], link: [ diff --git a/services/meta-builder.js b/services/meta-builder.js index a111de2cd..81abdad33 100644 --- a/services/meta-builder.js +++ b/services/meta-builder.js @@ -1,3 +1,6 @@ +export const fallbackDescription = + 'Pix est le service public en ligne pour évaluer, développer et certifier ses compétences numériques tout au long de la vie.' + export default function getMeta(meta, currentPagePath, prismic) { function getTwitterCard() { const twitterMeta = meta.find((meta) => meta.slice_type === 'twitter_card') @@ -39,7 +42,8 @@ export default function getMeta(meta, currentPagePath, prismic) { { hid: 'og:description', property: 'og:description', - content: prismic.asText(ogMeta.primary.description), + content: + prismic.asText(ogMeta.primary.description) || fallbackDescription, }, { hid: 'og:type', property: 'og:type', content: 'article' }, { @@ -65,7 +69,9 @@ export default function getMeta(meta, currentPagePath, prismic) { { hid: 'description', name: 'description', - content: prismic.asText(generalCard.primary.description), + content: + prismic.asText(generalCard.primary.description) || + fallbackDescription, }, ] } diff --git a/tests/pages/pix-site/__snapshots__/index.test.js.snap b/tests/pages/pix-site/__snapshots__/index.test.js.snap index daffa368c..38c3cdebc 100644 --- a/tests/pages/pix-site/__snapshots__/index.test.js.snap +++ b/tests/pages/pix-site/__snapshots__/index.test.js.snap @@ -1,13 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Index Page get the corrects meta 1`] = ` -VueWrapper { - "_emitted": Object {}, - "_emittedByOrder": Array [], - "isFunctionalComponent": undefined, -} -`; - exports[`Index Page renders properly 1`] = ` "
diff --git a/tests/pages/pix-site/index.test.js b/tests/pages/pix-site/index.test.js index eccf62605..11c2653cf 100644 --- a/tests/pages/pix-site/index.test.js +++ b/tests/pages/pix-site/index.test.js @@ -2,6 +2,7 @@ import VueMeta from 'vue-meta' import { getInitialised, createLocalVue } from './utils' import { documentFetcher } from '~/services/document-fetcher' import getMeta from '~/services/meta-builder' +import { fallbackDescription } from "~/services/meta-builder"; const localVue = createLocalVue() localVue.prototype.$getMeta = getMeta @@ -63,16 +64,30 @@ describe('Index Page', () => { expect(wrapper.html()).toMatchSnapshot() }) - test('get correct title info', () => { + test('gets the correct title', () => { expect(wrapper.vm.$metaInfo.title).toBe(`${PRISMIC_TITLE} | Pix`) expect(wrapper.vm.$data.title).toBe(PRISMIC_TITLE) }) - test('get the corrects meta', () => { + test('gets the correct meta description from Prismic', () => { expect(findMetaContent('og:description')).toBe(PRISMIC_META) expect(findMetaContent('description')).toBe(PRISMIC_META) }) + test('uses the fallback meta description when not filled in Prismic', async () => { + wrapper = await getInitialised('index', { + localVue, + computed: { + $prismic() { + return { asText: () => '' } + }, + }, + }) + + expect(findMetaContent('og:description')).toBe(fallbackDescription) + expect(findMetaContent('description')).toBe(fallbackDescription) + }) + function findMetaContent(hid) { const meta = wrapper.vm.$metaInfo.meta.find((m) => m.hid === hid) expect(meta).toBeTruthy()