Skip to content

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.

tests: add data-testids to components (#983)

Myles Scolnick2b25e53fb67a
diff --git a/frontend/src/components/app-config/app-config-button.tsx b/frontend/src/components/app-config/app-config-button.tsx
index d14a25269c..be66e6738c 100644
--- a/frontend/src/components/app-config/app-config-button.tsx
+++ b/frontend/src/components/app-config/app-config-button.tsx
@@ -16,6 +16,7 @@ export const AppConfigButton = () => {
<PopoverTrigger asChild={true}>
<Button
aria-label="Config"
+ data-testid="app-config-button"
shape="circle"
size="small"
className="h-[27px] w-[27px]"
diff --git a/frontend/src/components/app-config/app-config-form.tsx b/frontend/src/components/app-config/app-config-form.tsx
index 0799bd112d..fd5b516c67 100644
--- a/frontend/src/components/app-config/app-config-form.tsx
+++ b/frontend/src/components/app-config/app-config-form.tsx
@@ -64,6 +64,7 @@ export const AppConfigForm: React.FC = () => {
<FormLabel>Width</FormLabel>
<FormControl>
<NativeSelect
+ data-testid="app-width-select"
onChange={(e) => field.onChange(e.target.value)}
value={field.value}
disabled={field.disabled}
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsx
index f4c2418fe6..43d8502a8f 100644
--- a/frontend/src/components/app-config/user-config-form.tsx
+++ b/frontend/src/components/app-config/user-config-form.tsx
@@ -62,6 +62,7 @@ export const UserConfigForm: React.FC = () => {
<FormItem className="flex flex-row items-start space-x-2 space-y-0">
<FormControl>
<Checkbox
+ data-testid="autosave-checkbox"
checked={field.value === "after_delay"}
disabled={field.disabled}
onCheckedChange={(checked) => {
@@ -83,6 +84,7 @@ export const UserConfigForm: React.FC = () => {
<FormControl>
<span className="inline-flex mr-2">
<Input
+ data-testid="autosave-delay-input"
type="number"
className="m-0 w-20 inline-flex"
disabled={
@@ -110,6 +112,7 @@ export const UserConfigForm: React.FC = () => {
<FormItem className="flex flex-row items-start space-x-2 space-y-0">
<FormControl>
<Checkbox
+ data-testid="format-on-save-checkbox"
checked={field.value}
disabled={field.disabled}
onCheckedChange={(checked) => {
@@ -134,6 +137,7 @@ export const UserConfigForm: React.FC = () => {
<FormControl>
<span className="inline-flex mr-2">
<Input
+ data-testid="line-length-input"
type="number"
className="m-0 w-20 inline-flex"
{...field}
@@ -156,6 +160,7 @@ export const UserConfigForm: React.FC = () => {
<FormItem className="flex flex-row items-start space-x-2 space-y-0">
<FormControl>
<Checkbox
+ data-testid="autocomplete-checkbox"
checked={field.value}
disabled={field.disabled}
onCheckedChange={(checked) => {
@@ -180,6 +185,7 @@ export const UserConfigForm: React.FC = () => {
<FormLabel>Keymap</FormLabel>
<FormControl>
<NativeSelect
+ data-testid="keymap-select"
onChange={(e) => field.onChange(e.target.value)}
value={field.value}
disabled={field.disabled}
@@ -207,6 +213,7 @@ export const UserConfigForm: React.FC = () => {
<FormLabel>Theme</FormLabel>
<FormControl>
<NativeSelect
+ data-testid="theme-select"
onChange={(e) => field.onChange(e.target.value)}
value={field.value}
disabled={field.disabled}
@@ -232,6 +239,7 @@ export const UserConfigForm: React.FC = () => {
<FormControl>
<span className="inline-flex mr-2">
<Input
+ data-testid="code-editor-font-size-input"
type="number"
className="m-0 w-20 inline-flex"
{...field}
@@ -258,6 +266,7 @@ export const UserConfigForm: React.FC = () => {
<FormLabel>Cell output area</FormLabel>
<FormControl>
<NativeSelect
+ data-testid="cell-output-select"
onChange={(e) => field.onChange(e.target.value)}
value={field.value}
disabled={field.disabled}
@@ -290,6 +299,7 @@ export const UserConfigForm: React.FC = () => {
<FormLabel>Manager</FormLabel>
<FormControl>
<NativeSelect
+ data-testid="package-manager-select"
onChange={(e) => field.onChange(e.target.value)}
value={field.value}
disabled={field.disabled}
@@ -316,6 +326,7 @@ export const UserConfigForm: React.FC = () => {
<FormItem className="flex flex-row items-start space-x-2 space-y-0">
<FormControl>
<Checkbox
+ data-testid="auto-instantiate-checkbox"
disabled={field.disabled}
checked={field.value}
onCheckedChange={field.onChange}
@@ -339,6 +350,7 @@ export const UserConfigForm: React.FC = () => {
<FormItem className="flex flex-row items-center space-x-2 space-y-0">
<FormControl>
<Switch
+ data-testid="copilot-switch"
size={"sm"}
checked={field.value}
disabled={field.disabled}
diff --git a/frontend/src/components/audio/audio-recorder.tsx b/frontend/src/components/audio/audio-recorder.tsx
index a0c36e56f0..bd9290bf4e 100644
--- a/frontend/src/components/audio/audio-recorder.tsx
+++ b/frontend/src/components/audio/audio-recorder.tsx
@@ -23,7 +23,12 @@ export const AudioRecorder: React.FC<AudioRecorderProps> = ({
return (
<div className="flex items-center gap-3">
{status === "stopped" && (
- <Button variant="secondary" onClick={onStart} className="w-[50px]">
+ <Button
+ data-testid="audio-recorder-start"
+ variant="secondary"
+ onClick={onStart}
+ className="w-[50px]"
+ >
<CircleIcon
className={cn("w-6 h-6 border border-input rounded-full")}
strokeWidth={1.5}
@@ -32,7 +37,12 @@ export const AudioRecorder: React.FC<AudioRecorderProps> = ({
</Button>
)}
{status === "recording" && (
- <Button variant="secondary" onClick={onStop} className="w-[50px]">
+ <Button
+ data-testid="audio-recorder-pause"
+ variant="secondary"
+ onClick={onStop}
+ className="w-[50px]"
+ >
<SquareIcon
className="w-5 h-5 rounded-sm"
fill="var(--red-9)"
diff --git a/frontend/src/components/data-table/column-header.tsx b/frontend/src/components/data-table/column-header.tsx
index 28133c92f8..95af9172d7 100644
--- a/frontend/src/components/data-table/column-header.tsx
+++ b/frontend/src/components/data-table/column-header.tsx
@@ -46,6 +46,7 @@ export const DataTableColumnHeader = <TData, TValue>({
<DropdownMenuTrigger asChild={true}>
<Button
variant="ghost"
+ data-testid="data-table-sort-button"
size="xs"
className={cn(
"ml-3 h-5 data-[state=open]:bg-accent m-0 p-1",
diff --git a/frontend/src/components/data-table/columns.tsx b/frontend/src/components/data-table/columns.tsx
index d103a2f865..3c3b7f46e6 100644
--- a/frontend/src/components/data-table/columns.tsx
+++ b/frontend/src/components/data-table/columns.tsx
@@ -97,6 +97,7 @@ export function generateColumns<T>(
header: ({ table }) =>
selection === "multi" ? (
<Checkbox
+ data-testid="select-all-checkbox"
checked={table.getIsAllPageRowsSelected()}
onCheckedChange={(value) =>
table.toggleAllPageRowsSelected(!!value)
@@ -107,6 +108,7 @@ export function generateColumns<T>(
) : null,
cell: ({ row }) => (
<Checkbox
+ data-testid="select-row-checkbox"
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
diff --git a/frontend/src/components/data-table/download-actions.tsx b/frontend/src/components/data-table/download-actions.tsx
index 072d835a31..ac9e692da4 100644
--- a/frontend/src/components/data-table/download-actions.tsx
+++ b/frontend/src/components/data-table/download-actions.tsx
@@ -22,7 +22,7 @@ const options = [
export const DownloadAs: React.FC<DownloadActionProps> = (props) => {
const button = (
- <Button size="xs" variant="link">
+ <Button data-testid="download-as-button" size="xs" variant="link">
Download <ChevronDownIcon className="w-3 h-3 ml-1" />
</Button>
);
diff --git a/frontend/src/components/data-table/pagination.tsx b/frontend/src/components/data-table/pagination.tsx
index ef893e6b55..43fefbecf6 100644
--- a/frontend/src/components/data-table/pagination.tsx
+++ b/frontend/src/components/data-table/pagination.tsx
@@ -28,6 +28,7 @@ export const DataTablePagination = <TData,>({
{selected} selected
<Button
size="xs"
+ data-testid="select-all-button"
variant="link"
onClick={() => table.toggleAllRowsSelected(true)}
>
@@ -43,6 +44,7 @@ export const DataTablePagination = <TData,>({
{selected} selected
<Button
size="xs"
+ data-testid="clear-selection-button"
variant="link"
onClick={() => table.toggleAllRowsSelected(false)}
>
@@ -54,7 +56,6 @@ export const DataTablePagination = <TData,>({
return `${count} items`;
};
-
const currentPage = Math.min(
table.getState().pagination.pageIndex + 1,
table.getPageCount(),
@@ -68,6 +69,7 @@ export const DataTablePagination = <TData,>({
<Button
size="xs"
variant="outline"
+ data-testid="first-page-button"
className="hidden h-6 w-6 p-0 lg:flex"
onClick={() => table.setPageIndex(0)}
disabled={!table.getCanPreviousPage()}
@@ -78,6 +80,7 @@ export const DataTablePagination = <TData,>({
<Button
size="xs"
variant="outline"
+ data-testid="previous-page-button"
className="h-6 w-6 p-0"
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
@@ -90,6 +93,7 @@ export const DataTablePagination = <TData,>({
<select
className="cursor-pointer border rounded"
value={currentPage}
+ data-testid="page-select"
onChange={(e) => table.setPageIndex(Number(e.target.value) - 1)}
>
{Array.from({ length: totalPages }, (_, i) => (
@@ -103,6 +107,7 @@ export const DataTablePagination = <TData,>({
<Button
size="xs"
variant="outline"
+ data-testid="next-page-button"
className="h-6 w-6 p-0"
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
@@ -113,6 +118,7 @@ export const DataTablePagination = <TData,>({
<Button
size="xs"
variant="outline"
+ data-testid="last-page-button"
className="hidden h-6 w-6 p-0 lg:flex"
onClick={() => table.setPageIndex(table.getPageCount() - 1)}
disabled={!table.getCanNextPage()}
diff --git a/frontend/src/components/debugger/debugger-code.tsx b/frontend/src/components/debugger/debugger-code.tsx
index dfcf500222..7593d7f4d9 100644
--- a/frontend/src/components/debugger/debugger-code.tsx
+++ b/frontend/src/components/debugger/debugger-code.tsx
@@ -151,6 +151,7 @@ const DebuggerControls: React.FC<{
<Button
variant="text"
size="icon"
+ data-testid="debugger-next-button"
className={cn(buttonClasses, "rounded-bl-lg")}
onClick={() => onSubmit("n")}
>
@@ -161,6 +162,7 @@ const DebuggerControls: React.FC<{
<Button
variant="text"
size="icon"
+ data-testid="debugger-continue-button"
onClick={() => onSubmit("c")}
className={cn(
buttonClasses,
@@ -174,6 +176,7 @@ const DebuggerControls: React.FC<{
<Button
variant="text"
size="icon"
+ data-testid="debugger-stack-button"
className={buttonClasses}
onClick={() => onSubmit("bt")}
>
@@ -184,6 +187,7 @@ const DebuggerControls: React.FC<{
<Button
variant="text"
size="icon"
+ data-testid="debugger-help-button"
className={buttonClasses}
onClick={() => onSubmit("help")}
>
diff --git a/frontend/src/components/editor/DirCompletionInput.tsx b/frontend/src/components/editor/DirCompletionInput.tsx
index 04436f42bb..36538aecaf 100644
--- a/frontend/src/components/editor/DirCompletionInput.tsx
+++ b/frontend/src/components/editor/DirCompletionInput.tsx
@@ -226,6 +226,7 @@ export const DirCompletionInput = ({
return (
<div className="DirCompletionInput">
<Input
+ data-testid="dir-completion-input"
type="text"
spellCheck="false"
value={displayValue}
diff --git a/frontend/src/components/editor/FilenameForm.tsx b/frontend/src/components/editor/FilenameForm.tsx
index e4ce777f5c..3573e5e6ae 100644
--- a/frontend/src/components/editor/FilenameForm.tsx
+++ b/frontend/src/components/editor/FilenameForm.tsx
@@ -120,6 +120,7 @@ export const FilenameForm = ({
/>
<Button
type="submit"
+ data-testid="filename-form-submit-button"
color={validName ? "green" : "gray"}
onMouseDown={handleMouseDown}
style={{
@@ -137,6 +138,7 @@ export const FilenameForm = ({
</Button>
<Button
color="gray"
+ data-testid="filename-form-cancel-button"
style={{
marginRight: "0px",
padding: "0px",
diff --git a/frontend/src/components/editor/Output.tsx b/frontend/src/components/editor/Output.tsx
index 888781678e..e6729df879 100644
--- a/frontend/src/components/editor/Output.tsx
+++ b/frontend/src/components/editor/Output.tsx
@@ -172,6 +172,7 @@ const ExpandableOutput = React.memo(
{(isOverflowing || isExpanded) && (
<div className="relative">
<Button
+ data-testid="expand-output-button"
className={cn(
"absolute top-6 -right-12 z-10",
// Force show button if expanded
diff --git a/frontend/src/components/editor/RecoveryButton.tsx b/frontend/src/components/editor/RecoveryButton.tsx
index 2d3807b97b..126afc5255 100644
--- a/frontend/src/components/editor/RecoveryButton.tsx
+++ b/frontend/src/components/editor/RecoveryButton.tsx
@@ -70,11 +70,17 @@ const RecoveryModal = (props: {
<Button
aria-label="Cancel"
variant="secondary"
+ data-testid="cancel-recovery-button"
onClick={props.closeModal}
>
Cancel
</Button>
- <Button aria-label="Download" variant="default" type="submit">
+ <Button
+ data-testid="download-recovery-button"
+ aria-label="Download"
+ variant="default"
+ type="submit"
+ >
Download
</Button>
</DialogFooter>
diff --git a/frontend/src/components/editor/actions/name-cell-input.tsx b/frontend/src/components/editor/actions/name-cell-input.tsx
index bee0f0e2c3..a9a348d3c2 100644
--- a/frontend/src/components/editor/actions/name-cell-input.tsx
+++ b/frontend/src/components/editor/actions/name-cell-input.tsx
@@ -45,6 +45,7 @@ export const NameCellInput: React.FC<Props> = ({
return (
<Input
+ data-testid="cell-name-input"
value={inputProps.value}
onChange={inputProps.onChange}
ref={ref}
diff --git a/frontend/src/components/editor/actions/useCellActionButton.tsx b/frontend/src/components/editor/actions/useCellActionButton.tsx
index f7c9e67940..dc73300095 100644
--- a/frontend/src/components/editor/actions/useCellActionButton.tsx
+++ b/frontend/src/components/editor/actions/useCellActionButton.tsx
@@ -160,6 +160,7 @@ export function useCellActionButtons({
label: config.disabled === true ? "Enable cell" : "Disable cell",
rightElement: (
<Switch
+ data-testid="cell-disable-switch"
checked={!config.disabled}
size="sm"
onCheckedChange={toggleDisabled}
diff --git a/frontend/src/components/editor/boundary/ErrorBoundary.tsx b/frontend/src/components/editor/boundary/ErrorBoundary.tsx
index f3f4392301..dc7dd7a96a 100644
--- a/frontend/src/components/editor/boundary/ErrorBoundary.tsx
+++ b/frontend/src/components/editor/boundary/ErrorBoundary.tsx
@@ -34,7 +34,11 @@ const FallbackComponent: React.FC<FallbackProps> = (props) => {
</a>
.
</div>
- <Button onClick={props.resetErrorBoundary} variant="outline">
+ <Button
+ data-testid="reset-error-boundary-button"
+ onClick={props.resetErrorBoundary}
+ variant="outline"
+ >
Try again
</Button>
</div>
diff --git a/frontend/src/components/editor/cell/code/ai-completion-editor.tsx b/frontend/src/components/editor/cell/code/ai-completion-editor.tsx
index 2795f722eb..32a2509135 100644
--- a/frontend/src/components/editor/cell/code/ai-completion-editor.tsx
+++ b/frontend/src/components/editor/cell/code/ai-completion-editor.tsx
@@ -112,13 +112,20 @@ export const AiCompletionEditor: React.FC<Props> = ({
}}
/>
{isLoading && (
- <Button variant="text" size="xs" className="mb-0" onClick={stop}>
+ <Button
+ data-testid="stop-completion-button"
+ variant="text"
+ size="xs"
+ className="mb-0"
+ onClick={stop}
+ >
<Loader2Icon className="animate-spin mr-1" size={14} />
Stop
</Button>
)}
{!isLoading && completion && (
<Button
+ data-testid="accept-completion-button"
variant="text"
size="xs"
className="mb-0"
@@ -135,6 +142,7 @@ export const AiCompletionEditor: React.FC<Props> = ({
<Tooltip content="Include code from other cells">
<div className="flex flex-row items-start gap-1">
<Checkbox
+ data-testid="include-other-cells-checkbox"
id="include-other-cells"
checked={includeOtherCells}
onCheckedChange={(checked) =>
@@ -150,6 +158,7 @@ export const AiCompletionEditor: React.FC<Props> = ({
</div>
</Tooltip>
<Button
+ data-testid="decline-completion-button"
variant="text"
size="icon"
disabled={isLoading}
diff --git a/frontend/src/components/editor/cell/code/language-toggle.tsx b/frontend/src/components/editor/cell/code/language-toggle.tsx
index f712f47eb0..64efa40c07 100644
--- a/frontend/src/components/editor/cell/code/language-toggle.tsx
+++ b/frontend/src/components/editor/cell/code/language-toggle.tsx
@@ -33,7 +33,12 @@ export const LanguageToggle: React.FC<Props> = ({
return (
<div className="absolute top-0 right-5 z-20 hover-action">
<Tooltip content={`View as ${startCase(otherLanguage)}`}>
- <Button variant="text" size="xs" className="opacity-80">
+ <Button
+ data-testid="language-toggle-button"
+ variant="text"
+ size="xs"
+ className="opacity-80"
+ >
<Icon
className="cursor-pointer"
fill={"var(--sky-11)"}
diff --git a/frontend/src/components/editor/chrome/footer/feedback-button.tsx b/frontend/src/components/editor/chrome/footer/feedback-button.tsx
index d1c6f0fcb2..aba5f950d6 100644
--- a/frontend/src/components/editor/chrome/footer/feedback-button.tsx
+++ b/frontend/src/components/editor/chrome/footer/feedback-button.tsx
@@ -115,10 +115,19 @@ const FeedbackModal: React.FC<{
/>
</div>
<DialogFooter>
- <Button variant="secondary" onClick={onClose}>
+ <Button
+ data-testid="feedback-cancel-button"
+ variant="secondary"
+ onClick={onClose}
+ >
Cancel
</Button>
- <Button aria-label="Save" variant="default" type="submit">
+ <Button
+ data-testid="feedback-send-button"
+ aria-label="Save"
+ variant="default"
+ type="submit"
+ >
Send
</Button>
</DialogFooter>
diff --git a/frontend/src/components/editor/chrome/panels/logs-panel.tsx b/frontend/src/components/editor/chrome/panels/logs-panel.tsx
index 06ef08ce3a..7b0193a9d1 100644
--- a/frontend/src/components/editor/chrome/panels/logs-panel.tsx
+++ b/frontend/src/components/editor/chrome/panels/logs-panel.tsx
@@ -28,6 +28,7 @@ export const LogsPanel: React.FC = () => {
<>
<div className="flex flex-row justify-end px-2 py-1">
<button
+ data-testid="clear-logs-button"
className="text-xs font-semibold text-accent-foreground"
onClick={clearLogs}
>
diff --git a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
index bbae0f61d3..a73135d46b 100644
--- a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
+++ b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
@@ -82,6 +82,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
{selectedPanel}
</div>
<Button
+ data-testid="close-helper-pane"
className="m-0"
size="xs"
variant="text"
diff --git a/frontend/src/components/editor/controls/Controls.tsx b/frontend/src/components/editor/controls/Controls.tsx
index d059069434..32ba0a0606 100644
--- a/frontend/src/components/editor/controls/Controls.tsx
+++ b/frontend/src/components/editor/controls/Controls.tsx
@@ -71,6 +71,7 @@ export const Controls = ({
undoControl = (
<Tooltip content="Undo cell deletion">
<Button
+ data-testid="undo-delete-cell"
size="medium"
color="hint-green"
shape="circle"
@@ -118,6 +119,7 @@ export const Controls = ({
) : (
<Tooltip content={renderShortcut("global.save")}>
<Button
+ data-testid="save-button"
id="save-button"
shape="rectangle"
color={needsSave ? "yellow" : "hint-green"}
@@ -130,6 +132,7 @@ export const Controls = ({
<Tooltip content={renderShortcut("global.hideCode")}>
<Button
+ data-testid="hide-code-button"
id="preview-button"
shape="rectangle"
color="white"
@@ -180,6 +183,7 @@ const RunControlButton = ({
return (
<Tooltip content={renderShortcut("global.interrupt")}>
<Button
+ data-testid="interrupt-button"
size="medium"
color="yellow"
shape="circle"
@@ -192,7 +196,13 @@ const RunControlButton = ({
} else if (needsRun) {
return (
<Tooltip content={renderShortcut("global.runStale")}>
- <Button size="medium" color="yellow" shape="circle" onClick={onRun}>
+ <Button
+ data-testid="run-button"
+ size="medium"
+ color="yellow"
+ shape="circle"
+ onClick={onRun}
+ >
<PlayIcon strokeWidth={1.5} size={16} />
</Button>
</Tooltip>
@@ -202,6 +212,7 @@ const RunControlButton = ({
return (
<Tooltip content="Nothing to run">
<Button
+ data-testid="run-button"
className={"inactive-button"}
color="disabled"
size="medium"
diff --git a/frontend/src/components/editor/controls/command-palette-button.tsx b/frontend/src/components/editor/controls/command-palette-button.tsx
index a4ae4d1dd3..7e934b639e 100644
--- a/frontend/src/components/editor/controls/command-palette-button.tsx
+++ b/frontend/src/components/editor/controls/command-palette-button.tsx
@@ -13,7 +13,12 @@ export const CommandPaletteButton: React.FC = () => {
return (
<Tooltip content={renderShortcut("global.commandPalette")}>
- <Button onClick={toggle} shape="rectangle" color="white">
+ <Button
+ data-testid="command-palette-button"
+ onClick={toggle}
+ shape="rectangle"
+ color="white"
+ >
<CommandIcon strokeWidth={1.5} />
</Button>
</Tooltip>
diff --git a/frontend/src/components/editor/controls/shutdown-button.tsx b/frontend/src/components/editor/controls/shutdown-button.tsx
index 6839e193c8..196bfeccbb 100644
--- a/frontend/src/components/editor/controls/shutdown-button.tsx
+++ b/frontend/src/components/editor/controls/shutdown-button.tsx
@@ -17,6 +17,7 @@ export const ShutdownButton: React.FC<Props> = ({ onShutdown }) => {
<Tooltip content="Shutdown">
<Button
aria-label="Shutdown"
+ data-testid="shutdown-button"
shape="circle"
size="small"
color="red"
diff --git a/frontend/src/components/editor/file-tree/file-explorer.tsx b/frontend/src/components/editor/file-tree/file-explorer.tsx
index 4f4dae189e..95ef0b6b18 100644
--- a/frontend/src/components/editor/file-tree/file-explorer.tsx
+++ b/frontend/src/components/editor/file-tree/file-explorer.tsx
@@ -61,6 +61,7 @@ export const FileExplorer: React.FC<{
<div className="flex items-center pl-1 pr-3 flex-shrink-0 border-b justify-between">
<Button
onClick={() => setOpenFile(null)}
+ data-testid="file-explorer-back-button"
variant="text"
size="xs"
className="mb-0"
@@ -139,6 +140,7 @@ const Toolbar = ({ onRefresh }: { onRefresh: () => void }) => {
<div className="flex items-center justify-end px-2 flex-shrink-0 border-b">
<Tooltip content="Upload file">
<button
+ data-testid="file-explorer-upload-button"
{...getRootProps({})}
className={buttonVariants({
variant: "text",
@@ -151,7 +153,13 @@ const Toolbar = ({ onRefresh }: { onRefresh: () => void }) => {
</Tooltip>
<input {...getInputProps({})} type="file" />
<Tooltip content="Refresh">
- <Button onClick={onRefresh} variant="text" size="xs" className="mb-0">
+ <Button
+ data-testid="file-explorer-refresh-button"
+ onClick={onRefresh}
+ variant="text"
+ size="xs"
+ className="mb-0"
+ >
<RefreshCcwIcon size={16} />
</Button>
</Tooltip>
@@ -264,6 +272,7 @@ const Node = ({ node, style, dragHandle }: NodeRendererProps<FileInfo>) => {
onClick={(e) => e.stopPropagation()}
>
<Button
+ data-testid="file-explorer-more-button"
variant="text"
tabIndex={-1}
size="xs"
diff --git a/frontend/src/components/editor/notebook-banner.tsx b/frontend/src/components/editor/notebook-banner.tsx
index b1d4a5224c..a91146953f 100644
--- a/frontend/src/components/editor/notebook-banner.tsx
+++ b/frontend/src/components/editor/notebook-banner.tsx
@@ -29,6 +29,7 @@ export const NotebookBanner: React.FC = (props) => {
{banner.title}
</span>
<Button
+ data-testid="remove-banner-button"
variant="text"
size="icon"
onClick={() => removeBanner(banner.id)}
@@ -49,7 +50,12 @@ export const NotebookBanner: React.FC = (props) => {
const RestartSessionButton = () => {
const restartKernel = useRestartKernel();
return (
- <Button variant="link" size="sm" onClick={restartKernel}>
+ <Button
+ data-testid="restart-session-button"
+ variant="link"
+ size="sm"
+ onClick={restartKernel}
+ >
<RotateCcwIcon className="w-4 h-4 mr-2" />
Restart
</Button>
diff --git a/frontend/src/components/editor/output/ConsoleOutput.tsx b/frontend/src/components/editor/output/ConsoleOutput.tsx
index 252eb5f839..007d2b6fba 100644
--- a/frontend/src/components/editor/output/ConsoleOutput.tsx
+++ b/frontend/src/components/editor/output/ConsoleOutput.tsx
@@ -93,6 +93,7 @@ export const ConsoleOutput = (props: Props): React.ReactNode => {
<div key={idx} className="flex gap-2 items-center">
{renderText(output.data)}
<Input
+ data-testid="console-input"
type="text"
autoComplete="off"
autoFocus={true}
diff --git a/frontend/src/components/editor/package-alert.tsx b/frontend/src/components/editor/package-alert.tsx
index 4354e85ee4..767857694a 100644
--- a/frontend/src/components/editor/package-alert.tsx
+++ b/frontend/src/components/editor/package-alert.tsx
@@ -49,6 +49,7 @@ export const PackageAlert: React.FC = (props) => {
</span>
<Button
variant="text"
+ data-testid="remove-banner-button"
size="icon"
onClick={() => clearPackageAlert(packageAlert.id)}
>
@@ -116,6 +117,7 @@ export const PackageAlert: React.FC = (props) => {
</span>
<Button
variant="text"
+ data-testid="remove-banner-button"
size="icon"
onClick={() => clearPackageAlert(packageAlert.id)}
>
@@ -247,6 +249,7 @@ const InstallPackagesButton = ({
return (
<Button
variant="outline"
+ data-testid="install-packages-button"
size="sm"
onClick={() => installPackages(packages, manager, addPackageAlert)}
>
diff --git a/frontend/src/components/editor/renderers/grid-layout/grid-layout.tsx b/frontend/src/components/editor/renderers/grid-layout/grid-layout.tsx
index 81a3b46bf1..fca54540fa 100644
--- a/frontend/src/components/editor/renderers/grid-layout/grid-layout.tsx
+++ b/frontend/src/components/editor/renderers/grid-layout/grid-layout.tsx
@@ -386,6 +386,7 @@ const GridControls: React.FC<{
<div className="flex flex-row items-center gap-2">
<Label htmlFor="columns">Columns</Label>
<Input
+ data-testid="grid-columns-input"
id="columns"
type="number"
value={layout.columns}
@@ -403,6 +404,7 @@ const GridControls: React.FC<{
<div className="flex flex-row items-center gap-2">
<Label htmlFor="rowHeight">Row Height (px)</Label>
<Input
+ data-testid="grid-row-height-input"
id="rowHeight"
type="number"
value={layout.rowHeight}
@@ -420,6 +422,7 @@ const GridControls: React.FC<{
<div className="flex flex-row items-center gap-2">
<Label htmlFor="maxWidth">Max Width (px)</Label>
<Input
+ data-testid="grid-max-width-input"
id="maxWidth"
type="number"
value={layout.maxWidth}
@@ -440,6 +443,7 @@ const GridControls: React.FC<{
Bordered
</Label>
<Switch
+ data-testid="grid-bordered-switch"
id="lock"
checked={layout.bordered}
size="sm"
@@ -457,6 +461,7 @@ const GridControls: React.FC<{
Lock Grid
</Label>
<Switch
+ data-testid="grid-lock-switch"
id="lock"
checked={isLocked}
size="sm"
@@ -604,6 +609,7 @@ const GridHoverActions: React.FC<GridHoverActionsProps> = ({
<DropdownMenuItem onSelect={() => setIsScrollable(!isScrollable)}>
<span className="flex-1">Scrollable</span>
<Switch
+ data-testid="grid-scrollable-switch"
checked={isScrollable}
size="sm"
onCheckedChange={setIsScrollable}
diff --git a/frontend/src/components/editor/renderers/layout-select.tsx b/frontend/src/components/editor/renderers/layout-select.tsx
index 24a38ba1bf..1100293a05 100644
--- a/frontend/src/components/editor/renderers/layout-select.tsx
+++ b/frontend/src/components/editor/renderers/layout-select.tsx
@@ -26,6 +26,7 @@ export const LayoutSelect: React.FC = () => {
return (
<Select
+ data-testid="layout-select"
value={layoutType}
onValueChange={(v) => setLayoutType(v as LayoutType)}
>
diff --git a/frontend/src/components/find-replace/find-replace.tsx b/frontend/src/components/find-replace/find-replace.tsx
index ebb598d17a..de963319f2 100644
--- a/frontend/src/components/find-replace/find-replace.tsx
+++ b/frontend/src/components/find-replace/find-replace.tsx
@@ -105,6 +105,7 @@ export const FindReplace: React.FC = () => {
>
<div className="absolute top-0 right-0">
<Button
+ data-testid="close-find-replace-button"
onClick={() => dispatch({ type: "setIsOpen", isOpen: false })}
size="xs"
variant="text"
@@ -115,6 +116,7 @@ export const FindReplace: React.FC = () => {
<div className="flex items-center gap-3">
<div className="flex flex-col flex-2 gap-2 w-[55%]">
<Input
+ data-testid="find-input"
value={state.findText}
autoFocus={true}
className="mr-2 mb-0"
@@ -133,6 +135,7 @@ export const FindReplace: React.FC = () => {
}}
/>
<Input
+ data-testid="replace-input"
value={state.replaceText}
placeholder="Replace"
onChange={(e) => {
@@ -184,6 +187,7 @@ export const FindReplace: React.FC = () => {
</div>
<div className="flex items-center gap-[2px]">
<Button
+ data-testid="replace-next-button"
size="xs"
variant="outline"
className="h-6 text-xs"
@@ -193,6 +197,7 @@ export const FindReplace: React.FC = () => {
Replace Next
</Button>
<Button
+ data-testid="replace-all-button"
size="xs"
variant="outline"
className="h-6 text-xs"
@@ -207,6 +212,7 @@ export const FindReplace: React.FC = () => {
title: "Replaced all occurrences",
action: (
<Button
+ data-testid="undo-replace-all-button"
size="sm"
variant="outline"
onClick={() => {
@@ -228,12 +234,22 @@ export const FindReplace: React.FC = () => {
</div>
<div className="flex items-center gap-2">
<Tooltip content="Find Previous">
- <Button size="xs" variant="secondary" onClick={() => findPrev()}>
+ <Button
+ data-testid="find-prev-button"
+ size="xs"
+ variant="secondary"
+ onClick={() => findPrev()}
+ >
<ArrowLeftIcon className="w-4 h-4" />
</Button>
</Tooltip>
<Tooltip content="Find Next">
- <Button size="xs" variant="secondary" onClick={() => findNext()}>
+ <Button
+ data-testid="find-next-button"
+ size="xs"
+ variant="secondary"
+ onClick={() => findNext()}
+ >
<ArrowRightIcon className="w-4 h-4" />
</Button>
</Tooltip>
diff --git a/frontend/src/components/static-html/share-modal.tsx b/frontend/src/components/static-html/share-modal.tsx
index 667bd1cd09..2018f007ef 100644
--- a/frontend/src/components/static-html/share-modal.tsx
+++ b/frontend/src/components/static-html/share-modal.tsx
@@ -100,6 +100,7 @@ export const ShareStaticNotebookModal: React.FC<{
</DialogHeader>
<div className="flex flex-col gap-6 py-4">
<Input
+ data-testid="slug-input"
id="slug"
autoFocus={true}
value={slug}
@@ -124,10 +125,15 @@ export const ShareStaticNotebookModal: React.FC<{
</div>
</div>
<DialogFooter>
- <Button variant="secondary" onClick={onClose}>
+ <Button
+ data-testid="cancel-share-static-notebook-button"
+ variant="secondary"
+ onClick={onClose}
+ >
Cancel
</Button>
<Button
+ data-testid="share-static-notebook-button"
aria-label="Save"
variant="default"
type="submit"
@@ -155,7 +161,12 @@ const CopyButton = (props: { text: string }) => {
return (
<Tooltip content="Copied!" open={copied}>
- <Button onClick={copy} size="xs" variant="secondary">
+ <Button
+ data-testid="copy-static-notebook-url-button"
+ onClick={copy}
+ size="xs"
+ variant="secondary"
+ >
<CopyIcon size={14} strokeWidth={1.5} />
</Button>
</Tooltip>
diff --git a/frontend/src/components/static-html/static-banner.tsx b/frontend/src/components/static-html/static-banner.tsx
index 8bb4b41617..c8415e04d3 100644
--- a/frontend/src/components/static-html/static-banner.tsx
+++ b/frontend/src/components/static-html/static-banner.tsx
@@ -62,7 +62,12 @@ const StaticBannerDialog = () => {
return (
<Dialog>
<DialogTrigger asChild={true}>
- <Button variant="secondary">Run or edit this notebook</Button>
+ <Button
+ data-testid="static-notebook-dialog-trigger"
+ variant="secondary"
+ >
+ Run or edit this notebook
+ </Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
@@ -113,6 +118,7 @@ const StaticBannerDialog = () => {
</DialogHeader>
<div className="flex gap-4 flex-wrap">
<Button
+ data-testid="copy-static-notebook-dialog-button"
variant="secondary"
onClick={() => {
window.navigator.clipboard.writeText(code);
@@ -123,6 +129,7 @@ const StaticBannerDialog = () => {
Copy code
</Button>
<Button
+ data-testid="download-static-notebook-dialog-button"
variant="secondary"
onClick={() => {
downloadBlob(new Blob([code], { type: "text/plain" }), filename);
diff --git a/frontend/src/core/App.tsx b/frontend/src/core/App.tsx
index 33a181d592..935b1997b6 100644
--- a/frontend/src/core/App.tsx
+++ b/frontend/src/core/App.tsx
@@ -447,13 +447,19 @@ const SaveDialog = (props: {
</div>
<DialogFooter>
<Button
+ data-testid="cancel-save-dialog-button"
aria-label={cancelButtonLabel}
variant="secondary"
onClick={onClose}
>
Cancel
</Button>
- <Button aria-label="Save" variant="default" type="submit">
+ <Button
+ data-testid="submit-save-dialog-button"
+ aria-label="Save"
+ variant="default"
+ type="submit"
+ >
Save
</Button>
</DialogFooter>
diff --git a/frontend/src/core/config/config-schema.ts b/frontend/src/core/config/config-schema.ts
index 23ee0a1a2b..45e86cf957 100644
--- a/frontend/src/core/config/config-schema.ts
+++ b/frontend/src/core/config/config-schema.ts
@@ -5,9 +5,6 @@ import {
getRawMarimoAppConfig,
getRawMarimoUserConfig,
} from "../dom/marimo-tag";
-import { ZodLocalStorage } from "@/utils/localStorage";
-import { isPyodide } from "../pyodide/utils";
-import { repl } from "@/utils/repl";
export const UserConfigSchema = z
.object({
@@ -102,15 +99,6 @@ export function parseAppConfig() {
}
export function parseUserConfig(): UserConfig {
- // For Pyodide, we use the local storage to store the user config.
- if (isPyodide()) {
- return UserConfigLocalStorage.get();
- }
-
- return parseUserConfigDOM();
-}
-
-function parseUserConfigDOM(): UserConfig {
try {
const parsed = UserConfigSchema.parse(JSON.parse(getRawMarimoUserConfig()));
for (const [key, value] of Object.entries(parsed.experimental)) {
@@ -126,20 +114,3 @@ function parseUserConfigDOM(): UserConfig {
return UserConfigSchema.parse({});
}
}
-
-export const UserConfigLocalStorage = new ZodLocalStorage<UserConfig>(
- "marimo:user-config",
- UserConfigSchema,
- () => parseUserConfigDOM(),
-);
-
-function setFeatureFlag(
- feature: keyof UserConfig["experimental"],
- value: boolean,
-) {
- const userConfig = UserConfigLocalStorage.get();
- userConfig.experimental[feature] = value;
- UserConfigLocalStorage.set(userConfig);
-}
-
-repl(setFeatureFlag, "setFeatureFlag");
diff --git a/frontend/src/core/config/feature-flag.ts b/frontend/src/core/config/feature-flag.ts
index 95a59bbda0..a787d3f9da 100644
--- a/frontend/src/core/config/feature-flag.ts
+++ b/frontend/src/core/config/feature-flag.ts
@@ -1,5 +1,8 @@
/* Copyright 2024 Marimo. All rights reserved. */
+import { repl } from "@/utils/repl";
+import { UserConfig } from "vite";
+import { saveUserConfig } from "../network/requests";
import { getUserConfig } from "./config";
// eslint-disable-next-line @typescript-eslint/no-empty-interface
@@ -17,3 +20,15 @@ export function getFeatureFlag<T extends keyof ExperimentalFeatures>(
): ExperimentalFeatures[T] {
return getUserConfig().experimental?.[feature] ?? defaultValues[feature];
}
+
+function setFeatureFlag(
+ feature: keyof UserConfig["experimental"],
+ value: boolean,
+) {
+ const userConfig = getUserConfig();
+ userConfig.experimental[feature] = value;
+ saveUserConfig({ config: userConfig });
+}
+
+// Allow setting feature flags from the console
+repl(setFeatureFlag, "setFeatureFlag");
diff --git a/frontend/src/core/network/api.ts b/frontend/src/core/network/api.ts
index 89296471de..14db004a8d 100644
--- a/frontend/src/core/network/api.ts
+++ b/frontend/src/core/network/api.ts
@@ -13,15 +13,22 @@ const getServerTokenOnce = once(() => {
* strong types.
*/
export const API = {
- post<REQ, RESP = null>(url: string, body: REQ): Promise<RESP> {
- const BASE_URL = `${document.baseURI}api`;
-
- const fullUrl = BASE_URL + url;
+ post<REQ, RESP = null>(
+ url: string,
+ body: REQ,
+ opts: {
+ headers?: Record<string, string>;
+ baseUrl?: string;
+ } = {},
+ ): Promise<RESP> {
+ const baseUrl = opts.baseUrl ?? document.baseURI;
+ const fullUrl = `${baseUrl}api${url}`;
return fetch(fullUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
...API.headers(),
+ ...opts.headers,
},
body: JSON.stringify(body),
})
diff --git a/frontend/src/core/pyodide/bridge.ts b/frontend/src/core/pyodide/bridge.ts
index 16d0f900dd..ac4bc53b27 100644
--- a/frontend/src/core/pyodide/bridge.ts
+++ b/frontend/src/core/pyodide/bridge.ts
@@ -29,12 +29,12 @@ import { IReconnectingWebSocket } from "../websocket/types";
import { fallbackFileStore, notebookFileStore } from "./store";
import { isPyodide } from "./utils";
import { Deferred } from "@/utils/Deferred";
-import { UserConfigLocalStorage } from "../config/config-schema";
import { createShareableLink } from "./share";
import { PyodideRouter } from "./router";
import { Paths } from "@/utils/paths";
import { getMarimoVersion } from "../dom/marimo-tag";
import { getWorkerRPC } from "./rpc";
+import { API } from "../network/api";
export class PyodideBridge implements RunRequests, EditRequests {
static INSTANCE = new PyodideBridge();
@@ -201,8 +201,11 @@ export class PyodideBridge implements RunRequests, EditRequests {
};
saveUserConfig = async (request: SaveUserConfigRequest): Promise<null> => {
- UserConfigLocalStorage.set(request.config);
- return null;
+ return API.post<SaveUserConfigRequest>(
+ "/kernel/save_user_config",
+ request,
+ { baseUrl: "/" },
+ );
};
saveAppConfig = async (request: SaveAppConfigRequest): Promise<null> => {
diff --git a/frontend/src/plugins/impl/ButtonPlugin.tsx b/frontend/src/plugins/impl/ButtonPlugin.tsx
index 2abf87ddad..4cc7fb9643 100644
--- a/frontend/src/plugins/impl/ButtonPlugin.tsx
+++ b/frontend/src/plugins/impl/ButtonPlugin.tsx
@@ -34,6 +34,7 @@ export class ButtonPlugin implements IPlugin<number, Data> {
// value counts number of times button was clicked
const button = (
<Button
+ data-testid="marimo-plugin-button"
variant={kindToButtonVariant(kind)}
disabled={disabled}
size="xs"
diff --git a/frontend/src/plugins/impl/CheckboxPlugin.tsx b/frontend/src/plugins/impl/CheckboxPlugin.tsx
index 3c316d54f1..3062a783c5 100644
--- a/frontend/src/plugins/impl/CheckboxPlugin.tsx
+++ b/frontend/src/plugins/impl/CheckboxPlugin.tsx
@@ -38,7 +38,12 @@ const CheckboxComponent = ({
return (
<Labeled label={data.label} align="right" id={id}>
- <Checkbox checked={value} onCheckedChange={onClick} id={id} />
+ <Checkbox
+ data-testid="marimo-plugin-checkbox"
+ checked={value}
+ onCheckedChange={onClick}
+ id={id}
+ />
</Labeled>
);
};
diff --git a/frontend/src/plugins/impl/DatePickerPlugin.tsx b/frontend/src/plugins/impl/DatePickerPlugin.tsx
index db72004df3..7fdfe378f6 100644
--- a/frontend/src/plugins/impl/DatePickerPlugin.tsx
+++ b/frontend/src/plugins/impl/DatePickerPlugin.tsx
@@ -69,6 +69,7 @@ const DatePicker = (props: DatePickerProps): JSX.Element => {
return (
<Labeled label={props.label} id={id} fullWidth={props.fullWidth}>
<Input
+ data-testid="marimo-plugin-date-picker"
ref={inputRef}
type="date"
className={cn({
diff --git a/frontend/src/plugins/impl/DropdownPlugin.tsx b/frontend/src/plugins/impl/DropdownPlugin.tsx
index 0b3723e723..e590aff16d 100644
--- a/frontend/src/plugins/impl/DropdownPlugin.tsx
+++ b/frontend/src/plugins/impl/DropdownPlugin.tsx
@@ -61,6 +61,7 @@ const Dropdown = (props: DropdownProps): JSX.Element => {
return (
<Labeled label={label} id={id} fullWidth={fullWidth}>
<NativeSelect
+ data-testid="marimo-plugin-dropdown"
onChange={(e) => {
const newValue = e.target.value;
if (newValue === EMPTY_VALUE) {
diff --git a/frontend/src/plugins/impl/FileUploadPlugin.tsx b/frontend/src/plugins/impl/FileUploadPlugin.tsx
index 33e5b8096c..253e64f330 100644
--- a/frontend/src/plugins/impl/FileUploadPlugin.tsx
+++ b/frontend/src/plugins/impl/FileUploadPlugin.tsx
@@ -182,6 +182,7 @@ export const FileUpload = (props: FileUploadProps): JSX.Element => {
return (
<>
<button
+ data-testid="marimo-plugin-file-upload-button"
{...getRootProps({})}
className={buttonVariants({
variant: "secondary",
diff --git a/frontend/src/plugins/impl/FormPlugin.tsx b/frontend/src/plugins/impl/FormPlugin.tsx
index 7f21541e59..e330c73bf5 100644
--- a/frontend/src/plugins/impl/FormPlugin.tsx
+++ b/frontend/src/plugins/impl/FormPlugin.tsx
@@ -170,6 +170,7 @@ export const FormWrapper = <T,>({
{showClearButton &&
withTooltip(
<Button
+ data-testid="marimo-plugin-form-clear-button"
variant="text"
onClick={(e) => {
e.preventDefault();
@@ -182,6 +183,7 @@ export const FormWrapper = <T,>({
)}
{withTooltip(
<Button
+ data-testid="marimo-plugin-form-submit-button"
variant={variant}
disabled={submitButtonDisabled || loading}
type="submit"
diff --git a/frontend/src/plugins/impl/NumberPlugin.tsx b/frontend/src/plugins/impl/NumberPlugin.tsx
index ad72b06825..6bbd26bd78 100644
--- a/frontend/src/plugins/impl/NumberPlugin.tsx
+++ b/frontend/src/plugins/impl/NumberPlugin.tsx
@@ -63,6 +63,7 @@ const NumberComponent = (props: NumberComponentProps): JSX.Element => {
return (
<Labeled label={props.label} id={id} fullWidth={props.fullWidth}>
<Input
+ data-testid="marimo-plugin-number-input"
className={cn("min-w-[3em]", props.fullWidth && "w-full")}
ref={inputRef}
type="number"
diff --git a/frontend/src/plugins/impl/RadioPlugin.tsx b/frontend/src/plugins/impl/RadioPlugin.tsx
index 1b79011ada..f5ff1e0412 100644
--- a/frontend/src/plugins/impl/RadioPlugin.tsx
+++ b/frontend/src/plugins/impl/RadioPlugin.tsx
@@ -52,6 +52,7 @@ export const Radio = (props: RadioProps): JSX.Element => {
return (
<Labeled label={props.label} id={id} align={props.inline ? "left" : "top"}>
<RadioGroup
+ data-testid="marimo-plugin-radio"
value={props.value ?? ""}
onValueChange={props.setValue}
className={cn(props.inline && "grid-flow-col gap-4")}
diff --git a/frontend/src/plugins/impl/RefreshPlugin.tsx b/frontend/src/plugins/impl/RefreshPlugin.tsx
index 4029859d20..efc20021ba 100644
--- a/frontend/src/plugins/impl/RefreshPlugin.tsx
+++ b/frontend/src/plugins/impl/RefreshPlugin.tsx
@@ -119,6 +119,7 @@ const RefreshComponent = ({ setValue, data }: IPluginProps<Value, Data>) => {
<Labeled label={data.label}>
<span className="inline-flex items-center text-secondary-foreground rounded shadow-smSolid">
<Button
+ data-testid="marimo-plugin-refresh-button"
variant="secondary"
size="icon"
className={cn(
@@ -133,6 +134,7 @@ const RefreshComponent = ({ setValue, data }: IPluginProps<Value, Data>) => {
/>
</Button>
<NativeSelect
+ data-testid="marimo-plugin-refresh-select"
onChange={(e) => {
setSelected(e.target.value);
}}
diff --git a/frontend/src/plugins/impl/SwitchPlugin.tsx b/frontend/src/plugins/impl/SwitchPlugin.tsx
index 57d66a27aa..eeb88d7804 100644
--- a/frontend/src/plugins/impl/SwitchPlugin.tsx
+++ b/frontend/src/plugins/impl/SwitchPlugin.tsx
@@ -31,6 +31,7 @@ const SwitchComponent = ({
return (
<Labeled label={data.label} align="right" id={id} labelClassName="ml-1">
<Switch
+ data-testid="marimo-plugin-switch"
checked={value}
onCheckedChange={setValue}
id={id}
diff --git a/frontend/src/plugins/impl/TextInputPlugin.tsx b/frontend/src/plugins/impl/TextInputPlugin.tsx
index 0f7ed3165a..d6f4fbf9ea 100644
--- a/frontend/src/plugins/impl/TextInputPlugin.tsx
+++ b/frontend/src/plugins/impl/TextInputPlugin.tsx
@@ -74,6 +74,7 @@ const TextComponent = (props: TextComponentProps) => {
return (
<Labeled label={props.label} fullWidth={props.fullWidth}>
<Input
+ data-testid="marimo-plugin-text-input"
type={props.kind}
icon={icon[props.kind]}
placeholder={props.placeholder}
diff --git a/frontend/src/plugins/impl/data-explorer/DataExplorerPlugin.tsx b/frontend/src/plugins/impl/data-explorer/DataExplorerPlugin.tsx
index 6db1931f8b..1a2c66c03f 100644
--- a/frontend/src/plugins/impl/data-explorer/DataExplorerPlugin.tsx
+++ b/frontend/src/plugins/impl/data-explorer/DataExplorerPlugin.tsx
@@ -196,6 +196,7 @@ export const DataExplorerComponent = ({
actions={
<Tooltip content="Make main plot">
<Button
+ data-testid="marimo-plugin-data-explorer-make-main-plot"
variant="text"
size={"icon"}
onClick={() => {
diff --git a/frontend/src/plugins/impl/data-explorer/components/column-summary.tsx b/frontend/src/plugins/impl/data-explorer/components/column-summary.tsx
index ede2aa5988..daec3f6670 100644
--- a/frontend/src/plugins/impl/data-explorer/components/column-summary.tsx
+++ b/frontend/src/plugins/impl/data-explorer/components/column-summary.tsx
@@ -84,6 +84,7 @@ export const ColumnSummary: React.FC<Props> = ({ schema }) => {
})}
{hasMore && (
<Button
+ data-testid="marimo-plugin-data-explorer-show-more-columns"
variant="link"
size="sm"
className="self-center col-span-3 -mt-1"
@@ -95,6 +96,7 @@ export const ColumnSummary: React.FC<Props> = ({ schema }) => {
</div>
<div className="lg:hidden">
<Select
+ data-testid="marimo-plugin-data-explorer-column-select"
value={selectedField || ""}
disabled={fields.length === 0}
onValueChange={(value) => {
diff --git a/frontend/src/plugins/impl/data-explorer/components/query-form.tsx b/frontend/src/plugins/impl/data-explorer/components/query-form.tsx
index 17fa52332f..b67638c0b8 100644
--- a/frontend/src/plugins/impl/data-explorer/components/query-form.tsx
+++ b/frontend/src/plugins/impl/data-explorer/components/query-form.tsx
@@ -65,6 +65,7 @@ export const QueryForm: React.FC<Props> = ({ schema, mark }) => {
const markSelect = (
<Select
+ data-testid="marimo-plugin-data-explorer-mark-select"
value={mark.toString()}
onValueChange={(value) => actions.setMark(value as SpecMark)}
>
@@ -252,6 +253,7 @@ const FieldOptions = ({
if (options.length > 0) {
return (
<Select
+ data-testid="marimo-plugin-data-explorer-field-options"
value={field.fn}
onValueChange={(value) => {
onChange({
diff --git a/frontend/src/plugins/impl/data-frames/forms/form.tsx b/frontend/src/plugins/impl/data-frames/forms/form.tsx
index bd1dfeeec3..d69d1298e1 100644
--- a/frontend/src/plugins/impl/data-frames/forms/form.tsx
+++ b/frontend/src/plugins/impl/data-frames/forms/form.tsx
@@ -154,6 +154,7 @@ function renderZodSchema<T extends FieldValues, S>(
<FormDescription>{description}</FormDescription>
<FormControl>
<Checkbox
+ data-testid="marimo-plugin-data-frames-boolean-checkbox"
checked={field.value}
onCheckedChange={field.onChange}
/>
@@ -173,6 +174,7 @@ function renderZodSchema<T extends FieldValues, S>(
render={({ field }) => (
<Button
size="xs"
+ data-testid="marimo-plugin-data-frames-random-number-button"
variant="secondary"
onClick={() => {
field.onChange(randomNumber());
@@ -317,7 +319,10 @@ function renderZodSchema<T extends FieldValues, S>(
return (
<div className="flex flex-col">
<FormLabel>{label}</FormLabel>
- <NativeSelect {...field}>
+ <NativeSelect
+ data-testid="marimo-plugin-data-frames-union-select"
+ {...field}
+ >
{types.map((type: string) => {
return (
<option key={type} value={type}>
@@ -425,6 +430,7 @@ const FormArray = ({
<div>
<Button
size="xs"
+ data-testid="marimo-plugin-data-frames-add-array-item"
variant="text"
className="hover:text-accent-foreground"
onClick={() => {
@@ -468,6 +474,7 @@ const ColumnFormField = ({
<StyledFormMessage />
<FormControl>
<Select
+ data-testid="marimo-plugin-data-frames-column-select"
value={field.value}
onValueChange={(value) => {
onChange?.(value);
@@ -654,7 +661,11 @@ const FilterForm = ({
<FormLabel className="whitespace-pre"> </FormLabel>
<FormDescription>{description}</FormDescription>
<FormControl>
- <Select value={field.value} onValueChange={field.onChange}>
+ <Select
+ data-testid="marimo-plugin-data-frames-filter-operator-select"
+ value={field.value}
+ onValueChange={field.onChange}
+ >
<SelectTrigger className="min-w-[210px]">
<SelectValue placeholder="--" />
</SelectTrigger>
@@ -855,7 +866,11 @@ const SelectFormField = ({
<FormLabel className="whitespace-pre">{label}</FormLabel>
<FormDescription>{description}</FormDescription>
<FormControl>
- <Select value={field.value} onValueChange={field.onChange}>
+ <Select
+ data-testid="marimo-plugin-data-frames-select"
+ value={field.value}
+ onValueChange={field.onChange}
+ >
<SelectTrigger className="min-w-[210px]">
<SelectValue placeholder="--" />
</SelectTrigger>
diff --git a/frontend/src/plugins/impl/data-frames/panel.tsx b/frontend/src/plugins/impl/data-frames/panel.tsx
index 64867d312f..a590ea923e 100644
--- a/frontend/src/plugins/impl/data-frames/panel.tsx
+++ b/frontend/src/plugins/impl/data-frames/panel.tsx
@@ -155,7 +155,11 @@ export const TransformPanel: React.FC<Props> = ({
<div className="flex flex-col items-center justify-center flex-grow gap-3">
<MousePointerSquareDashedIcon className="w-8 h-8 text-muted-foreground" />
<AddTransformDropdown onAdd={handleAddTransform}>
- <Button variant="text" size="xs">
+ <Button
+ data-testid="marimo-plugin-data-frames-add-transform"
+ variant="text"
+ size="xs"
+ >
<div className="text-sm">Select a transform to begin</div>
</Button>
</AddTransformDropdown>
@@ -218,6 +222,7 @@ export const Sidebar: React.FC<SidebarProps> = ({
<div className="flex flex-row flex-shrink-0">
<AddTransformDropdown onAdd={onAdd}>
<Button
+ data-testid="marimo-plugin-data-frames-add-transform"
variant="text"
className="w-full rounded-none m-0 hover:text-accent-foreground"
size="xs"
diff --git a/frontend/src/plugins/layout/CarouselPlugin.tsx b/frontend/src/plugins/layout/CarouselPlugin.tsx
index 93aa0b650f..9e5f6e64bb 100644
--- a/frontend/src/plugins/layout/CarouselPlugin.tsx
+++ b/frontend/src/plugins/layout/CarouselPlugin.tsx
@@ -126,6 +126,7 @@ const CarouselComponent = ({
<Button
variant="link"
size="sm"
+ data-testid="marimo-plugin-carousel-fullscreen"
onClick={async () => {
if (!el.current) {
return;
diff --git a/frontend/src/utils/Logger.ts b/frontend/src/utils/Logger.ts
index bf654a9b2a..cb194f117f 100644
--- a/frontend/src/utils/Logger.ts
+++ b/frontend/src/utils/Logger.ts
@@ -1,4 +1,11 @@
/* Copyright 2024 Marimo. All rights reserved. */
+
+declare global {
+ interface Window {
+ Logger?: ILogger;
+ }
+}
+
interface ILogger {
debug: (typeof console)["debug"];
log: (typeof console)["log"];
@@ -9,7 +16,7 @@ interface ILogger {
/**
* Wrapper around console.log that can be used to disable logging in production or add additional logging.
*/
-export const Logger: ILogger = {
+const ConsoleLogger: ILogger = {
debug: (...args) => {
if (process.env.NODE_ENV !== "production") {
console.debug(...args);
@@ -25,3 +32,12 @@ export const Logger: ILogger = {
console.error(...args);
},
};
+
+function getLogger(): ILogger {
+ if (typeof window !== "undefined") {
+ return window.Logger || ConsoleLogger;
+ }
+ return ConsoleLogger;
+}
+
+export const Logger = getLogger();