Skip to content

Commit

Permalink
341 create component test for slicepreviewtext (#342)
Browse files Browse the repository at this point in the history
* test(frontend): 🧪 write component test for sharebuttons

* test(frontend): 🧪 write test for slicepreviewtest to check if the component slices the 100 first chars in the first paragraph
  • Loading branch information
luctra02 authored and GitHub committed Apr 21, 2024
1 parent 3681e85 commit bf1d167
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ test("Check content rendering in BlockRendererClient", async ({ mount }) => {
},
],
},
// Add other content blocks as needed
];

// Mount the BlockRendererClient with mock content
Expand All @@ -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
});
53 changes: 53 additions & 0 deletions frontend/tests/componentTests/slicepreviewtext.spec.tsx
Original file line number Diff line number Diff line change
@@ -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...",
);
});

0 comments on commit bf1d167

Please sign in to comment.