blob: 459a7de898dc1bc7f3b4e3eef91f9b7c6cbb0327 [file] [log] [blame]
Stone, Avi (as206k)9b2ceb32018-04-12 16:36:39 +03001const randomNodeName = () =>
2 Math.random()
3 .toString(36)
4 .substr(2, 7);
5const NODE_NAME = randomNodeName();
6
7const serverGetDDLData = () => {
8 return cy
9 .server()
10 .route(
11 'GET',
12 Cypress.env('backendUrl') + '/getResourcesByMonitoringTemplateCategory'
13 )
14 .as('templateAPi')
15 .route(
16 'GET',
17 Cypress.env('backendUrl') +
18 '/service/06c7d927-4e2f-47e1-a29d-b6ed229ebc0a'
19 )
20 .as('vfniListAPi');
21};
22
23const saveAndDoneHttp = () => {
24 cy.server();
25 cy
26 .route({
27 method: 'POST',
28 url: Cypress.env('backendUrl') + '/rule-editor/rule/**/**/**/**'
29 })
30 .as('doneSaveCopyRule');
31};
32
33const createNewMC = () => {
34 cy
35 .get('input[data-tests-id="nameMc"]')
36 .type(`Hello${NODE_NAME}`)
37 .get('textarea[data-tests-id="descMc"]')
38 .type('Hello Description')
39 .get('select[data-tests-id="templateDdl"]')
40 .then($els => {
41 const opt = $els.find('option');
42 const first = opt.get(1) as any;
43 return $els.val(first.value);
44 })
45 .trigger('change')
46 .get('select[data-tests-id="vfniDdl"]')
47 .then($els => {
48 const opt = $els.find('option');
49 const first = opt.get(1) as any;
50 return $els.val(first.value);
51 })
52 .trigger('change')
53 .get('button[data-tests-id="createMonitoring"]')
54 .not('[disabled]')
55 .should('not.contain', 'Disabled');
56 cy
57 .server()
58 .route({
59 method: 'POST',
60 url: Cypress.env('backendUrl') + '/createMC'
61 })
62 .as('newMC')
63 .get('button[data-tests-id="createMonitoring"]')
64 .click()
65 .wait('@newMC');
66};
67
68import { buttonCreateMC } from '../mocks/homePage-spec';
69import {
70 selectVersionAndTypeAndAddFirstRule,
71 fillRuleDecription,
72 addCopyAction,
73 editFirstRule
74} from '../mocks/ruleEngine-spec';
75
76describe('DCAED - forntend e2e and inagration test', () => {
77 context('Empty Monitoring Configuration list for service', () => {
78 it('Loads', () => {
79 cy.homePage();
80 });
81 });
82
83 context('Create new monitoring configuration', () => {
84 beforeEach(() => {
85 serverGetDDLData();
86 cy.homePage();
87 buttonCreateMC()
88 .click()
89 .wait(['@templateAPi', '@vfniListAPi']);
90 });
91
92 it('After api call success verify create button is disabled', () => {
93 cy
94 .get('button[data-tests-id="createMonitoring"]')
95 .should('be.visible')
96 .and('be.disabled');
97 });
98
99 it('click on create mc - more then one tab should be visible', () => {
100 createNewMC();
101 cy
102 .get('ul[p-tabviewnav]')
103 .children()
104 .should($el => {
105 expect($el.length).to.be.greaterThan(1);
106 });
107 });
108
109 it('should enter rule engine in map tab and create new rule', () => {
110 createNewMC();
111 cy
112 .get('#ui-tabpanel-1-label')
113 .should('contain', 'map')
114 .click();
115 selectVersionAndTypeAndAddFirstRule();
116 fillRuleDecription('newRule');
117 addCopyAction();
118 saveAndDoneHttp();
119 cy.get('button[data-tests-id="btnDone"]').click();
120 cy
121 .wait('@doneSaveCopyRule')
122 .get('div[data-tests-id="ruleElement"]')
123 .should('be.visible')
124 .then(function($lis) {
125 expect($lis).to.have.length(1);
126 expect($lis.eq(0)).to.contain('newRule');
127 });
128 editFirstRule();
129 fillRuleDecription('LiavRule');
130 saveAndDoneHttp();
131 cy
132 .get('button[data-tests-id="btnSave"]')
133 .click()
134 .wait('@doneSaveCopyRule')
135 .get('a[data-tests-id="btnBackRule"]')
136 .click()
137 .get('div[data-tests-id="ruleElement"]')
138 .should('be.visible')
139 .then(function($lis) {
140 expect($lis).to.have.length(1);
141 expect($lis.eq(0)).to.contain('LiavRule');
142 });
143 });
144 });
145});