Skip to content

Commit

Permalink
[#1050] Add missing data-testid attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dyczka committed Aug 13, 2024
1 parent e687650 commit 3158146
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ changes.
- Fix displaying incorrect connected to Voltaire GovTool network
- Runtime error at /edit_drep when metadata incorrect [Issue 1675](https://github.com/IntersectMBO/govtool/issues/1675)
- Restrict access to registration routes when user s already registered and to retirement routes when the use is not registered [Issue 1183](https://github.com/IntersectMBO/govtool/issues/1183)
- Add missing data-testid attributes [Issue 1050](https://github.com/IntersectMBO/govtool/issues/1050)

### Changed

Expand Down
3 changes: 3 additions & 0 deletions govtool/frontend/src/components/molecules/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type CardProps = PropsWithChildren & {
elevation?: number;
dataTestId?: string;
label?: string;
labelDataTestId?: string;
sx?: SxProps<Theme>;
variant?: "default" | "error" | "primary" | "success" | "warning";
onCardClick?: () => void;
Expand Down Expand Up @@ -44,6 +45,7 @@ export const Card = ({
children,
elevation = 3,
label,
labelDataTestId = "card-label",
sx,
onCardClick,
}: CardProps) => {
Expand All @@ -66,6 +68,7 @@ export const Card = ({
>
{label && (
<Chip
data-testid={labelDataTestId}
color={variant}
label={label}
sx={{
Expand Down
31 changes: 18 additions & 13 deletions govtool/frontend/src/components/molecules/DashboardActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,30 @@ export type DashboardActionCardProps = {
state?: "active" | "inProgress" | "default";
title?: ReactNode;
transactionId?: string | null;
type:
| "delegate"
| "d-rep"
| "direct-voter"
| "list-gov-actions"
| "propose-gov-action";
isSpaceBetweenButtons?: boolean;
};

export const DashboardActionCard: FC<DashboardActionCardProps> = ({
...props
buttons,
children,
description,
imageURL,
isLoading = false,
isInProgressOnCard = true,
state = "default",
title,
type,
transactionId,
isSpaceBetweenButtons,
}) => {
const { t } = useTranslation();
const { cExplorerBaseUrl } = useAppContext();
const {
buttons,
children,
description,
imageURL,
isLoading = false,
isInProgressOnCard = true,
state = "default",
title,
transactionId,
isSpaceBetweenButtons,
} = props;

const { screenWidth } = useScreenDimension();

Expand All @@ -50,6 +54,7 @@ export const DashboardActionCard: FC<DashboardActionCardProps> = ({
{...(state === "inProgress" && {
border: true,
label: t("inProgress"),
labelDataTestId: `${type}-in-progress`,
variant: "warning",
})}
sx={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const DRepDashboardCard = ({

const learnMoreButton = {
children: t("learnMore"),
dataTestId: "register-learn-more-button",
dataTestId: "d-rep-learn-more-button",
onClick: () =>
openInNewTab(
"https://docs.sanchogov.tools/how-to-use-the-govtool/using-govtool/dreps",
Expand Down Expand Up @@ -149,6 +149,7 @@ export const DRepDashboardCard = ({
return (
<DashboardActionCard
imageURL={IMAGES.govActionRegisterImage}
type="d-rep"
{...cardProps}
>
{voter?.isRegisteredAsDRep && !pendingTransaction?.retireAsDrep && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const DelegateDashboardCard = ({
? delegateTx?.transactionHash ?? currentDelegation?.txHash
: undefined
}
type="delegate"
{...cardProps}
>
{displayedDelegationId &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const DirectVoterDashboardCard = ({
// learn more button
const learnMoreButton: LoadingButtonProps = {
children: t("learnMore"),
dataTestId: "learn-more-button",
dataTestId: "direct-voter-learn-more-button",
onClick: () =>
openInNewTab(
"https://docs.sanchogov.tools/how-to-use-the-govtool/using-govtool/direct-voting",
Expand Down Expand Up @@ -135,6 +135,10 @@ export const DirectVoterDashboardCard = ({
})();

return (
<DashboardActionCard imageURL={IMAGES.directVoterImage} {...cardProps} />
<DashboardActionCard
imageURL={IMAGES.directVoterImage}
type="direct-voter"
{...cardProps}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ListGovActionsDashboardCards = () => {
},
{
children: t("learnMore"),
dataTestId: "learn-more-governance-actions-button",
dataTestId: "list-gov-actions-learn-more-button",
onClick: () =>
openInNewTab(
"https://docs.sanchogov.tools/how-to-use-the-govtool/using-govtool/governance-actions",
Expand All @@ -31,6 +31,7 @@ export const ListGovActionsDashboardCards = () => {
description={t("dashboard.cards.govActions.description")}
imageURL={IMAGES.govActionListImage}
title={t("dashboard.cards.govActions.title")}
type="list-gov-actions"
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const ProposeGovActionDashboardCard = ({
// common
{
children: t("learnMore"),
dataTestId: "learn-more-button",
dataTestId: "propose-gov-action-learn-more-button",
onClick: () =>
openInNewTab(
"https://docs.sanchogov.tools/how-to-use-the-govtool/using-govtool/governance-actions/propose-a-governance-action",
Expand All @@ -64,6 +64,7 @@ export const ProposeGovActionDashboardCard = ({
transactionId={createGovActionTx?.transactionHash}
state={createGovActionTx ? "inProgress" : "default"}
title={t("dashboard.cards.proposeGovernanceAction.title")}
type="propose-gov-action"
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const EditDRepStorageInformation = ({
<Step
component={
<Button
data-testid="metadata-download-button"
onClick={onClickDownloadJson}
size="extraLarge"
startIcon={<img alt="download" src={ICONS.download} />}
Expand Down
7 changes: 4 additions & 3 deletions govtool/frontend/src/components/organisms/HomeCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const HomeCards = () => {
{/* REGISTER AS DREP CARD */}
<ActionCard
dataTestIdFirstButton="register-connect-wallet-button"
dataTestIdSecondButton="register-learn-more-button"
dataTestIdSecondButton="d-rep-learn-more-button"
description={t("home.cards.registerAsDRep.description")}
firstButtonAction={() => openWalletModal(PATHS.registerAsdRep)}
firstButtonLabel={t("home.cards.registerAsDRep.firstButtonLabel")}
Expand All @@ -117,8 +117,8 @@ export const HomeCards = () => {
{/* REGISTER AS DREP CARD END */}
{/* REGISTER AS DIRECT VOTER CARD */}
<ActionCard
dataTestIdFirstButton="register-as-sole-voter-button"
dataTestIdSecondButton="lear-more-about-sole-voter-button"
dataTestIdFirstButton="register-as-direct-voter-button"
dataTestIdSecondButton="direct-voter-learn-more-button"
description={t("home.cards.registerAsDirectVoter.description")}
firstButtonAction={() => openWalletModal(PATHS.registerAsDirectVoter)}
firstButtonLabel={t(
Expand Down Expand Up @@ -147,6 +147,7 @@ export const HomeCards = () => {
{/* PROPOSE GOV ACTION CARD */}
<ActionCard
dataTestIdFirstButton="propose-a-governance-action-button"
dataTestIdSecondButton="view-proposals-button"
description={t("home.cards.proposeAGovernanceAction.description")}
firstButtonAction={() => openWalletModal(PATHS.createGovernanceAction)}
firstButtonLabel={t(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const VoteContextStoringInformation = ({
<Step
component={
<Button
data-testid="metadata-download-button"
onClick={onClickDownloadJson}
size="extraLarge"
startIcon={<img alt="download" src={ICONS.download} />}
Expand Down Expand Up @@ -127,6 +128,7 @@ export const VoteContextStoringInformation = ({
component={
<ControlledField.Input
{...{ control, errors }}
dataTestId="metadata-url-input"
name="storingURL"
layoutStyles={{ mt: 1.5 }}
placeholder={t(
Expand Down
3 changes: 3 additions & 0 deletions govtool/frontend/src/stories/DashboardCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { IMAGES } from "@/consts";
const meta = {
title: "Example/DashboardCard",
component: DashboardActionCard,
args: {
type: "d-rep",
},
parameters: {
layout: "centered",
},
Expand Down

0 comments on commit 3158146

Please sign in to comment.