Skip to content

Commit

Permalink
Test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tofarr committed Nov 10, 2024
1 parent f2d4039 commit 3cabac4
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions frontend/__tests__/hooks/use-terminal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { afterEach } from "node:test";
import { useTerminal } from "#/hooks/useTerminal";
import { Command } from "#/state/commandSlice";
import { WsClientProvider } from "#/context/ws-client-provider";
import { ReactNode } from "react";

interface TestTerminalComponentProps {
commands: Command[];
Expand All @@ -18,6 +19,17 @@ function TestTerminalComponent({
return <div ref={ref} />;
}

interface WrapperProps {
children: ReactNode;
}


function Wrapper({children}: WrapperProps) {
return (
<WsClientProvider enabled={true} token="NO_JWT" ghToken="NO_GITHUB" settings={null}>{children}</WsClientProvider>
)
}

describe("useTerminal", () => {
const mockTerminal = vi.hoisted(() => ({
loadAddon: vi.fn(),
Expand Down Expand Up @@ -50,7 +62,7 @@ describe("useTerminal", () => {

it("should render", () => {
render(<TestTerminalComponent commands={[]} secrets={[]} />, {
wrapper: WsClientProvider,
wrapper: Wrapper,
});
});

Expand All @@ -61,7 +73,7 @@ describe("useTerminal", () => {
];

render(<TestTerminalComponent commands={commands} secrets={[]} />, {
wrapper: WsClientProvider,
wrapper: Wrapper,
});

expect(mockTerminal.writeln).toHaveBeenNthCalledWith(1, "echo hello");
Expand All @@ -85,7 +97,7 @@ describe("useTerminal", () => {
secrets={[secret, anotherSecret]}
/>,
{
wrapper: WsClientProvider,
wrapper: Wrapper,
},
);

Expand Down

0 comments on commit 3cabac4

Please sign in to comment.