summaryrefslogtreecommitdiffstats
path: root/public/cypress/integration/e2e/e2eWithIntegration-spec.ts
blob: 459a7de898dc1bc7f3b4e3eef91f9b7c6cbb0327 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const randomNodeName = () =>
  Math.random()
    .toString(36)
    .substr(2, 7);
const NODE_NAME = randomNodeName();

const serverGetDDLData = () => {
  return cy
    .server()
    .route(
      'GET',
      Cypress.env('backendUrl') + '/getResourcesByMonitoringTemplateCategory'
    )
    .as('templateAPi')
    .route(
      'GET',
      Cypress.env('backendUrl') +
        '/service/06c7d927-4e2f-47e1-a29d-b6ed229ebc0a'
    )
    .as('vfniListAPi');
};

const saveAndDoneHttp = () => {
  cy.server();
  cy
    .route({
      method: 'POST',
      url: Cypress.env('backendUrl') + '/rule-editor/rule/**/**/**/**'
    })
    .as('doneSaveCopyRule');
};

const createNewMC = () => {
  cy
    .get('input[data-tests-id="nameMc"]')
    .type(`Hello${NODE_NAME}`)
    .get('textarea[data-tests-id="descMc"]')
    .type('Hello Description')
    .get('select[data-tests-id="templateDdl"]')
    .then($els => {
      const opt = $els.find('option');
      const first = opt.get(1) as any;
      return $els.val(first.value);
    })
    .trigger('change')
    .get('select[data-tests-id="vfniDdl"]')
    .then($els => {
      const opt = $els.find('option');
      const first = opt.get(1) as any;
      return $els.val(first.value);
    })
    .trigger('change')
    .get('button[data-tests-id="createMonitoring"]')
    .not('[disabled]')
    .should('not.contain', 'Disabled');
  cy
    .server()
    .route({
      method: 'POST',
      url: Cypress.env('backendUrl') + '/createMC'
    })
    .as('newMC')
    .get('button[data-tests-id="createMonitoring"]')
    .click()
    .wait('@newMC');
};

import { buttonCreateMC } from '../mocks/homePage-spec';
import {
  selectVersionAndTypeAndAddFirstRule,
  fillRuleDecription,
  addCopyAction,
  editFirstRule
} from '../mocks/ruleEngine-spec';

describe('DCAED - forntend e2e and inagration test', () => {
  context('Empty Monitoring Configuration list for service', () => {
    it('Loads', () => {
      cy.homePage();
    });
  });

  context('Create new monitoring configuration', () => {
    beforeEach(() => {
      serverGetDDLData();
      cy.homePage();
      buttonCreateMC()
        .click()
        .wait(['@templateAPi', '@vfniListAPi']);
    });

    it('After api call success verify create button is disabled', () => {
      cy
        .get('button[data-tests-id="createMonitoring"]')
        .should('be.visible')
        .and('be.disabled');
    });

    it('click on create mc - more then one tab should be visible', () => {
      createNewMC();
      cy
        .get('ul[p-tabviewnav]')
        .children()
        .should($el => {
          expect($el.length).to.be.greaterThan(1);
        });
    });

    it('should enter rule engine in map tab and create new rule', () => {
      createNewMC();
      cy
        .get('#ui-tabpanel-1-label')
        .should('contain', 'map')
        .click();
      selectVersionAndTypeAndAddFirstRule();
      fillRuleDecription('newRule');
      addCopyAction();
      saveAndDoneHttp();
      cy.get('button[data-tests-id="btnDone"]').click();
      cy
        .wait('@doneSaveCopyRule')
        .get('div[data-tests-id="ruleElement"]')
        .should('be.visible')
        .then(function($lis) {
          expect($lis).to.have.length(1);
          expect($lis.eq(0)).to.contain('newRule');
        });
      editFirstRule();
      fillRuleDecription('LiavRule');
      saveAndDoneHttp();
      cy
        .get('button[data-tests-id="btnSave"]')
        .click()
        .wait('@doneSaveCopyRule')
        .get('a[data-tests-id="btnBackRule"]')
        .click()
        .get('div[data-tests-id="ruleElement"]')
        .should('be.visible')
        .then(function($lis) {
          expect($lis).to.have.length(1);
          expect($lis.eq(0)).to.contain('LiavRule');
        });
    });
  });
});