Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSnow committed May 16, 2024
1 parent 3a2d601 commit c99d73d
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ exports[`can handle article 1`] = `
}
`;

exports[`can handle article with html 1`] = `
{
"description": "blurb",
"ogDescription": "blurb",
"ogImage": "cover_url",
"ogTitle": "title",
"ogType": "website",
"ogUrl": "/article_url",
"title": "title",
"twitterCard": "summary_large_image",
"twitterDescription": "blurb",
"twitterImage": "cover_url",
"twitterTitle": "title",
}
`;

exports[`can handle author page 1`] = `
{
"description": "<p>Hello world</p>",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, it } from 'vitest'
import { identity, reduce } from 'remeda'
import { htmlFilter } from '@storipress/karbon-utils'
import type { SEOContext } from '../seo-preset'
import { resolveSEOPresets } from '../seo-preset'
import type { BaseMeta, ResourcePage } from '../../types'
Expand Down Expand Up @@ -62,6 +63,76 @@ it('can handle article', () => {
expect(reduce(results, (acc, cur) => Object.assign(acc, cur), {})).toMatchSnapshot()
})

it.only('can handle article with html', () => {
const handlers = resolveSEOPresets([{ preset: 'basic' }])
const results: unknown[] = []
const resourceURL: ResourcePage<BaseMeta> = {
enable: true,
isValid: () => true,
getIdentity: () => ({ type: 'article', id: '1' }),
toURL: () => '',
route: '',
}
const context: SEOContext = {
metaType: 'article',
runtimeConfig: {} as any,
site: {
name: 'site_name',
},
articleFilter: htmlFilter,
useHead: (input: unknown) => void results.push(input),
useSeoMeta: (input: unknown) => void results.push(input),
resourceUrls: {
article: {
...resourceURL,
toURL: () => 'article_url',
},
desk: {
...resourceURL,
toURL: () => 'desk_url',
},
author: {
...resourceURL,
toURL: () => 'author_url',
},
tag: {
...resourceURL,
toURL: () => 'tag_url',
},
},
}

const article = {
title: '<p>title</p>',
blurb: 'blurb',
bio: 'author_bio',
seo: {
og: {
title: '',
description: '',
},
meta: {
title: '',
description: '',
},
hasSlug: false,
ogImage: '',
},
cover: {
url: 'cover_url',
},
author: {
name: 'author_name',
},
}

for (const handler of handlers) {
handler(article, context)
}

expect(reduce(results, (acc, cur) => Object.assign(acc, cur), {})).toMatchSnapshot()
})

const ARTICLE_FIXTURE = {
__typename: 'Article',
slug: 'article_slug',
Expand Down

0 comments on commit c99d73d

Please sign in to comment.