Repository navigation
fix: Stake Pool table improvements #413
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
Changes from all commits
b8b434f
55a590d
28a898e
0eb0053
f60760b
7c7363d
ca26384
45f4e76
4cbdf07
e7aa474
17d90f0
4fccfbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,9 @@ | |
| > * { | ||
| flex: 1; | ||
|
|
||
| height: unset; | ||
| align-content: stretch; | ||
|
|
||
| &:not(:last-child) { | ||
| margin-right: 16px; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| import '@testing-library/jest-dom/extend-expect'; | ||
| import { | ||
| fireEvent, | ||
| render, | ||
| screen, | ||
| waitForElementToBeRemoved, | ||
| } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom/extend-expect'; | ||
|
|
||
| import { ethers } from 'ethers'; | ||
|
|
||
| import { | ||
| MESSAGE, | ||
| TABLE_HEADERS, | ||
| TABLE_HEADERS_DISCONNECTED, | ||
| } from './StakePoolTable.constants'; | ||
| import StakePoolTableRow, { TEST_ID } from './StakePoolTableRow'; | ||
|
|
||
| ////////// | ||
| // Mock // | ||
| ////////// | ||
|
|
||
| var mockUserValueStaked = jest.fn(); | ||
|
|
||
| /** | ||
| * Note: | ||
| * This is directly copied from pool output in SDK | ||
| * as of Fri 18 Mar 2022 | ||
| */ | ||
|
Comment on lines
+25
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice comment 💯 |
||
| const mockPoolData = { | ||
| instance: { | ||
| address: '0x9E87a268D42B0Aba399C121428fcE2c626Ea01FF', | ||
| userValueStaked: mockUserValueStaked, | ||
| }, | ||
| content: { | ||
| image: '/staking/farm.png', | ||
| name: 'Farm WILD - WETH LP', | ||
| token: 'Liquidity Provider', | ||
| tokenTicker: 'LP', | ||
| domain: '/pools/lp', | ||
| tokenPurchaseUrl: '', | ||
| }, | ||
| metrics: { | ||
| apy: 145.03269039595662, | ||
| tvl: { | ||
| numberOfTokens: 35576.6553275205, | ||
| valueOfTokensUSD: 6971564.4606713345, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const mockUserData = { | ||
| userValueUnlocked: ethers.utils.parseEther('1000'), | ||
| userValueLocked: ethers.utils.parseEther('1000'), | ||
| }; | ||
|
|
||
| var mockAccountValid = { account: '1' }; | ||
| var mockAccountInvalid = { account: undefined }; | ||
| var mockAccount: { account: string | undefined } = mockAccountValid; | ||
|
|
||
| jest.mock('@web3-react/core', () => ({ | ||
| useWeb3React: () => mockAccount, | ||
| })); | ||
|
|
||
| var mockSelectStakePool = jest.fn(); | ||
| jest.mock('lib/providers/staking/PoolSelectProvider', () => ({ | ||
| useStakingPoolSelector: () => ({ | ||
| selectStakePool: mockSelectStakePool, | ||
| }), | ||
| })); | ||
|
|
||
| /////////// | ||
| // Setup // | ||
| /////////// | ||
|
|
||
| const renderComponent = () => { | ||
| return render( | ||
| <table> | ||
| <tbody> | ||
| <StakePoolTableRow data={mockPoolData} rowNumber={'1'} /> | ||
| </tbody> | ||
| </table>, | ||
|
Comment on lines
+78
to
+82
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was getting some compile errors for not putting a |
||
| ); | ||
| }; | ||
|
|
||
| const jestConsole = console; | ||
| const consoleError = console.error; | ||
|
|
||
| beforeEach(() => { | ||
| global.console = require('console'); | ||
| console.error = jest.fn(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| mockAccount = mockAccountValid; // reset mock account value | ||
| global.console = jestConsole; | ||
| console.error = consoleError; | ||
| }); | ||
|
|
||
| /////////// | ||
| // Tests // | ||
| /////////// | ||
|
|
||
| test('should render', async () => { | ||
| mockUserValueStaked.mockResolvedValue(mockUserData); | ||
| renderComponent(); | ||
| await screen.findByText(mockPoolData.content.name); | ||
| }); | ||
|
|
||
| test('should render correct number of columns with wallet connected', async () => { | ||
| mockUserValueStaked.mockResolvedValue(mockUserData); | ||
| const { getByTestId } = renderComponent(); | ||
| await screen.findByText(mockPoolData.content.name); | ||
| expect(getByTestId(TEST_ID.CONTAINER).childElementCount).toBe( | ||
| TABLE_HEADERS.length, | ||
| ); | ||
| }); | ||
|
|
||
| test('should render correct number of columns with wallet disconnected', async () => { | ||
| mockAccount = mockAccountInvalid; | ||
| const { getByTestId } = renderComponent(); | ||
| await screen.findByText(mockPoolData.content.name); | ||
| expect(getByTestId(TEST_ID.CONTAINER).childElementCount).toBe( | ||
| TABLE_HEADERS_DISCONNECTED.length, | ||
| ); | ||
| }); | ||
|
|
||
| test('should handle row click event', async () => { | ||
| mockUserValueStaked.mockResolvedValue(mockUserData); | ||
| const { getByTestId } = renderComponent(); | ||
| await screen.findByText(mockPoolData.content.name); | ||
| const container = getByTestId(TEST_ID.CONTAINER); | ||
| fireEvent.click(container); | ||
| expect(mockSelectStakePool).toBeCalledWith(mockPoolData); | ||
| }); | ||
|
|
||
| test('should handle button click event', async () => { | ||
| mockUserValueStaked.mockResolvedValue(mockUserData); | ||
| renderComponent(); | ||
| await screen.findByText(mockPoolData.content.name); | ||
| const button = screen.getByRole('button', { name: 'Stake' }); | ||
| fireEvent.mouseUp(button); | ||
| expect(mockSelectStakePool).toBeCalledWith(mockPoolData); | ||
| }); | ||
|
|
||
| test('should render spinner while loading', async 10BC8 () => { | ||
| mockUserValueStaked.mockResolvedValue(mockUserData); | ||
| const { getByTestId } = renderComponent(); | ||
| const spinner = getByTestId(TEST_ID.SPINNER); | ||
| expect(spinner).toBeInTheDocument(); | ||
| await waitForElementToBeRemoved(spinner); | ||
| }); | ||
|
|
||
| test('should handle failed load', async () => { | ||
| mockUserValueStaked.mockRejectedValue(undefined); | ||
| renderComponent(); | ||
| await screen.findByText(MESSAGE.FAILED_TO_LOAD); | ||
| expect(console.error).toBeCalledTimes(1); | ||
| }); | ||
|
|
||
| test('should format apy correctly', async () => { | ||
| mockUserValueStaked.mockResolvedValue(mockUserData); | ||
| renderComponent(); | ||
| await screen.findByText('145.03%'); | ||
| }); | ||
|
|
||
| test('should format total stake correctly', async () => { | ||
| mockUserValueStaked.mockResolvedValue(mockUserData); | ||
| renderComponent(); | ||
| await screen.findByText('$6,971,564.46'); | ||
| }); | ||
|
|
||
| test('should format user stake correctly', async () => { | ||
| mockUserValueStaked.mockResolvedValue(mockUserData); | ||
| renderComponent(); | ||
| await screen.findByText('2,000.00 ' + mockPoolData.content.tokenTicker); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect test!