Skip to content
Merged

wip #1572

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
19 changes: 13 additions & 6 deletions __tests__/components/common/TabToggleWithOverflow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,27 @@ describe('TabToggleWithOverflow', () => {

await user.tab(); // focus first tab
await user.tab(); // focus second tab
await user.tab(); // focus overflow trigger
moreButton.focus();
expect(moreButton).toHaveFocus();
await user.keyboard('{Enter}');
expect(moreButton).toHaveAttribute('aria-expanded', 'true');
const optionC = screen.getByRole('menuitem', { name: 'C' });
await waitFor(() =>
expect(moreButton).toHaveAttribute('aria-expanded', 'true')
);
const optionC = await screen.findByRole('menuitem', { name: 'C' });
expect(optionC).toBeInTheDocument();

await user.keyboard('{Escape}');
expect(moreButton).toHaveAttribute('aria-expanded', 'false');
await waitFor(() =>
expect(screen.queryByRole('menuitem', { name: 'C' })).not.toBeInTheDocument()
expect(moreButton).toHaveAttribute('aria-expanded', 'false')
);
await waitFor(() => {
expect(screen.queryByRole('menuitem', { name: 'C' })).not.toBeInTheDocument();
});

await user.keyboard(' ');
expect(moreButton).toHaveAttribute('aria-expanded', 'true');
await waitFor(() =>
expect(moreButton).toHaveAttribute('aria-expanded', 'true')
);
});

