add create another one menu item to instantiationStatus 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-recreate';
11
12   beforeEach(() => {
13       cy.clearSessionStorage();
14       cy.setReduxState();
15       cy.preventErrorsOnLoading();
16       cy.initAAIMock();
17       cy.initVidMock();
18       jsonBuilderInstantiationBuilder.basicMock('cypress/support/jsonBuilders/mocks/jsons/asyncInstantiation.json',
19         Cypress.config('baseUrl') + "/asyncInstantiation**",
20         (res: any) => {
21             asyncRes = res;
22             return res;
23       });
24       cy.login();
25   });
26
27   afterEach(() => {
28     cy.screenshot();
29   });
30
31   it('should display the correct icons per status', function () {
32       const serviceAction:any = {INSTANTIATE : 'Instantiate', DELETE: 'Delete', UPDATE: 'Update', UPGRADE: 'Upgrade'};
33       cy.openIframe('app/ui/#/instantiationStatus');
34       for(let i = 0 ; i < asyncRes.length; i++){
35         if(asyncRes[i].project){
36           cy.getTableRowByIndex('instantiation-status', i).get('td#project span').contains(asyncRes[i].project);
37         }
38         if(asyncRes[i].userId){
39           cy.getTableRowByIndex('instantiation-status', i).get('td#userId span').contains(asyncRes[i].userId);
40         }
41         if(asyncRes[i].tenantName){
42           cy.getTableRowByIndex('instantiation-status', i).get('td#tenantName span').contains(asyncRes[i].tenantName);
43         }
44         if(asyncRes[i].serviceModelName){
45           cy.getTableRowByIndex('instantiation-status', i).get('td#serviceModelName span').contains(asyncRes[i].serviceModelName);
46         }
47         if(asyncRes[i].serviceInstanceName){
48           cy.getTableRowByIndex('instantiation-status', i).get('td#serviceInstanceName span').contains(asyncRes[i].serviceInstanceName);
49         }
50         if(asyncRes[i].serviceModelVersion){
51           cy.getTableRowByIndex('instantiation-status', i).get('td#serviceModelVersion span').contains(asyncRes[i].serviceModelVersion);
52         }
53         if(asyncRes[i].subscriberName){
54           cy.getTableRowByIndex('instantiation-status', i).get('td#subscriberName span').contains(asyncRes[i].subscriberName);
55         }
56         if(asyncRes[i].action) {
57           cy.getTableRowByIndex('instantiation-status', i).get('td#action span').contains(serviceAction[asyncRes[i].action]);
58         }
59     }
60   });
61
62   it('should filter rows by filter text', function () {
63     cy.openIframe('app/ui/#/instantiationStatus');
64     cy.getElementByDataTestsId("instantiationStatusFilter").type("ComplexService");
65     cy.get('table#instantiation-status tbody tr').should('have.length', 2);
66   });
67
68   it('should filter rows by url filter text', function () {
69     cy.openIframe('app/ui/#/instantiationStatus?filterText=ComplexService');
70     cy.getElementByDataTestsId("instantiationStatusFilter").should('have.value','ComplexService');
71     cy.get('table#instantiation-status tbody tr').should('have.length', 2);
72   });
73
74   function getDisabledDropDownItemByDataTestId(testId:String) {
75     return cy.get('.dropdown-menu').find('.disabled').find(`[data-tests-id='${testId}']`);
76   }
77
78   function clickOnTitleAndThenOnMenuWithJobId(jobId: string) {
79     cy.getElementByDataTestsId("instantiation-status-title").click();
80     cy.get('#' + jobId).find('.menu-div').click();
81   }
82
83   it('should disabled correct menu items', function () {
84
85     cy.openIframe('app/ui/#/instantiationStatus');
86
87     // Instantiate action with Job status FAILED - isRetry = true
88
89     clickOnTitleAndThenOnMenuWithJobId('5c2cd8e5-27d0-42e3-85a1-85db5eaba459');
90     getDisabledDropDownItemByDataTestId('context-menu-retry').should('not.exist');
91     getDisabledDropDownItemByDataTestId('context-menu-remove').should('exist');
92     getDisabledDropDownItemByDataTestId('context-menu-open').should('exist');
93     getDisabledDropDownItemByDataTestId('context-menu-hide').should('not.exist');
94     getDisabledDropDownItemByDataTestId('context-menu-audit-info').should('not.exist');
95     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('not.exist');
96
97     // Instantiate action with Job status FAILED - isRetry = false
98     clickOnTitleAndThenOnMenuWithJobId('e1db03c3-6274-4ff7-84cf-7bd3a3946de7');
99     getDisabledDropDownItemByDataTestId('context-menu-retry').should('not.be.visible');
100     getDisabledDropDownItemByDataTestId('context-menu-open').should('exist');
101     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('not.exist');
102
103     //Delete action with Job status IN_PROGRESS
104     clickOnTitleAndThenOnMenuWithJobId('850dc7d2-5240-437f-9bcd-b1ed7dc339c2');
105     getDisabledDropDownItemByDataTestId('context-menu-remove').should('exist');
106     getDisabledDropDownItemByDataTestId('context-menu-open').should('exist');
107     getDisabledDropDownItemByDataTestId('context-menu-hide').should('exist');
108     getDisabledDropDownItemByDataTestId('context-menu-audit-info').should('not.exist');
109     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('exist');
110
111     //Update action with Job status COMPLETED
112     clickOnTitleAndThenOnMenuWithJobId('850dc7d2-5240-437f-9bcd-b1ed7dc339c1');
113     getDisabledDropDownItemByDataTestId('context-menu-remove').should('exist');
114     getDisabledDropDownItemByDataTestId('context-menu-open').should('not.exist');
115     getDisabledDropDownItemByDataTestId('context-menu-hide').should('not.exist');
116     getDisabledDropDownItemByDataTestId('context-menu-audit-info').should('not.exist');
117     getDisabledDropDownItemByDataTestId(contextMenuCreateAnotherOne).should('exist');
118   });
119
120   it('clicking on create another one item, go to expected url', function () {
121     //see cypress/support/jsonBuilders/mocks/jsons/asyncInstantiation.json id:8
122     const jobId = '5c2cd8e5-27d0-42e3-85a1-85db5eaba459';
123     const serviceModelId = 'e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0';
124     const vidBaseUrl = `http://localhost:8080/vid/serviceModels.htm`;
125
126     cy.openIframe('app/ui/#/instantiationStatus');
127
128     clickOnTitleAndThenOnMenuWithJobId(jobId);
129     cy.get('.dropdown-menu').getElementByDataTestsId(contextMenuCreateAnotherOne).click();
130     cy.location().should((loc) => {
131       expect(loc.toString()).to.eq(`${vidBaseUrl}#/servicePlanning/RECREATE?serviceModelId=${serviceModelId}&jobId=${jobId}`);
132     });
133   });
134
135 });