1
1
import React from 'react'
2
2
import { instance , mock } from 'ts-mockito'
3
- import { render } from 'uiSrc/utils/test-utils'
3
+ import { render , screen } from 'uiSrc/utils/test-utils'
4
+ import { appFeatureFlagsFeaturesSelector } from 'uiSrc/slices/app/features'
4
5
import DatabaseListHeader , { Props } from './DatabaseListHeader'
5
6
6
7
const mockedProps = mock < Props > ( )
7
8
9
+ jest . mock ( 'uiSrc/slices/app/features' , ( ) => ( {
10
+ ...jest . requireActual ( 'uiSrc/slices/app/features' ) ,
11
+ appFeatureFlagsFeaturesSelector : jest . fn ( ) . mockReturnValue ( {
12
+ enhancedCloudUI : {
13
+ flag : false
14
+ }
15
+ } ) ,
16
+ } ) )
17
+
18
+ jest . mock ( 'uiSrc/slices/content/create-redis-buttons' , ( ) => ( {
19
+ ...jest . requireActual ( 'uiSrc/slices/content/create-redis-buttons' ) ,
20
+ contentSelector : jest . fn ( ) . mockReturnValue ( {
21
+ data : {
22
+ cloud : {
23
+ title : 'Try Redis Cloud: your ultimate Redis starting point' ,
24
+ description : 'Includes native support for JSON, Search and Query, and more' ,
25
+ links : {
26
+ main : {
27
+ altText : 'Try Redis Cloud.' ,
28
+ url : 'https://redis.io/try-free/?utm_source=redisinsight&utm_medium=main&utm_campaign=main'
29
+ }
30
+ } ,
31
+ }
32
+ }
33
+ } ) ,
34
+ } ) )
35
+
8
36
jest . mock ( 'uiSrc/telemetry' , ( ) => ( {
9
37
...jest . requireActual ( 'uiSrc/telemetry' ) ,
10
38
sendEventTelemetry : jest . fn ( ) ,
@@ -14,4 +42,28 @@ describe('DatabaseListHeader', () => {
14
42
it ( 'should render' , ( ) => {
15
43
expect ( render ( < DatabaseListHeader { ...instance ( mockedProps ) } /> ) ) . toBeTruthy ( )
16
44
} )
45
+
46
+ it ( 'should not show promo cloud button with disabled feature flag' , ( ) => {
47
+ ( appFeatureFlagsFeaturesSelector as jest . Mock ) . mockReturnValueOnce ( {
48
+ enhancedCloudUI : {
49
+ flag : true
50
+ }
51
+ } )
52
+
53
+ render ( < DatabaseListHeader { ...instance ( mockedProps ) } /> )
54
+
55
+ expect ( screen . queryByTestId ( 'promo-btn' ) ) . not . toBeInTheDocument ( )
56
+ } )
57
+
58
+ it ( 'should show promo cloud button with enabled feature flag' , ( ) => {
59
+ ( appFeatureFlagsFeaturesSelector as jest . Mock ) . mockReturnValueOnce ( {
60
+ enhancedCloudUI : {
61
+ flag : false
62
+ }
63
+ } )
64
+
65
+ render ( < DatabaseListHeader { ...instance ( mockedProps ) } /> )
66
+
67
+ expect ( screen . getByTestId ( 'promo-btn' ) ) . toBeInTheDocument ( )
68
+ } )
17
69
} )
0 commit comments