Skip to content
1 change: 1 addition & 0 deletions __tests__/components/header/HeaderSearchModalItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const getProfileTargetRouteMock = jest.fn(() => "/profile-route");
jest.mock("@/helpers/Helpers", () => ({
cicToType: (n: number) => `type${n}`,
formatNumberWithCommas: (n: number) => `formatted-${n}`,
formatStatFloor: (n: number) => n,
getProfileTargetRoute: () => getProfileTargetRouteMock(),
}));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import NextGenMintBurnWidget from '@/components/nextGen/collections/collectionParts/mint/NextGenMintBurnWidget';
import { Status } from '@/components/nextGen/nextgen_entities';
import { NEXTGEN_CHAIN_ID, NEXTGEN_CORE } from '@/components/nextGen/nextgen_contracts';

jest.mock('react-bootstrap', () => {
const React = require('react');
import NextGenMintBurnWidget from "@/components/nextGen/collections/collectionParts/mint/NextGenMintBurnWidget";
import {
NEXTGEN_CHAIN_ID,
NEXTGEN_CORE,
} from "@/components/nextGen/nextgen_contracts";
import { Status } from "@/components/nextGen/nextgen_entities";
import { render, screen, waitFor } from "@testing-library/react";

jest.mock("react-bootstrap", () => {
const Form = (p: any) => <form {...p}>{p.children}</form>;
Form.Group = (p: any) => <div data-testid="form-group" {...p} />;
Form.Label = (p: any) => <label {...p} />;
Expand All @@ -20,32 +21,44 @@ jest.mock('react-bootstrap', () => {
};
});

jest.mock('@/components/nextGen/collections/collectionParts/mint/NextGenMintShared', () => ({
NextGenMintingFor: () => <div data-testid="minting-for" />,
}));
jest.mock(
"@/components/nextGen/collections/collectionParts/mint/NextGenMintShared",
() => ({
NextGenMintingFor: () => <div data-testid="minting-for" />,
})
);

jest.mock('@/components/nextGen/NextGenContractWriteStatus', () => () => <div data-testid="status" />);
jest.mock("@/components/nextGen/NextGenContractWriteStatus", () => () => (
<div data-testid="status" />
));

const mockFetchUrl = jest.fn();
jest.mock('@/services/6529api', () => ({ fetchUrl: (...args: any[]) => mockFetchUrl(...args) }));
jest.mock("@/services/6529api", () => ({
fetchUrl: (...args: any[]) => mockFetchUrl(...args),
}));

jest.mock('@/components/auth/SeizeConnectContext', () => ({
jest.mock("@/components/auth/SeizeConnectContext", () => ({
useSeizeConnectContext: jest.fn(),
}));

jest.mock('wagmi', () => ({
jest.mock("wagmi", () => ({
useChainId: jest.fn(),
useWriteContract: jest.fn(),
}));

jest.mock('@/components/nextGen/nextgen_helpers', () => ({
jest.mock("@/components/nextGen/nextgen_helpers", () => ({
useMintSharedState: jest.fn(),
getStatusFromDates: jest.fn(),
}));

const { useChainId, useWriteContract } = require('wagmi');
const { useSeizeConnectContext } = require('@/components/auth/SeizeConnectContext');
const { useMintSharedState, getStatusFromDates } = require('@/components/nextGen/nextgen_helpers');
const { useChainId, useWriteContract } = require("wagmi");
const {
useSeizeConnectContext,
} = require("@/components/auth/SeizeConnectContext");
const {
useMintSharedState,
getStatusFromDates,
} = require("@/components/nextGen/nextgen_helpers");

const originalFetch = global.fetch;
const mockFetch = jest.fn() as jest.MockedFunction<typeof fetch>;
Comment thread
prxt6529 marked this conversation as resolved.
Expand All @@ -54,9 +67,9 @@ function createMintState(overrides: Partial<any> = {}) {
return {
burnProofResponse: undefined,
setBurnProofResponse: jest.fn(),
mintForAddress: '0xabc',
mintForAddress: "0xabc",
setMintForAddress: jest.fn(),
tokenId: '',
tokenId: "",
setTokenId: jest.fn(),
salt: 0,
isMinting: false,
Expand All @@ -79,7 +92,7 @@ const baseProps = {
} as any,
collection_merkle: {
collection_id: 1,
merkle_root: 'root',
merkle_root: "root",
burn_collection: NEXTGEN_CORE[NEXTGEN_CHAIN_ID],
burn_collection_id: 1,
min_token_index: 0,
Expand All @@ -95,12 +108,28 @@ const baseProps = {
refreshMintCounts: jest.fn(),
};

function renderWidget(props: Partial<typeof baseProps> = {}, state: any = {}, context: any = {}, chainId?: number) {
function renderWidget(
props: Partial<typeof baseProps> = {},
state: any = {},
context: any = {},
chainId?: number
) {
const mintState = createMintState(state);
(useMintSharedState as jest.Mock).mockReturnValue(mintState);
(useSeizeConnectContext as jest.Mock).mockReturnValue({ isConnected: true, address: '0xabc', seizeConnect: jest.fn(), ...context });
(useSeizeConnectContext as jest.Mock).mockReturnValue({
isConnected: true,
address: "0xabc",
seizeConnect: jest.fn(),
...context,
});
(useChainId as jest.Mock).mockReturnValue(chainId ?? NEXTGEN_CHAIN_ID);
(useWriteContract as jest.Mock).mockReturnValue({ writeContract: jest.fn(), reset: jest.fn(), isPending: false, isSuccess: false, isError: false });
(useWriteContract as jest.Mock).mockReturnValue({
writeContract: jest.fn(),
reset: jest.fn(),
isPending: false,
isSuccess: false,
isError: false,
});
(getStatusFromDates as jest.Mock).mockReturnValue(Status.LIVE);
return render(<NextGenMintBurnWidget {...baseProps} {...props} />);
}
Expand All @@ -115,17 +144,18 @@ afterAll(() => {
global.fetch = originalFetch;
});


describe('NextGenMintBurnWidget', () => {
it('filters tokens by range and prefix', async () => {
describe("NextGenMintBurnWidget", () => {
it("filters tokens by range and prefix", async () => {
mockFetch.mockResolvedValue({
ok: true,
json: async () => [
{ tokenId: 90 },
{ tokenId: 110, name: 'A' },
{ tokenId: 115 },
{ tokenId: 201 },
],
json: async () => ({
ownedNfts: [
{ tokenId: "90" },
{ tokenId: "110", name: "A" },
{ tokenId: "115" },
{ tokenId: "201" },
],
}),
} as unknown as Response);

renderWidget(
Expand All @@ -137,38 +167,40 @@ describe('NextGenMintBurnWidget', () => {
burn_collection_id: 1,
},
},
{ mintForAddress: '0xabc' }
{ mintForAddress: "0xabc" }
);

await waitFor(() => {
expect(mockFetch).toHaveBeenCalled();
expect(screen.getAllByRole('option').length).toBeGreaterThan(1);
expect(screen.getAllByRole("option").length).toBeGreaterThan(1);
});
const options = screen.getAllByRole('option');
expect(options[1]).toHaveValue('110');
expect(options[2]).toHaveValue('115');
const options = screen.getAllByRole("option");
expect(options[1]).toHaveValue("110");
expect(options[2]).toHaveValue("115");
});

it('shows connect wallet when not connected', () => {
it("shows connect wallet when not connected", () => {
renderWidget({}, {}, { isConnected: false });
expect(screen.getByRole('button')).toHaveTextContent('Connect Wallet');
expect(screen.getByRole("button")).toHaveTextContent("Connect Wallet");
});

it('prompts network switch when chain differs', () => {
it("prompts network switch when chain differs", () => {
renderWidget({}, {}, {}, NEXTGEN_CHAIN_ID + 1);
expect(screen.getByRole('button')).toHaveTextContent('Switch to');
expect(screen.getByRole("button")).toHaveTextContent("Switch to");
});

it('shows processing state when minting', () => {
it("shows processing state when minting", () => {
const { container } = renderWidget({}, { isMinting: true });
expect(screen.getByRole('button')).toHaveTextContent('Processing...');
expect(container.querySelector('output')).toBeInTheDocument();
expect(screen.getByRole("button")).toHaveTextContent("Processing...");
expect(container.querySelector("output")).toBeInTheDocument();
});

it('disables button when burn not active', () => {
renderWidget({ collection_merkle: { ...baseProps.collection_merkle, status: false } });
const btn = screen.getByRole('button');
it("disables button when burn not active", () => {
renderWidget({
collection_merkle: { ...baseProps.collection_merkle, status: false },
});
const btn = screen.getByRole("button");
expect(btn).toBeDisabled();
expect(btn).toHaveTextContent('Burn Not Active');
expect(btn).toHaveTextContent("Burn Not Active");
});
});
9 changes: 8 additions & 1 deletion __tests__/components/user/layout/UserPageTabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import { AuthContext } from "@/components/auth/Auth";
import UserPageTabs from "@/components/user/layout/UserPageTabs";
import { USER_PAGE_TAB_IDS } from "@/components/user/layout/userTabs.config";
import { render, screen } from "@testing-library/react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import {
useParams,
usePathname,
useRouter,
useSearchParams,
} from "next/navigation";

jest.mock("next/navigation", () => ({
useRouter: jest.fn(),
usePathname: jest.fn(),
useSearchParams: jest.fn(),
useParams: jest.fn(),
}));
const capacitorMock = jest.fn();
jest.mock("@/hooks/useCapacitor", () => ({
Expand All @@ -34,6 +40,7 @@ const renderTabs = (
(useRouter as jest.Mock).mockReturnValue({ push: jest.fn() });
(usePathname as jest.Mock).mockReturnValue("/[user]/rep");
(useSearchParams as jest.Mock).mockReturnValue(new URLSearchParams());
(useParams as jest.Mock).mockReturnValue({ user: "testuser" });
capacitorMock.mockReturnValue({ isIos });
(useCookieConsent as jest.Mock).mockReturnValue({
showCookieConsent: false,
Expand Down
Loading