it('indicates overflow active state via data attribute when opened', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ describe("Eastern time transitions", () => {
const mintStart = mintStartInstantUtcForMintDay(mintDay);
const mintEnd = mintEndInstantUtcForMintDay(mintDay);

expect(mintStart.toISOString()).toBe("2024-03-11T14:40:00.000Z");
expect(mintEnd.toISOString()).toBe("2024-03-12T14:00:00.000Z");
expect(mintStart.toISOString()).toBe("2024-03-11T15:40:00.000Z");
expect(mintEnd.toISOString()).toBe("2024-03-12T15:00:00.000Z");
Comment thread
simo6529 marked this conversation as resolved.
});

it("returns to EST once the fall shift completes", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ describe('IdentitySearch', () => {

it('opens dropdown after typing and selects value', () => {
render(<IdentitySearch identity={null} setIdentity={setIdentity} />);
const input = screen.getByRole('textbox');
const input = screen.getByRole('combobox', { name: 'Identity' });
fireEvent.focus(input);
expect(receivedProps.open).toBe(false);
fireEvent.change(input, { target: { value: 'a' } });
expect(receivedProps.open).toBe(false);
fireEvent.change(input, { target: { value: 'abc' } });
expect(receivedProps.open).toBe(true);
receivedProps.onProfileSelect({ handle: 'user' });
expect(setIdentity).toHaveBeenCalledWith('user');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ const profile = { handle: "alice", wallet: "0x1", display: "Alice", pfp: "img.pn
it("calls on select and shows checkmark when selected", () => {
const onSelect = jest.fn();
render(
<CommonProfileSearchItem
profile={profile}
selected="0x1"
onProfileSelect={onSelect}
id="profile-search-item-0x1"
/>
<ul>
<CommonProfileSearchItem
profile={profile}
selected="0x1"
onProfileSelect={onSelect}
id="profile-search-item-0x1"
/>
</ul>
);
expect(screen.getByAltText(/Community Table Profile Picture/)).toBeInTheDocument();
expect(screen.getByRole("option")).toHaveAttribute("aria-selected", "true");
fireEvent.click(screen.getByRole("button"));
expect(screen.getByAltText(/Alice avatar/i)).toBeInTheDocument();
const listItem = screen.getByText("Alice").closest("li");
if (!listItem) {
throw new Error("List item not found");
}
expect(listItem).toHaveAttribute("data-option-id", "profile-search-item-0x1");
expect(listItem.querySelector("svg")).toBeInTheDocument();
fireEvent.click(listItem);
expect(onSelect).toHaveBeenCalled();
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ describe('CommonProfileSearchItems', () => {
const { rerender } = render(
<CommonProfileSearchItems open profiles={[]} selected={null} searchCriteria="ab" onProfileSelect={jest.fn()} />
);
expect(screen.getByText('Type at least 3 characters')).toBeInTheDocument();
expect(screen.getAllByText('Type at least 3 characters')).toHaveLength(2);

rerender(
<CommonProfileSearchItems open profiles={[]} selected={null} searchCriteria="abcd" onProfileSelect={jest.fn()} />
);
expect(screen.getByText('No results')).toBeInTheDocument();
expect(screen.getAllByText('No results')).toHaveLength(2);
});

it('notifies highlighted option id when highlighted option changes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('calls setSelected on click', () => {
const setSelected = jest.fn();
const item = { label: 'Item', value: 'v', key: 'k' };
render(<CommonDropdownItem item={item} activeItem="" setSelected={setSelected} isMobile={false} />);
fireEvent.click(screen.getByRole('button'));
fireEvent.click(screen.getByRole('menuitem', { name: 'Item' }));
expect(setSelected).toHaveBeenCalledWith('v');
});

Expand All @@ -22,7 +22,7 @@ test('shows check icon when active', () => {
render(<CommonDropdownItem item={item} activeItem="v" setSelected={jest.fn()} isMobile={false} sortDirection={SortDirection.ASC} />);
expect(screen.getByTestId('sort')).toBeInTheDocument();
expect(screen.getByTestId('sort')).toHaveTextContent('ASC');
expect(screen.getByRole('button').querySelector('svg')).toBeInTheDocument();
expect(screen.getByRole('menuitem', { name: /Item/ }).querySelector('svg')).toBeInTheDocument();
});

test('handles copy feedback', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,44 @@ import WaveGroupEditButtons from '@/components/waves/specs/groups/group/edit/Wav
import { WaveGroupType } from '@/components/waves/specs/groups/group/WaveGroup.types';
import { AuthContext } from '@/components/auth/Auth';
import { ReactQueryWrapperContext } from '@/components/react-query-wrapper/ReactQueryWrapper';
import { useMutation } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';

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

jest.mock('@/components/waves/specs/groups/group/edit/WaveGroupEditButton', () => ({
__esModule: true,
default: ({ onWaveUpdate, renderTrigger }: any) => {
default: React.forwardRef(({ onWaveUpdate, renderTrigger }: any, ref: any) => {
const handleOpen = () => onWaveUpdate({});
if (typeof ref === 'function') {
ref({ open: handleOpen });
} else if (ref) {
ref.current = { open: handleOpen };
}
if (renderTrigger === null) {
return null;
}
return renderTrigger ? <>{renderTrigger({ open: handleOpen })}</> : <button onClick={handleOpen}>edit</button>;
},
}),
}));

jest.mock('@/components/waves/specs/groups/group/edit/WaveGroupRemoveButton', () => ({
__esModule: true,
default: ({ onWaveUpdate, renderTrigger }: any) => {
default: React.forwardRef(({ onWaveUpdate, renderTrigger }: any, ref: any) => {
const handleOpen = () => onWaveUpdate({});
if (typeof ref === 'function') {
ref({ open: handleOpen });
} else if (ref) {
ref.current = { open: handleOpen };
}
if (renderTrigger === null) {
return null;
}
return renderTrigger ? <>{renderTrigger({ open: handleOpen })}</> : <button onClick={handleOpen}>remove</button>;
},
}),
}));

jest.mock('@/components/waves/specs/groups/group/edit/WaveGroupManageIdentitiesModal', () => ({
Expand All @@ -49,7 +63,15 @@ jest.mock('@/components/distribution-plan-tool/common/CircleLoader', () => ({
}));

const mutateAsync = jest.fn();
const queryClientMock = {
ensureQueryData: jest.fn(),
fetchQuery: jest.fn(),
setQueryData: jest.fn(),
};

(useMutation as jest.Mock).mockReturnValue({ mutateAsync });
(useQuery as jest.Mock).mockReturnValue({ data: undefined });
(useQueryClient as jest.Mock).mockImplementation(() => queryClientMock);

const auth = {
setToast: jest.fn(),
Expand Down Expand Up @@ -98,6 +120,16 @@ const wave: any = {
describe('WaveGroupEditButtons', () => {
beforeEach(() => {
jest.clearAllMocks();
mutateAsync.mockClear();
queryClientMock.ensureQueryData.mockReset();
queryClientMock.fetchQuery.mockReset();
queryClientMock.setQueryData.mockReset();
queryClientMock.ensureQueryData.mockResolvedValue(null);
queryClientMock.fetchQuery.mockResolvedValue([]);
queryClientMock.setQueryData.mockImplementation(() => {});
(useMutation as jest.Mock).mockReturnValue({ mutateAsync });
(useQuery as jest.Mock).mockReturnValue({ data: undefined });
(useQueryClient as jest.Mock).mockImplementation(() => queryClientMock);
});

it('opens menu and calls mutate on edit', async () => {
Expand Down
Loading