summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/cypress/support/steps/drawingBoard/general.steps.ts
blob: 797fff095a3da0114c75afa9d71a1d509b1d32bc (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
declare namespace Cypress {
  interface Chainable {
    updateServiceShouldNotOverrideChild: typeof updateServiceShouldNotOverrideChild
    openServiceContextMenu: typeof openServiceContextMenu,
    drawingBoardTreeClickOnContextMenuOptionByName : typeof  drawingBoardTreeClickOnContextMenuOptionByName,
    nodeAction: typeof nodeAction,
    editNode : typeof editNode
  }
}

function updateServiceShouldNotOverrideChild() : void  {
    cy.getElementByDataTestsId('drawing-board-tree').find('.node-content-wrapper').then((elements)=>{
      let numberOfExistingElements = elements.length;
        cy.openServiceContextMenu().then(() =>{
          cy.getElementByDataTestsId('context-menu-header-edit-item').click({force : true}).then(()=>{
            cy.genericFormSubmitForm().then(()=>{
              cy.getElementByDataTestsId('drawing-board-tree').find('.node-content-wrapper').then((afterUpdateServiceElements)=>{
                chai.expect(numberOfExistingElements).equal(afterUpdateServiceElements.length);
              });
            });
          });
        });
    });
}


function openServiceContextMenu() :  Chainable<any> {
 return cy.getElementByDataTestsId('openMenuBtn').click({force: true});
}

function nodeAction(dataTestId: string, action: string, index ?: number) {
  return cy.drawingBoardTreeOpenContextMenuByElementDataTestId(dataTestId, index)
    .drawingBoardTreeClickOnContextMenuOptionByName(action)
}

function drawingBoardTreeClickOnContextMenuOptionByName(optionName : string) : Chainable<any>  {
  switch (optionName) {
    case 'Duplicate':
      return cy.getElementByDataTestsId('context-menu-duplicate').click({force : true});
    case 'Remove':
      return cy.getElementByDataTestsId('context-menu-remove').click({force : true});
    case 'Edit':
      return cy.getElementByDataTestsId('context-menu-edit').click({force : true});
    case 'Delete':
      return cy.getElementByDataTestsId('context-menu-delete').trigger('mouseover').click();
    case 'Upgrade':
      return cy.getElementByDataTestsId('context-menu-upgrade').trigger('mouseover').click();
    case 'Undo Upgrade':
      return cy.getElementByDataTestsId('context-menu-undoUpgrade').trigger('mouseover').click();
    default:
      return cy.getElementByDataTestsId('context-menu-duplicate').click({force : true});
  }
}

function editNode(dataTestId: string, index ?: number) {
  return cy.nodeAction(dataTestId, 'Edit', index);
}

Cypress.Commands.add('updateServiceShouldNotOverrideChild', updateServiceShouldNotOverrideChild);
Cypress.Commands.add('openServiceContextMenu', openServiceContextMenu);
Cypress.Commands.add('drawingBoardTreeClickOnContextMenuOptionByName', drawingBoardTreeClickOnContextMenuOptionByName);
Cypress.Commands.add('nodeAction', nodeAction);
Cypress.Commands.add('editNode', editNode);