@@ -334,4 +334,52 @@ describe("Ticket Form", () => {
334334 cy . findByRole ( 'cell' ) . should ( 'contain.text' , 'No results found' ) ;
335335 } ) ;
336336 } ) ;
337+
338+ it ( 'Create/update a ticket using a template with readonly fields' , ( ) => {
339+ const ticket_template_name = `test template ${ rand } ` ;
340+ cy . createWithAPI ( 'TicketTemplate' , {
341+ 'name' : ticket_template_name ,
342+ } ) . as ( 'ticket_template_id' ) ;
343+
344+ cy . get ( '@ticket_template_id' ) . then ( ( ticket_template_id ) => {
345+ cy . createWithAPI ( 'TicketTemplatePredefinedField' , {
346+ 'tickettemplates_id' : ticket_template_id , // Default template
347+ 'num' : 10 , // Urgency
348+ 'value' : 4 , // High
349+ } ) ;
350+
351+ cy . createWithAPI ( 'TicketTemplateReadonlyField' , {
352+ 'tickettemplates_id' : ticket_template_id ,
353+ 'num' : 10 ,
354+ } ) ;
355+
356+ cy . createWithAPI ( 'ITILCategory' , {
357+ 'name' :ticket_template_name ,
358+ 'tickettemplates_id' : ticket_template_id ,
359+ 'tickettemplates_id_incident' : ticket_template_id ,
360+ 'tickettemplates_id_demand' : ticket_template_id ,
361+ 'changetemplates_id' : ticket_template_id ,
362+ 'problemtemplates_id' : ticket_template_id ,
363+ } ) ;
364+ } ) ;
365+
366+ // Create form
367+ cy . visit ( `/front/ticket.form.php` ) ;
368+
369+ // intercept form submit
370+ cy . intercept ( 'POST' , '/front/ticket.form.php' ) . as ( 'submit' ) ;
371+
372+ cy . getDropdownByLabelText ( 'Category' ) . selectDropdownValue ( `»${ ticket_template_name } ` ) ;
373+
374+ // We change the value of a readonly field, it should be ignored
375+ cy . get ( 'input[name="urgency"]' ) . invoke ( 'val' , '1' ) ;
376+ cy . findByRole ( 'button' , { 'name' : 'Add' } ) . click ( ) ;
377+ cy . wait ( '@submit' ) . its ( 'response.statusCode' ) . should ( 'eq' , 200 ) ;
378+ cy . get ( 'input[name="urgency"]' ) . should ( 'have.value' , '4' ) ; // Should be the template 4 value
379+
380+ // We try updating it
381+ cy . get ( 'input[name="urgency"]' ) . invoke ( 'val' , '1' ) ;
382+ cy . findByRole ( 'button' , { 'name' : 'Save' } ) . click ( ) ;
383+ cy . get ( 'input[name="urgency"]' ) . should ( 'have.value' , '4' ) ; // Should be the template 4 value
384+ } ) ;
337385} ) ;
0 commit comments