1
1
import { ApplicationObject } from '@deriv/api-types' ;
2
2
import useAuthContext from '@site/src/hooks/useAuthContext' ;
3
- import { render , screen , cleanup , within } from '@site/src/test-utils' ;
3
+ import { render , screen , within } from '@site/src/test-utils' ;
4
4
import userEvent from '@testing-library/user-event' ;
5
5
import React from 'react' ;
6
6
import AppsTable from '..' ;
7
+ import useDeviceType from '@site/src/hooks/useDeviceType' ;
8
+ import useAppManager from '@site/src/hooks/useAppManager' ;
7
9
8
10
jest . mock ( '@site/src/hooks/useAuthContext' ) ;
9
11
const mockUseAuthContext = useAuthContext as jest . MockedFunction <
10
12
( ) => Partial < ReturnType < typeof useAuthContext > >
11
13
> ;
12
14
15
+ jest . mock ( '@site/src/hooks/useDeviceType' ) ;
16
+ const mockDeviceType = useDeviceType as jest . MockedFunction <
17
+ ( ) => Partial < ReturnType < typeof useDeviceType > >
18
+ > ;
19
+ mockDeviceType . mockImplementation ( ( ) => ( {
20
+ deviceType : 'desktop' ,
21
+ } ) ) ;
22
+
13
23
mockUseAuthContext . mockImplementation ( ( ) => ( {
14
24
is_authorized : true ,
15
25
currentLoginAccount : {
@@ -19,6 +29,18 @@ mockUseAuthContext.mockImplementation(() => ({
19
29
} ,
20
30
} ) ) ;
21
31
32
+ jest . mock ( '@site/src/hooks/useAppManager' ) ;
33
+ const mockUseAppManager = useAppManager as jest . MockedFunction <
34
+ ( ) => Partial < ReturnType < typeof useAppManager > >
35
+ > ;
36
+ const mockUpdateCurrentTab = jest . fn ( ) ;
37
+ mockUseAppManager . mockImplementation ( ( ) => ( {
38
+ getApps : jest . fn ( ) ,
39
+ apps : undefined ,
40
+ tokens : undefined ,
41
+ updateCurrentTab : mockUpdateCurrentTab ,
42
+ } ) ) ;
43
+
22
44
const fakeApplications : ApplicationObject [ ] = [
23
45
{
24
46
active : 1 ,
@@ -51,15 +73,12 @@ const fakeApplications: ApplicationObject[] = [
51
73
] ;
52
74
53
75
describe ( 'Apps Table' , ( ) => {
54
- beforeEach ( ( ) => {
76
+ const renderAppTable = ( ) => {
55
77
render ( < AppsTable apps = { fakeApplications } /> ) ;
56
- } ) ;
57
-
58
- afterEach ( ( ) => {
59
- cleanup ( ) ;
60
- } ) ;
78
+ } ;
61
79
62
80
it ( 'Should render all applications properly' , ( ) => {
81
+ renderAppTable ( ) ;
63
82
const rows = screen . getAllByRole ( 'row' ) ;
64
83
expect ( rows . length ) . toBe ( 3 ) ;
65
84
} ) ;
@@ -139,4 +158,28 @@ describe('Apps Table', () => {
139
158
const updateDialogTitle = await screen . findByText ( 'Update App' ) ;
140
159
expect ( updateDialogTitle ) . toBeInTheDocument ( ) ;
141
160
} ) ;
161
+
162
+ it ( 'Should render responsive view properly' , ( ) => {
163
+ mockDeviceType . mockImplementation ( ( ) => ( {
164
+ deviceType : 'mobile' ,
165
+ } ) ) ;
166
+ renderAppTable ( ) ;
167
+ const accordion = screen . getAllByTestId ( 'dt_accordion_root' ) ;
168
+ expect ( accordion . length ) . toBe ( 1 ) ;
169
+ } ) ;
170
+
171
+ it ( 'Should update current tab on clicking Register new application button' , async ( ) => {
172
+ renderAppTable ( ) ;
173
+ const registerButton = screen . getByText ( 'Register new application' ) ;
174
+ await userEvent . click ( registerButton ) ;
175
+ expect ( mockUpdateCurrentTab ) . toBeCalled ( ) ;
176
+ } ) ;
177
+
178
+ it ( 'Should open first accordion on item click' , async ( ) => {
179
+ renderAppTable ( ) ;
180
+ const item = screen . getByText ( 'first app' ) ;
181
+ await userEvent . click ( item ) ;
182
+ const content = screen . getByText ( '11111' ) ;
183
+ expect ( content ) . toBeInTheDocument ( ) ;
184
+ } ) ;
142
185
} ) ;
0 commit comments