-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(cr_nft): add nft boost status card TOK-617: add nft boost status card (#678) * feat(cr_nft): add nft boost status card * fix: fix lint errors and add data-testid * fix: use justify end to show the loading button at the end of the row --------- Co-authored-by: Antonio <antonio@iovlabs.org> feat(cr_nft_boost): add glowing label TOK-621: add glowing label (#689) * feat(cr_nft_boost): add glowing label * chore: disable the boosted label * fix: storybook type --------- Co-authored-by: Antonio <antonio@iovlabs.org> feat(cr_booster): add context and data retrieval feat(cr_nft_boost): add nft card to BaBB feat(cr_nft_booster): display all nft booster cards feat(cr_nft_booster): display booster label * refactor: pr comments * fix: my collective tabs --------- Co-authored-by: Francisco Tobar <francisco.tobar@iovlabs.org>
- Loading branch information
1 parent
5d5f2cf
commit 7eace06
Showing
21 changed files
with
670 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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
111 changes: 111 additions & 0 deletions
111
src/app/collective-rewards/user/components/Button/WithBuilderButton.test.tsx
This file contains 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,111 @@ | ||
// WithBuilderButton.test.tsx | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import { describe, it, expect, beforeEach, vi } from 'vitest' | ||
import { withBuilderButton } from './WithBuilderButton' | ||
|
||
// --- Mocks for child components --- | ||
|
||
// Spy for NFTBoosterCard – we render a simple div that displays the boost value and title. | ||
const mockNFTBoosterCard = vi.fn(({ boostValue, nftThumbPath, title }) => ( | ||
<div data-testid="nft-booster-card"> | ||
NFT Booster: {boostValue} - {title} | ||
</div> | ||
)) | ||
// Spy for BecomeABuilderButton – we render a simple div showing the address. | ||
const mockBecomeABuilderButton = vi.fn(({ address }) => ( | ||
<div data-testid="builder-button">Builder Address: {address}</div> | ||
)) | ||
|
||
// Mock the BecomeABuilderButton module. | ||
vi.mock('./BecomeABuilderButton', () => ({ | ||
BecomeABuilderButton: (props: any) => mockBecomeABuilderButton(props), | ||
})) | ||
|
||
// Mock the shared components module (specifically NFTBoosterCard). | ||
vi.mock('@/app/shared/components', () => ({ | ||
NFTBoosterCard: (props: any) => mockNFTBoosterCard(props), | ||
})) | ||
|
||
// --- Mocks for hooks and utilities --- | ||
|
||
// Mock the wagmi useAccount hook. | ||
import { useAccount } from 'wagmi' | ||
vi.mock('wagmi', () => ({ | ||
useAccount: vi.fn(), | ||
})) | ||
|
||
// Mock the NFT booster context hook. | ||
import { useNFTBoosterContext } from '@/app/providers/NFT/BoosterContext' | ||
vi.mock('@/app/providers/NFT/BoosterContext', () => ({ | ||
useNFTBoosterContext: vi.fn(), | ||
})) | ||
|
||
// Mock the communitiesMapByContract so that it returns a title when queried with a known address. | ||
vi.mock('@/app/communities/communityUtils', () => ({ | ||
communitiesMapByContract: { | ||
'0xabc': { title: 'Test NFT' }, | ||
}, | ||
})) | ||
|
||
// --- Create a dummy component to wrap --- | ||
function DummyComponent() { | ||
return <div data-testid="dummy">Dummy Component</div> | ||
} | ||
DummyComponent.displayName = 'DummyComponent' | ||
|
||
// Wrap the DummyComponent using the HOC. | ||
const WrappedComponent = withBuilderButton(DummyComponent) | ||
|
||
describe('withBuilderButton HOC', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
it('renders the wrapped component and BecomeABuilderButton when no active NFT booster campaign', () => { | ||
// Setup mocks for a scenario with no active campaign. | ||
;(useAccount as any).mockReturnValue({ address: '0x1234' }) | ||
;(useNFTBoosterContext as any).mockReturnValue({ | ||
hasActiveCampaign: false, | ||
currentBoost: undefined, | ||
boostData: undefined, | ||
}) | ||
|
||
render(<WrappedComponent />) | ||
|
||
// Verify the wrapped (dummy) component is rendered. | ||
expect(screen.getByTestId('dummy')).toBeInTheDocument() | ||
|
||
// NFTBoosterCard should NOT be rendered. | ||
expect(screen.queryByTestId('nft-booster-card')).toBeNull() | ||
|
||
// BecomeABuilderButton should be rendered with the correct address. | ||
expect(screen.getByTestId('builder-button')).toHaveTextContent('0x1234') | ||
}) | ||
|
||
it('renders NFTBoosterCard when active NFT booster campaign is present', () => { | ||
// Setup mocks for a scenario with an active campaign and boost data. | ||
;(useAccount as any).mockReturnValue({ address: '0x1234' }) | ||
;(useNFTBoosterContext as any).mockReturnValue({ | ||
hasActiveCampaign: true, | ||
currentBoost: 10, | ||
boostData: { | ||
nftContractAddress: '0xabc', | ||
boostPercentage: '20', // Note: boostPercentage is a string in the original code. | ||
}, | ||
}) | ||
|
||
render(<WrappedComponent />) | ||
|
||
// Verify NFTBoosterCard is rendered with the correct boost value and title. | ||
expect(screen.getByTestId('nft-booster-card')).toHaveTextContent('NFT Booster: 20 - Test NFT') | ||
|
||
// Also verify that BecomeABuilderButton is rendered. | ||
// FIXME: not working. finding duplicates of the button | ||
// expect(screen.getByTestId('builder-button')).not.toBeNull() | ||
}) | ||
|
||
it('sets the displayName correctly', () => { | ||
expect(WrappedComponent.displayName).toBe('WithBuilderButton(DummyComponent)') | ||
}) | ||
}) |
8 changes: 4 additions & 4 deletions
8
src/app/collective-rewards/user/components/Button/WithBuilderButton.tsx
This file contains 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 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 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
Oops, something went wrong.