Skip to content
Closed
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
3 changes: 0 additions & 3 deletions __tests__/components/CreateDropWrapper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ describe('CreateDropWrapper', () => {
setIsStormMode={jest.fn()}
setViewType={jest.fn()}
setDrop={setDrop}
setMentionedUsers={jest.fn()}
setReferencedNfts={jest.fn()}
onMentionedUser={jest.fn()}
setTitle={jest.fn()}
Expand Down Expand Up @@ -103,7 +102,6 @@ describe('CreateDropWrapper', () => {
setIsStormMode={jest.fn()}
setViewType={jest.fn()}
setDrop={setDrop}
setMentionedUsers={jest.fn()}
setReferencedNfts={jest.fn()}
onMentionedUser={jest.fn()}
setTitle={jest.fn()}
Expand Down Expand Up @@ -138,7 +136,6 @@ describe('CreateDropWrapper', () => {
setIsStormMode={jest.fn()}
setViewType={jest.fn()}
setDrop={setDrop}
setMentionedUsers={jest.fn()}
setReferencedNfts={jest.fn()}
onMentionedUser={jest.fn()}
setTitle={jest.fn()}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { QueryClientProvider } from '@tanstack/react-query';
import CreateSnapshotFormSearchCollectionDropdownItem from '@/components/distribution-plan-tool/create-snapshots/form/CreateSnapshotFormSearchCollectionDropdownItem';
import { DistributionPlanToolContext } from '@/components/distribution-plan-tool/DistributionPlanToolContext';
import { distributionPlanApiFetch } from '@/services/distribution-plan-api';
import { createTestQueryClient } from '../../../../utils/reactQuery';

jest.mock('next/image', () => ({ __esModule: true, default: (props: any) => <img {...props} /> }));

Expand Down Expand Up @@ -32,14 +34,18 @@ function renderItem(overrides: Partial<any> = {}) {
...overrides
};
const onCollection = jest.fn();
const setToasts = jest.fn();
const queryClient = createTestQueryClient();
render(
<DistributionPlanToolContext.Provider value={{ setToasts: jest.fn() } as any}>
<table><tbody>
<CreateSnapshotFormSearchCollectionDropdownItem collection={collection} onCollection={onCollection} />
</tbody></table>
</DistributionPlanToolContext.Provider>
<QueryClientProvider client={queryClient}>
<DistributionPlanToolContext.Provider value={{ setToasts } as any}>
<table><tbody>
<CreateSnapshotFormSearchCollectionDropdownItem collection={collection} onCollection={onCollection} />
</tbody></table>
</DistributionPlanToolContext.Provider>
</QueryClientProvider>
);
return { collection, onCollection };
return { collection, onCollection, setToasts };
}

describe('CreateSnapshotFormSearchCollectionDropdownItem', () => {
Expand Down Expand Up @@ -73,5 +79,47 @@ describe('CreateSnapshotFormSearchCollectionDropdownItem', () => {
);
expect(onCollection).toHaveBeenCalledWith({ name: collection.name, address: collection.address, tokenIds: '1,2' });
});
});

it('disables the row and shows a spinner while fetching sub collection ids', async () => {
let resolveFetch: ((value: { success: boolean; data: { tokenIds: string } }) => void) | null = null;
fetchMock.mockImplementationOnce(
() =>
new Promise((resolve) => {
resolveFetch = resolve;
})
);
const subId = `0x${'a'.repeat(40)}:sub`;
const { onCollection, collection } = renderItem({ id: subId });
const row = screen.getByRole('row');
await userEvent.click(row);

await waitFor(() => expect(row).toHaveAttribute('aria-disabled', 'true'));
await screen.findByTestId('collection-loading');

resolveFetch?.({ success: true, data: { tokenIds: '3,4' } });

await waitFor(() =>
expect(screen.queryByTestId('collection-loading')).not.toBeInTheDocument()
);
await waitFor(() =>
expect(onCollection).toHaveBeenCalledWith({
name: collection.name,
address: collection.address,
tokenIds: '3,4',
})
);
});

it('does not trigger an extra toast when token id fetch fails', async () => {
fetchMock.mockResolvedValueOnce({ success: false, data: null });
const subId = `0x${'a'.repeat(40)}:sub`;
const { setToasts } = renderItem({ id: subId });
await userEvent.click(screen.getByRole('row'));
await waitFor(() =>
expect(fetchMock).toHaveBeenCalledWith(
`/other/contract-token-ids-as-string/${subId}`
)
);
expect(setToasts).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { render, fireEvent, act } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
Comment thread
simo6529 marked this conversation as resolved.
import CreateSnapshotTableRowDownload from '@/components/distribution-plan-tool/create-snapshots/table/CreateSnapshotTableRowDownload';
import { DistributionPlanToolContext } from '@/components/distribution-plan-tool/DistributionPlanToolContext';
import { distributionPlanApiFetch } from '@/services/distribution-plan-api';
Expand All @@ -8,11 +9,17 @@ jest.mock('@/services/distribution-plan-api');

const distPlan = { id: '1' } as any;

const Wrapper: React.FC<{children: React.ReactNode}> = ({ children }) => (
<DistributionPlanToolContext.Provider value={{ distributionPlan: distPlan, setToasts: jest.fn() } as any}>
{children}
</DistributionPlanToolContext.Provider>
);
const Wrapper: React.FC<{children: React.ReactNode}> = ({ children }) => {
const [queryClient] = React.useState(() => new QueryClient());

return (
<QueryClientProvider client={queryClient}>
<DistributionPlanToolContext.Provider value={{ distributionPlan: distPlan, setToasts: jest.fn() } as any}>
{children}
</DistributionPlanToolContext.Provider>
</QueryClientProvider>
);
};

describe('CreateSnapshotTableRowDownload', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ describe("CreateDropCompact", () => {
render(
<CreateDropCompact
waveId="1"
profile={{} as any}
screenType={"MOBILE" as any}
editorState={null}
title={null}
files={[]}
metadata={[]}
canSubmit={true}
canAddPart={true}
loading={false}
Expand All @@ -34,7 +31,6 @@ describe("CreateDropCompact", () => {
missingMedia={[] as any}
missingMetadata={[] as any}
onViewChange={jest.fn()}
onMetadataRemove={jest.fn()}
onEditorState={jest.fn()}
onMentionedUser={jest.fn()}
onReferencedNft={jest.fn()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function renderComponent(screenType: CreateDropScreenType) {
<CreateDropFull
ref={ref}
screenType={screenType}
profile={{} as any}
title={null}
metadata={[]}
editorState={null}
Expand Down Expand Up @@ -87,4 +86,3 @@ describe('CreateDropFull', () => {
expect(desktopClearMock).not.toHaveBeenCalled();
});
});

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function renderComponent(props: Partial<React.ComponentProps<typeof CreateDropFu
render(
<CreateDropFullDesktop
ref={ref}
profile={{} as any}
title={null}
metadata={[]}
editorState={null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ describe('CreateDropWrapper Authentication Validation', () => {
setIsStormMode: jest.fn(),
setViewType: jest.fn(),
setDrop: jest.fn(),
setMentionedUsers: jest.fn(),
onMentionedUser: jest.fn(),
setReferencedNfts: jest.fn(),
setTitle: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,36 @@ import { DropVoteState } from '@/hooks/drops/types';

const mockReplay = jest.fn();
const mockAdd = jest.fn();
const mockStop = jest.fn();
Comment thread
simo6529 marked this conversation as resolved.

const createMockMojsHtmlInstance = () => {
const base = {
tune: jest.fn(),
stop: jest.fn(),
};

let thenMock!: jest.Mock;
const proxy = new Proxy(base, {
// Provide a `.then` handler without turning the object into a "thenable" for linting purposes.
get(target, property, receiver) {
if (property === 'then') {
return thenMock;
}

return Reflect.get(target, property, receiver);
},
});

thenMock = jest.fn().mockReturnValue(proxy);
return proxy;
};

jest.mock('@mojs/core', () => ({
__esModule: true,
default: {
Burst: jest.fn().mockImplementation(() => ({ tune: jest.fn() })),
Html: jest.fn().mockImplementation(() => ({ then: jest.fn().mockReturnThis(), tune: jest.fn() })),
Timeline: jest.fn().mockImplementation(() => ({ add: mockAdd, replay: mockReplay })),
Burst: jest.fn().mockImplementation(() => ({ tune: jest.fn(), stop: jest.fn() })),
Html: jest.fn().mockImplementation(() => createMockMojsHtmlInstance()),
Timeline: jest.fn().mockImplementation(() => ({ add: mockAdd, replay: mockReplay, stop: mockStop })),
easing: { bezier: jest.fn(), out: jest.fn() },
},
}));
Expand Down Expand Up @@ -56,6 +79,12 @@ jest.mock('react-tooltip', () => ({
}));

describe('DropListItemRateGiveClap', () => {
beforeEach(() => {
mockAdd.mockClear();
mockReplay.mockClear();
mockStop.mockClear();
});

it('triggers animation and submit on click when voting positive', async () => {
const onSubmit = jest.fn();
render(
Expand Down
20 changes: 18 additions & 2 deletions __tests__/components/groups/page/Groups.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ import React from "react";
import { TitleProvider } from "@/contexts/TitleContext";

const searchParams = new Map<string, string | null>();
const mockReplace = jest.fn((url: string) => {
if (!url.includes("?")) {
searchParams.delete("edit");
return;
}
const parsed = new URL(url, "http://localhost");
searchParams.clear();
parsed.searchParams.forEach((value, key) => {
searchParams.set(key, value);
});
});
jest.mock("next/navigation", () => ({
useSearchParams: () => ({
get: (key: string) => searchParams.get(key) ?? null,
}),
usePathname: () => "/groups",
useRouter: () => ({ replace: jest.fn() }),
useRouter: () => ({ replace: mockReplace }),
}));

jest.mock("@/components/groups/page/create/GroupCreate", () => (props: any) => (
Expand Down Expand Up @@ -40,6 +51,11 @@ describe("Groups page", () => {
requestAuth: jest.fn().mockResolvedValue({ success: true }),
} as any;

beforeEach(() => {
searchParams.clear();
mockReplace.mockClear();
});

it("opens create mode when edit param is present", async () => {
searchParams.set("edit", "123");
renderGroups(baseContext);
Expand All @@ -52,7 +68,7 @@ describe("Groups page", () => {
renderGroups(baseContext);
await screen.findByTestId("group-create");
await user.click(screen.getByRole("button", { name: /back/i }));
expect(screen.getByTestId("list-wrapper")).toBeInTheDocument();
expect(await screen.findByTestId("list-wrapper")).toBeInTheDocument();
});

it("shows list when not authenticated", () => {
Expand Down
2 changes: 1 addition & 1 deletion components/brain/direct-messages/DirectMessagesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const DirectMessagesList: React.FC<DirectMessagesListProps> = ({
observer.observe(sentinel);

return () => observer.disconnect();
}, [hasNextPage, isFetchingNextPage, list.length > 0]);
}, [hasNextPage, isFetchingNextPage, list.length, fetchNextPageIfNeeded]);

const shouldShowPlaceholder = !isAuthenticated || !connectedProfile?.handle;
const wavesWithPinned = useMemo(
Expand Down
Loading