test COMPLETED_AND_PAUSED should have correct menu items
[vid.git] / vid-webpack-master / cypress / integration / iFrames / instantiationStatus.e2e.ts
1 ///<reference path="../../../node_modules/cypress/types/index.d.ts"/>
2 /// <reference types="Cypress" />
3
4 import {JsonBuilder} from '../../support/jsonBuilders/jsonBuilder';
5 import {AsyncInstantiationModel} from '../../support/jsonBuilders/models/asyncInstantiation.model';
6
7 describe('Instantiation status', function () {
8   var jsonBuilderInstantiationBuilder : JsonBuilder<AsyncInstantiationModel> = new JsonBuilder<AsyncInstantiationModel>();
9   var asyncRes: Array<any>;
10   const contextMenuCreateAnotherOne = 'context-menu-create-another-one';
11   const contextMenuNewViewEdit = 'context-menu-new-view-edit';
12
13   beforeEach(() => {
14       cy.clearSessionStorage();
15       cy.setReduxState();
16       cy.preventErrorsOnLoading();
17       cy.initAAIMock();
18       cy.initVidMock();
19       jsonBuilderInstantiationBuilder.basicMock('cypress/support/jsonBuilders/mocks/jsons/asyncInstantiation.json',
20         Cypress.config('baseUrl') + "/asyncInstantiation**",
21         (res: any) => {
22             asyncRes = res;
23             return res;
24       });
25       cy.login();
26   });
27
28   afterEach(() => {
29     cy.screenshot();
30   });
31
32   it('should display the correct icons per status', function () {
33       const serviceAction:any = {INSTANTIATE : 'Instantiate', DELETE: 'Delete', UPDATE: 'Update', UPGRADE: 'Upgrade'};
34       cy.openIframe('app/ui/#/instantiationStatus');
35       for(let i = 0 ; i < asyncRes.length; i++){
36         cy.getTableRowByIndex('instantiation-status', i).get(`td custom-icon#jobStatusIcon-${i} div`)
37         .should('have.class', `__${getJobIconClass(asyncRes[i].jobStatus)}`);
38
39         if(asyncRes[i].project){
40           cy.getTableRowByIndex('instantiation-status', i).get('td#project span').contains(asyncRes[i].project);
41         }
42         if(asyncRes[i].userId){
43           cy.getTableRowByIndex('instantiation-status', i).get('td#userId span').contains(asyncRes[i].userId);
44         }
45         if(asyncRes[i].tenantName){
46           cy.getTableRowByIndex('instantiation-status', i).get('td#tenantName span').contains(asyncRes[i].tenantName);
47         }
48         if(asyncRes[i].serviceModelName){
49           cy.getTableRowByIndex('instantiation-status', i).get('td#serviceModelName span').contains(asyncRes[i].serviceModelName);
50         }
51         if(asyncRes[i].serviceInstanceName){
52           cy.getTableRowByIndex('instantiation-status', i).get('td#serviceInstanceName span').contains(asyncRes[i].serviceInstanceName);
53         }
54         if(asyncRes[i].serviceModelVersion){
55           cy.getTableRowByIndex('instantiation-status', i).get('td#serviceModelVersion span').contains(asyncRes[i].serviceModelVersion);
56         }
57         if(asyncRes[i].subscriberName){
58           cy.getTableRowByIndex('instantiation-status', i).get('td#subscriberName span').contains(asyncRes[i].subscriberName);
59         }
60         if(asyncRes[i].action) {
61           cy.getTableRowByIndex('instantiation-status', i).get('td#action span').contains(serviceAction[asyncRes[i].action]);
62         }
63     }
64   });
65
66   function getJobIconClass(status: string) : string{
67     switch(`${status}`.toUpperCase()) {
68       case  'PENDING' :
69         return "pending";
70       case  'IN_PROGRESS' :
71         return  "in_progress";
72       case  'PAUSED' :
73         return "pause";
74       case  'FAILED' :
75         return "x-circle-o";
76       case  'COMPLETED' :
77         return "success-circle-o";
78       case  'STOPPED' :
79         return "stop";
80       case  'COMPLETED_WITH_ERRORS' :
81         return "success_with_warning";
82       case  'COMPLETED_AND_PAUSED' :
83         return "stopped-upon-success";
84       default:
85         return "question-mark-circle-o";
86     }
87   }
88
89   it('should filter rows by filter text', function () {
90     cy.openIframe('app/ui/#/instantiationStatus');
91     cy.getElementByDataTestsId("instantiation-status-filter").type("ComplexService");
92     cy.get('table#instantiation-status tbody tr').should('have.length', 2);
93   });
94
95   it('should filter rows by url filter text', function () {
96     cy.openIframe('app/ui/#/instantiationStatus?filterText=ComplexService');
97     cy.getElementByDataTestsId("instantiation-status-filter").should('have.value','ComplexService');
98     cy.get('table#instantiation-status tbody tr').should('have.length', 2);
99   });
100
101   function getDisabledDropDownItemByDataTestId(testId:String) {
102     return cy.get('.dropdown-menu').find('.disabled').find(`[data-tests-id='${testId}']`);
103   }
104
105   function getDropDownItemByDataTestId(testId:String) {
106     return cy.get('.dropdown-menu').find(`[data-tests-id='${testId}']`);
107   }
108
109   function clickOnTitleAndThenOnMenuWithJobId(jobId: string) {
110     cy.getElementByDataTestsId("instantiation-status-title").click();
111     cy.get('#' + jobId).find('.menu-div').click({force: true});
112   }
113
114   it('should disabled correct menu items', function () {
115
116     cy.openIframe('app/ui/#/instantiationStatus');
117
118     // Instantiate action with Job status FAILED - isRetry = true
119     clickOnTitleAndThenOnMenuWithJobId('5c2cd8e5-27d0-42e3-85a1-85db5eaba459');
120     getDisabledDropDownItemByDataTestId('context-menu-retry').should('not.exist');
121     getDisabledDropDownItemByDataTestId('context-menu-remove').should('exist');
122     getDisabledDropDownItemByDataTestId('context-menu-open').should('exist');
123     getDisabledDropDownItemByDataTestId('context-menu-hide').should('not.exist');
124     getDisabledDropDownItemByDataTestId('context-menu-audit-info').should('not.exist');
125     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('not.exist');
126
127     // Instantiate action with Job status FAILED - isRetry = false
128     clickOnTitleAndThenOnMenuWithJobId('e1db03c3-6274-4ff7-84cf-7bd3a3946de7');
129     getDisabledDropDownItemByDataTestId('context-menu-retry').should('not.be.visible');
130     getDisabledDropDownItemByDataTestId('context-menu-open').should('exist');
131     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('not.exist');
132
133     //Delete action with Job status IN_PROGRESS
134     clickOnTitleAndThenOnMenuWithJobId('850dc7d2-5240-437f-9bcd-b1ed7dc339c2');
135     getDisabledDropDownItemByDataTestId('context-menu-remove').should('exist');
136     getDisabledDropDownItemByDataTestId('context-menu-open').should('exist');
137     getDisabledDropDownItemByDataTestId('context-menu-hide').should('exist');
138     getDisabledDropDownItemByDataTestId('context-menu-audit-info').should('not.exist');
139     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('exist');
140
141     //Update action with Job status COMPLETED
142     clickOnTitleAndThenOnMenuWithJobId('850dc7d2-5240-437f-9bcd-b1ed7dc339c1');
143     getDisabledDropDownItemByDataTestId('context-menu-remove').should('exist');
144     getDisabledDropDownItemByDataTestId('context-menu-open').should('not.exist');
145     getDisabledDropDownItemByDataTestId('context-menu-hide').should('not.exist');
146     getDisabledDropDownItemByDataTestId('context-menu-audit-info').should('not.exist');
147     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('exist');
148   });
149
150   it('COMPLETED_AND_PAUSED should have correct menu items', function () {
151     cy.openIframe('app/ui/#/instantiationStatus');
152
153     //COMPLETED_AND_PAUSED
154     clickOnTitleAndThenOnMenuWithJobId('850dc7d2-5240-437f-9bcd-b1ed7dc339d9');
155     getDropDownItemByDataTestId('context-menu-retry').should('exist');
156     getDropDownItemByDataTestId('context-menu-open').should('exist');
157     getDropDownItemByDataTestId('context-menu-audit-info').should('exist');
158     getDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('exist');
159   });
160
161   it('clicking on create another one item, go to expected url', function () {
162     //see cypress/support/jsonBuilders/mocks/jsons/asyncInstantiation.json id:8
163     const jobId = '5c2cd8e5-27d0-42e3-85a1-85db5eaba459';
164     const serviceModelId = 'e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0';
165     const vidBaseUrl = `${Cypress.config().baseUrl}/serviceModels.htm`;
166
167     cy.openIframe('app/ui/#/instantiationStatus');
168
169     clickOnTitleAndThenOnMenuWithJobId(jobId);
170     cy.get('.dropdown-menu').getElementByDataTestsId(contextMenuCreateAnotherOne).contains('Create another one');
171     cy.get('.dropdown-menu').getElementByDataTestsId(contextMenuCreateAnotherOne).click();
172     cy.location().should((loc) => {
173       expect(loc.toString()).to.eq(`${vidBaseUrl}#/servicePlanning/RECREATE?serviceModelId=${serviceModelId}&jobId=${jobId}`);
174     });
175   });
176
177   it('clicking on new view edit, go to expected url', function () {
178     //see cypress/support/jsonBuilders/mocks/jsons/asyncInstantiation.json id:10
179     const jobId = '850dc7d2-5240-437f-9bcd-b1ed7dc339c1';
180     const serviceModelId = 'e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0';
181     const vidBaseUrl = `${Cypress.config().baseUrl}/serviceModels.htm`;
182     const serviceType = 'TYLER%20SILVIA';
183
184     cy.openIframe('app/ui/#/instantiationStatus');
185     clickOnTitleAndThenOnMenuWithJobId(jobId);
186     cy.get('.dropdown-menu').getElementByDataTestsId(contextMenuNewViewEdit).contains('New View/Edit');
187     cy.get('.dropdown-menu').getElementByDataTestsId(contextMenuNewViewEdit).click();
188     cy.location().should((location) => {
189       expect(location.toString()).to.eq(`${vidBaseUrl}#/servicePlanning/EDIT?serviceModelId=${serviceModelId}&serviceType=${serviceType}&jobId=${jobId}`);
190     });
191   });
192 });