summaryrefslogtreecommitdiffstats
path: root/public/cypress/integration/mocks/ruleEngine-spec.ts
blob: 9a75b878aa1832f8238df90dc2ab5ba68ea0cdc1 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
export const mappingTragetDDL = () => {
  return cy.get('select[data-tests-id="mappingDdl"]');
};

export const selectVersionAndTypeAndAddFirstRule = () => {
  return cy
    .get('select[data-tests-id="selectVersion"]')
    .select('4.1')
    .get('select[data-tests-id="selectEventType"]')
    .select('syslog')
    .get('button[data-tests-id="btnAddFirstRule"]')
    .click();
};

export const fillRuleDecription = text => {
  return cy
    .get('input[data-tests-id="inputDescription"]')
    .clear()
    .type(text);
};

export const addCopyAction = () => {
  return cy
    .get('select[data-tests-id="selectAction"]')
    .select('copy')
    .get('button[data-tests-id="btnAddAction"]')
    .click()
    .get('input[data-tests-id="valueInput"]')
    .type('A')
    .get('span[data-tests-id="openTargetTree"]')
    .click()
    .get('.bottom-select')
    .should('be.visible')
    .find('.toggle-children')
    .first()
    .click()
    .get('span[data-tests-id="targetNode"]')
    .should(node => {
      expect(node.eq(0)).to.contain('commonEventHeader');
      expect(node.eq(1)).to.contain('domain');
    })
    .each(($el, index) => {
      if (index === 1) {
        cy.wrap($el).click();
      }
    });
};

export const editFirstRule = () => {
  return cy
    .get('div[data-tests-id="ruleElement"]')
    .first()
    .trigger('mouseover')
    .get('button[data-tests-id="editRule"]')
    .should('be.visible')
    .click();
};

export const translateValue = () => {
  return '{"processing":[{"phase":"snmp_map","processors":[{"array":"varbinds","datacolumn":"varbind_value","keycolumn":"varbind_oid","class":"SnmpConvertor"},{"phase":"sto2","class":"RunPhase"}]},{"phase":"sto2","processors":[{"updates":{"event.commonEventHeader.domain":"a"},"class":"Set"}]},{"phase":"sto2","processors":[{"phase":"map_publish","class":"RunPhase"}]}]}';
};

describe('Rule engine - E2E test flow with mock', () => {
  describe('Mapping target select', () => {
    beforeEach(() => {
      cy.httpGetDDLData();
      cy.getMCListEmpty();
      cy.homePage();
      cy.get('button[data-tests-id="btn-create-mc"]').click();
      cy.fillNewMcForm();
      cy.httpCreateNewMc();
      cy.emptyRuleEngine('Type1');
      cy.get('button[data-tests-id="createMonitoring"]').click();
      cy
        .get('#ui-tabpanel-1-label')
        .should('contain', 'map')
        .click();
    });

    it('should exist and contain options', () => {
      mappingTragetDDL()
        .should('be.visible')
        .contains('json');
    });

    it('should page refrash after change select value in mapping target ddl', () => {
      cy.httpTargetTree();
      cy
        .get('select[data-tests-id="selectVersion"]')
        .select('4.1')
        .get('select[data-tests-id="selectEventType"]')
        .select('syslog')
        .get('button[data-tests-id="btnAddFirstRule"]')
        .should('be.visible');
      cy.emptyRuleEngine('json');
      mappingTragetDDL()
        .select('json')
        .get('select[data-tests-id="selectVersion"]')
        .should('have.value', null);
    });
  });

  describe('Translate And Save Rule List', () => {
    beforeEach(() => {
      cy.httpGetDDLData();
      cy.getMCListEmpty();
      cy.homePage();
      cy.get('button[data-tests-id="btn-create-mc"]').click();
      cy.fillNewMcForm();
      cy.httpCreateNewMc();
      cy.emptyRuleEngine('Type1');
      cy
        .get('button[data-tests-id="createMonitoring"]')
        .click()
        .get('#ui-tabpanel-1-label')
        .should('contain', 'map')
        .click();
      cy.httpTargetTree();
      selectVersionAndTypeAndAddFirstRule();
      fillRuleDecription('newRule');
      addCopyAction();
      cy.doneSaveRule();
    });

    context('Play with save, back and done button', () => {
      it('should rule exist in list after save rule and click back', () => {
        cy
          .get('button[data-tests-id="btnSave"]')
          .click()
          .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('newRule');
          });
      });

      it('should rule exist in list after done edit rule', () => {
        cy
          .get('button[data-tests-id="btnDone"]')
          .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('newRule');
          });
      });
    });

    context('Translate', () => {
      it('should open advanced setting when translate successfuly', () => {
        cy.get('button[data-tests-id="btnDone"]').click();
        cy.httpTransalte();
        cy
          .get('button[data-tests-id="btnTranslate"]')
          .click()
          .get('.toast-container')
          .should('be.visible')
          .get('.map-setting-list > #Type1 > input')
          .should('be.visible')
          .and('have.value', translateValue());
      });
    });
  });
});