-
Notifications
You must be signed in to change notification settings - Fork 4
Network table - xTDH #1716
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
Network table - xTDH #1716
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5d0f960
Network table - xTDH
prxt6529 391ac15
Merge branch 'main' into community-members-xtdh
prxt6529 9d8ce72
WIP
prxt6529 101f3e2
WIP
prxt6529 5280f28
WIP
prxt6529 b5e586b
WIP
prxt6529 96fc56b
WIP
prxt6529 f3a31b1
WIP
prxt6529 9f0575b
Merge branch 'main' into community-members-xtdh
prxt6529 7983155
WIP
prxt6529 e0b4b95
WIP
prxt6529 cacc0ce
WIP
prxt6529 4d042c8
WIP
prxt6529 617f4cb
WIP
prxt6529 15bb361
WIP
prxt6529 24b4fd2
WIP
prxt6529 4ce7eca
WIP
prxt6529 79b0a7e
WIP
prxt6529 f6d9b99
WIP
prxt6529 72cdd13
WIP
prxt6529 d910387
Merge branch 'main' into community-members-xtdh
prxt6529 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
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
168 changes: 136 additions & 32 deletions
168
__tests__/components/community/members-table/CommunityMembersMobileCard.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,45 +1,149 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import React from 'react'; | ||
|
|
||
| jest.mock('next/link', () => ({ __esModule: true, default: ({ href, children }: any) => <a href={href}>{children}</a> })); | ||
| jest.mock('@/components/utils/CommonTimeAgo', () => ({ __esModule: true, default: ({ timestamp }: any) => <span data-testid="time">{timestamp}</span> })); | ||
| jest.mock('@/components/user/utils/user-cic-type/UserCICTypeIcon', () => ({ __esModule: true, default: () => <span data-testid="cic" /> })); | ||
| jest.mock('@/components/user/utils/level/UserLevel', () => ({ __esModule: true, default: () => <div data-testid="level" /> })); | ||
| jest.mock('@/helpers/Helpers', () => ({ | ||
| import CommunityMembersMobileCard from "@/components/community/members-table/CommunityMembersMobileCard"; | ||
| import type { ApiCommunityMemberOverview } from "@/generated/models/ApiCommunityMemberOverview"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import type { ReactNode } from "react"; | ||
|
|
||
| jest.mock("next/link", () => ({ | ||
| __esModule: true, | ||
| default: ({ href, children }: { href: string; children: ReactNode }) => ( | ||
| <a href={href}>{children}</a> | ||
| ), | ||
| })); | ||
|
prxt6529 marked this conversation as resolved.
|
||
| jest.mock("@/components/user/utils/level/UserLevel", () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="level" />, | ||
| })); | ||
| jest.mock("@/components/user/utils/user-cic-type/UserCICTypeIcon", () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="cic-icon" />, | ||
| })); | ||
| jest.mock("@/helpers/Helpers", () => ({ | ||
| formatNumberWithCommasOrDash: (n: number) => `f${n}`, | ||
| cicToType: (c: number) => c, | ||
| formatLargeNumber: (n: number) => `${n}M`, | ||
| getTimeAgoShort: () => "2d", | ||
| })); | ||
| jest.mock('@/helpers/AllowlistToolHelpers', () => ({ | ||
| isEthereumAddress: () => false, | ||
| jest.mock("@/helpers/AllowlistToolHelpers", () => ({ | ||
| isEthereumAddress: (val: string) => val.startsWith("0x"), | ||
| isAutoGeneratedHandle: () => false, | ||
| })); | ||
| jest.mock('@/helpers/image.helpers', () => ({ | ||
| ImageScale: { W_AUTO_H_50: '50' }, | ||
| jest.mock("@/helpers/image.helpers", () => ({ | ||
| ImageScale: { W_AUTO_H_50: "50" }, | ||
| getScaledImageUri: (u: string) => u, | ||
| })); | ||
|
|
||
| import CommunityMembersMobileCard from '@/components/community/members-table/CommunityMembersMobileCard'; | ||
|
|
||
| const member = { | ||
| display: 'Alice', | ||
| detail_view_key: 'alice', | ||
| const baseMember: ApiCommunityMemberOverview = { | ||
| display: "Alice", | ||
| detail_view_key: "alice", | ||
| level: 1, | ||
| tdh: 100, | ||
| rep: 50, | ||
| tdh_rate: 10, | ||
| xtdh: 55, | ||
| xtdh_rate: 5, | ||
| combined_tdh: 150, | ||
| combined_tdh_rate: 15, | ||
| rep: 60, | ||
| cic: 1, | ||
| pfp: 'url', | ||
| pfp: "url", | ||
| last_activity: 10, | ||
| wallet: '0x1', | ||
| } as any; | ||
|
|
||
| describe('CommunityMembersMobileCard', () => { | ||
| it('renders member info and link', () => { | ||
| render(<CommunityMembersMobileCard member={member} rank={2} />); | ||
| expect(screen.getByText('#2')).toBeInTheDocument(); | ||
| expect(screen.getByText('Alice')).toBeInTheDocument(); | ||
| expect(screen.getByText('f100')).toBeInTheDocument(); | ||
| expect(screen.getByText('f50')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('cic')).toBeInTheDocument(); | ||
| expect(screen.getByRole('link')).toHaveAttribute('href', '/alice'); | ||
| wallet: "0x1", | ||
| xtdh_outgoing: 0, | ||
| xtdh_incoming: 0, | ||
| }; | ||
|
|
||
| describe("CommunityMembersMobileCard", () => { | ||
| describe("rendering", () => { | ||
| it("renders rank badge and profile link", () => { | ||
| render(<CommunityMembersMobileCard member={baseMember} rank={2} />); | ||
|
|
||
| expect(screen.getByText("#2")).toBeInTheDocument(); | ||
| expect(screen.getByRole("link")).toHaveAttribute("href", "/alice"); | ||
| }); | ||
|
|
||
| it("renders member display name", () => { | ||
| render(<CommunityMembersMobileCard member={baseMember} rank={1} />); | ||
|
|
||
| expect(screen.getByText("Alice")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders level and CIC icon", () => { | ||
| render(<CommunityMembersMobileCard member={baseMember} rank={1} />); | ||
|
|
||
| expect(screen.getByTestId("level")).toBeInTheDocument(); | ||
| expect(screen.getByTestId("cic-icon")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders all stat labels", () => { | ||
| render(<CommunityMembersMobileCard member={baseMember} rank={1} />); | ||
|
|
||
| expect(screen.getByText("TDH")).toBeInTheDocument(); | ||
| expect(screen.getByText("xTDH")).toBeInTheDocument(); | ||
| expect(screen.getByText("REP")).toBeInTheDocument(); | ||
| expect(screen.getByText("NIC")).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("TDH/xTDH formatting", () => { | ||
| it("formats large numbers correctly", () => { | ||
| render(<CommunityMembersMobileCard member={baseMember} rank={1} />); | ||
|
|
||
| expect(screen.getByText("100M")).toBeInTheDocument(); | ||
| expect(screen.getByText("55M")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("handles zero values with dash", () => { | ||
| const zeroMember: ApiCommunityMemberOverview = { | ||
| ...baseMember, | ||
| tdh: 0, | ||
| xtdh: 0, | ||
| }; | ||
| render(<CommunityMembersMobileCard member={zeroMember} rank={1} />); | ||
|
|
||
| const dashValues = screen.getAllByText("-"); | ||
| expect(dashValues).toHaveLength(2); | ||
| }); | ||
| }); | ||
|
|
||
| describe("last activity", () => { | ||
| it("renders Last Seen when last_activity is present", () => { | ||
| render(<CommunityMembersMobileCard member={baseMember} rank={1} />); | ||
|
|
||
| expect(screen.getByText("Last Seen")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("does not render Last Seen when last_activity is null", () => { | ||
| const noActivityMember: ApiCommunityMemberOverview = { | ||
| ...baseMember, | ||
| last_activity: null, | ||
| }; | ||
| render(<CommunityMembersMobileCard member={noActivityMember} rank={1} />); | ||
|
|
||
| expect(screen.queryByText("Last Seen")).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("profile type branches", () => { | ||
| it("renders with ethereum address as detail_view_key", () => { | ||
| const ethMember: ApiCommunityMemberOverview = { | ||
| ...baseMember, | ||
| detail_view_key: "0xabc123", | ||
| display: "0xabc123", | ||
| }; | ||
| render(<CommunityMembersMobileCard member={ethMember} rank={1} />); | ||
|
|
||
| expect(screen.getByRole("link")).toHaveAttribute("href", "/0xabc123"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("keyboard accessibility", () => { | ||
| it("link can receive focus via keyboard", async () => { | ||
| const user = userEvent.setup(); | ||
| render(<CommunityMembersMobileCard member={baseMember} rank={1} />); | ||
|
|
||
| await user.tab(); | ||
|
|
||
| const link = screen.getByRole("link"); | ||
| expect(link).toHaveFocus(); | ||
| }); | ||
| }); | ||
| }); | ||
|
prxt6529 marked this conversation as resolved.
|
||
45 changes: 0 additions & 45 deletions
45
__tests__/components/community/members-table/CommunityMembersMobileFilterBar.test.tsx
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
__tests__/components/community/members-table/CommunityMembersMobileSortContent.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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { render, screen, fireEvent } from "@testing-library/react"; | ||
| import CommunityMembersMobileSortContent from "@/components/community/members-table/CommunityMembersMobileSortContent"; | ||
| import { ApiCommunityMembersSortOption } from "@/generated/models/ApiCommunityMembersSortOption"; | ||
| import { SortDirection } from "@/entities/ISort"; | ||
|
|
||
| jest.mock("@/components/user/utils/icons/CommonTableSortIcon", () => ({ | ||
| __esModule: true, | ||
| default: ({ direction }: { direction: string }) => ( | ||
| <span data-testid="sort-icon">{direction}</span> | ||
| ), | ||
| })); | ||
|
|
||
| describe("CommunityMembersMobileSortContent", () => { | ||
| const defaultProps = { | ||
| activeSort: ApiCommunityMembersSortOption.Level, | ||
| sortDirection: SortDirection.DESC, | ||
| onSort: jest.fn(), | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("renders all sort options", () => { | ||
| render(<CommunityMembersMobileSortContent {...defaultProps} />); | ||
|
|
||
| expect(screen.getByText("Level")).toBeInTheDocument(); | ||
| expect(screen.getByText("TDH")).toBeInTheDocument(); | ||
| expect(screen.getByText("xTDH")).toBeInTheDocument(); | ||
| expect(screen.getByText("REP")).toBeInTheDocument(); | ||
| expect(screen.getByText("NIC")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("calls onSort when clicking an option", () => { | ||
| const onSort = jest.fn(); | ||
| render( | ||
| <CommunityMembersMobileSortContent {...defaultProps} onSort={onSort} /> | ||
| ); | ||
|
|
||
| fireEvent.click(screen.getByText("TDH")); | ||
|
|
||
| expect(onSort).toHaveBeenCalledWith(ApiCommunityMembersSortOption.Tdh); | ||
| }); | ||
|
|
||
| it("shows active styling for selected option", () => { | ||
| render(<CommunityMembersMobileSortContent {...defaultProps} />); | ||
|
|
||
| const levelButton = screen.getByText("Level").closest("button"); | ||
| expect(levelButton?.className).toContain("tw-border-primary-500"); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.