forked from lensapp/generator-lens-ext
-
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.
Add extension testing examples (lensapp#15)
* Add extension testing examples * Copy missing files * Move bable.config to correct folder * Add new files to test case * Add new npm script test * Update test snapshot for npm test Signed-off-by: Hung-Han (Henry) Chen <[email protected]>
- Loading branch information
1 parent
d4b4c8e
commit d139b84
Showing
8 changed files
with
85 additions
and
2 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
File renamed without changes.
33 changes: 33 additions & 0 deletions
33
generators/app/templates/ext-ts/components/GlobalPage.test.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,33 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom/extend-expect"; | ||
|
||
import GlobalPage from "./GlobalPage"; | ||
|
||
describe("<GlobalPage />", () => { | ||
it("renders w/o issues", () => { | ||
const { container } = render(<GlobalPage />); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders texts", () => { | ||
render(<GlobalPage />); | ||
expect(screen.getByTestId("global-page-header")).toHaveTextContent( | ||
"Extension Global Page" | ||
); | ||
expect(screen.getByTestId("global-page-title")).toHaveTextContent( | ||
"Global Page Content" | ||
); | ||
expect(screen.getByTestId("global-page-paragraph")).toHaveTextContent( | ||
"A very long paragraph" | ||
); | ||
}); | ||
|
||
it("matches snapshot", () => { | ||
// this test is totally optional, but might be useful for extension developers | ||
// to track the version diffs in "Component" from @k8slens/extensions (if you upgrade) | ||
// and react to the upstream changes. | ||
const { asFragment } = render(<GlobalPage />); | ||
expect(asFragment()).toMatchInlineSnapshot(); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
generators/app/templates/ext-ts/components/GlobalPageMenuIcon.test.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,19 @@ | ||
import React from "react" | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import "@testing-library/jest-dom/extend-expect" | ||
|
||
import GlobalPageMenuIcon from "./GlobalPageMenuIcon"; | ||
|
||
describe("<GlobalPageMenuIcon />", () => { | ||
it("renders w/o issues", () => { | ||
const { container } = render(<GlobalPageMenuIcon />); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
it("click called navigate()", () => { | ||
const navigate = jest.fn(); | ||
render(<GlobalPageMenuIcon navigate={navigate} />); | ||
fireEvent.click(screen.getByTestId("global-page-menu-icon")); | ||
expect(navigate).toHaveBeenCalled(); | ||
}); | ||
}) |
20 changes: 20 additions & 0 deletions
20
generators/app/templates/ext-ts/components/StatusBarItemIcon.test.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 React from "react" | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import "@testing-library/jest-dom/extend-expect" | ||
|
||
import StatusBarItemIcon from "./StatusBarItemIcon"; | ||
|
||
describe("<StatusBarItemIcon />", () => { | ||
it("renders w/o issues", () => { | ||
const { container } = render(<StatusBarItemIcon />); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
it("click called navigate()", () => { | ||
const navigate = jest.fn(); | ||
render(<StatusBarItemIcon navigate={navigate} />); | ||
fireEvent.click(screen.getByTestId("statusbar-item-icon")); | ||
expect(navigate).toHaveBeenCalled(); | ||
expect(screen.getByTestId("statusbar-item-icon")).toHaveStyle({ color: "rgb(255, 255, 0)" }); | ||
}); | ||
}) |
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
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