forked from Axionvera/pocketpay-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkStatusBanner.test.tsx
More file actions
165 lines (145 loc) · 5.39 KB
/
Copy pathNetworkStatusBanner.test.tsx
File metadata and controls
165 lines (145 loc) · 5.39 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* NetworkStatusBanner – component tests
*
* Acceptance criteria covered:
* AC-NB1 – Banner is not rendered when state is 'online'.
* AC-NB2 – Banner is rendered for 'offline'.
* AC-NB3 – Banner is rendered for 'service-unavailable'.
* AC-NB4 – Banner is rendered for 'wrong-network'.
* AC-NB5 – Retry button calls onRetry when tapped.
* AC-NB6 – Retry button is disabled while isRetrying is true.
* AC-NB7 – App does not crash when rendered with any valid state.
*/
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
jest.mock('lucide-react-native', () => ({
WifiOff: () => null,
AlertTriangle: () => null,
CloudOff: () => null,
RefreshCw: () => null,
}));
import { NetworkStatusBanner } from '../src/components/NetworkStatusBanner';
// ─── AC-NB1: Hidden when online ────────────────────────────────────────────
describe('AC-NB1 – not rendered when state is online', () => {
it('returns null when state is "online"', () => {
const { queryByTestId } = render(
<NetworkStatusBanner
state="online"
onRetry={jest.fn()}
/>
);
expect(queryByTestId('network-status-banner')).toBeNull();
});
});
// ─── AC-NB2: Offline banner ───────────────────────────────────────────────────
describe('AC-NB2 – offline banner', () => {
it('renders the banner and message when state is "offline"', () => {
const { getByTestId, getByText } = render(
<NetworkStatusBanner
state="offline"
onRetry={jest.fn()}
/>
);
expect(getByTestId('network-status-banner')).toBeTruthy();
expect(getByText(/You are offline/i)).toBeTruthy();
});
});
// ─── AC-NB3: Service-unavailable banner ──────────────────────────────────────
describe('AC-NB3 – service-unavailable banner', () => {
it('renders the banner and message when state is "service-unavailable"', () => {
const { getByTestId, getByText } = render(
<NetworkStatusBanner
state="service-unavailable"
onRetry={jest.fn()}
/>
);
expect(getByTestId('network-status-banner')).toBeTruthy();
expect(getByText(/Stellar network services are unavailable/i)).toBeTruthy();
});
});
// ─── AC-NB4: Wrong-network banner ────────────────────────────────────────────
describe('AC-NB4 – wrong-network banner', () => {
it('renders the banner and message when state is "wrong-network"', () => {
const { getByTestId, getByText } = render(
<NetworkStatusBanner
state="wrong-network"
onRetry={jest.fn()}
/>
);
expect(getByTestId('network-status-banner')).toBeTruthy();
expect(getByText(/Connected to the wrong blockchain network/i)).toBeTruthy();
});
});
// ─── AC-NB5: Retry callback ───────────────────────────────────────────────────
describe('AC-NB5 – retry button calls onRetry', () => {
it('calls onRetry when the retry button is pressed', () => {
const onRetry = jest.fn();
const { getByTestId } = render(
<NetworkStatusBanner
state="offline"
onRetry={onRetry}
/>
);
fireEvent.press(getByTestId('network-status-retry'));
expect(onRetry).toHaveBeenCalledTimes(1);
});
});
// ─── AC-NB6: Retry disabled while retrying ───────────────────────────────────
describe('AC-NB6 – retry button is disabled while isRetrying', () => {
it('renders retry button as disabled when isRetrying is true', () => {
const onRetry = jest.fn();
const { getByTestId } = render(
<NetworkStatusBanner
state="offline"
onRetry={onRetry}
isRetrying={true}
/>
);
const retryBtn = getByTestId('network-status-retry');
fireEvent.press(retryBtn);
expect(onRetry).not.toHaveBeenCalled();
});
});
// ─── AC-NB7: Does not crash ───────────────────────────────────────────────────
describe('AC-NB7 – does not crash with any valid state', () => {
it('renders without crashing for "offline"', () => {
expect(() =>
render(
<NetworkStatusBanner
state="offline"
onRetry={jest.fn()}
/>
)
).not.toThrow();
});
it('renders without crashing for "service-unavailable"', () => {
expect(() =>
render(
<NetworkStatusBanner
state="service-unavailable"
onRetry={jest.fn()}
/>
)
).not.toThrow();
});
it('renders without crashing for "wrong-network"', () => {
expect(() =>
render(
<NetworkStatusBanner
state="wrong-network"
onRetry={jest.fn()}
/>
)
).not.toThrow();
});
it('renders without crashing for "online"', () => {
expect(() =>
render(
<NetworkStatusBanner
state="online"
onRetry={jest.fn()}
/>
)
).not.toThrow();
});
});