Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | declare namespace Cypress { |
| 2 | interface Chainable { |
| 3 | setReduxState : typeof setReduxState; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 4 | getReduxState : typeof getReduxState; |
| 5 | setTestApiParamToGR: typeof setTestApiParamToGR; |
| 6 | setTestApiParamToVNF: typeof setTestApiParamToVNF; |
| 7 | buildReduxStateWithServiceRespone: typeof buildReduxStateWithServiceRespone; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 8 | } |
| 9 | } |
| 10 | |
| 11 | /********************************** |
| 12 | Type to input with id some text |
| 13 | *********************************/ |
| 14 | function setReduxState(state?: string) : void { |
| 15 | cy.readFile('/cypress/support/jsonBuilders/mocks/jsons/basicRedux.json').then((res) => { |
| 16 | cy.window().then((win) => { |
| 17 | win.sessionStorage.setItem('reduxState', JSON.stringify(state ? state : res)); |
| 18 | }); |
| 19 | }); |
| 20 | } |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 21 | function getReduxState(): Chainable<any> { |
| 22 | return cy.window().then((win) => { |
| 23 | let stateRaw = win.sessionStorage.getItem('reduxState'); |
| 24 | return JSON.parse(stateRaw ? stateRaw : '{}'); |
| 25 | }); |
| 26 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 27 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 28 | function setTestApiParamToGR() : void { |
| 29 | cy.window().then((win) => { |
| 30 | win.sessionStorage.setItem('msoRequestParametersTestApiValue', 'GR_API'); |
| 31 | }); |
| 32 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 33 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 34 | function setTestApiParamToVNF() : void { |
| 35 | cy.window().then((win) => { |
| 36 | win.sessionStorage.setItem('msoRequestParametersTestApiValue', 'VNF_API'); |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | function updateObject(obj: any, key: string, val: any, value:any) { |
| 41 | return JSON.parse(JSON.stringify(obj) |
| 42 | .replace(new RegExp(`"${key}":"${val}"`), `"${key}":"${value}"`)) |
| 43 | } |
| 44 | |
| 45 | function buildReduxStateWithServiceRespone(res: any, serviceId:string, isEcompGeneratedNaming:boolean) :void { |
| 46 | res = updateObject(res, "ecomp_generated_naming", !isEcompGeneratedNaming, isEcompGeneratedNaming); |
| 47 | cy.window().then((win) => { |
| 48 | win.sessionStorage.setItem('reduxState', JSON.stringify({ |
| 49 | "global": { |
| 50 | "name": null |
| 51 | }, |
| 52 | "service": { |
| 53 | "serviceHierarchy": { |
| 54 | [serviceId] : res |
| 55 | }, |
| 56 | "serviceInstance": { |
| 57 | [serviceId]: { |
| 58 | "existingVNFCounterMap": {}, |
| 59 | "existingVnfGroupCounterMap": {}, |
| 60 | "existingNetworksCounterMap": {}, |
| 61 | "vnfs": {}, |
| 62 | "vnfGroups": {}, |
| 63 | "isEcompGeneratedNaming": isEcompGeneratedNaming, |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 64 | "existingNames": {}, |
| 65 | "vidNotions": res.service.vidNotions |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | } |
| 69 | })); |
| 70 | }); |
| 71 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 72 | |
| 73 | Cypress.Commands.add('setReduxState', setReduxState); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 74 | Cypress.Commands.add('getReduxState', getReduxState); |
| 75 | Cypress.Commands.add('setTestApiParamToGR', setTestApiParamToGR); |
| 76 | Cypress.Commands.add('setTestApiParamToVNF',setTestApiParamToVNF); |
| 77 | Cypress.Commands.add('buildReduxStateWithServiceRespone', buildReduxStateWithServiceRespone); |