@@ -11,8 +11,10 @@ import HomePage from './Home';
11
11
12
12
// Mock AppContext
13
13
const mockedUseAppContext = jest . fn ( ) ;
14
+ const mockedUseQuery = jest . fn ( ) ;
14
15
jest . mock ( '../../hooks' , ( ) => ( {
15
16
useAppContext : ( ) => mockedUseAppContext ( ) ,
17
+ useQuery : ( ) => mockedUseQuery ( ) ,
16
18
} ) ) ;
17
19
18
20
// Mock sha256Hash
@@ -22,20 +24,24 @@ jest.mock('@fedimint/utils', () => ({
22
24
} ) ) ;
23
25
24
26
describe ( 'pages/Home' , ( ) => {
27
+ const mockDispatch = jest . fn ( ) ;
28
+
29
+ beforeEach ( ( ) => {
30
+ mockedUseAppContext . mockImplementation ( ( ) => ( {
31
+ service : null ,
32
+ dispatch : mockDispatch ,
33
+ } ) ) ;
34
+
35
+ mockedUseQuery . mockReturnValue ( {
36
+ get : jest . fn ( ) ,
37
+ } ) ;
38
+ } ) ;
39
+
25
40
afterEach ( ( ) => {
26
41
jest . clearAllMocks ( ) ;
27
42
} ) ;
28
43
29
44
describe ( 'When a user clicks the connect button with an empty input value' , ( ) => {
30
- const mockDispatch = jest . fn ( ) ;
31
-
32
- beforeEach ( ( ) => {
33
- mockedUseAppContext . mockImplementation ( ( ) => ( {
34
- service : null ,
35
- dispatch : mockDispatch ,
36
- } ) ) ;
37
- } ) ;
38
-
39
45
it ( 'should not call dispatch' , async ( ) => {
40
46
render ( < HomePage /> ) ;
41
47
@@ -52,15 +58,6 @@ describe('pages/Home', () => {
52
58
53
59
// We don't support gateway urls at this time so check for this
54
60
describe ( 'When a user clicks the connect button with a gateway url input value' , ( ) => {
55
- const mockDispatch = jest . fn ( ) ;
56
-
57
- beforeEach ( ( ) => {
58
- mockedUseAppContext . mockImplementation ( ( ) => ( {
59
- service : null ,
60
- dispatch : mockDispatch ,
61
- } ) ) ;
62
- } ) ;
63
-
64
61
it ( 'should not call dispatch' , async ( ) => {
65
62
render ( < HomePage /> ) ;
66
63
@@ -82,15 +79,6 @@ describe('pages/Home', () => {
82
79
} ) ;
83
80
84
81
describe ( 'When a user clicks the connect button with a guardian url input value' , ( ) => {
85
- const mockDispatch = jest . fn ( ) ;
86
-
87
- beforeEach ( ( ) => {
88
- mockedUseAppContext . mockImplementation ( ( ) => ( {
89
- service : null ,
90
- dispatch : mockDispatch ,
91
- } ) ) ;
92
- } ) ;
93
-
94
82
it ( 'should call dispatch' , async ( ) => {
95
83
render ( < HomePage /> ) ;
96
84
@@ -112,13 +100,6 @@ describe('pages/Home', () => {
112
100
} ) ;
113
101
114
102
describe ( 'When there is no service in LocalStorage' , ( ) => {
115
- beforeEach ( ( ) => {
116
- mockedUseAppContext . mockImplementation ( ( ) => ( {
117
- service : null ,
118
- dispatch : jest . fn ( ) ,
119
- } ) ) ;
120
- } ) ;
121
-
122
103
it ( 'should render an input without a value' , ( ) => {
123
104
render ( < HomePage /> ) ;
124
105
const input = screen . getByPlaceholderText ( 'Guardian URL' ) ;
@@ -170,4 +151,18 @@ describe('pages/Home', () => {
170
151
expect ( url ) . toBeInTheDocument ( ) ;
171
152
} ) ;
172
153
} ) ;
154
+
155
+ describe ( 'When a url is passed as a query param' , ( ) => {
156
+ beforeEach ( ( ) => {
157
+ mockedUseQuery . mockReturnValue ( {
158
+ get : jest . fn ( ) . mockReturnValue ( 'wss://guardian-url.test.com:8174' ) ,
159
+ } ) ;
160
+ } ) ;
161
+
162
+ it ( 'should set query param value in input box' , ( ) => {
163
+ render ( < HomePage /> ) ;
164
+ const url = screen . getByDisplayValue ( 'wss://guardian-url.test.com:8174' ) ;
165
+ expect ( url ) . toBeInTheDocument ( ) ;
166
+ } ) ;
167
+ } ) ;
173
168
} ) ;
0 commit comments