add "new view/edit" button in the Instantiation Status page
[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         if(asyncRes[i].project){
37           cy.getTableRowByIndex('instantiation-status', i).get('td#project span').contains(asyncRes[i].project);
38         }
39         if(asyncRes[i].userId){
40           cy.getTableRowByIndex('instantiation-status', i).get('td#userId span').contains(asyncRes[i].userId);
41         }
42         if(asyncRes[i].tenantName){
43           cy.getTableRowByIndex('instantiation-status', i).get('td#tenantName span').contains(asyncRes[i].tenantName);
44         }
45         if(asyncRes[i].serviceModelName){
46           cy.getTableRowByIndex('instantiation-status', i).get('td#serviceModelName span').contains(asyncRes[i].serviceModelName);
47         }
48         if(asyncRes[i].serviceInstanceName){
49           cy.getTableRowByIndex('instantiation-status', i).get('td#serviceInstanceName span').contains(asyncRes[i].serviceInstanceName);
50         }
51         if(asyncRes[i].serviceModelVersion){
52           cy.getTableRowByIndex('instantiation-status', i).get('td#serviceModelVersion span').contains(asyncRes[i].serviceModelVersion);
53         }
54         if(asyncRes[i].subscriberName){
55           cy.getTableRowByIndex('instantiation-status', i).get('td#subscriberName span').contains(asyncRes[i].subscriberName);
56         }
57         if(asyncRes[i].action) {
58           cy.getTableRowByIndex('instantiation-status', i).get('td#action span').contains(serviceAction[asyncRes[i].action]);
59         }
60     }
61   });
62
63   it('should filter rows by filter text', function () {
64     cy.openIframe('app/ui/#/instantiationStatus');
65     cy.getElementByDataTestsId("instantiation-status-filter").type("ComplexService");
66     cy.get('table#instantiation-status tbody tr').should('have.length', 2);
67   });
68
69   it('should filter rows by url filter text', function () {
70     cy.openIframe('app/ui/#/instantiationStatus?filterText=ComplexService');
71     cy.getElementByDataTestsId("instantiation-status-filter").should('have.value','ComplexService');
72     cy.get('table#instantiation-status tbody tr').should('have.length', 2);
73   });
74
75   function getDisabledDropDownItemByDataTestId(testId:String) {
76     return cy.get('.dropdown-menu').find('.disabled').find(`[data-tests-id='${testId}']`);
77   }
78
79   function clickOnTitleAndThenOnMenuWithJobId(jobId: string) {
80     cy.getElementByDataTestsId("instantiation-status-title").click();
81     cy.get('#' + jobId).find('.menu-div').click();
82   }
83
84   it('should disabled correct menu items', function () {
85
86     cy.openIframe('app/ui/#/instantiationStatus');
87
88     // Instantiate action with Job status FAILED - isRetry = true
89
90     clickOnTitleAndThenOnMenuWithJobId('5c2cd8e5-27d0-42e3-85a1-85db5eaba459');
91     getDisabledDropDownItemByDataTestId('context-menu-retry').should('not.exist');
92     getDisabledDropDownItemByDataTestId('context-menu-remove').should('exist');
93     getDisabledDropDownItemByDataTestId('context-menu-open').should('exist');
94     getDisabledDropDownItemByDataTestId('context-menu-hide').should('not.exist');
95     getDisabledDropDownItemByDataTestId('context-menu-audit-info').should('not.exist');
96     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('not.exist');
97
98     // Instantiate action with Job status FAILED - isRetry = false
99     clickOnTitleAndThenOnMenuWithJobId('e1db03c3-6274-4ff7-84cf-7bd3a3946de7');
100     getDisabledDropDownItemByDataTestId('context-menu-retry').should('not.be.visible');
101     getDisabledDropDownItemByDataTestId('context-menu-open').should('exist');
102     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('not.exist');
103
104     //Delete action with Job status IN_PROGRESS
105     clickOnTitleAndThenOnMenuWithJobId('850dc7d2-5240-437f-9bcd-b1ed7dc339c2');
106     getDisabledDropDownItemByDataTestId('context-menu-remove').should('exist');
107     getDisabledDropDownItemByDataTestId('context-menu-open').should('exist');
108     getDisabledDropDownItemByDataTestId('context-menu-hide').should('exist');
109     getDisabledDropDownItemByDataTestId('context-menu-audit-info').should('not.exist');
110     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('exist');
111
112     //Update action with Job status COMPLETED
113     clickOnTitleAndThenOnMenuWithJobId('850dc7d2-5240-437f-9bcd-b1ed7dc339c1');
114     getDisabledDropDownItemByDataTestId('context-menu-remove').should('exist');
115     getDisabledDropDownItemByDataTestId('context-menu-open').should('not.exist');
116     getDisabledDropDownItemByDataTestId('context-menu-hide').should('not.exist');
117     getDisabledDropDownItemByDataTestId('context-menu-audit-info').should('not.exist');
118     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('exist');
119   });
120
121   it('clicking on create another one item, go to expected url', function () {
122     //see cypress/support/jsonBuilders/mocks/jsons/asyncInstantiation.json id:8
123     const jobId = '5c2cd8e5-27d0-42e3-85a1-85db5eaba459';
124     const serviceModelId = 'e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0';
125     const vidBaseUrl = `${Cypress.config().baseUrl}/serviceModels.htm`;
126
127     cy.openIframe('app/ui/#/instantiationStatus');
128
129     clickOnTitleAndThenOnMenuWithJobId(jobId);
130     cy.get('.dropdown-menu').getElementByDataTestsId(contextMenuCreateAnotherOne).contains('Create another one');
131     cy.get('.dropdown-menu').getElementByDataTestsId(contextMenuCreateAnotherOne).click();
132     cy.location().should((loc) => {
133       expect(loc.toString()).to.eq(`${vidBaseUrl}#/servicePlanning/RECREATE?serviceModelId=${serviceModelId}&jobId=${jobId}`);
134     });
135   });
136
137   it('clicking on new view edit, go to expected url', function () {
138     //see cypress/support/jsonBuilders/mocks/jsons/asyncInstantiation.json id:10
139     const jobId = '850dc7d2-5240-437f-9bcd-b1ed7dc339c1';
140     const serviceModelId = 'e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0';
141     const vidBaseUrl = `${Cypress.config().baseUrl}/serviceModels.htm`;
142     const serviceType = 'TYLER%20SILVIA';
143
144     cy.openIframe('app/ui/#/instantiationStatus');
145     clickOnTitleAndThenOnMenuWithJobId(jobId);
146     cy.get('.dropdown-menu').getElementByDataTestsId(contextMenuNewViewEdit).contains('New View/Edit');
147     cy.get('.dropdown-menu').getElementByDataTestsId(contextMenuNewViewEdit).click();
148     cy.location().should((location) => {
149       expect(location.toString()).to.eq(`${vidBaseUrl}#/servicePlanning/EDIT?serviceModelId=${serviceModelId}&serviceType=${serviceType}&jobId=${jobId}`);
150     });
151   });
152 });