Skip to content

Commit a9649ab

Browse files
authored
Add various attributes to help with testing & CSS selectors (#906)
1 parent d2decfa commit a9649ab

File tree

16 files changed

+84
-74
lines changed

16 files changed

+84
-74
lines changed

frontend/app/src/comps/ErrorBox/ErrorBox.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { ReactNode } from "react";
22

3-
import { css } from "@/styled-system/css";
3+
import { css, cx } from "@/styled-system/css";
44
import { IconChevronDown, useElementSize } from "@liquity2/uikit";
55
import { a, useSpring } from "@react-spring/web";
6-
import { useRef, useState } from "react";
6+
import { useId, useRef, useState } from "react";
77

88
export function ErrorBox({
99
children,
@@ -29,19 +29,26 @@ export function ErrorBox({
2929
},
3030
});
3131

32+
const detailsId = useId();
33+
3234
return (
3335
<section
34-
className={css({
35-
width: "100%",
36-
minWidth: 0,
37-
background: "negativeSurface",
38-
color: "negative",
39-
fontSize: 14,
40-
border: "1px solid token(colors.negativeSurfaceBorder)",
41-
borderRadius: 8,
42-
})}
36+
className={cx(
37+
"error-box",
38+
css({
39+
width: "100%",
40+
minWidth: 0,
41+
background: "negativeSurface",
42+
color: "negative",
43+
fontSize: 14,
44+
border: "1px solid token(colors.negativeSurfaceBorder)",
45+
borderRadius: 8,
46+
}),
47+
)}
4348
>
4449
<button
50+
aria-expanded={expanded}
51+
aria-controls={detailsId}
4552
onClick={() => setExpanded(!expanded)}
4653
className={css({
4754
display: "flex",
@@ -87,6 +94,7 @@ export function ErrorBox({
8794
</div>
8895
</button>
8996
<a.div
97+
id={detailsId}
9098
style={{
9199
overflow: "hidden",
92100
willChange: "height",

frontend/app/src/comps/Field/Field.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@ type FooterRow = {
2020
export function Field({
2121
field,
2222
footer,
23+
id,
2324
label,
2425
}: {
2526
field: ReactNode;
2627
footer?: FooterRow | FooterRow[];
28+
id?: string;
2729
label?: ReactNode;
2830
}) {
2931
if (footer && !Array.isArray(footer)) {
3032
footer = [footer];
3133
}
3234
return (
3335
<div
36+
id={id}
3437
className={css({
3538
display: "flex",
3639
flexDirection: "column",

frontend/app/src/comps/FlowButton/FlowButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export function FlowButton({
3131
>
3232
<ConnectWarningBox />
3333
<Button
34+
className="flow-button"
3435
disabled={disabled || !request}
3536
label={label ?? "Next: Summary"}
3637
mode="primary"

frontend/app/src/comps/Positions/PositionCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export function PositionCard({
7575
onMouseUp={() => setActive(false)}
7676
className={cx(
7777
"group",
78+
anchorProps.className,
7879
css({
7980
position: "relative",
8081
overflow: "hidden",

frontend/app/src/comps/Positions/PositionCardBorrow.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export function PositionCardBorrow({
5858

5959
return (
6060
<PositionCard
61+
className="position-card position-card-loan position-card-borrow"
6162
href={`/loan?id=${branchId}:${troveId}`}
6263
title={title.join("\n")}
6364
heading={

frontend/app/src/comps/Positions/PositionCardEarn.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export function PositionCardEarn({
2020
const earnPosition = useEarnPosition(branchId, owner ?? null);
2121
return (
2222
<PositionCard
23+
className="position-card position-card-earn"
2324
href={token ? `/earn/${token.symbol.toLowerCase()}` : ""}
2425
heading={[
2526
<div

frontend/app/src/comps/Positions/PositionCardLeverage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function PositionCardLeverage({
4949

5050
return (
5151
<PositionCard
52+
className="position-card position-card-loan position-card-leverage"
5253
href={`/loan?id=${branchId}:${troveId}`}
5354
heading={[
5455
<div

frontend/app/src/comps/Positions/PositionCardStake.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function PositionCardStake({
3737
});
3838
return (
3939
<PositionCard
40+
className="position-card position-card-stake"
4041
href="/stake"
4142
heading={[
4243
<div

frontend/app/src/comps/Screen/ScreenCard.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReactNode } from "react";
22

33
import { useBreakpoint } from "@/src/breakpoints";
4-
import { css } from "@/styled-system/css";
4+
import { css, cx } from "@/styled-system/css";
55
import { LoadingSurface } from "@liquity2/uikit";
66
import { a, useSpring } from "@react-spring/web";
77
import { useState } from "react";
@@ -12,10 +12,12 @@ const FINAL_CARD_WIDTH = 534;
1212

1313
export function ScreenCard({
1414
children,
15+
className,
1516
finalHeight,
1617
mode,
1718
}: {
1819
children: ReactNode;
20+
className?: string;
1921
finalHeight?: number;
2022
mode: "ready" | "loading" | "error";
2123
}) {
@@ -55,12 +57,15 @@ export function ScreenCard({
5557

5658
return (
5759
<a.div
58-
className={css({
59-
flexShrink: 0,
60-
display: "flex",
61-
justifyContent: "center",
62-
flexDirection: "column",
63-
})}
60+
className={cx(
61+
className,
62+
css({
63+
flexShrink: 0,
64+
display: "flex",
65+
justifyContent: "center",
66+
flexDirection: "column",
67+
}),
68+
)}
6469
style={{
6570
width: compactMode ? "100%" : FINAL_CARD_WIDTH,
6671
height: spring.containerHeight,

frontend/app/src/screens/AccountScreen/AccountScreen.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { CHAIN_ID } from "@/src/env";
1111
import { fmtnum } from "@/src/formatting";
1212
import { getBranches } from "@/src/liquity-utils";
1313
import { useAccount, useBalance } from "@/src/wagmi-utils";
14-
import { css } from "@/styled-system/css";
14+
import { css, cx } from "@/styled-system/css";
1515
import {
1616
addressesEqual,
1717
Button,
@@ -175,11 +175,14 @@ function Balance({
175175

176176
return (
177177
<div
178-
className={css({
179-
display: "flex",
180-
alignItems: "center",
181-
gap: 8,
182-
})}
178+
className={cx(
179+
`balance-${tokenSymbol.toLowerCase()}`,
180+
css({
181+
display: "flex",
182+
alignItems: "center",
183+
gap: 8,
184+
}),
185+
)}
183186
>
184187
<div
185188
title={`${fmtnum(balance.data, "full")} ${tokenSymbol}`}

0 commit comments

Comments
 (0)