-
Notifications
You must be signed in to change notification settings - Fork 4
Mobile leaderboard responsiveness #2065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
160 changes: 115 additions & 45 deletions
160
__tests__/components/waves/leaderboard/drops/DefaultWaveLeaderboardDrop.interaction.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,74 +1,144 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { DefaultWaveLeaderboardDrop } from '@/components/waves/leaderboard/drops/DefaultWaveLeaderboardDrop'; | ||
| import React from "react"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { DefaultWaveLeaderboardDrop } from "@/components/waves/leaderboard/drops/DefaultWaveLeaderboardDrop"; | ||
|
|
||
| jest.mock('next/navigation', () => ({ | ||
| jest.mock("next/navigation", () => ({ | ||
| useRouter: jest.fn(() => ({ push: jest.fn() })), | ||
| usePathname: () => '/', | ||
| useSearchParams: () => ({ toString: () => '', get: () => null }), | ||
| usePathname: () => "/", | ||
| useSearchParams: () => ({ toString: () => "", get: () => null }), | ||
| })); | ||
| jest.mock('@/hooks/drops/useDropInteractionRules', () => ({ | ||
| jest.mock("@/hooks/drops/useDropInteractionRules", () => ({ | ||
| useDropInteractionRules: jest.fn(), | ||
| })); | ||
| jest.mock('@/hooks/useDeviceInfo', () => jest.fn()); | ||
| jest.mock('@/hooks/isMobileScreen', () => jest.fn()); | ||
| jest.mock('@/hooks/useLongPressInteraction', () => jest.fn()); | ||
| jest.mock('@/components/voting', () => ({ | ||
| jest.mock("@/hooks/useDeviceInfo", () => jest.fn()); | ||
| jest.mock("@/hooks/isMobileScreen", () => jest.fn()); | ||
| jest.mock("@/hooks/useLongPressInteraction", () => jest.fn()); | ||
| jest.mock("@/components/voting", () => ({ | ||
| VotingModal: (p: any) => <div data-testid="modal">{String(p.isOpen)}</div>, | ||
| MobileVotingModal: (p: any) => <div data-testid="mobile">{String(p.isOpen)}</div>, | ||
| MobileVotingModal: (p: any) => ( | ||
| <div data-testid="mobile">{String(p.isOpen)}</div> | ||
| ), | ||
| })); | ||
| jest.mock('@/components/voting/VotingModalButton', () => (p: any) => <button data-testid="vote-btn" onClick={p.onClick} />); | ||
| jest.mock('@/components/waves/drops/WaveDropActionsOptions', () => ({ __esModule: true, default: () => <div data-testid="options" /> })); | ||
| jest.mock('@/components/waves/drops/WaveDropActionsOpen', () => ({ __esModule: true, default: () => <div /> })); | ||
| jest.mock('@/components/waves/drops/WaveDropMobileMenuOpen', () => () => <div />); | ||
| jest.mock('@/components/waves/drops/WaveDropMobileMenuDelete', () => () => <div />); | ||
| jest.mock('@/components/utils/select/dropdown/CommonDropdownItemsMobileWrapper', () => (p: any) => <div>{p.children}</div>); | ||
| jest.mock('@/components/waves/leaderboard/drops/header/WaveLeaderboardDropHeader', () => ({ WaveLeaderboardDropHeader: () => <div data-testid="header" /> })); | ||
| jest.mock('@/components/waves/leaderboard/content/WaveLeaderboardDropContent', () => ({ WaveLeaderboardDropContent: () => <div data-testid="content" /> })); | ||
| jest.mock('@/components/waves/leaderboard/drops/footer/WaveLeaderboardDropFooter', () => ({ WaveLeaderboardDropFooter: () => <div data-testid="footer" /> })); | ||
| jest.mock('@/components/waves/leaderboard/drops/header/WaveleaderboardDropRaters', () => ({ WaveLeaderboardDropRaters: () => <div data-testid="raters" /> })); | ||
| jest.mock("@/components/voting/VotingModalButton", () => (p: any) => ( | ||
| <button data-testid="vote-btn" onClick={p.onClick} /> | ||
| )); | ||
| jest.mock("@/components/waves/drops/WaveDropActionsOptions", () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="options" />, | ||
| })); | ||
| jest.mock("@/components/waves/drops/WaveDropActionsOpen", () => ({ | ||
| __esModule: true, | ||
| default: () => <div />, | ||
| })); | ||
| jest.mock("@/components/waves/drops/WaveDropMobileMenuOpen", () => () => ( | ||
| <div /> | ||
| )); | ||
| jest.mock("@/components/waves/drops/WaveDropMobileMenuDelete", () => () => ( | ||
| <div /> | ||
| )); | ||
| jest.mock( | ||
| "@/components/utils/select/dropdown/CommonDropdownItemsMobileWrapper", | ||
| () => (p: any) => <div>{p.children}</div> | ||
| ); | ||
| jest.mock( | ||
| "@/components/waves/leaderboard/drops/header/WaveLeaderboardDropHeader", | ||
| () => ({ WaveLeaderboardDropHeader: () => <div data-testid="header" /> }) | ||
| ); | ||
| jest.mock( | ||
| "@/components/waves/leaderboard/content/WaveLeaderboardDropContent", | ||
| () => ({ WaveLeaderboardDropContent: () => <div data-testid="content" /> }) | ||
| ); | ||
| jest.mock( | ||
| "@/components/waves/leaderboard/drops/footer/WaveLeaderboardDropFooter", | ||
| () => ({ WaveLeaderboardDropFooter: () => <div data-testid="footer" /> }) | ||
| ); | ||
| jest.mock( | ||
| "@/components/waves/leaderboard/drops/header/WaveleaderboardDropRaters", | ||
| () => ({ WaveLeaderboardDropRaters: () => <div data-testid="raters" /> }) | ||
| ); | ||
|
|
||
| const useRules = require('@/hooks/drops/useDropInteractionRules').useDropInteractionRules as jest.Mock; | ||
| const useDeviceInfo = require('@/hooks/useDeviceInfo') as jest.Mock; | ||
| const useIsMobileScreen = require('@/hooks/isMobileScreen') as jest.Mock; | ||
| const useLongPressInteraction = require('@/hooks/useLongPressInteraction') as jest.Mock; | ||
| const useRules = require("@/hooks/drops/useDropInteractionRules") | ||
| .useDropInteractionRules as jest.Mock; | ||
| const useDeviceInfo = require("@/hooks/useDeviceInfo") as jest.Mock; | ||
| const useIsMobileScreen = require("@/hooks/isMobileScreen") as jest.Mock; | ||
| const useLongPressInteraction = | ||
| require("@/hooks/useLongPressInteraction") as jest.Mock; | ||
|
|
||
| const drop = { | ||
| id: 'd1', | ||
| const drop = { | ||
| id: "d1", | ||
| rank: 1, | ||
| author: { | ||
| handle: 'testuser', | ||
| handle: "testuser", | ||
| pfp: null, | ||
| level: 1, | ||
| cic: 0 | ||
| cic: 0, | ||
| }, | ||
| created_at: new Date().toISOString() | ||
| created_at: new Date().toISOString(), | ||
| } as any; | ||
| const wave = { id: 'w1' } as any; | ||
| const wave = { id: "w1" } as any; | ||
|
|
||
| beforeEach(() => { | ||
| useLongPressInteraction.mockReturnValue({ isActive: false, setIsActive: jest.fn(), touchHandlers: {} }); | ||
| useLongPressInteraction.mockReturnValue({ | ||
| isActive: false, | ||
| setIsActive: jest.fn(), | ||
| touchHandlers: {}, | ||
| }); | ||
| }); | ||
|
|
||
| test('opens voting modal when button clicked', async () => { | ||
| test("opens voting modal when button clicked", async () => { | ||
| const user = userEvent.setup(); | ||
| useRules.mockReturnValue({ canShowVote: true, canDelete: true }); | ||
| useDeviceInfo.mockReturnValue({ hasTouchScreen: false }); | ||
| useIsMobileScreen.mockReturnValue(false); | ||
| render(<DefaultWaveLeaderboardDrop drop={drop} wave={wave} onDropClick={jest.fn()} />); | ||
| expect(screen.getByTestId('modal')).toHaveTextContent('false'); | ||
| await user.click(screen.getByTestId('vote-btn')); | ||
| expect(screen.getByTestId('modal')).toHaveTextContent('true'); | ||
| expect(screen.getByTestId('options')).toBeInTheDocument(); | ||
| render( | ||
| <DefaultWaveLeaderboardDrop | ||
| drop={drop} | ||
| wave={wave} | ||
| onDropClick={jest.fn()} | ||
| /> | ||
| ); | ||
| expect(screen.getByTestId("modal")).toHaveTextContent("false"); | ||
| await user.click(screen.getByTestId("vote-btn")); | ||
| expect(screen.getByTestId("modal")).toHaveTextContent("true"); | ||
| expect(screen.getByTestId("options")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('uses mobile modal and hides options when cannot delete', () => { | ||
| test("uses mobile modal and hides options when cannot delete", () => { | ||
| useRules.mockReturnValue({ canShowVote: true, canDelete: false }); | ||
| useDeviceInfo.mockReturnValue({ hasTouchScreen: false }); | ||
| useIsMobileScreen.mockReturnValue(true); | ||
| useLongPressInteraction.mockReturnValue({ isActive: false, setIsActive: jest.fn(), touchHandlers: {} }); | ||
| render(<DefaultWaveLeaderboardDrop drop={drop} wave={wave} onDropClick={jest.fn()} />); | ||
| expect(screen.getByTestId('mobile')).toHaveTextContent('false'); | ||
| expect(screen.queryByTestId('options')).toBeNull(); | ||
| useLongPressInteraction.mockReturnValue({ | ||
| isActive: false, | ||
| setIsActive: jest.fn(), | ||
| touchHandlers: {}, | ||
| }); | ||
| render( | ||
| <DefaultWaveLeaderboardDrop | ||
| drop={drop} | ||
| wave={wave} | ||
| onDropClick={jest.fn()} | ||
| /> | ||
| ); | ||
| expect(screen.getByTestId("mobile")).toHaveTextContent("false"); | ||
| expect(screen.queryByTestId("options")).toBeNull(); | ||
| }); | ||
|
|
||
| test("keeps native touch scrolling enabled for long-press handlers", () => { | ||
| useRules.mockReturnValue({ canShowVote: true, canDelete: false }); | ||
| useDeviceInfo.mockReturnValue({ hasTouchScreen: true }); | ||
| useIsMobileScreen.mockReturnValue(true); | ||
|
|
||
| render( | ||
| <DefaultWaveLeaderboardDrop | ||
| drop={drop} | ||
| wave={wave} | ||
| onDropClick={jest.fn()} | ||
| /> | ||
| ); | ||
|
|
||
| expect(useLongPressInteraction).toHaveBeenCalledWith({ | ||
| hasTouchScreen: true, | ||
| preventDefault: false, | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.