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