Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("UserPageBrainWrapper", () => {
},
identity: { id: "1" },
});
expect(routerPush).toHaveBeenCalledWith("/alice/rep");
expect(routerPush).toHaveBeenCalledWith("/alice/identity");
});

it("shows drops when waves enabled", () => {
Expand Down
33 changes: 0 additions & 33 deletions __tests__/components/user/identity/UserPageIdentity.test.tsx

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,41 @@ import { render, screen } from '@testing-library/react';
import UserPageIdentityHeaderCIC from '@/components/user/identity/header/UserPageIdentityHeaderCIC';
import type { ApiIdentity } from '@/generated/models/ApiIdentity';

jest.mock('@tanstack/react-query', () => ({
useQuery: jest.fn(() => ({ data: { count: 2 } })),
}));

jest.mock('@/components/user/utils/user-cic-type/UserCICTypeIconWrapper', () => ({
__esModule: true,
default: () => <div data-testid="icon" />,
}));

jest.mock('@/components/user/rep/header/TopRaterAvatars', () => ({
__esModule: true,
default: () => <div data-testid="raters-avatars" />,
}));

jest.mock('@/components/user/utils/user-cic-status/UserCICStatus', () => ({
__esModule: true,
default: ({ cic }: { cic: number }) => <div data-testid="status">{cic}</div>,
}));

describe('UserPageIdentityHeaderCIC', () => {
const baseProfile: ApiIdentity = { cic: 1000 } as ApiIdentity;
const baseProfile: ApiIdentity = { cic: 1000, handle: 'alice' } as ApiIdentity;

it('displays NIC and status info', () => {
render(<UserPageIdentityHeaderCIC profile={baseProfile} />);
expect(screen.getByText('NIC:')).toBeInTheDocument();
expect(screen.getByText('NIC')).toBeInTheDocument();
expect(screen.getByText('1,000')).toBeInTheDocument();
expect(screen.getByTestId('raters-avatars')).toBeInTheDocument();
expect(screen.getByText('2 raters')).toBeInTheDocument();
expect(screen.getByTestId('icon')).toBeInTheDocument();
expect(screen.getByTestId('status')).toHaveTextContent('1000');
});

it('updates when profile prop changes', () => {
const { rerender } = render(<UserPageIdentityHeaderCIC profile={baseProfile} />);
rerender(<UserPageIdentityHeaderCIC profile={{ cic: 2000 } as ApiIdentity} />);
rerender(<UserPageIdentityHeaderCIC profile={{ cic: 2000, handle: 'alice' } as ApiIdentity} />);
expect(screen.getByText('2,000')).toBeInTheDocument();
expect(screen.getByTestId('status')).toHaveTextContent('2000');
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/components/user/layout/UserPageTabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const renderTabs = (
country: string = "US"
) => {
(useRouter as jest.Mock).mockReturnValue({ push: jest.fn() });
(usePathname as jest.Mock).mockReturnValue("/[user]/rep");
(usePathname as jest.Mock).mockReturnValue("/[user]/identity");
(useSearchParams as jest.Mock).mockReturnValue(new URLSearchParams());
(useParams as jest.Mock).mockReturnValue({ user: "testuser" });
capacitorMock.mockReturnValue({ isIos });
Expand Down
21 changes: 0 additions & 21 deletions __tests__/components/user/rep/UserPageRepActivityLog.test.tsx

This file was deleted.

16 changes: 11 additions & 5 deletions __tests__/components/user/rep/header/UserPageRepHeader.test.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { render, screen } from '@testing-library/react';
import UserPageRepHeader from '@/components/user/rep/header/UserPageRepHeader';

const mockProfile = {
handle: 'testuser',
display: 'Test User',
query: 'testuser',
} as any;

describe('UserPageRepHeader', () => {
it('shows rep totals when provided', () => {
const repRates = {
total_rep_rating: 1500,
number_of_raters: 25,
rating_stats: [],
} as any;
render(<UserPageRepHeader repRates={repRates} />);
render(<UserPageRepHeader repRates={repRates} profile={mockProfile} />);
expect(screen.getByText('1,500')).toBeInTheDocument();
expect(screen.getByText('25')).toBeInTheDocument();
});

it('renders empty values without repRates', () => {
const { container } = render(<UserPageRepHeader repRates={null} />);
expect(container).toHaveTextContent('Rep:');
it('renders without repRates', () => {
const { container } = render(<UserPageRepHeader repRates={null} profile={mockProfile} />);
expect(container).toHaveTextContent('Reputation');
});
Comment thread
ragnep marked this conversation as resolved.
});
10 changes: 3 additions & 7 deletions __tests__/components/user/rep/new-rep/UserPageRepNewRep.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import UserPageRepNewRep from '@/components/user/rep/new-rep/UserPageRepNewRep';
import type { ApiIdentity } from '@/generated/models/ApiIdentity';

jest.mock('@/components/user/rep/new-rep/UserPageRepNewRepSearch', () => ({
__esModule: true,
default: ({ onRepSearch }: { onRepSearch: (v: string) => void }) => (
<button onClick={() => onRepSearch('Art')}>search</button>
),
default: () => <div data-testid="search" />,
}));

jest.mock('@/components/user/rep/modify-rep/UserPageRepModifyModal', () => ({
Expand All @@ -19,9 +16,8 @@ describe('UserPageRepNewRep', () => {
const profile = { id: '1' } as ApiIdentity;
const repRates = { rating_stats: [] } as any;

it('opens modal when search selects rep', async () => {
it('renders search component', () => {
render(<UserPageRepNewRep profile={profile} repRates={repRates} />);
await userEvent.click(screen.getByRole('button', { name: 'search' }));
expect(screen.getByTestId('modal')).toBeInTheDocument();
expect(screen.getByTestId('search')).toBeInTheDocument();
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import userEvent from "@testing-library/user-event";
import UserPageRepNewRepSearch from "@/components/user/rep/new-rep/UserPageRepNewRepSearch";
import { useQuery } from "@tanstack/react-query";

jest.mock("@tanstack/react-query", () => ({ useQuery: jest.fn() }));
jest.mock("@tanstack/react-query", () => ({ useQuery: jest.fn(), useMutation: jest.fn().mockReturnValue({ mutateAsync: jest.fn() }) }));

jest.mock("@/components/user/rep/new-rep/UserPageRepNewRepSearchHeader", () => () => <div data-testid="header" />);
jest.mock("@/components/user/rep/new-rep/UserPageRepNewRepSearchDropdown", () => (props: any) => (
Expand All @@ -15,14 +15,14 @@ jest.mock("@/components/user/rep/new-rep/UserPageRepNewRepSearchDropdown", () =>
));
jest.mock("@/components/user/rep/new-rep/UserPageRepNewRepError", () => () => <div data-testid="error" />);
jest.mock("@/components/distribution-plan-tool/common/CircleLoader", () => () => <div data-testid="loader" />);
jest.mock("services/api/common-api", () => ({ commonApiFetch: jest.fn() }));
jest.mock("services/api/common-api", () => ({ commonApiFetch: jest.fn(), commonApiPost: jest.fn() }));

describe("UserPageRepNewRepSearch", () => {
it("shows dropdown results and handles selection", async () => {
(useQuery as jest.Mock).mockReturnValue({ isFetching: false, data: ["cat1"] });
const user = userEvent.setup();
render(
<UserPageRepNewRepSearch repRates={null} onRepSearch={jest.fn()} profile={{} as any} />
<UserPageRepNewRepSearch repRates={null} profile={{} as any} />
);
await user.type(screen.getByPlaceholderText(/Category to grant rep/), "art");
await waitFor(() => screen.getByTestId("dropdown"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('UserPageHeaderStats', () => {
/>
);
expect(screen.getByRole('link', { name: 'fmt-10 TDH' })).toHaveAttribute('href', '/bob/collected');
expect(screen.getByRole('link', { name: 'fmt-20 Rep' })).toHaveAttribute('href', '/bob/rep');
expect(screen.getByRole('link', { name: 'fmt-20 Rep' })).toHaveAttribute('href', '/bob/identity');
expect(screen.getByRole('link', { name: 'fmt-3 TDH Rate' })).toHaveAttribute(
'href',
'/bob/stats?activity=tdh-history'
Expand Down
41 changes: 39 additions & 2 deletions __tests__/components/user/utils/rate/UserPageRateWrapper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ describe("UserPageRateWrapper", () => {
wallets: [{ wallet: "0xabc" }],
};

function renderWrapper(ctx: any, seize: any, type = RateMatter.NIC) {
function renderWrapper(
ctx: any,
seize: any,
type = RateMatter.NIC,
options?: { hideOwnProfileMessage?: boolean }
) {
useCtx.mockReturnValue(seize);
return render(
<AuthContext.Provider value={ctx as any}>
<UserPageRateWrapper profile={profile} type={type}>
<UserPageRateWrapper
profile={profile}
type={type}
hideOwnProfileMessage={options?.hideOwnProfileMessage}>
<div data-testid="child" />
</UserPageRateWrapper>
</AuthContext.Provider>
Expand All @@ -47,4 +55,33 @@ describe("UserPageRateWrapper", () => {
);
expect(screen.getByTestId("child")).toBeInTheDocument();
});

it.each([RateMatter.REP, RateMatter.NIC])(
"shows own-profile message by default (%s)",
(type) => {
renderWrapper(
{ connectedProfile: { handle: "alice" }, activeProfileProxy: undefined },
{ address: "0xabc" },
type
);
expect(screen.getByTestId("infobox")).toHaveTextContent(
"You can't"
);
expect(screen.queryByTestId("child")).not.toBeInTheDocument();
}
);

it.each([RateMatter.REP, RateMatter.NIC])(
"hides own-profile section when hideOwnProfileMessage is true (%s)",
(type) => {
renderWrapper(
{ connectedProfile: { handle: "alice" }, activeProfileProxy: undefined },
{ address: "0xabc" },
type,
{ hideOwnProfileMessage: true }
);
expect(screen.queryByTestId("infobox")).not.toBeInTheDocument();
expect(screen.queryByTestId("child")).not.toBeInTheDocument();
}
);
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ProfileRatersTableBody from "@/components/user/utils/raters-table/ProfileRatersTableBody";
import { ProfileRatersTableType } from "@/types/enums";
import { render } from "@testing-library/react";

let itemProps: any[] = [];
Expand Down Expand Up @@ -27,7 +26,6 @@ describe("ProfileRatersTableBody", () => {
<table>
<ProfileRatersTableBody
ratings={ratings}
type={ProfileRatersTableType.CIC_RECEIVED}
/>
</table>
);
Expand Down
Loading