-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathPredictFeedView.view.test.tsx
More file actions
123 lines (109 loc) · 3.81 KB
/
Copy pathPredictFeedView.view.test.tsx
File metadata and controls
123 lines (109 loc) · 3.81 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Component view tests for the generic PredictFeedView.
*
* Behaviour is driven via Engine spies (listMarkets / listFilterOptions) and
* real hooks/components — no hook or FlashList mocks.
*
* Run with: yarn jest -c jest.config.view.js PredictFeedView.view.test --runInBand --silent --coverage=false
*/
import '../../../../../../tests/component-view/mocks';
import Engine from '../../../../../../app/core/Engine';
import { cleanup, within } from '@testing-library/react-native';
import { renderPredictFeedView } from '../../../../../../tests/component-view/renderers/predictFeedView';
import {
PredictFeedViewSelectorsIDs,
getPredictFeedViewSelector,
} from '../../Predict.testIds';
import { MOCK_PREDICT_MARKET } from '../../../../../../tests/component-view/fixtures/predict';
import type { PredictMarket } from '../../types';
const createMarket = (id: string, title: string): PredictMarket => ({
...MOCK_PREDICT_MARKET,
id,
slug: id,
title,
outcomes: [
{
...MOCK_PREDICT_MARKET.outcomes[0],
id: `${id}-outcome`,
marketId: id,
title,
},
],
});
describe('PredictFeedView (component view)', () => {
afterEach(() => {
cleanup();
});
beforeEach(() => {
(
Engine.context.PredictController.listMarkets as jest.Mock
).mockResolvedValue({ markets: [], nextCursor: null });
(
Engine.context.PredictController.listFilterOptions as jest.Mock
).mockResolvedValue([]);
});
it('renders the configured feed header, tabs, and filters for a multi-tab feed', async () => {
const { findByText, getByTestId, getAllByText } = renderPredictFeedView({
initialParams: { feedId: 'sports' },
});
expect(await findByText('Sports')).toBeOnTheScreen();
// sports is a multi-tab feed -> tab bar is visible with the sport tabs
expect(getByTestId(PredictFeedViewSelectorsIDs.TABS)).toBeOnTheScreen();
expect(getAllByText('Basketball').length).toBeGreaterThan(0);
// static filter chips for the active tab
expect(getByTestId(PredictFeedViewSelectorsIDs.FILTERS)).toBeOnTheScreen();
expect(getAllByText('All').length).toBeGreaterThan(0);
expect(getAllByText('Live').length).toBeGreaterThan(0);
expect(Engine.context.PredictController.listMarkets).toHaveBeenCalled();
});
it('renders market cards for the active tab/filter', async () => {
(
Engine.context.PredictController.listMarkets as jest.Mock
).mockResolvedValue({
markets: [
createMarket('market-1', 'Lakers to win the title'),
createMarket('market-2', 'Celtics to win the title'),
],
nextCursor: null,
});
const { findByTestId } = renderPredictFeedView({
initialParams: { feedId: 'sports' },
});
const firstCard = await findByTestId(
getPredictFeedViewSelector.marketCard(1),
{},
{ timeout: 10000 },
);
expect(
within(firstCard).getByText('Lakers to win the title'),
).toBeOnTheScreen();
});
it('renders the empty state when the feed returns no markets', async () => {
const { findByTestId } = renderPredictFeedView({
initialParams: { feedId: 'live' },
});
expect(
await findByTestId(
PredictFeedViewSelectorsIDs.EMPTY_STATE,
{},
{ timeout: 10000 },
),
).toBeOnTheScreen();
});
it('hides Live filter chips while requesting only live markets', async () => {
const { findByTestId, queryByTestId } = renderPredictFeedView({
initialParams: { feedId: 'live' },
});
await findByTestId(
PredictFeedViewSelectorsIDs.EMPTY_STATE,
{},
{ timeout: 10000 },
);
expect(
queryByTestId(PredictFeedViewSelectorsIDs.FILTERS),
).not.toBeOnTheScreen();
expect(Engine.context.PredictController.listMarkets).toHaveBeenCalledWith(
expect.objectContaining({ live: true }),
);
});
});