A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
/* Copyright 2026 Marimo. All rights reserved. */
// @vitest-environment jsdom
import { fireEvent, render } from "@testing-library/react";
import { createStore, Provider as JotaiProvider } from "jotai";
import type React from "react";
import { describe, expect, it, vi } from "vitest";
import { TooltipProvider } from "@/components/ui/tooltip";
import { viewStateAtom } from "@/core/mode";
import {
type ConnectionStatus,
WebSocketClosedReason,
ConnectionState,
} from "@/core/session/types";
import { StatusOverlay } from "../status";
function renderOverlay(
connection: ConnectionStatus,
onReconnect?: () => void,
): ReturnType<typeof render> {
const store = createStore();
store.set(viewStateAtom, { mode: "edit", cellAnchor: null });
const wrapper: React.FC<React.PropsWithChildren> = ({ children }) => (
<JotaiProvider store={store}>
<TooltipProvider>{children}</TooltipProvider>
</JotaiProvider>
);
return render(
<StatusOverlay
connection={connection}
isRunning={false}
onReconnect={onReconnect}
/>,
{ wrapper },
);
}
describe("StatusOverlay disconnect indicator", () => {
it("invokes onReconnect when the disconnect icon is clicked", () => {
const onReconnect = vi.fn();
const { getByTestId } = renderOverlay(
{
state: ConnectionState.CLOSED,
code: WebSocketClosedReason.KERNEL_DISCONNECTED,
reason: "kernel not found",
},
onReconnect,
);
const icon = getByTestId("disconnected-indicator") as HTMLButtonElement;
expect(icon.tagName).toBe("BUTTON");
expect(icon.disabled).toBe(false);
expect(icon.getAttribute("aria-label")).toBe("Reconnect to app");
fireEvent.click(icon);
expect(onReconnect).toHaveBeenCalledTimes(1);
});
it("keeps the unavailable reconnect button focusable for its tooltip", () => {
const { getByTestId } = renderOverlay({
state: ConnectionState.CLOSED,
code: WebSocketClosedReason.KERNEL_DISCONNECTED,
reason: "kernel not found",
});
const button = getByTestId("disconnected-indicator");
expect(button).toHaveAttribute("aria-disabled", "true");
button.focus();
expect(button).toHaveFocus();
});
it("leaves editor startup failures to the inline notice", () => {
const { queryByTestId } = renderOverlay({
state: ConnectionState.CLOSED,
code: WebSocketClosedReason.KERNEL_STARTUP_ERROR,
reason: "Failed to start kernel sandbox",
});
expect(queryByTestId("disconnected-indicator")).not.toBeInTheDocument();
});
});