mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
test(site): make loading snapshots more predictable (#14564)
Abstracts the Spinner component to control the display of the CircularProgress component. This allows us to make it static during Chromatic tests, making loading tests easier to visualize.
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
import type { Interpolation, Theme } from "@emotion/react";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import { Spinner } from "components/Spinner/Spinner";
|
||||
import type { FC, HTMLAttributes } from "react";
|
||||
|
||||
interface LoaderProps extends HTMLAttributes<HTMLDivElement> {
|
||||
fullscreen?: boolean;
|
||||
size?: number;
|
||||
/**
|
||||
* A label for the loader. This is used for accessibility purposes.
|
||||
*/
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export const Loader: FC<LoaderProps> = ({
|
||||
fullscreen,
|
||||
size = 26,
|
||||
label = "Loading...",
|
||||
...attrs
|
||||
}) => {
|
||||
return (
|
||||
@@ -18,7 +23,7 @@ export const Loader: FC<LoaderProps> = ({
|
||||
data-testid="loader"
|
||||
{...attrs}
|
||||
>
|
||||
<CircularProgress size={size} />
|
||||
<Spinner aria-label={label} size={size} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import CircularProgress, {
|
||||
type CircularProgressProps,
|
||||
} from "@mui/material/CircularProgress";
|
||||
import isChromatic from "chromatic/isChromatic";
|
||||
import type { FC } from "react";
|
||||
|
||||
/**
|
||||
* Spinner component used to indicate loading states. This component abstracts
|
||||
* the MUI CircularProgress to provide better control over its rendering,
|
||||
* especially in snapshot tests with Chromatic.
|
||||
*/
|
||||
export const Spinner: FC<CircularProgressProps> = (props) => {
|
||||
/**
|
||||
* During Chromatic snapshots, we render the spinner as determinate to make it
|
||||
* static without animations, using a deterministic value (75%).
|
||||
*/
|
||||
if (isChromatic()) {
|
||||
props.variant = "determinate";
|
||||
props.value = 75;
|
||||
}
|
||||
return <CircularProgress {...props} />;
|
||||
};
|
||||
Reference in New Issue
Block a user