blob: c054b264028884a8f0849c202557509d0220247c [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001declare namespace Cypress {
2 interface Chainable {
3 setReduxState : typeof setReduxState;
Ittay Stern6f900cc2018-08-29 17:01:32 +03004 getReduxState : typeof getReduxState;
Ittay Stern32dbf802019-10-29 12:58:49 +02005 clearSessionStorage: typeof clearSessionStorage;
Ittay Stern6f900cc2018-08-29 17:01:32 +03006 setTestApiParamToGR: typeof setTestApiParamToGR;
7 setTestApiParamToVNF: typeof setTestApiParamToVNF;
8 buildReduxStateWithServiceRespone: typeof buildReduxStateWithServiceRespone;
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03009 }
10}
11
12/**********************************
13 Type to input with id some text
14 *********************************/
15function setReduxState(state?: string) : void {
Ittay Stern607ea3d2019-10-23 17:10:52 +030016 cy.readFile('cypress/support/jsonBuilders/mocks/jsons/basicRedux.json').then((res) => {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030017 cy.window().then((win) => {
18 win.sessionStorage.setItem('reduxState', JSON.stringify(state ? state : res));
19 });
20 });
21}
Ittay Stern6f900cc2018-08-29 17:01:32 +030022function getReduxState(): Chainable<any> {
23 return cy.window().then((win) => {
24 let stateRaw = win.sessionStorage.getItem('reduxState');
25 return JSON.parse(stateRaw ? stateRaw : '{}');
26 });
27}
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030028
Ittay Stern32dbf802019-10-29 12:58:49 +020029function clearSessionStorage() : void {
30 cy.window().then((win) => {
31 win.sessionStorage.clear();
32 });
33}
34
Ittay Stern6f900cc2018-08-29 17:01:32 +030035function setTestApiParamToGR() : void {
36 cy.window().then((win) => {
37 win.sessionStorage.setItem('msoRequestParametersTestApiValue', 'GR_API');
38 });
39}
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030040
Ittay Stern6f900cc2018-08-29 17:01:32 +030041function setTestApiParamToVNF() : void {
42 cy.window().then((win) => {
43 win.sessionStorage.setItem('msoRequestParametersTestApiValue', 'VNF_API');
44 });
45}
46
47function updateObject(obj: any, key: string, val: any, value:any) {
48 return JSON.parse(JSON.stringify(obj)
49 .replace(new RegExp(`"${key}":"${val}"`), `"${key}":"${value}"`))
50}
51
52function buildReduxStateWithServiceRespone(res: any, serviceId:string, isEcompGeneratedNaming:boolean) :void {
53 res = updateObject(res, "ecomp_generated_naming", !isEcompGeneratedNaming, isEcompGeneratedNaming);
54 cy.window().then((win) => {
55 win.sessionStorage.setItem('reduxState', JSON.stringify({
56 "global": {
57 "name": null
58 },
59 "service": {
60 "serviceHierarchy": {
61 [serviceId] : res
62 },
63 "serviceInstance": {
64 [serviceId]: {
65 "existingVNFCounterMap": {},
66 "existingVnfGroupCounterMap": {},
67 "existingNetworksCounterMap": {},
68 "vnfs": {},
69 "vnfGroups": {},
70 "isEcompGeneratedNaming": isEcompGeneratedNaming,
Ittay Sternf7926712019-07-07 19:23:03 +030071 "existingNames": {},
72 "vidNotions": res.service.vidNotions
Ittay Stern6f900cc2018-08-29 17:01:32 +030073 }
74 }
75 }
76 }));
77 });
78}
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030079
80Cypress.Commands.add('setReduxState', setReduxState);
Ittay Stern6f900cc2018-08-29 17:01:32 +030081Cypress.Commands.add('getReduxState', getReduxState);
Ittay Stern32dbf802019-10-29 12:58:49 +020082Cypress.Commands.add('clearSessionStorage', clearSessionStorage);
Ittay Stern6f900cc2018-08-29 17:01:32 +030083Cypress.Commands.add('setTestApiParamToGR', setTestApiParamToGR);
84Cypress.Commands.add('setTestApiParamToVNF',setTestApiParamToVNF);
85Cypress.Commands.add('buildReduxStateWithServiceRespone', buildReduxStateWithServiceRespone);