@@ -45,30 +45,73 @@ const mockUseDynamicImportJSON = useDynamicImportJSON as jest.MockedFunction<
4545
4646const mockHandleSelectChange = jest . fn ( ) ;
4747
48- mockUseDynamicImportJSON . mockImplementation ( ( ) => ( {
49- request_info : {
50- auth_required : 1 ,
51- auth_scopes : [ ] ,
52- description : 'this is a test with `echo_req` description' ,
53- title : 'this is a test title' ,
54- } ,
55- response_info : {
56- description : 'this is a test with `echo_req` description' ,
57- title : 'this is a test title' ,
58- } ,
59- setSelected : jest . fn ( ) ,
60- handleTextAreaInput : mockHandleSelectChange ,
61- handleSelectChange : jest . fn ( ) ,
62- text_data : {
63- name : null ,
64- selected_value : 'Select API Call - Version 3' ,
65- request : '{ "echo_req": 1 } ' ,
66- } ,
67- } ) ) ;
68-
6948describe ( 'ApiExplorerFeatures' , ( ) => {
49+ describe ( 'Empty request body' , ( ) => {
50+ beforeEach ( ( ) => {
51+ mockUseDynamicImportJSON . mockImplementation ( ( ) => ( {
52+ request_info : {
53+ auth_required : 1 ,
54+ auth_scopes : [ ] ,
55+ description : 'this is a test with `echo_req` description' ,
56+ title : 'this is a test title' ,
57+ } ,
58+ response_info : {
59+ description : 'this is a test with `echo_req` description' ,
60+ title : 'this is a test title' ,
61+ } ,
62+ setSelected : jest . fn ( ) ,
63+ handleTextAreaInput : mockHandleSelectChange ,
64+ handleSelectChange : jest . fn ( ) ,
65+ text_data : {
66+ name : null ,
67+ selected_value : 'Select API Call - Version 3' ,
68+ request : '' ,
69+ } ,
70+ } ) ) ;
71+ mockUseAuthContext . mockImplementation ( ( ) => {
72+ return {
73+ is_logged_in : false ,
74+ is_authorized : false ,
75+ } ;
76+ } ) ;
77+ render ( < ApiExplorerFeatures /> ) ;
78+ } ) ;
79+
80+ afterEach ( ( ) => {
81+ jest . clearAllMocks ( ) ;
82+ cleanup ( ) ;
83+ } ) ;
84+
85+ it ( 'Should disable the buttons when there is no data in the request body' , ( ) => {
86+ const request_button = screen . getByRole ( 'button' , { name : / s e n d r e q u e s t / i } ) ;
87+ const clear_button = screen . getByRole ( 'button' , { name : / c l e a r / i } ) ;
88+
89+ expect ( request_button ) . toBeDisabled ( ) ;
90+ expect ( clear_button ) . toBeDisabled ( ) ;
91+ } ) ;
92+ } ) ;
7093 describe ( 'Logged out' , ( ) => {
7194 beforeEach ( ( ) => {
95+ mockUseDynamicImportJSON . mockImplementation ( ( ) => ( {
96+ request_info : {
97+ auth_required : 1 ,
98+ auth_scopes : [ ] ,
99+ description : 'this is a test with `echo_req` description' ,
100+ title : 'this is a test title' ,
101+ } ,
102+ response_info : {
103+ description : 'this is a test with `echo_req` description' ,
104+ title : 'this is a test title' ,
105+ } ,
106+ setSelected : jest . fn ( ) ,
107+ handleTextAreaInput : mockHandleSelectChange ,
108+ handleSelectChange : jest . fn ( ) ,
109+ text_data : {
110+ name : null ,
111+ selected_value : 'Select API Call - Version 3' ,
112+ request : '{ "echo_req": 1 } ' ,
113+ } ,
114+ } ) ) ;
72115 mockUseAuthContext . mockImplementation ( ( ) => {
73116 return {
74117 is_logged_in : false ,
@@ -154,6 +197,29 @@ describe('ApiExplorerFeatures', () => {
154197 } ) ;
155198
156199 describe ( 'Logged in' , ( ) => {
200+ beforeEach ( ( ) => {
201+ mockUseDynamicImportJSON . mockImplementation ( ( ) => ( {
202+ request_info : {
203+ auth_required : 1 ,
204+ auth_scopes : [ ] ,
205+ description : 'this is a test with `echo_req` description' ,
206+ title : 'this is a test title' ,
207+ } ,
208+ response_info : {
209+ description : 'this is a test with `echo_req` description' ,
210+ title : 'this is a test title' ,
211+ } ,
212+ setSelected : jest . fn ( ) ,
213+ handleTextAreaInput : mockHandleSelectChange ,
214+ handleSelectChange : jest . fn ( ) ,
215+ text_data : {
216+ name : null ,
217+ selected_value : 'Select API Call - Version 3' ,
218+ request : '{ "echo_req": 1 } ' ,
219+ } ,
220+ } ) ) ;
221+ } ) ;
222+
157223 afterEach ( ( ) => {
158224 jest . clearAllMocks ( ) ;
159225 cleanup ( ) ;
@@ -196,6 +262,29 @@ describe('ApiExplorerFeatures', () => {
196262 } ) ;
197263
198264 describe ( 'Disabled send request button' , ( ) => {
265+ beforeEach ( ( ) => {
266+ mockUseDynamicImportJSON . mockImplementation ( ( ) => ( {
267+ request_info : {
268+ auth_required : 1 ,
269+ auth_scopes : [ ] ,
270+ description : 'this is a test with `echo_req` description' ,
271+ title : 'this is a test title' ,
272+ } ,
273+ response_info : {
274+ description : 'this is a test with `echo_req` description' ,
275+ title : 'this is a test title' ,
276+ } ,
277+ setSelected : jest . fn ( ) ,
278+ handleTextAreaInput : mockHandleSelectChange ,
279+ handleSelectChange : jest . fn ( ) ,
280+ text_data : {
281+ name : null ,
282+ selected_value : 'Select API Call - Version 3' ,
283+ request : '{ "echo_req": 1 } ' ,
284+ } ,
285+ } ) ) ;
286+ } ) ;
287+
199288 afterEach ( ( ) => {
200289 jest . clearAllMocks ( ) ;
201290 cleanup ( ) ;
0 commit comments