@@ -3,6 +3,9 @@ import arrayMutators from 'final-form-arrays';
33import React from 'react' ;
44import { Form } from 'react-final-form' ;
55
6+ import { BasicOptionsFields } from 'app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterBasicOptions/DBClusterBasicOptions.types' ;
7+ import { Databases } from 'app/percona/shared/core' ;
8+
69import NetworkAndSecurity from './NetworkAndSecurity' ;
710import { Messages } from './NetworkAndSecurity.messages' ;
811import { NetworkAndSecurityFields } from './NetworkAndSecurity.types' ;
@@ -11,7 +14,10 @@ describe('DBClusterAdvancedOptions NetworkAndSecurity::', () => {
1114 it ( 'render items correctly for create and edit mode' , ( ) => {
1215 render (
1316 < Form
14- initialValues = { { [ NetworkAndSecurityFields . sourceRanges ] : [ { } ] } }
17+ initialValues = { {
18+ [ NetworkAndSecurityFields . sourceRanges ] : [ { } ] ,
19+ [ BasicOptionsFields . databaseType ] : { value : Databases . mysql } ,
20+ } }
1521 onSubmit = { jest . fn ( ) }
1622 mutators = { { ...arrayMutators } }
1723 render = { ( { form } ) => < NetworkAndSecurity form = { form } /> }
@@ -38,7 +44,10 @@ describe('DBClusterAdvancedOptions NetworkAndSecurity::', () => {
3844 it ( 'the delete button should not delete the first field' , ( ) => {
3945 render (
4046 < Form
41- initialValues = { { [ NetworkAndSecurityFields . sourceRanges ] : [ { sourceRange : '1' } ] } }
47+ initialValues = { {
48+ [ NetworkAndSecurityFields . sourceRanges ] : [ { sourceRange : '1' } ] ,
49+ [ BasicOptionsFields . databaseType ] : { value : Databases . mongodb } ,
50+ } }
4251 onSubmit = { jest . fn ( ) }
4352 mutators = { { ...arrayMutators } }
4453 render = { ( { form } ) => < NetworkAndSecurity form = { form } /> }
@@ -58,7 +67,10 @@ describe('DBClusterAdvancedOptions NetworkAndSecurity::', () => {
5867 it ( 'the delete button should delete field from the form if it is not the first one ' , ( ) => {
5968 render (
6069 < Form
61- initialValues = { { [ NetworkAndSecurityFields . sourceRanges ] : [ { sourceRange : '1' } , { sourceRange : '2' } ] } }
70+ initialValues = { {
71+ [ NetworkAndSecurityFields . sourceRanges ] : [ { sourceRange : '1' } , { sourceRange : '2' } ] ,
72+ [ BasicOptionsFields . databaseType ] : { value : Databases . mysql } ,
73+ } }
6274 onSubmit = { jest . fn ( ) }
6375 mutators = { { ...arrayMutators } }
6476 render = { ( { form } ) => < NetworkAndSecurity form = { form } /> }
@@ -74,4 +86,23 @@ describe('DBClusterAdvancedOptions NetworkAndSecurity::', () => {
7486 fireEvent . click ( deleteBtn ) ;
7587 expect ( screen . queryByTestId ( 'sourceRanges[1].sourceRange-text-input' ) ) . not . toBeInTheDocument ( ) ;
7688 } ) ;
89+ it ( 'source range field should be hidden whe database is postgreSQL ' , ( ) => {
90+ render (
91+ < Form
92+ initialValues = { {
93+ [ NetworkAndSecurityFields . sourceRanges ] : [ { sourceRange : '1' } ] ,
94+ [ BasicOptionsFields . databaseType ] : { value : Databases . postgresql } ,
95+ } }
96+ onSubmit = { jest . fn ( ) }
97+ mutators = { { ...arrayMutators } }
98+ render = { ( { form } ) => < NetworkAndSecurity form = { form } /> }
99+ />
100+ ) ;
101+ expect ( screen . getByTestId ( 'toggle-network-and-security' ) ) . toBeInTheDocument ( ) ;
102+ const checkbox = screen . getByTestId ( 'toggle-network-and-security' ) ;
103+
104+ fireEvent . click ( checkbox ) ;
105+
106+ expect ( screen . queryByTestId ( 'source-ranges' ) ) . not . toBeInTheDocument ( ) ;
107+ } ) ;
77108} ) ;
0 commit comments