summaryrefslogtreecommitdiffstats
path: root/public/cypress/support/generalCommands.ts
blob: 35d2fa79c73525dae28ca19ff5ca5c51100f19e0 (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
declare namespace Cypress {
  interface Chainable {
    httpGetDDLData: typeof httpGetDDLData;
    fillNewMcForm: typeof fillNewMcForm;
    httpCreateNewMc: typeof httpCreateNewMc;
    httpCreateNewMcWithBooleanDDL: typeof httpCreateNewMcWithBooleanDDL;
  }
}

function httpGetDDLData(): void {
  cy
    .server()
    .route({
      method: 'GET',
      url:
        Cypress.env('backendUrl') +
        '/service/06c7d927-4e2f-47e1-a29d-b6ed229ebc0a',
      response: 'fixture:serviceDdl'
    })
    .as('vfniListApi')
    .route({
      method: 'GET',
      url:
        Cypress.env('backendUrl') + '/getResourcesByMonitoringTemplateCategory',
      response: [{ name: 'AviStone1234' }]
    })
    .as('templateAPi');
}

function fillNewMcForm() {
  cy.get('input[data-tests-id="nameMc"]').type('new mc');
  cy.get('textarea[data-tests-id="descMc"]').type('Hello Description');
  cy.get('select[data-tests-id="templateDdl"]').select('AviStone1234');
  cy.get('select[data-tests-id="vfniDdl"]').select('LiavSrv');
}

function httpCreateNewMc() {
  cy.server();
  cy
    .route({
      method: 'POST',
      url: Cypress.env('backendUrl') + '/createMC',
      response: 'fixture:createMcRes'
    })
    .as('newMC');
}

function httpCreateNewMcWithBooleanDDL() {
  cy.server();
  cy
    .route({
      method: 'POST',
      url: Cypress.env('backendUrl') + '/createMC',
      response: 'fixture:createMcResWithBooleanDDL'
    })
    .as('newMCWithBooleanDDL');
}

// Add cypress commands
Cypress.Commands.add('httpGetDDLData', httpGetDDLData);
Cypress.Commands.add('fillNewMcForm', fillNewMcForm);
Cypress.Commands.add('httpCreateNewMc', httpCreateNewMc);
Cypress.Commands.add(
  'httpCreateNewMcWithBooleanDDL',
  httpCreateNewMcWithBooleanDDL
);