From bf1d1677fb5c9f4a45269aaf1549624bfb54fd36 Mon Sep 17 00:00:00 2001 From: luctra02 <64017398+luctra02@users.noreply.github.com> Date: Sun, 21 Apr 2024 19:28:18 +0200 Subject: [PATCH] 341 create component test for slicepreviewtext (#342) * test(frontend): :test_tube: write component test for sharebuttons * test(frontend): :test_tube: write test for slicepreviewtest to check if the component slices the 100 first chars in the first paragraph --- ...spec.tsx => blocksrendererclient.spec.tsx} | 3 -- .../componentTests/slicepreviewtext.spec.tsx | 53 +++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) rename frontend/tests/componentTests/{blocksrendererclient.desktop.spec.tsx => blocksrendererclient.spec.tsx} (91%) create mode 100644 frontend/tests/componentTests/slicepreviewtext.spec.tsx diff --git a/frontend/tests/componentTests/blocksrendererclient.desktop.spec.tsx b/frontend/tests/componentTests/blocksrendererclient.spec.tsx similarity index 91% rename from frontend/tests/componentTests/blocksrendererclient.desktop.spec.tsx rename to frontend/tests/componentTests/blocksrendererclient.spec.tsx index a307383..94f2bc3 100644 --- a/frontend/tests/componentTests/blocksrendererclient.desktop.spec.tsx +++ b/frontend/tests/componentTests/blocksrendererclient.spec.tsx @@ -24,7 +24,6 @@ test("Check content rendering in BlockRendererClient", async ({ mount }) => { }, ], }, - // Add other content blocks as needed ]; // Mount the BlockRendererClient with mock content @@ -37,6 +36,4 @@ test("Check content rendering in BlockRendererClient", async ({ mount }) => { await expect(component.getByRole("paragraph")).toContainText( "Dolor sit amet", ); - - // Add more assertions based on your content blocks }); diff --git a/frontend/tests/componentTests/slicepreviewtext.spec.tsx b/frontend/tests/componentTests/slicepreviewtext.spec.tsx new file mode 100644 index 0000000..b09ec88 --- /dev/null +++ b/frontend/tests/componentTests/slicepreviewtext.spec.tsx @@ -0,0 +1,53 @@ +import { test, expect } from "@playwright/experimental-ct-react"; +import { SlicePreviewText } from "@/components/SlicePreviewText"; +import { BlocksContent } from "@strapi/blocks-react-renderer"; + +test("Check SlicePreviewText function", async () => { + // Mock content with a paragraph block + const mockContent: BlocksContent = [ + { + type: "heading", + children: [ + { + type: "text", + text: "Lorem ipsum", + }, + ], + level: 1, + }, + { + type: "paragraph", + children: [ + { + type: "text", + text: "", + }, + ], + }, + { + type: "paragraph", + children: [ + { + type: "text", + text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pulvinar viverra diam. Aliquam venenatis fermentum nisl, ut pulvinar nunc consectetur ac. Nunc sit amet velit nibh. Sed sagittis mauris in elit varius aliquet. Phasellus lacus risus, suscipit sed nisl ac, consectetur faucibus est. Curabitur porta ante nec tortor finibus venenatis. Etiam ac nulla vitae est dapibus tincidunt. Quisque mollis pulvinar bibendum.", + }, + ], + }, + { + type: "paragraph", + children: [ + { + type: "text", + text: "Do not slice this paragraph, only the first one", + }, + ], + }, + ]; + + const slicedText = SlicePreviewText(mockContent); + + // Assert that the sliced text contains the expected content + expect(slicedText).toContain( + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pulvinar viverra diam. Aliquam v...", + ); +});