@@ -39,7 +39,6 @@ describe('ConnectionForm Component', function () {
3939 connectionString : 'mongodb://pineapple:orangutans@localhost:27019' ,
4040 } ,
4141 } }
42- onSaveClicked = { noop }
4342 { ...props }
4443 />
4544 ) ;
@@ -54,10 +53,55 @@ describe('ConnectionForm Component', function () {
5453 expect ( screen . getByText ( 'New Connection' ) ) . to . exist ;
5554 } ) ;
5655
57- it ( 'should show the connect button ' , function ( ) {
56+ it ( 'should show no save or connect buttons by default ' , function ( ) {
5857 renderForm ( ) ;
59- const button = screen . getByText ( 'Connect' ) . closest ( 'button' ) ;
58+ expect ( screen . queryByRole ( 'button' , { name : 'Save' } ) ) . to . be . null ;
59+ expect ( screen . queryByRole ( 'button' , { name : 'Connect' } ) ) . to . be . null ;
60+ expect ( screen . queryByRole ( 'button' , { name : 'Save & Connect' } ) ) . to . be . null ;
61+ } ) ;
62+
63+ it ( 'should show the save button if onSaveClicked is specified' , function ( ) {
64+ const onSaveClicked = Sinon . spy ( ) ;
65+ renderForm ( {
66+ onSaveClicked : onSaveClicked ,
67+ } ) ;
68+ const button = screen
69+ . getByRole ( 'button' , { name : 'Save' } )
70+ . closest ( 'button' ) ;
6071 expect ( button ?. getAttribute ( 'aria-disabled' ) ) . to . not . equal ( 'true' ) ;
72+
73+ button ?. click ( ) ;
74+ expect ( onSaveClicked . callCount ) . to . equal ( 1 ) ;
75+ } ) ;
76+
77+ it ( 'should show the connect button if onConnectClicked is specified' , function ( ) {
78+ const onConnectClicked = Sinon . spy ( ) ;
79+
80+ renderForm ( {
81+ onConnectClicked,
82+ } ) ;
83+ const button = screen
84+ . getByRole ( 'button' , { name : 'Connect' } )
85+ . closest ( 'button' ) ;
86+ expect ( button ?. getAttribute ( 'aria-disabled' ) ) . to . not . equal ( 'true' ) ;
87+
88+ button ?. click ( ) ;
89+ expect ( onConnectClicked . callCount ) . to . equal ( 1 ) ;
90+ } ) ;
91+
92+ it ( 'should show the save & connect button if onSaveAndConnectClicked is specified' , function ( ) {
93+ const onSaveAndConnectClicked = Sinon . spy ( ) ;
94+
95+ renderForm ( {
96+ onSaveAndConnectClicked,
97+ } ) ;
98+ const button = screen
99+ . getByRole ( 'button' , { name : 'Save & Connect' } )
100+ . closest ( 'button' ) ;
101+ expect ( button ?. getAttribute ( 'aria-disabled' ) ) . to . not . equal ( 'true' ) ;
102+
103+ button ?. click ( ) ;
104+ expect ( onSaveAndConnectClicked . callCount ) . to . equal ( 1 ) ;
61105 } ) ;
62106
63107 it ( 'should render the connection string textbox' , function ( ) {
@@ -103,6 +147,9 @@ describe('ConnectionForm Component', function () {
103147 screen . getByTestId ( 'advanced-connection-options' )
104148 ) . to . throw ;
105149 expect ( ( ) => screen . getByRole ( 'button' , { name : 'Connect' } ) ) . to . throw ;
150+ expect ( ( ) =>
151+ screen . getByRole ( 'button' , { name : 'Save & Connect' } )
152+ ) . to . throw ;
106153
107154 // pressing enter calls onSubmit which saves
108155 fireEvent . submit ( screen . getByRole ( 'form' ) ) ;
@@ -137,6 +184,7 @@ describe('ConnectionForm Component', function () {
137184 expect ( screen . getByTestId ( 'toggle-edit-connection-string' ) ) . to . exist ;
138185 expect ( screen . getByTestId ( 'advanced-connection-options' ) ) . to . exist ;
139186 expect ( screen . getByRole ( 'button' , { name : 'Connect' } ) ) . to . exist ;
187+ expect ( screen . getByRole ( 'button' , { name : 'Save & Connect' } ) ) . to . exist ;
140188
141189 // pressing enter calls onSubmit which saves and connects (the default)
142190 fireEvent . submit ( screen . getByRole ( 'form' ) ) ;
0 commit comments