-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
341 create component test for slicepreviewtext (#342)
* 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
Showing
2 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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...", | ||
| ); | ||
| }); |