-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathStakingRewardsWarning.test.tsx
More file actions
61 lines (51 loc) · 2.13 KB
/
Copy pathStakingRewardsWarning.test.tsx
File metadata and controls
61 lines (51 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { render, screen } from '@testing-library/react';
import { StakingRewardsWarning } from '../../../components/SelectStakingPage/components/SelectActivityRewardsConfiguration';
import { StakingProgramId } from '../../../constants';
import { useStakingContractDetails } from '../../../hooks';
import { makeStakingContractDetails } from '../../helpers/factories';
jest.mock('../../../hooks', () => ({
useStakingContractDetails: jest.fn(),
}));
// Isolate the gating logic from the alert's markup.
jest.mock('../../../components/NoStakingRewardsAlert', () => ({
NoStakingRewardsAlert: () => <div data-testid="no-rewards-alert" />,
}));
const mockUseStakingContractDetails =
useStakingContractDetails as jest.MockedFunction<
typeof useStakingContractDetails
>;
const programId = 'pearl_beta_mech_marketplace_1' as StakingProgramId;
const setup = (
value: Partial<ReturnType<typeof useStakingContractDetails>>,
) => {
mockUseStakingContractDetails.mockReturnValue({
stakingContractInfo: undefined,
isRewardsAvailable: false,
hasEnoughServiceSlots: false,
hasEnoughRewardsAndSlots: false,
...value,
});
return render(<StakingRewardsWarning stakingProgramId={programId} />);
};
describe('StakingRewardsWarning', () => {
beforeEach(() => jest.clearAllMocks());
it('renders nothing while contract details are still loading', () => {
// stakingContractInfo undefined => not loaded; must not flash the warning
setup({ stakingContractInfo: undefined, isRewardsAvailable: false });
expect(screen.queryByTestId('no-rewards-alert')).not.toBeInTheDocument();
});
it('renders nothing when rewards are available', () => {
setup({
stakingContractInfo: makeStakingContractDetails({ availableRewards: 10 }),
isRewardsAvailable: true,
});
expect(screen.queryByTestId('no-rewards-alert')).not.toBeInTheDocument();
});
it('renders the warning when the reward pool is empty', () => {
setup({
stakingContractInfo: makeStakingContractDetails({ availableRewards: 0 }),
isRewardsAvailable: false,
});
expect(screen.getByTestId('no-rewards-alert')).toBeInTheDocument();
});
});