diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-30 19:30:43 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-12-01 16:08:54 +0100 |
| commit | 5b762b1b669454a89899c4bdf6008027d9615acf (patch) | |
| tree | 37087f4ee9d14ae131bde15a48d7d04e83ae6cbd /src/services | |
| parent | f7e6f42216c3cbeab9add475a61bb407c6be3519 (diff) | |
refactor(pages): refine Article pages
* use rehype to update code blocks class names
* fix widget heading level (after a level 1 it should always be a level
2 and not 3)
* replace Spinner with LoadingPage and LoadingPageComments components to
keep layout coherent
* refactor useArticle and useComments hooks
* fix URLs in JSON LD schema
* add Cypress tests
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/graphql/helpers/convert-post-to-article.test.ts | 22 | ||||
| -rw-r--r-- | src/services/graphql/helpers/convert-post-to-article.ts | 9 |
2 files changed, 13 insertions, 18 deletions
diff --git a/src/services/graphql/helpers/convert-post-to-article.test.ts b/src/services/graphql/helpers/convert-post-to-article.test.ts index 0a1c359..9fd74af 100644 --- a/src/services/graphql/helpers/convert-post-to-article.test.ts +++ b/src/services/graphql/helpers/convert-post-to-article.test.ts @@ -1,11 +1,12 @@ import { describe, expect, it } from '@jest/globals'; import type { WPPost } from '../../../types'; +import { ROUTES } from '../../../utils/constants'; import { convertPostToArticle } from './convert-post-to-article'; import { convertWPImgToImg } from './convert-wp-image-to-img'; describe('convert-post-to-article', () => { /* eslint-disable max-statements */ - it('converts a WPPost object to an Article object', async () => { + it('converts a WPPost object to an Article object', () => { const post: WPPost = { acfPosts: null, author: { node: { name: 'Vince5' } }, @@ -28,10 +29,7 @@ describe('convert-post-to-article', () => { slug: '/the-post-slug', title: 'ea vero repellat', }; - const result = await convertPostToArticle(post); - - // eslint-disable-next-line @typescript-eslint/no-magic-numbers - expect.assertions(15); + const result = convertPostToArticle(post); expect(result.content).toBe(post.contentParts.afterMore); expect(result.id).toBe(post.databaseId); @@ -46,12 +44,12 @@ describe('convert-post-to-article', () => { expect(result.meta.thematics).toBeUndefined(); expect(result.meta.topics).toBeUndefined(); expect(result.meta.wordsCount).toBe(post.info.wordsCount); - expect(result.slug).toBe(post.slug); + expect(result.slug).toBe(`${ROUTES.ARTICLE}/${post.slug}`); expect(result.title).toBe(post.title); }); /* eslint-enable max-statements */ - it('can convert the cover', async () => { + it('can convert the cover', () => { const post = { acfPosts: null, author: { node: { name: 'Vince5' } }, @@ -84,16 +82,14 @@ describe('convert-post-to-article', () => { slug: '/the-post-slug', title: 'ea vero repellat', } satisfies WPPost; - const result = await convertPostToArticle(post); - - expect.assertions(1); + const result = convertPostToArticle(post); expect(result.meta.cover).toStrictEqual( convertWPImgToImg(post.featuredImage.node) ); }); - it('can return 0 as comment count when not defined', async () => { + it('can return 0 as comment count when not defined', () => { const post: WPPost = { acfPosts: null, author: { node: { name: 'Vince5' } }, @@ -116,9 +112,7 @@ describe('convert-post-to-article', () => { slug: '/the-post-slug', title: 'ea vero repellat', }; - const result = await convertPostToArticle(post); - - expect.assertions(1); + const result = convertPostToArticle(post); expect(result.meta.commentsCount).toBe(0); }); diff --git a/src/services/graphql/helpers/convert-post-to-article.ts b/src/services/graphql/helpers/convert-post-to-article.ts index 383dc47..14c572d 100644 --- a/src/services/graphql/helpers/convert-post-to-article.ts +++ b/src/services/graphql/helpers/convert-post-to-article.ts @@ -1,4 +1,5 @@ import type { Article, WPPost } from '../../../types'; +import { ROUTES } from '../../../utils/constants'; import { updateContentTree } from '../../../utils/helpers'; import { convertWPThematicPreviewToPageLink, @@ -6,7 +7,7 @@ import { } from './convert-taxonomy-to-page-link'; import { convertWPImgToImg } from './convert-wp-image-to-img'; -export const convertPostToArticle = async ({ +export const convertPostToArticle = ({ acfPosts, author, commentCount, @@ -19,9 +20,9 @@ export const convertPostToArticle = async ({ seo, slug, title, -}: WPPost): Promise<Article> => { +}: WPPost): Article => { return { - content: await updateContentTree(contentParts.afterMore), + content: updateContentTree(contentParts.afterMore), id: databaseId, intro: contentParts.beforeMore, meta: { @@ -42,7 +43,7 @@ export const convertPostToArticle = async ({ topics: acfPosts?.postsInTopic?.map(convertWPTopicPreviewToPageLink), wordsCount: info.wordsCount, }, - slug, + slug: `${ROUTES.ARTICLE}/${slug}`, title, }; }; |
