aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/cypress/support/application/application.session.actions.ts
blob: 9126ae1a45ad7c37ded8306c9526ed0d99d3cdba (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
declare namespace Cypress {
  interface Chainable {
    setReduxState : typeof setReduxState;
    getReduxState : typeof getReduxState;
    clearSessionStorage: typeof clearSessionStorage;
    setTestApiParamToGR: typeof setTestApiParamToGR;
    setTestApiParamToVNF: typeof setTestApiParamToVNF;
  }
}

/**********************************
 Type to input with id some text
 *********************************/
function setReduxState(state?: string) : void {
  cy.readFile('cypress/support/jsonBuilders/mocks/jsons/basicRedux.json').then((res) => {
    cy.window().then((win) => {
      win.sessionStorage.setItem('reduxState',  JSON.stringify(state ? state : res));
    });
  });
}
function getReduxState(): Chainable<any> {
  return cy.window().then((win) => {
    let stateRaw = win.sessionStorage.getItem('reduxState');
    return JSON.parse(stateRaw ?  stateRaw : '{}');
  });
}

function clearSessionStorage() : void {
  cy.window().then((win) => {
    win.sessionStorage.clear();
  });
}

function setTestApiParamToGR() : void {
  cy.window().then((win) => {
    win.sessionStorage.setItem('msoRequestParametersTestApiValue', 'GR_API');
  });
}

function setTestApiParamToVNF() : void {
  cy.window().then((win) => {
    win.sessionStorage.setItem('msoRequestParametersTestApiValue', 'VNF_API');
  });
}

Cypress.Commands.add('setReduxState', setReduxState);
Cypress.Commands.add('getReduxState', getReduxState);
Cypress.Commands.add('clearSessionStorage', clearSessionStorage);
Cypress.Commands.add('setTestApiParamToGR', setTestApiParamToGR);
Cypress.Commands.add('setTestApiParamToVNF',setTestApiParamToVNF);