22 * NetworkStatusBanner – component tests
33 *
44 * Acceptance criteria covered:
5- * AC-NB1 – Banner is not rendered when networkErrorType is 'none '.
5+ * AC-NB1 – Banner is not rendered when state is 'online '.
66 * AC-NB2 – Banner is rendered for 'offline'.
77 * AC-NB3 – Banner is rendered for 'service-unavailable'.
8- * AC-NB4 – Retry button calls onRetry when tapped.
9- * AC-NB5 – Retry button is disabled while isRetrying is true.
10- * AC-NB6 – App does not crash when rendered with any valid props.
8+ * AC-NB4 – Banner is rendered for 'wrong-network'.
9+ * AC-NB5 – Retry button calls onRetry when tapped.
10+ * AC-NB6 – Retry button is disabled while isRetrying is true.
11+ * AC-NB7 – App does not crash when rendered with any valid state.
1112 */
1213
1314import React from 'react' ;
@@ -16,22 +17,19 @@ import { render, fireEvent } from '@testing-library/react-native';
1617jest . mock ( 'lucide-react-native' , ( ) => ( {
1718 WifiOff : ( ) => null ,
1819 AlertTriangle : ( ) => null ,
20+ CloudOff : ( ) => null ,
1921 RefreshCw : ( ) => null ,
2022} ) ) ;
2123
2224import { NetworkStatusBanner } from '../src/components/NetworkStatusBanner' ;
2325
24- const OFFLINE_MESSAGE = 'No internet connection. Check your network and try again.' ;
25- const SERVICE_MESSAGE = 'Stellar Testnet services appear unavailable. Please try again shortly.' ;
26+ // ─── AC-NB1: Hidden when online ────────────────────────────────────────────
2627
27- // ─── AC-NB1: Hidden when no error ────────────────────────────────────────────
28-
29- describe ( 'AC-NB1 – not rendered when networkErrorType is none' , ( ) => {
30- it ( 'returns null when type is "none"' , ( ) => {
28+ describe ( 'AC-NB1 – not rendered when state is online' , ( ) => {
29+ it ( 'returns null when state is "online"' , ( ) => {
3130 const { queryByTestId } = render (
3231 < NetworkStatusBanner
33- networkErrorType = "none"
34- message = ""
32+ state = "online"
3533 onRetry = { jest . fn ( ) }
3634 />
3735 ) ;
@@ -42,44 +40,56 @@ describe('AC-NB1 – not rendered when networkErrorType is none', () => {
4240// ─── AC-NB2: Offline banner ───────────────────────────────────────────────────
4341
4442describe ( 'AC-NB2 – offline banner' , ( ) => {
45- it ( 'renders the banner and message when type is "offline"' , ( ) => {
43+ it ( 'renders the banner and message when state is "offline"' , ( ) => {
4644 const { getByTestId, getByText } = render (
4745 < NetworkStatusBanner
48- networkErrorType = "offline"
49- message = { OFFLINE_MESSAGE }
46+ state = "offline"
5047 onRetry = { jest . fn ( ) }
5148 />
5249 ) ;
5350 expect ( getByTestId ( 'network-status-banner' ) ) . toBeTruthy ( ) ;
54- expect ( getByText ( OFFLINE_MESSAGE ) ) . toBeTruthy ( ) ;
51+ expect ( getByText ( / Y o u a r e o f f l i n e / i ) ) . toBeTruthy ( ) ;
5552 } ) ;
5653} ) ;
5754
5855// ─── AC-NB3: Service-unavailable banner ──────────────────────────────────────
5956
6057describe ( 'AC-NB3 – service-unavailable banner' , ( ) => {
61- it ( 'renders the banner and message when type is "service-unavailable"' , ( ) => {
58+ it ( 'renders the banner and message when state is "service-unavailable"' , ( ) => {
59+ const { getByTestId, getByText } = render (
60+ < NetworkStatusBanner
61+ state = "service-unavailable"
62+ onRetry = { jest . fn ( ) }
63+ />
64+ ) ;
65+ expect ( getByTestId ( 'network-status-banner' ) ) . toBeTruthy ( ) ;
66+ expect ( getByText ( / S t e l l a r n e t w o r k s e r v i c e s a r e u n a v a i l a b l e / i) ) . toBeTruthy ( ) ;
67+ } ) ;
68+ } ) ;
69+
70+ // ─── AC-NB4: Wrong-network banner ────────────────────────────────────────────
71+
72+ describe ( 'AC-NB4 – wrong-network banner' , ( ) => {
73+ it ( 'renders the banner and message when state is "wrong-network"' , ( ) => {
6274 const { getByTestId, getByText } = render (
6375 < NetworkStatusBanner
64- networkErrorType = "service-unavailable"
65- message = { SERVICE_MESSAGE }
76+ state = "wrong-network"
6677 onRetry = { jest . fn ( ) }
6778 />
6879 ) ;
6980 expect ( getByTestId ( 'network-status-banner' ) ) . toBeTruthy ( ) ;
70- expect ( getByText ( SERVICE_MESSAGE ) ) . toBeTruthy ( ) ;
81+ expect ( getByText ( / C o n n e c t e d t o t h e w r o n g b l o c k c h a i n n e t w o r k / i ) ) . toBeTruthy ( ) ;
7182 } ) ;
7283} ) ;
7384
74- // ─── AC-NB4 : Retry callback ───────────────────────────────────────────────────
85+ // ─── AC-NB5 : Retry callback ───────────────────────────────────────────────────
7586
76- describe ( 'AC-NB4 – retry button calls onRetry' , ( ) => {
87+ describe ( 'AC-NB5 – retry button calls onRetry' , ( ) => {
7788 it ( 'calls onRetry when the retry button is pressed' , ( ) => {
7889 const onRetry = jest . fn ( ) ;
7990 const { getByTestId } = render (
8091 < NetworkStatusBanner
81- networkErrorType = "offline"
82- message = { OFFLINE_MESSAGE }
92+ state = "offline"
8393 onRetry = { onRetry }
8494 />
8595 ) ;
@@ -88,35 +98,32 @@ describe('AC-NB4 – retry button calls onRetry', () => {
8898 } ) ;
8999} ) ;
90100
91- // ─── AC-NB5 : Retry disabled while retrying ───────────────────────────────────
101+ // ─── AC-NB6 : Retry disabled while retrying ───────────────────────────────────
92102
93- describe ( 'AC-NB5 – retry button is disabled while isRetrying' , ( ) => {
103+ describe ( 'AC-NB6 – retry button is disabled while isRetrying' , ( ) => {
94104 it ( 'renders retry button as disabled when isRetrying is true' , ( ) => {
95105 const onRetry = jest . fn ( ) ;
96106 const { getByTestId } = render (
97107 < NetworkStatusBanner
98- networkErrorType = "offline"
99- message = { OFFLINE_MESSAGE }
108+ state = "offline"
100109 onRetry = { onRetry }
101110 isRetrying = { true }
102111 />
103112 ) ;
104113 const retryBtn = getByTestId ( 'network-status-retry' ) ;
105- // The button should not respond to presses when disabled
106114 fireEvent . press ( retryBtn ) ;
107115 expect ( onRetry ) . not . toHaveBeenCalled ( ) ;
108116 } ) ;
109117} ) ;
110118
111- // ─── AC-NB6 : Does not crash ───────────────────────────────────────────────────
119+ // ─── AC-NB7 : Does not crash ───────────────────────────────────────────────────
112120
113- describe ( 'AC-NB6 – does not crash with any valid props ' , ( ) => {
121+ describe ( 'AC-NB7 – does not crash with any valid state ' , ( ) => {
114122 it ( 'renders without crashing for "offline"' , ( ) => {
115123 expect ( ( ) =>
116124 render (
117125 < NetworkStatusBanner
118- networkErrorType = "offline"
119- message = { OFFLINE_MESSAGE }
126+ state = "offline"
120127 onRetry = { jest . fn ( ) }
121128 />
122129 )
@@ -127,20 +134,29 @@ describe('AC-NB6 – does not crash with any valid props', () => {
127134 expect ( ( ) =>
128135 render (
129136 < NetworkStatusBanner
130- networkErrorType = "service-unavailable"
131- message = { SERVICE_MESSAGE }
137+ state = "service-unavailable"
138+ onRetry = { jest . fn ( ) }
139+ />
140+ )
141+ ) . not . toThrow ( ) ;
142+ } ) ;
143+
144+ it ( 'renders without crashing for "wrong-network"' , ( ) => {
145+ expect ( ( ) =>
146+ render (
147+ < NetworkStatusBanner
148+ state = "wrong-network"
132149 onRetry = { jest . fn ( ) }
133150 />
134151 )
135152 ) . not . toThrow ( ) ;
136153 } ) ;
137154
138- it ( 'renders without crashing for "none "' , ( ) => {
155+ it ( 'renders without crashing for "online "' , ( ) => {
139156 expect ( ( ) =>
140157 render (
141158 < NetworkStatusBanner
142- networkErrorType = "none"
143- message = ""
159+ state = "online"
144160 onRetry = { jest . fn ( ) }
145161 />
146162 )
0 commit comments