-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathperps-tab-control-bar.test.tsx
More file actions
101 lines (75 loc) · 3.56 KB
/
perps-tab-control-bar.test.tsx
File metadata and controls
101 lines (75 loc) · 3.56 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React from 'react';
import { fireEvent, screen } from '@testing-library/react';
import { renderWithProvider } from '../../../../../test/lib/render-helpers-navigate';
import configureStore from '../../../../store/store';
import mockState from '../../../../../test/data/mock-state.json';
import { PerpsTabControlBar } from './perps-tab-control-bar';
const mockStore = configureStore({
metamask: {
...mockState.metamask,
},
});
describe('PerpsTabControlBar', () => {
it('renders the control bar component', () => {
renderWithProvider(<PerpsTabControlBar />, mockStore);
expect(screen.getByTestId('perps-tab-control-bar')).toBeInTheDocument();
});
it('displays the total balance label', () => {
renderWithProvider(<PerpsTabControlBar />, mockStore);
expect(screen.getByText(/total balance/iu)).toBeInTheDocument();
});
it('displays the formatted total balance from mock data', () => {
renderWithProvider(<PerpsTabControlBar />, mockStore);
// Mock account state has totalBalance: '15250.00'
expect(screen.getByText('$15,250.00')).toBeInTheDocument();
});
it('renders the balance row as clickable', () => {
renderWithProvider(<PerpsTabControlBar />, mockStore);
expect(screen.getByTestId('perps-control-bar-balance')).toBeInTheDocument();
});
it('calls onManageBalancePress when balance row is clicked', () => {
const onManageBalancePress = jest.fn();
renderWithProvider(
<PerpsTabControlBar onManageBalancePress={onManageBalancePress} />,
mockStore,
);
const balanceRow = screen.getByTestId('perps-control-bar-balance');
fireEvent.click(balanceRow);
expect(onManageBalancePress).toHaveBeenCalledTimes(1);
});
it('does not show P&L row when hasPositions is false', () => {
renderWithProvider(<PerpsTabControlBar hasPositions={false} />, mockStore);
expect(
screen.queryByTestId('perps-control-bar-pnl'),
).not.toBeInTheDocument();
});
it('shows P&L row when hasPositions is true', () => {
renderWithProvider(<PerpsTabControlBar hasPositions />, mockStore);
expect(screen.getByTestId('perps-control-bar-pnl')).toBeInTheDocument();
});
it('displays the unrealized P&L label when hasPositions is true', () => {
renderWithProvider(<PerpsTabControlBar hasPositions />, mockStore);
expect(screen.getByText(/unrealized p&l/iu)).toBeInTheDocument();
});
it('displays formatted P&L value when hasPositions is true', () => {
renderWithProvider(<PerpsTabControlBar hasPositions />, mockStore);
// Mock account state has unrealizedPnl: '375.00' and returnOnEquity: '7.32'
expect(screen.getByText(/\+\$375\.00/u)).toBeInTheDocument();
expect(screen.getByText(/7\.32%/u)).toBeInTheDocument();
});
it('renders without onManageBalancePress callback', () => {
renderWithProvider(<PerpsTabControlBar />, mockStore);
const balanceRow = screen.getByTestId('perps-control-bar-balance');
expect(() => fireEvent.click(balanceRow)).not.toThrow();
});
it('applies single row styling when hasPositions is false', () => {
renderWithProvider(<PerpsTabControlBar hasPositions={false} />, mockStore);
const balanceButton = screen.getByTestId('perps-control-bar-balance');
expect(balanceButton).toHaveClass('perps-tab-control-bar__row--single');
});
it('applies top row styling when hasPositions is true', () => {
renderWithProvider(<PerpsTabControlBar hasPositions />, mockStore);
const balanceButton = screen.getByTestId('perps-control-bar-balance');
expect(balanceButton).toHaveClass('perps-tab-control-bar__row--top');
});
});