-
Notifications
You must be signed in to change notification settings - Fork 48
Feature: Core Component & Service API Test Coverage (vertex app) #3694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
82b97b0
Add tests and extract isRouteAccessible helper
Codebmk 8ce1def
Add hook tests and test utilities
Codebmk b69c38a
Use combineReducers to create root reducer
Codebmk 7be62ca
Assert info severity in banner test
Codebmk ec983b1
Add tests for shared and UI components
Codebmk 96acc8e
Add unit tests for UI components
Codebmk 1a27e89
Update tests and remove ReusableTable defaultProps
Codebmk df6784a
Add tests for network, onboarding, proxy, platform
Codebmk d845948
Update changelog.md
Codebmk e203f33
Tighten test typings and remove unused imports
Codebmk 781d537
Add domMocks test utilities and update tests
Codebmk 940baab
Isolate the env precedence cases from the host environment
Codebmk 929054a
Prime the token cache before asserting 401 invalidation
Codebmk b50d369
Always restore global.window, even on failure
Codebmk 63d47d8
Fail these negative-path tests when the promise resolves unexpectedly
Codebmk b071d90
Prefix matching currently misses nested routes under multi-segment bases
Codebmk bb907db
fix
Codebmk bc82e98
Ensure cleanup in ErrorBoundary test
Codebmk fc15dcf
Update changelog.md
Codebmk 62e2946
Update hcaptcha-widget.test.tsx
Codebmk b3998e9
Update changelog.md
Codebmk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
28 changes: 28 additions & 0 deletions
28
src/vertex/components/shared/button/ReusableButton.test.tsx
This file contains hidden or 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,28 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { describe, it, expect } from "vitest"; | ||
| import ReusableButton from "./ReusableButton"; | ||
|
|
||
| describe("ReusableButton", () => { | ||
| it("renders as a button by default", () => { | ||
| render(<ReusableButton>Click me</ReusableButton>); | ||
| expect(screen.getByRole("button", { name: "Click me" })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders as an anchor when path is provided", () => { | ||
| render(<ReusableButton path="/home">Go Home</ReusableButton>); | ||
| expect(screen.getByRole("link", { name: "Go Home" })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("handles loading state", () => { | ||
| render(<ReusableButton loading>Submit</ReusableButton>); | ||
| const button = screen.getByRole("button", { name: "Submit" }); | ||
| expect(button).toHaveAttribute("aria-busy", "true"); | ||
| expect(button).toBeDisabled(); | ||
| }); | ||
|
|
||
| it("renders tooltip span when disabled with permission", () => { | ||
| render(<ReusableButton disabled permission="CREATE_USER">Action</ReusableButton>); | ||
| const actionText = screen.getByText("Action"); | ||
| expect(actionText).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or 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,28 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { describe, it, expect, vi } from "vitest"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import Card from "./CardWrapper"; | ||
|
|
||
| describe("CardWrapper", () => { | ||
| it("renders with basic content", () => { | ||
| render(<Card>Card Content</Card>); | ||
| expect(screen.getByText("Card Content")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders with headers and footers", () => { | ||
| render( | ||
| <Card header={<div data-testid="header">Header</div>} footer={<div data-testid="footer">Footer</div>}> | ||
| Content | ||
| </Card> | ||
| ); | ||
| expect(screen.getByTestId("header")).toBeInTheDocument(); | ||
| expect(screen.getByTestId("footer")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("handles clicks", async () => { | ||
| const handleClick = vi.fn(); | ||
| render(<Card onClick={handleClick} testId="clickable-card">Content</Card>); | ||
| await userEvent.click(screen.getByTestId("clickable-card")); | ||
| expect(handleClick).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
27 changes: 27 additions & 0 deletions
27
src/vertex/components/shared/fileupload/ReusableFileUpload.test.tsx
This file contains hidden or 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,27 @@ | ||
| import { render, screen, fireEvent } from "@testing-library/react"; | ||
| import { describe, it, expect, vi } from "vitest"; | ||
| import ReusableFileUpload from "./ReusableFileUpload"; | ||
|
|
||
| describe("ReusableFileUpload", () => { | ||
| it("renders with placeholder and label", () => { | ||
| render(<ReusableFileUpload label="Upload File" />); | ||
| expect(screen.getByLabelText("Upload File")).toBeInTheDocument(); | ||
| expect(screen.getByText("Upload file")).toBeInTheDocument(); // default placeholder | ||
| }); | ||
|
|
||
| it("handles file selection", () => { | ||
| const handleChange = vi.fn(); | ||
| render(<ReusableFileUpload label="Upload" onChange={handleChange} />); | ||
|
|
||
| const file = new File(["hello"], "hello.png", { type: "image/png" }); | ||
| const input = screen.getByLabelText("Upload"); | ||
|
|
||
| fireEvent.change(input, { target: { files: [file] } }); | ||
| expect(handleChange).toHaveBeenCalledWith(file); | ||
| }); | ||
|
|
||
| it("shows error state", () => { | ||
| render(<ReusableFileUpload label="Upload" error="File too large" />); | ||
| expect(screen.getByText("File too large")).toBeInTheDocument(); | ||
| }); | ||
| }); |
60 changes: 60 additions & 0 deletions
60
src/vertex/components/shared/inputfield/ReusableInputField.test.tsx
This file contains hidden or 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,60 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { describe, it, expect, vi } from "vitest"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import ReusableInputField from "./ReusableInputField"; | ||
|
|
||
| // Mock toast to avoid missing canvas/window functions in jsdom sometimes or to just isolate | ||
| vi.mock("../toast/ReusableToast", () => ({ | ||
| default: vi.fn(), | ||
| })); | ||
|
|
||
| // Mock clipboard | ||
| Object.assign(navigator, { | ||
| clipboard: { | ||
| writeText: vi.fn(), | ||
| }, | ||
| }); | ||
|
|
||
| describe("ReusableInputField", () => { | ||
| it("renders basic input", () => { | ||
| render(<ReusableInputField label="Email" placeholder="Enter email" />); | ||
| expect(screen.getByLabelText("Email")).toBeInTheDocument(); | ||
| expect(screen.getByPlaceholderText("Enter email")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("shows error message", () => { | ||
| render(<ReusableInputField label="Email" error="Invalid email" />); | ||
| expect(screen.getByText("Invalid email")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("toggles password visibility", async () => { | ||
| render(<ReusableInputField label="Password" type="password" />); | ||
| const input = screen.getByLabelText("Password"); | ||
| expect(input).toHaveAttribute("type", "password"); | ||
|
|
||
| const toggleBtn = screen.getByRole("button", { name: /show password/i }); | ||
| await userEvent.click(toggleBtn); | ||
| expect(input).toHaveAttribute("type", "text"); | ||
|
|
||
| await userEvent.click(screen.getByRole("button", { name: /hide password/i })); | ||
| expect(input).toHaveAttribute("type", "password"); | ||
| }); | ||
|
|
||
| it("calls custom action", async () => { | ||
| const handleAction = vi.fn(); | ||
| const MockIcon = () => <div data-testid="custom-icon" />; | ||
|
|
||
| render( | ||
| <ReusableInputField | ||
| label="Search" | ||
| customActionIcon={MockIcon} | ||
| onCustomAction={handleAction} | ||
| customActionLabel="Do search" | ||
| /> | ||
| ); | ||
|
|
||
| const actionBtn = screen.getByRole("button", { name: "Do search" }); | ||
| await userEvent.click(actionBtn); | ||
| expect(handleAction).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
60 changes: 60 additions & 0 deletions
60
src/vertex/components/shared/select/ReusableSelectInput.test.tsx
This file contains hidden or 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,60 @@ | ||
| import { render, screen, fireEvent } from "@testing-library/react"; | ||
| import { describe, it, expect, vi } from "vitest"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import ReusableSelectInput from "./ReusableSelectInput"; | ||
|
|
||
| window.HTMLElement.prototype.scrollIntoView = vi.fn(); | ||
|
|
||
| describe("ReusableSelectInput", () => { | ||
| it("renders placeholder correctly", () => { | ||
| render( | ||
| <ReusableSelectInput label="Fruit" placeholder="Pick fruit"> | ||
| <option value="apple">Apple</option> | ||
| </ReusableSelectInput> | ||
| ); | ||
|
|
||
| const button = screen.getByRole("button"); | ||
| expect(button).toBeInTheDocument(); | ||
| expect(screen.getByText("Pick fruit")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("shows options and handles selection", async () => { | ||
| const handleChange = vi.fn(); | ||
| render( | ||
| <ReusableSelectInput label="Fruit" onChange={handleChange}> | ||
| <option value="apple">Apple</option> | ||
| <option value="banana">Banana</option> | ||
| </ReusableSelectInput> | ||
| ); | ||
|
|
||
| const button = screen.getByRole("button"); | ||
| await userEvent.click(button); | ||
|
|
||
| expect(screen.getByRole("listbox")).toBeInTheDocument(); | ||
| const bananaOption = screen.getByText("Banana"); | ||
|
|
||
| await userEvent.click(bananaOption); | ||
|
|
||
| expect(handleChange).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| target: expect.objectContaining({ value: "banana" }) | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| it("handles keyboard navigation", async () => { | ||
| render( | ||
| <ReusableSelectInput label="Fruit"> | ||
| <option value="apple">Apple</option> | ||
| <option value="banana">Banana</option> | ||
| </ReusableSelectInput> | ||
| ); | ||
|
|
||
| const button = screen.getByRole("button"); | ||
| button.focus(); | ||
|
|
||
| // Open with arrow down | ||
| fireEvent.keyDown(button, { key: "ArrowDown" }); | ||
| expect(screen.getByRole("listbox")).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or 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,35 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { describe, it, expect, vi } from "vitest"; | ||
| import ReusableTable from "./ReusableTable"; | ||
|
|
||
| vi.mock("next/navigation", () => ({ | ||
| useRouter: () => ({ replace: vi.fn() }), | ||
| usePathname: () => "/test-path", | ||
| useSearchParams: () => new URLSearchParams(), | ||
| })); | ||
|
|
||
| vi.mock("@/context/banner-context", () => ({ | ||
| useBanner: () => ({ showBanner: vi.fn(), hideBanner: vi.fn() }), | ||
| })); | ||
|
|
||
| describe("ReusableTable", () => { | ||
| it("renders with empty data", () => { | ||
| render(<ReusableTable columns={[]} data={[]} title="Test Table" />); | ||
| expect(screen.getByText("Test Table")).toBeInTheDocument(); | ||
| expect(screen.getByText("No data available")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders data correctly", () => { | ||
| const columns = [ | ||
| { key: "name", render: (val: unknown) => String(val) }, | ||
| ]; | ||
| const data = [ | ||
| { id: 1, name: "Alice" }, | ||
| { id: 2, name: "Bob" } | ||
| ]; | ||
|
|
||
| render(<ReusableTable columns={columns as never} data={data} />); | ||
| expect(screen.getByText("Alice")).toBeInTheDocument(); | ||
| expect(screen.getByText("Bob")).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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,17 @@ | ||
| import { render } from "@testing-library/react"; | ||
| import { describe, it, expect } from "vitest"; | ||
| import { Toaster, toast } from "./ReusableToast"; | ||
| import ReusableToast from "./ReusableToast"; | ||
|
|
||
| describe("ReusableToast", () => { | ||
| it("can render the Toaster component", () => { | ||
| const { container } = render(<Toaster />); | ||
| expect(container).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("exports toast methods", () => { | ||
| expect(typeof toast.success).toBe("function"); | ||
| expect(typeof toast.error).toBe("function"); | ||
| expect(typeof ReusableToast).toBe("function"); | ||
| }); | ||
| }); |
This file contains hidden or 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,27 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { describe, it, expect, vi } from "vitest"; | ||
| import ErrorBoundary from "./ErrorBoundary"; | ||
|
|
||
| const ThrowError = () => { | ||
| throw new Error("Test error"); | ||
| }; | ||
|
|
||
| describe("ErrorBoundary", () => { | ||
| it("catches errors and displays fallback", () => { | ||
| const consoleError = vi.spyOn(console, "error").mockImplementation(() => {}); | ||
| const preventError = (e: ErrorEvent) => e.preventDefault(); | ||
| window.addEventListener("error", preventError); | ||
| try { | ||
| render( | ||
| <ErrorBoundary> | ||
| <ThrowError /> | ||
| </ErrorBoundary> | ||
| ); | ||
|
|
||
| expect(screen.getByText("Sorry.. there was an error")).toBeInTheDocument(); | ||
| } finally { | ||
| window.removeEventListener("error", preventError); | ||
| consoleError.mockRestore(); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.