-
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.
316 component test for blocksrendererclient (#322)
* chore(frontend): 📦 Donwload packages for playwright component testing * refactor(frontend): 🚚 move all e2e tests to a seperate folder * test(frontend): ✅ Added simple component test and configured alias handling * test(frontend): 🧪 create test file for blockrendererclient * test(frontend): 🧪 Write component test for blockrendererclient * refactor(frontend): ♻️ Run prettier --------- Co-authored-by: Jakob Grøtan Gregusson <jakobgg@stud.ntnu.no>
- Loading branch information
2 people
authored and
GitHub
committed
Apr 18, 2024
1 parent
f6be12b
commit c54d498
Showing
13 changed files
with
986 additions
and
9 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,58 @@ | ||
| import { defineConfig, devices } from "@playwright/experimental-ct-react"; | ||
|
|
||
| /** | ||
| * See https://playwright.dev/docs/test-configuration. | ||
| */ | ||
|
|
||
| // playwright.config.js | ||
|
|
||
| import { resolve } from "path"; | ||
| export default defineConfig({ | ||
| testDir: "./tests/componentTests", | ||
| /* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */ | ||
| snapshotDir: "./tests/componentTests/__snapshots__", | ||
| /* Maximum time one test can run for. */ | ||
| timeout: 10 * 1000, | ||
| /* Run tests in files in parallel */ | ||
| fullyParallel: true, | ||
| /* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
| forbidOnly: !!process.env.CI, | ||
| /* Retry on CI only */ | ||
| retries: process.env.CI ? 2 : 0, | ||
| /* Opt out of parallel tests on CI. */ | ||
| workers: process.env.CI ? 1 : undefined, | ||
| /* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
| reporter: "html", | ||
| /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
| use: { | ||
| /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
| trace: "on-first-retry", | ||
|
|
||
| /* Port to use for Playwright component endpoint. */ | ||
| ctPort: 3100, | ||
| ctViteConfig: { | ||
| resolve: { | ||
| alias: { | ||
| "@/components": resolve("./src/components"), | ||
| "@/lib": resolve("./src/lib"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| /* Configure projects for major browsers */ | ||
| projects: [ | ||
| { | ||
| name: "chromium", | ||
| use: { ...devices["Desktop Chrome"] }, | ||
| }, | ||
| { | ||
| name: "firefox", | ||
| use: { ...devices["Desktop Firefox"] }, | ||
| }, | ||
| { | ||
| name: "webkit", | ||
| use: { ...devices["Desktop Safari"] }, | ||
| }, | ||
| ], | ||
| }); |
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,12 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>Testing Page</title> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="./index.tsx"></script> | ||
| </body> | ||
| </html> |
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,2 @@ | ||
| // Import styles, initialize component theme here. | ||
| // import '../src/common.css'; |
20 changes: 20 additions & 0 deletions
20
frontend/tests/componentTests/RelatedProjectAndSatellites.spec.tsx
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,20 @@ | ||
| import RelatedProjectsAndSatellites from "@/components/RelatedProjectsAndSatellites"; | ||
| import { test, expect } from "@playwright/experimental-ct-react"; | ||
|
|
||
| test("should work", async ({ mount }) => { | ||
| // Mock project data | ||
| const mockProject = { | ||
| id: "test", | ||
| title: "Learn React", | ||
| previewImage: "test", | ||
| slug: "test", | ||
| isProject: true, | ||
| // Add other required properties | ||
| }; | ||
|
|
||
| const component = await mount( | ||
| <RelatedProjectsAndSatellites project={mockProject} />, | ||
| ); | ||
|
|
||
| await expect(component).toContainText("Learn React"); | ||
| }); |
42 changes: 42 additions & 0 deletions
42
frontend/tests/componentTests/blocksrendererclient.desktop.spec.tsx
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,42 @@ | ||
| import { test, expect } from "@playwright/experimental-ct-react"; | ||
| import BlockRendererClient from "@/components/BlockRendererClient"; | ||
| import { BlocksContent } from "@strapi/blocks-react-renderer"; | ||
|
|
||
| test("Check content rendering in BlockRendererClient", async ({ mount }) => { | ||
| // Mock content data | ||
| const mockContent: BlocksContent = [ | ||
| { | ||
| type: "heading", | ||
| children: [ | ||
| { | ||
| type: "text", | ||
| text: "Lorem ipsum", | ||
| }, | ||
| ], | ||
| level: 1, | ||
| }, | ||
| { | ||
| type: "paragraph", | ||
| children: [ | ||
| { | ||
| type: "text", | ||
| text: "Dolor sit amet", | ||
| }, | ||
| ], | ||
| }, | ||
| // Add other content blocks as needed | ||
| ]; | ||
|
|
||
| // Mount the BlockRendererClient with mock content | ||
| const component = await mount( | ||
| <BlockRendererClient content={mockContent} />, | ||
| ); | ||
|
|
||
| // Assertions | ||
| await expect(component.getByRole("heading")).toContainText("Lorem ipsum"); | ||
| await expect(component.getByRole("paragraph")).toContainText( | ||
| "Dolor sit amet", | ||
| ); | ||
|
|
||
| // Add more assertions based on your content blocks | ||
| }); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.