@@ -2,9 +2,10 @@ import React from 'react'
2
2
import { cloneDeep } from 'lodash'
3
3
import { act , cleanup , fireEvent , mockedStore , render , screen , waitForEuiPopoverVisible } from 'uiSrc/utils/test-utils'
4
4
5
- import { getCapiKeys , oauthCapiKeysSelector , removeAllCapiKeys } from 'uiSrc/slices/oauth/cloud'
5
+ import { getCapiKeys , getCapiKeysSuccess , oauthCapiKeysSelector , removeAllCapiKeys } from 'uiSrc/slices/oauth/cloud'
6
6
import { apiService } from 'uiSrc/services'
7
7
import { sendEventTelemetry , TelemetryEvent } from 'uiSrc/telemetry'
8
+ import { OAUTH_CLOUD_CAPI_KEYS_DATA } from 'uiSrc/mocks/data/oauth'
8
9
9
10
import CloudSettings from './CloudSettings'
10
11
@@ -29,6 +30,22 @@ jest.mock('uiSrc/telemetry', () => ({
29
30
} ) )
30
31
31
32
describe ( 'CloudSettings' , ( ) => {
33
+ it ( 'should show delete popover and call proper action on delete' , async ( ) => {
34
+ ( oauthCapiKeysSelector as jest . Mock ) . mockReturnValue ( {
35
+ data : OAUTH_CLOUD_CAPI_KEYS_DATA ,
36
+ loading : false
37
+ } )
38
+ render ( < CloudSettings /> )
39
+
40
+ fireEvent . click ( screen . getByTestId ( 'delete-key-btn' ) )
41
+ await waitForEuiPopoverVisible ( )
42
+
43
+ fireEvent . click ( screen . getByTestId ( 'delete-key-confirm-btn' ) )
44
+
45
+ expect ( store . getActions ( ) )
46
+ . toEqual ( [ getCapiKeys ( ) , getCapiKeysSuccess ( OAUTH_CLOUD_CAPI_KEYS_DATA ) , removeAllCapiKeys ( ) ] )
47
+ } )
48
+
32
49
it ( 'should render' , ( ) => {
33
50
expect ( render ( < CloudSettings /> ) ) . toBeTruthy ( )
34
51
} )
@@ -40,32 +57,14 @@ describe('CloudSettings', () => {
40
57
} )
41
58
42
59
it ( 'should be disabled delete all button' , ( ) => {
43
- render ( < CloudSettings /> )
44
-
45
- expect ( screen . getByTestId ( 'delete-key-btn' ) ) . toBeDisabled ( )
46
- } )
47
-
48
- it ( 'should show delete popover and call proper action on delete' , async ( ) => {
49
60
( oauthCapiKeysSelector as jest . Mock ) . mockReturnValue ( {
50
- data : [
51
- {
52
- id : '1' ,
53
- name : 'RedisInsight-f4868252-a128-4a02-af75-bd3c99898267-2020-11-01T-123' ,
54
- createdAt : '2023-08-02T09:07:41.680Z' ,
55
- lastUsed : '2023-08-02T09:07:41.680Z' ,
56
- valid : true ,
57
- }
58
- ] ,
61
+ data : [ ] ,
59
62
loading : false
60
63
} )
61
- render ( < CloudSettings /> )
62
64
63
- fireEvent . click ( screen . getByTestId ( 'delete-key-btn' ) )
64
- await waitForEuiPopoverVisible ( )
65
-
66
- fireEvent . click ( screen . getByTestId ( 'delete-key-confirm-btn' ) )
65
+ render ( < CloudSettings /> )
67
66
68
- expect ( store . getActions ( ) ) . toEqual ( [ getCapiKeys ( ) , removeAllCapiKeys ( ) ] )
67
+ expect ( screen . getByTestId ( 'delete-key-btn' ) ) . toBeDisabled ( )
69
68
} )
70
69
71
70
it ( 'should call proper telemetry events' , async ( ) => {
@@ -74,15 +73,7 @@ describe('CloudSettings', () => {
74
73
sendEventTelemetry . mockImplementation ( ( ) => sendEventTelemetryMock ) ;
75
74
76
75
( oauthCapiKeysSelector as jest . Mock ) . mockReturnValue ( {
77
- data : [
78
- {
79
- id : '1' ,
80
- name : 'RedisInsight-f4868252-a128-4a02-af75-bd3c99898267-2020-11-01T-123' ,
81
- createdAt : '2023-08-02T09:07:41.680Z' ,
82
- lastUsed : '2023-08-02T09:07:41.680Z' ,
83
- valid : true ,
84
- }
85
- ] ,
76
+ data : OAUTH_CLOUD_CAPI_KEYS_DATA ,
86
77
loading : false
87
78
} )
88
79
render ( < CloudSettings /> )
0 commit comments