Skip to content

Commit 4b365dd

Browse files
committed
test: remove toMatchSnapshot and removed snapshot files in predict & perps tests
1 parent e632cc6 commit 4b365dd

19 files changed

Lines changed: 80 additions & 911 deletions

File tree

app/components/UI/Perps/components/PerpsBadge/PerpsBadge.test.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ jest.mock('../../../../../../locales/i18n', () => ({
2626
}));
2727

2828
describe('PerpsBadge', () => {
29-
it('renders badges with correct labels and styles for all types', () => {
30-
// Arrange
29+
it('renders correct i18n label for each badge type', () => {
3130
const badgeTypes: BadgeType[] = [
3231
'experimental',
3332
'crypto',
@@ -43,12 +42,11 @@ describe('PerpsBadge', () => {
4342
'Forex',
4443
];
4544

46-
// Act & Assert - Test each badge type
4745
badgeTypes.forEach((type, index) => {
48-
const { getByText } = render(<PerpsBadge type={type} />);
46+
const { getByText, unmount } = render(<PerpsBadge type={type} />);
4947

50-
const labelElement = getByText(expectedLabels[index]);
51-
expect(labelElement).toBeTruthy();
48+
expect(getByText(expectedLabels[index])).toBeOnTheScreen();
49+
unmount();
5250
});
5351
});
5452

app/components/UI/Perps/components/PerpsDeveloperOptionsSection/PerpsDeveloperOptionsSection.test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ jest.mock('@react-navigation/native', () => {
1515
});
1616

1717
describe('PerpsDeveloperOptionsSection', () => {
18-
it('renders correctly', () => {
19-
const { toJSON } = renderWithProvider(<PerpsDeveloperOptionsSection />);
20-
expect(toJSON()).toMatchSnapshot();
21-
});
22-
2318
it('renders the perpetual trading heading', () => {
2419
const { getByText } = renderWithProvider(<PerpsDeveloperOptionsSection />);
2520
expect(getByText('Perps trading')).toBeVisible();

app/components/UI/Perps/components/PerpsDeveloperOptionsSection/PerpsTestnetToggle.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,10 @@ describe('PerpsTestnetToggle', () => {
5151
it('renders correctly with testnet network', () => {
5252
mockUsePerpsNetwork.mockReturnValue('testnet');
5353

54-
const { toJSON, getByTestId, getByText } = renderWithToastContext(
54+
const { getByTestId, getByText } = renderWithToastContext(
5555
<PerpsTestnetToggle />,
5656
);
5757

58-
expect(toJSON()).toMatchSnapshot();
59-
6058
const switchElement = getByTestId(PerpsTestnetToggleSelectorsIDs.SWITCH);
6159
expect(switchElement.props.value).toBe(true);
6260

app/components/UI/Perps/components/PerpsDeveloperOptionsSection/__snapshots__/PerpsDeveloperOptionsSection.test.tsx.snap

Lines changed: 0 additions & 81 deletions
This file was deleted.

app/components/UI/Perps/components/PerpsDeveloperOptionsSection/__snapshots__/PerpsTestnetToggle.test.tsx.snap

Lines changed: 0 additions & 57 deletions
This file was deleted.

app/components/UI/Perps/components/PerpsHomeSection/PerpsHomeSection.test.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ describe('PerpsHomeSection', () => {
177177
});
178178

179179
it('header is not pressable when onActionPress not provided', () => {
180-
const { getByText } = render(
180+
const { queryByTestId, getByText } = render(
181181
<PerpsHomeSection
182182
title="Test Section"
183183
isLoading={false}
@@ -188,8 +188,9 @@ describe('PerpsHomeSection', () => {
188188
</PerpsHomeSection>,
189189
);
190190

191-
// Header should render but not be pressable
192191
expect(getByText('Test Section')).toBeTruthy();
192+
// Action button must be absent when no onActionPress is provided
193+
expect(queryByTestId(PerpsHomeSectionTestIds.ACTION_BUTTON)).toBeNull();
193194
});
194195

195196
it('hides action icon when loading', () => {

app/components/UI/Perps/components/PerpsMarketSortDropdowns/PerpsMarketSortDropdowns.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ describe('PerpsMarketSortDropdowns', () => {
248248
expect(() => unmount()).not.toThrow();
249249
});
250250

251-
it('cleans up properly when remounted with different props', () => {
252-
const { root, rerender, unmount } = render(
251+
it('updates displayed label when selectedOptionId prop changes', () => {
252+
const { rerender, getByText, queryByText, unmount } = render(
253253
<PerpsMarketSortDropdowns
254254
selectedOptionId="volume"
255255
onSortPress={mockOnSortPress}
256256
/>,
257257
);
258258

259-
expect(root).toBeTruthy();
259+
expect(getByText('Volume')).toBeOnTheScreen();
260260

261261
rerender(
262262
<PerpsMarketSortDropdowns
@@ -265,7 +265,8 @@ describe('PerpsMarketSortDropdowns', () => {
265265
/>,
266266
);
267267

268-
expect(root).toBeTruthy();
268+
expect(queryByText('Volume')).toBeNull();
269+
expect(getByText('Price change')).toBeOnTheScreen();
269270

270271
expect(() => unmount()).not.toThrow();
271272
});

app/components/UI/Perps/components/PerpsMarketTradesList/PerpsMarketTradesList.test.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { FlatList } from 'react-native';
23
import { render, screen, fireEvent } from '@testing-library/react-native';
34
import PerpsMarketTradesList from './PerpsMarketTradesList';
45
import Routes from '../../../../../constants/navigation/Routes';
@@ -580,21 +581,29 @@ describe('PerpsMarketTradesList', () => {
580581
createMockFillsReturn(mockOrderFills),
581582
);
582583

583-
render(<PerpsMarketTradesList symbol="ETH" />);
584+
const { UNSAFE_getByType } = render(
585+
<PerpsMarketTradesList symbol="ETH" />,
586+
);
584587

585-
expect(screen.getByText('Opened long')).toBeOnTheScreen();
586-
expect(screen.getByText('Closed long')).toBeOnTheScreen();
587-
expect(screen.getByText('Opened short')).toBeOnTheScreen();
588+
const flatList = UNSAFE_getByType(FlatList);
589+
// keyExtractor uses item.id — verify it returns the item's id
590+
const firstItem = flatList.props.data[0];
591+
expect(flatList.props.keyExtractor(firstItem, 0)).toBe(
592+
String(firstItem.id),
593+
);
588594
});
589595

590596
it('disables scroll on FlatList', () => {
591597
mockUsePerpsMarketFills.mockReturnValue(
592598
createMockFillsReturn(mockOrderFills),
593599
);
594600

595-
const { root } = render(<PerpsMarketTradesList symbol="ETH" />);
601+
const { UNSAFE_getByType } = render(
602+
<PerpsMarketTradesList symbol="ETH" />,
603+
);
596604

597-
expect(root).toBeTruthy();
605+
const flatList = UNSAFE_getByType(FlatList);
606+
expect(flatList.props.scrollEnabled).toBe(false);
598607
});
599608
});
600609

app/components/UI/Perps/components/PerpsOICapWarning/PerpsOICapWarning.test.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { render } from '@testing-library/react-native';
33
import PerpsOICapWarning from './PerpsOICapWarning';
44
import { usePerpsOICap } from '../../hooks/usePerpsOICap';
55
import { strings } from '../../../../../../locales/i18n';
6+
import { TextVariant } from '../../../../../component-library/components/Texts/Text';
67

78
jest.mock('../../hooks/usePerpsOICap');
89

@@ -81,25 +82,34 @@ describe('PerpsOICapWarning', () => {
8182
});
8283

8384
it('should render inline variant by default', () => {
84-
const { getByTestId } = render(<PerpsOICapWarning symbol="BTC" />);
85+
const { UNSAFE_getByProps } = render(<PerpsOICapWarning symbol="BTC" />);
8586

86-
expect(getByTestId('perps-oi-cap-warning')).toBeTruthy();
87+
// Inline variant uses BodySM text
88+
expect(
89+
UNSAFE_getByProps({ variant: TextVariant.BodySM }).props.variant,
90+
).toBe(TextVariant.BodySM);
8791
});
8892

8993
it('should render banner variant when specified', () => {
90-
const { getByTestId } = render(
94+
const { UNSAFE_getByProps } = render(
9195
<PerpsOICapWarning symbol="BTC" variant="banner" />,
9296
);
9397

94-
expect(getByTestId('perps-oi-cap-warning')).toBeTruthy();
98+
// Banner variant uses BodyMD text (larger text for banner prominence)
99+
expect(
100+
UNSAFE_getByProps({ variant: TextVariant.BodyMD }).props.variant,
101+
).toBe(TextVariant.BodyMD);
95102
});
96103

97104
it('should render inline variant when specified', () => {
98-
const { getByTestId } = render(
105+
const { UNSAFE_getByProps } = render(
99106
<PerpsOICapWarning symbol="BTC" variant="inline" />,
100107
);
101108

102-
expect(getByTestId('perps-oi-cap-warning')).toBeTruthy();
109+
// Inline variant uses BodySM text
110+
expect(
111+
UNSAFE_getByProps({ variant: TextVariant.BodySM }).props.variant,
112+
).toBe(TextVariant.BodySM);
103113
});
104114
});
105115

0 commit comments

Comments
 (0)