Skip to content

Commit

Permalink
test: admin options render
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency committed Aug 23, 2024
1 parent 22e257c commit c0c63bb
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
58 changes: 58 additions & 0 deletions components/admins/components/__tests__/adminOptions.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { afterEach, describe, expect, test } from "bun:test";
import React from "react";
import { screen, cleanup, within } from "@testing-library/react";
import AdminOptions from "@/components/admins/components/adminOptions";
import matchers from "@testing-library/jest-dom/matchers";
import { renderWithChainProvider } from "@/tests/render";
import { mockPoaParams, mockGroup } from "@/tests/mock";

expect.extend(matchers);

const renderWithProps = (props = {}) => {
const defaultProps = {
poaParams: mockPoaParams,
group: mockGroup,
isLoading: false,
address: "test_address",
admin: "admin1",
};
return renderWithChainProvider(<AdminOptions {...defaultProps} {...props} />);
};

describe("AdminOptions", () => {
afterEach(cleanup);

test("renders loading state correctly", () => {
renderWithProps({ isLoading: true });
expect(screen.getByText("Admin")).toBeInTheDocument();
});

test("renders admin details correctly when not loading", () => {
renderWithProps();
expect(screen.getByText("Admin")).toBeInTheDocument();
expect(screen.getByAltText("Profile Avatar")).toBeInTheDocument();
const titleContainer = screen.getByLabelText("title");
expect(within(titleContainer).getByText("title1")).toBeInTheDocument();
const detailsContainer = screen.getByLabelText("details");
expect(within(detailsContainer).getByText("details1")).toBeInTheDocument();
});

test("opens update modal on button click", () => {
renderWithProps();
const updateAdminButtonContainer = screen.getByLabelText("update admin");
const updateButton = within(updateAdminButtonContainer).getByText("Update Admin");
updateButton.click();
const modal = document.getElementById("update-admin-modal") as HTMLDialogElement;
expect(modal).toBeInTheDocument();
expect(modal.open).toBe(true);
});

test("opens description modal on button click", () => {
renderWithProps();
const descriptionButton = screen.getByLabelText("three-dots");
descriptionButton.click();
const modal = document.getElementById("description-modal") as HTMLDialogElement;
expect(modal).toBeInTheDocument();
expect(modal.open).toBe(true);
});
});
6 changes: 4 additions & 2 deletions components/admins/components/adminOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,17 @@ export default function AdminOptions({
size={64}
/>
</div>
<a className="lg:text-2xl text-xl leading-6 -mt-2">
<a className="lg:text-2xl text-xl leading-6 -mt-2" aria-label="title">
{group?.ipfsMetadata?.title}
</a>

<a className="text-sm leading-tight flex-wrap text-center text-neutral-content max-h-10 max-w-96 overflow-y-auto -mt-6">
<a className="text-sm leading-tight flex-wrap text-center text-neutral-content max-h-10 max-w-96 overflow-y-auto -mt-6" aria-label="details">
{group?.ipfsMetadata?.details}
</a>
<button
className="btn btn-sm btn-ghost absolute right-2 bottom-17"
onClick={handleDescription}
aria-label="three-dots"
>
<BsThreeDots />
</button>
Expand All @@ -121,6 +122,7 @@ export default function AdminOptions({
<button
className="btn hidden lg:block btn-primary btn-sm w-2/6"
onClick={handleOpen}
aria-label="update admin"
>
Update Admin
</button>
Expand Down
26 changes: 26 additions & 0 deletions tests/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Chain} from "@chain-registry/types";
import {BondStatus, ParamsSDKType} from "@chalabi/manifestjs/dist/codegen/cosmos/staking/v1beta1/staking";
import {ExtendedValidatorSDKType, TransactionGroup} from "@/components";
import {CombinedBalanceInfo} from "@/pages/bank";
import {ExtendedGroupType} from "@/hooks";

export const mockBalances: CombinedBalanceInfo[] = [
{
Expand Down Expand Up @@ -182,3 +183,28 @@ export const mockStakingParams: ParamsSDKType = {
historical_entries: 200,
};

// TODO: Not compatible with alpha.12 as poaParams is not defined in the current version
export const mockPoaParams = {
admins: ["admin1"],
allow_validator_self_exit: true,
};

export const mockGroup : ExtendedGroupType = {
id: 1n,
admin: "admin1",
metadata: "metadata1",
version: 1n,
created_at: new Date(),
ipfsMetadata: {
title: "title1",
summary: "summary1",
details: "details1",
authors: "author1",
proposalForumURL: "forum1.com",
voteOptionContext: "context1",
},
total_weight: "456",
policies: ["policy1"],
members: ["foo", "bar"],
};

0 comments on commit c0c63bb

Please sign in to comment.