11/* eslint-disable no-undef */
2- import { flashClassMap } from '../../../../support/assertions/assertion_constants' ;
32import {
43 LABEL_CONFIG_KEYS ,
54 FIELD_CONFIG_KEYS ,
@@ -10,23 +9,6 @@ import {
109// Menu options
1110const SERVICES_MENU_OPTION = 'Services' ;
1211const REQUESTS_MENU_OPTION = 'Requests' ;
13- const CATALOGS_MENU_OPTION = 'Catalogs' ;
14- const AUTOMATION_MENU_OPTION = 'Automation' ;
15- const EMBEDDED_AUTOMATION_MENU_OPTION = 'Embedded Automate' ;
16- const CUSTOMIZATION_MENU_OPTION = 'Customization' ;
17-
18- // Accordion items
19- const SERVICE_DIALOGS_ACCORDION = 'Service Dialogs' ;
20- const ALL_DIALOGS_ACCORDION_ITEM = 'All Dialogs' ;
21- const SERVICE_CATALOGS_ACCORDION = 'Service Catalogs' ;
22- const ALL_SERVICES_ACCORDION_ITEM = 'All Services' ;
23- const CATALOG_ITEMS_ACCORDION_ITEM = 'Catalog Items' ;
24- const ALL_CATALOG_ITEMS_ACCORDION_ITEM = 'All Catalog Items' ;
25-
26- // Toolbar options
27- const TOOLBAR_CONFIGURATION = 'Configuration' ;
28- const TOOLBAR_ADD_NEW_DIALOG = 'Add a new Dialog' ;
29- const TOOLBAR_ADD_CATALOG_ITEM = 'Add a New Catalog Item' ;
3012
3113// Field labels
3214const FORM_HEADER = 'Requests' ;
@@ -37,10 +19,8 @@ const REQUEST_DATE_LABEL = 'Request Date';
3719const REASON_LABEL = 'Reason' ;
3820
3921// Field values
40- const TEST_DIALOG_NAME = 'Test-Dialog-Name' ;
41- const CATALOG_ITEM_NAME = 'Test-Catalog-Item' ;
4222const SELECT_OPTION_ALL = 'all' ;
43- const TYPE_VM_PROVISION = 'VM Provision ' ;
23+ const TYPE_VM_RECONFIGURE = 'vm_reconfigure ' ;
4424const REQUEST_DATE_LAST_7_DAYS = '7' ;
4525
4626// Checkbox labels
@@ -51,99 +31,24 @@ const DENIED_LABEL = 'Denied';
5131// Button texts
5232const APPLY_BUTTON_TEXT = 'Apply' ;
5333const RESET_BUTTON_TEXT = 'Reset' ;
54- const SAVE_BUTTON_TEXT = 'Save' ;
55- const ADD_BUTTON_TEXT = 'Add' ;
56- const ORDER_BUTTON_TEXT = 'Order' ;
57- const SUBMIT_BUTTON_TEXT = 'Submit' ;
5834
59- // Flash message text snippets
60- const FLASH_MESSAGE_ADD_SUCCESS = 'added' ;
61- const FLASH_MESSAGE_SAVE_SUCCESS = 'saved' ;
62- const FLASH_MESSAGE_SUBMITTED = 'submitted' ;
35+ /**
36+ * Converts a JavaScript Date object to a database-compatible timestamp string.
37+ * @param {Date } [dateObject=new Date()] - The date to convert. Defaults to current date/time.
38+ * @returns {string } Formatted timestamp string in format: "YYYY-MM-DD HH:MM:SS.mmmmmm" like "2025-11-06 05:30:45.123000"
39+ */
40+ function getDateStringInDbFormat ( dateObject = new Date ( ) ) {
41+ const year = dateObject . getFullYear ( ) ;
42+ const month = String ( dateObject . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
43+ const day = String ( dateObject . getDate ( ) ) . padStart ( 2 , '0' ) ;
44+ const hours = String ( dateObject . getHours ( ) ) . padStart ( 2 , '0' ) ;
45+ const minutes = String ( dateObject . getMinutes ( ) ) . padStart ( 2 , '0' ) ;
46+ const seconds = String ( dateObject . getSeconds ( ) ) . padStart ( 2 , '0' ) ;
47+ const millis = String ( dateObject . getMilliseconds ( ) ) . padStart ( 3 , '0' ) ;
48+ // JS only gives milliseconds (3 digits) so converting it to 6 digits like ".812169"
49+ const micros = millis + '000' ;
6350
64- function dataSetup ( ) {
65- // Adding a dialog
66- cy . menu (
67- AUTOMATION_MENU_OPTION ,
68- EMBEDDED_AUTOMATION_MENU_OPTION ,
69- CUSTOMIZATION_MENU_OPTION
70- ) ;
71- cy . accordion ( SERVICE_DIALOGS_ACCORDION ) ;
72- cy . selectAccordionItem ( [ ALL_DIALOGS_ACCORDION_ITEM ] ) ;
73- cy . toolbar ( TOOLBAR_CONFIGURATION , TOOLBAR_ADD_NEW_DIALOG ) ;
74- cy . contains ( 'ul.static-field-list li.static-field-item' , 'Text Box' ) . trigger (
75- 'mousedown' ,
76- { which : 1 }
77- ) ;
78- cy . get ( '.well-lg' ) . trigger ( 'mousemove' ) . trigger ( 'mouseup' , { force : true } ) ;
79- cy . getFormInputFieldByIdAndType ( { inputId : 'name' } ) . type ( TEST_DIALOG_NAME ) ;
80- cy . interceptApi ( {
81- urlPattern : '/api/service_dialogs' ,
82- alias : 'addDialogApi' ,
83- triggerFn : ( ) =>
84- cy
85- . contains ( '.pull-right button' , SAVE_BUTTON_TEXT )
86- . should ( 'be.enabled' )
87- . click ( ) ,
88- onApiResponse : ( interception ) =>
89- expect ( interception . response . statusCode ) . to . equal ( 200 ) ,
90- } ) ;
91- cy . expect_flash ( flashClassMap . success , FLASH_MESSAGE_SAVE_SUCCESS ) ;
92- // Adding a catalog item
93- cy . menu ( SERVICES_MENU_OPTION , CATALOGS_MENU_OPTION ) ;
94- cy . accordion ( CATALOG_ITEMS_ACCORDION_ITEM ) ;
95- cy . selectAccordionItem ( [ ALL_CATALOG_ITEMS_ACCORDION_ITEM ] ) ;
96- cy . toolbar ( TOOLBAR_CONFIGURATION , TOOLBAR_ADD_CATALOG_ITEM ) ;
97- cy . contains ( '.form-group button[data-id="st_prov_type"]' , 'Choose' ) . click ( ) ;
98- cy . interceptApi ( {
99- urlPattern : '/catalog/atomic_form_field_changed/new?st_prov_type=generic' ,
100- alias : 'getGenericCatalogItemTypeDetailsApi' ,
101- triggerFn : ( ) =>
102- cy . contains ( '.form-group ul.dropdown-menu li a' , 'Generic' ) . click ( ) ,
103- onApiResponse : ( interception ) =>
104- expect ( interception . response . statusCode ) . to . equal ( 200 ) ,
105- } ) ;
106- cy . get ( 'input#name' ) . type ( CATALOG_ITEM_NAME ) ;
107- cy . contains ( '.form-group button[data-id="catalog_id"]' , 'Unassigned' ) . click ( ) ;
108- cy . contains (
109- '.form-group ul.dropdown-menu li a' ,
110- 'My Company/My Catalog'
111- ) . click ( ) ;
112- cy . contains ( '.form-group button[data-id="dialog_id"]' , 'No Dialog' ) . click ( ) ;
113- cy . contains ( ' .form-group ul.dropdown-menu li a' , TEST_DIALOG_NAME ) . click ( ) ;
114- cy . get ( 'input#display' ) . check ( ) ;
115- cy . interceptApi ( {
116- urlPattern : '/catalog/servicetemplate_edit?button=add' ,
117- alias : 'addCatalogItemApi' ,
118- triggerFn : ( ) =>
119- cy . contains ( '#form_buttons_div button' , ADD_BUTTON_TEXT ) . click ( ) ,
120- onApiResponse : ( interception ) =>
121- expect ( interception . response . statusCode ) . to . equal ( 200 ) ,
122- } ) ;
123- cy . expect_flash ( flashClassMap . success , FLASH_MESSAGE_ADD_SUCCESS ) ;
124- // Order
125- cy . accordion ( SERVICE_CATALOGS_ACCORDION ) ;
126- cy . selectAccordionItem ( [ ALL_SERVICES_ACCORDION_ITEM ] ) ;
127- cy . clickTableRowByText ( { text : CATALOG_ITEM_NAME , columnIndex : 0 } ) ;
128- cy . interceptApi ( {
129- urlPattern : / \/ c a t a l o g \/ x _ b u t t o n \/ \d + \? p r e s s e d = s v c _ c a t a l o g _ p r o v i s i o n / ,
130- alias : 'orderApi' ,
131- triggerFn : ( ) =>
132- cy
133- . contains ( `#main-content button[type="button"]` , ORDER_BUTTON_TEXT )
134- . click ( ) ,
135- onApiResponse : ( interception ) =>
136- expect ( interception . response . statusCode ) . to . equal ( 200 ) ,
137- } ) ;
138- cy . interceptApi ( {
139- urlPattern : / \/ a p i \/ s e r v i c e _ c a t a l o g s \/ \d + \/ s e r v i c e _ t e m p l a t e s \/ \d + $ / ,
140- alias : 'submitOrderApi' ,
141- triggerFn : ( ) =>
142- cy . contains ( '.pull-right button' , SUBMIT_BUTTON_TEXT ) . click ( ) ,
143- onApiResponse : ( interception ) =>
144- expect ( interception . response . statusCode ) . to . equal ( 200 ) ,
145- } ) ;
146- cy . expect_flash ( flashClassMap . success , FLASH_MESSAGE_SUBMITTED ) ;
51+ return `${ year } -${ month } -${ day } ${ hours } :${ minutes } :${ seconds } .${ micros } ` ;
14752}
14853
14954describe ( 'Automate Service Requests form operations: Services > Requests' , ( ) => {
@@ -239,8 +144,71 @@ describe('Automate Service Requests form operations: Services > Requests', () =>
239144
240145 describe ( 'Validate button click actions' , ( ) => {
241146 beforeEach ( ( ) => {
242- // TODO: Replace with better setup approach
243- dataSetup ( ) ;
147+ const tenDaysAgo = new Date (
148+ new Date ( ) . getTime ( ) - 10 * 24 * 60 * 60 * 1000
149+ ) ;
150+
151+ cy . appFactories ( [
152+ [
153+ 'create' ,
154+ 'service_template_provision_request' ,
155+ {
156+ description : 'Cypress mock data for approval state: Approved' ,
157+ approval_state : 'approved' ,
158+ type : 'ServiceTemplateProvisionRequest' ,
159+ fulfilled_on : getDateStringInDbFormat ( ) ,
160+ request_type : 'clone_to_service' ,
161+ request_state : 'finished' ,
162+ message : 'Cypress mock data for approval state: Approved' ,
163+ status : 'Ok' ,
164+ } ,
165+ ] ,
166+ [
167+ 'create' ,
168+ 'service_template_provision_request' ,
169+ {
170+ description : 'Cypress mock data for approval state: Denied' ,
171+ approval_state : 'denied' ,
172+ type : 'ServiceTemplateProvisionRequest' ,
173+ fulfilled_on : getDateStringInDbFormat ( ) ,
174+ request_type : 'clone_to_service' ,
175+ request_state : 'finished' ,
176+ message : 'Cypress mock data for approval state: Denied' ,
177+ status : 'Ok' ,
178+ } ,
179+ ] ,
180+ [
181+ 'create' ,
182+ 'vm_reconfigure_request' ,
183+ {
184+ description :
185+ 'Cypress mock data for approval state: Pending-Approval' ,
186+ approval_state : 'pending_approval' ,
187+ type : 'VmReconfigureRequest' ,
188+ request_type : TYPE_VM_RECONFIGURE ,
189+ request_state : 'pending' ,
190+ message : 'Cypress mock data for approval state: Pending-Approval' ,
191+ status : 'Ok' ,
192+ } ,
193+ ] ,
194+ // This record is used to filter data for requests made in the last 30 days
195+ [
196+ 'create' ,
197+ 'service_template_provision_request' ,
198+ {
199+ description :
200+ 'Cypress mock data for request made in the last 30 days' ,
201+ approval_state : 'approved' ,
202+ type : 'ServiceTemplateProvisionRequest' ,
203+ created_on : getDateStringInDbFormat ( tenDaysAgo ) ,
204+ fulfilled_on : getDateStringInDbFormat ( ) ,
205+ request_type : 'clone_to_service' ,
206+ request_state : 'finished' ,
207+ message : 'Cypress mock data for request made in the last 30 days' ,
208+ status : 'Ok' ,
209+ } ,
210+ ] ,
211+ ] ) ;
244212 } ) ;
245213
246214 it ( 'Validate reset & apply buttons' , ( ) => {
0 commit comments