Skip to content

Commit c3f0db3

Browse files
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.
1 parent 8f07d33 commit c3f0db3

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

site/src/components/Loader/Loader.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import type { Interpolation, Theme } from "@emotion/react";
2-
import CircularProgress from "@mui/material/CircularProgress";
2+
import { Spinner } from "components/Spinner/Spinner";
33
import type { FC, HTMLAttributes } from "react";
44

55
interface LoaderProps extends HTMLAttributes<HTMLDivElement> {
66
fullscreen?: boolean;
77
size?: number;
8+
/**
9+
* A label for the loader. This is used for accessibility purposes.
10+
*/
11+
label?: string;
812
}
913

1014
export const Loader: FC<LoaderProps> = ({
1115
fullscreen,
1216
size = 26,
17+
label = "Loading...",
1318
...attrs
1419
}) => {
1520
return (
@@ -18,7 +23,7 @@ export const Loader: FC<LoaderProps> = ({
1823
data-testid="loader"
1924
{...attrs}
2025
>
21-
<CircularProgress size={size} />
26+
<Spinner aria-label={label} size={size} />
2227
</div>
2328
);
2429
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import CircularProgress, {
2+
type CircularProgressProps,
3+
} from "@mui/material/CircularProgress";
4+
import isChromatic from "chromatic/isChromatic";
5+
import type { FC } from "react";
6+
7+
/**
8+
* Spinner component used to indicate loading states. This component abstracts
9+
* the MUI CircularProgress to provide better control over its rendering,
10+
* especially in snapshot tests with Chromatic.
11+
*/
12+
export const Spinner: FC<CircularProgressProps> = (props) => {
13+
/**
14+
* During Chromatic snapshots, we render the spinner as determinate to make it
15+
* static without animations, using a deterministic value (75%).
16+
*/
17+
if (isChromatic()) {
18+
props.variant = "determinate";
19+
props.value = 75;
20+
}
21+
return <CircularProgress {...props} />;
22+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy