-
Notifications
You must be signed in to change notification settings - Fork 4
total rep received and given #2023
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
12 commits
Select commit
Hold shift + click to select a range
3a80cb8
total rep received and given
ragnep 892814c
received and given rep views
ragnep fbf757b
deleted leftovers
ragnep 5c368ab
wip
ragnep abea606
Merge branch 'main' into outoing-rep
ragnep d2cba09
merge main
ragnep a07bbf2
wip
ragnep 6868cb1
wip
ragnep 726ca4e
Merge branch 'main' into outoing-rep
ragnep f2dfde4
wip
ragnep cec1d97
Merge branch 'main' into outoing-rep
ragnep fbe41ff
Merge branch 'main' into outoing-rep
ragnep 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
99 changes: 71 additions & 28 deletions
99
__tests__/components/user/identity/header/UserPageIdentityHeaderCIC.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,43 +1,86 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import UserPageIdentityHeaderCIC from '@/components/user/identity/header/UserPageIdentityHeaderCIC'; | ||
| import type { ApiIdentity } from '@/generated/models/ApiIdentity'; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import UserPageIdentityHeaderCIC from "@/components/user/identity/header/UserPageIdentityHeaderCIC"; | ||
| import type { ApiIdentity } from "@/generated/models/ApiIdentity"; | ||
| import type { ApiCicOverview } from "@/generated/models/ApiCicOverview"; | ||
|
|
||
| jest.mock('@tanstack/react-query', () => ({ | ||
| useQuery: jest.fn(() => ({ data: { count: 2 } })), | ||
| })); | ||
| jest.mock( | ||
| "@/components/user/utils/user-cic-type/UserCICTypeIconWrapper", | ||
| () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="icon" />, | ||
| }) | ||
| ); | ||
|
|
||
| jest.mock('@/components/user/utils/user-cic-type/UserCICTypeIconWrapper', () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="icon" />, | ||
| })); | ||
|
|
||
| jest.mock('@/components/user/rep/header/TopRaterAvatars', () => ({ | ||
| jest.mock("@/components/common/OverlappingAvatars", () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="raters-avatars" />, | ||
| })); | ||
|
|
||
| jest.mock('@/components/user/utils/user-cic-status/UserCICStatus', () => ({ | ||
| jest.mock("@/components/user/utils/user-cic-status/UserCICStatus", () => ({ | ||
| __esModule: true, | ||
| default: ({ cic }: { cic: number }) => <div data-testid="status">{cic}</div>, | ||
| })); | ||
|
|
||
| describe('UserPageIdentityHeaderCIC', () => { | ||
| const baseProfile: ApiIdentity = { cic: 1000, handle: 'alice' } as ApiIdentity; | ||
| const makeCicOverview = ( | ||
| totalCic: number, | ||
| contributorCount: number | ||
| ): ApiCicOverview => | ||
| ({ | ||
| total_cic: totalCic, | ||
| authenticated_user_contribution: null, | ||
| contributor_count: contributorCount, | ||
| contributors: { | ||
| data: [ | ||
| { | ||
| contribution: 500, | ||
| profile: { | ||
| id: "1", | ||
| handle: "bob", | ||
| pfp: null, | ||
| primary_address: "0x123", | ||
| }, | ||
| }, | ||
| ], | ||
| page: 1, | ||
| next: false, | ||
| }, | ||
| }) as unknown as ApiCicOverview; | ||
|
|
||
| describe("UserPageIdentityHeaderCIC", () => { | ||
| const baseProfile: ApiIdentity = { | ||
| cic: 1000, | ||
| handle: "alice", | ||
| } as ApiIdentity; | ||
|
|
||
| it('displays NIC and status info', () => { | ||
| render(<UserPageIdentityHeaderCIC profile={baseProfile} />); | ||
| expect(screen.getByText('NIC')).toBeInTheDocument(); | ||
| expect(screen.getByText('1,000')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('raters-avatars')).toBeInTheDocument(); | ||
| expect(screen.getByText('2 raters')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('icon')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('status')).toHaveTextContent('1000'); | ||
| it("displays NIC and status info from cicOverview", () => { | ||
| const overview = makeCicOverview(1000, 2); | ||
| render( | ||
| <UserPageIdentityHeaderCIC profile={baseProfile} cicOverview={overview} /> | ||
| ); | ||
| expect(screen.getByText("NIC")).toBeInTheDocument(); | ||
| expect(screen.getByText("1,000")).toBeInTheDocument(); | ||
| expect(screen.getByTestId("raters-avatars")).toBeInTheDocument(); | ||
| expect(screen.getByText("2 raters")).toBeInTheDocument(); | ||
| expect(screen.getByTestId("icon")).toBeInTheDocument(); | ||
| expect(screen.getByTestId("status")).toHaveTextContent("1000"); | ||
| }); | ||
|
|
||
| it('updates when profile prop changes', () => { | ||
| const { rerender } = render(<UserPageIdentityHeaderCIC profile={baseProfile} />); | ||
| rerender(<UserPageIdentityHeaderCIC profile={{ cic: 2000, handle: 'alice' } as ApiIdentity} />); | ||
| expect(screen.getByText('2,000')).toBeInTheDocument(); | ||
| expect(screen.getByTestId('status')).toHaveTextContent('2000'); | ||
| it("updates when cicOverview prop changes", () => { | ||
| const overview1 = makeCicOverview(1000, 2); | ||
| const overview2 = makeCicOverview(2000, 3); | ||
| const { rerender } = render( | ||
| <UserPageIdentityHeaderCIC | ||
| profile={baseProfile} | ||
| cicOverview={overview1} | ||
| /> | ||
| ); | ||
| rerender( | ||
| <UserPageIdentityHeaderCIC | ||
| profile={{ cic: 2000, handle: "alice" } as ApiIdentity} | ||
| cicOverview={overview2} | ||
| /> | ||
| ); | ||
| expect(screen.getByText("2,000")).toBeInTheDocument(); | ||
| expect(screen.getByTestId("status")).toHaveTextContent("2000"); | ||
| }); | ||
| }); |
51 changes: 35 additions & 16 deletions
51
__tests__/components/user/rep/header/UserPageRepHeader.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,25 +1,44 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import UserPageRepHeader from '@/components/user/rep/header/UserPageRepHeader'; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import UserPageRepHeader from "@/components/user/rep/header/UserPageRepHeader"; | ||
|
|
||
| const mockProfile = { | ||
| handle: 'testuser', | ||
| display: 'Test User', | ||
| query: 'testuser', | ||
| handle: "testuser", | ||
| display: "Test User", | ||
| query: "testuser", | ||
| } as any; | ||
|
|
||
| describe('UserPageRepHeader', () => { | ||
| it('shows rep totals when provided', () => { | ||
| const repRates = { | ||
| total_rep_rating: 1500, | ||
| number_of_raters: 25, | ||
| rating_stats: [], | ||
| describe("UserPageRepHeader", () => { | ||
| it("shows rep totals when provided", () => { | ||
| const overview = { | ||
| total_rep: 1500, | ||
| contributor_count: 25, | ||
| authenticated_user_contribution: null, | ||
| contributors: { data: [], page: 1, next: false }, | ||
| } as any; | ||
| render(<UserPageRepHeader repRates={repRates} profile={mockProfile} />); | ||
| expect(screen.getByText('1,500')).toBeInTheDocument(); | ||
| render( | ||
| <UserPageRepHeader | ||
| overview={overview} | ||
| categories={[]} | ||
| profile={mockProfile} | ||
| repDirection="received" | ||
| onRepDirectionChange={() => {}} | ||
| loading={false} | ||
| /> | ||
| ); | ||
| expect(screen.getByText("1,500")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders without repRates', () => { | ||
| const { container } = render(<UserPageRepHeader repRates={null} profile={mockProfile} />); | ||
| expect(container).toHaveTextContent('Rep'); | ||
| it("renders without overview", () => { | ||
| const { container } = render( | ||
| <UserPageRepHeader | ||
| overview={null} | ||
| categories={[]} | ||
| profile={mockProfile} | ||
| repDirection="received" | ||
| onRepDirectionChange={() => {}} | ||
| loading={false} | ||
| /> | ||
| ); | ||
| expect(container).toHaveTextContent("Rep"); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,26 @@ | ||
| import type { ApiCicOverview } from "@/generated/models/ApiCicOverview"; | ||
| import type { ApiIdentity } from "@/generated/models/ApiIdentity"; | ||
| import UserPageIdentityHeaderCIC from "./UserPageIdentityHeaderCIC"; | ||
|
|
||
| export default function UserPageIdentityHeader({ | ||
| profile, | ||
| cicOverview, | ||
| }: { | ||
| readonly profile: ApiIdentity; | ||
| readonly cicOverview: ApiCicOverview | null; | ||
| }) { | ||
| return ( | ||
| <div className="tw-px-6 tw-pt-6"> | ||
| <div className="tw-mb-6"> | ||
| <h2 className="tw-mb-1 tw-text-xl tw-font-semibold tw-text-iron-100"> | ||
| Network Identity Check (NIC) | ||
| </h2> | ||
| <p className="tw-mb-0 tw-text-iron-500 tw-text-sm tw-font-normal tw-leading-relaxed"> | ||
| Does the network believe this profile accurately represents its identity? | ||
| <p className="tw-mb-0 tw-text-sm tw-font-normal tw-leading-relaxed tw-text-iron-500"> | ||
| Does the network believe this profile accurately represents its | ||
| identity? | ||
| </p> | ||
| </div> | ||
| <UserPageIdentityHeaderCIC profile={profile} /> | ||
| <UserPageIdentityHeaderCIC profile={profile} cicOverview={cicOverview} /> | ||
| </div> | ||
| ); | ||
| } |
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.