forked from calcom/cal.com
-
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.
test: RFC: tests for EventTypeAppCardInterface (CALCOM-11005 ) (calco…
…m#11344) Co-authored-by: gitstart-calcom <[email protected]> Co-authored-by: gitstart-calcom <[email protected]>
- Loading branch information
1 parent
a86d4ec
commit bba52db
Showing
3 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
packages/app-store/_components/eventTypeAppCardInterface.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,97 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import type { CredentialOwner } from "types"; | ||
import { vi } from "vitest"; | ||
|
||
import type { RouterOutputs } from "@calcom/trpc"; | ||
|
||
import { DynamicComponent } from "./DynamicComponent"; | ||
import { EventTypeAppCard } from "./EventTypeAppCardInterface"; | ||
|
||
vi.mock("./DynamicComponent", async () => { | ||
const actual = (await vi.importActual("./DynamicComponent")) as object; | ||
return { | ||
...actual, | ||
DynamicComponent: vi.fn(() => <div>MockedDynamicComponent</div>), | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
const getAppDataMock = vi.fn(); | ||
const setAppDataMock = vi.fn(); | ||
const mockProps = { | ||
app: { | ||
name: "TestApp", | ||
slug: "testapp", | ||
credentialOwner: {}, | ||
} as RouterOutputs["viewer"]["integrations"]["items"][number] & { credentialOwner?: CredentialOwner }, | ||
eventType: {}, | ||
getAppData: getAppDataMock, | ||
setAppData: setAppDataMock, | ||
LockedIcon: <div>MockedIcon</div>, | ||
disabled: false, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any; | ||
|
||
describe("Tests for EventTypeAppCard component", () => { | ||
test("Should render DynamicComponent with correct slug", () => { | ||
render(<EventTypeAppCard {...mockProps} />); | ||
|
||
expect(DynamicComponent).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
slug: mockProps.app.slug, | ||
}), | ||
{} | ||
); | ||
|
||
expect(screen.getByText("MockedDynamicComponent")).toBeInTheDocument(); | ||
}); | ||
|
||
test("Should invoke getAppData and setAppData from context on render", () => { | ||
render( | ||
<EventTypeAppCard | ||
{...mockProps} | ||
value={{ | ||
getAppData: getAppDataMock(), | ||
setAppData: setAppDataMock(), | ||
}} | ||
/> | ||
); | ||
|
||
expect(getAppDataMock).toHaveBeenCalled(); | ||
expect(setAppDataMock).toHaveBeenCalled(); | ||
}); | ||
|
||
test("Should render DynamicComponent with 'stripepayment' slug for stripe app", () => { | ||
const stripeProps = { | ||
...mockProps, | ||
app: { | ||
...mockProps.app, | ||
slug: "stripe", | ||
}, | ||
}; | ||
|
||
render(<EventTypeAppCard {...stripeProps} />); | ||
|
||
expect(DynamicComponent).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
slug: "stripepayment", | ||
}), | ||
{} | ||
); | ||
|
||
expect(screen.getByText("MockedDynamicComponent")).toBeInTheDocument(); | ||
}); | ||
|
||
test("Should display error boundary message on child component error", () => { | ||
(DynamicComponent as jest.Mock).mockImplementation(() => { | ||
return Error("Mocked error from DynamicComponent"); | ||
}); | ||
|
||
render(<EventTypeAppCard {...mockProps} />); | ||
const errorMessage = screen.getByText(`There is some problem with ${mockProps.app.name} App`); | ||
expect(errorMessage).toBeInTheDocument(); | ||
}); | ||
}); |
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,27 @@ | ||
import matchers from "@testing-library/jest-dom/matchers"; | ||
import { cleanup } from "@testing-library/react"; | ||
import { afterEach, expect, vi } from "vitest"; | ||
|
||
vi.mock("@calcom/lib/OgImages", async () => { | ||
return {}; | ||
}); | ||
|
||
vi.mock("@calcom/lib/hooks/useLocale", () => ({ | ||
useLocale: () => { | ||
return { | ||
t: (str: string) => str, | ||
}; | ||
}, | ||
})); | ||
|
||
global.ResizeObserver = vi.fn().mockImplementation(() => ({ | ||
observe: vi.fn(), | ||
unobserve: vi.fn(), | ||
disconnect: vi.fn(), | ||
})); | ||
|
||
expect.extend(matchers); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
}); |
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