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; |
Ittay Stern | 32dbf80 | 2019-10-29 12:58:49 +0200 | [diff] [blame] | 5 | clearSessionStorage: typeof clearSessionStorage; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 6 | setTestApiParamToGR: typeof setTestApiParamToGR; |
| 7 | setTestApiParamToVNF: typeof setTestApiParamToVNF; |
| 8 | buildReduxStateWithServiceRespone: typeof buildReduxStateWithServiceRespone; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 9 | } |
| 10 | } |
| 11 | |
| 12 | /********************************** |
| 13 | Type to input with id some text |
| 14 | *********************************/ |
| 15 | function setReduxState(state?: string) : void { |
Ittay Stern | 607ea3d | 2019-10-23 17:10:52 +0300 | [diff] [blame] | 16 | cy.readFile('cypress/support/jsonBuilders/mocks/jsons/basicRedux.json').then((res) => { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 17 | cy.window().then((win) => { |
| 18 | win.sessionStorage.setItem('reduxState', JSON.stringify(state ? state : res)); |
| 19 | }); |
| 20 | }); |
| 21 | } |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 22 | function 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) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 28 | |
Ittay Stern | 32dbf80 | 2019-10-29 12:58:49 +0200 | [diff] [blame] | 29 | function clearSessionStorage() : void { |
| 30 | cy.window().then((win) => { |
| 31 | win.sessionStorage.clear(); |
| 32 | }); |
| 33 | } |
| 34 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 35 | function setTestApiParamToGR() : void { |
| 36 | cy.window().then((win) => { |
| 37 | win.sessionStorage.setItem('msoRequestParametersTestApiValue', 'GR_API'); |
| 38 | }); |
| 39 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 40 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 41 | function setTestApiParamToVNF() : void { |
| 42 | cy.window().then((win) => { |
| 43 | win.sessionStorage.setItem('msoRequestParametersTestApiValue', 'VNF_API'); |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | function 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 | |
| 52 | function 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 Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 71 | "existingNames": {}, |
| 72 | "vidNotions": res.service.vidNotions |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | } |
| 76 | })); |
| 77 | }); |
| 78 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 79 | |
| 80 | Cypress.Commands.add('setReduxState', setReduxState); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 81 | Cypress.Commands.add('getReduxState', getReduxState); |
Ittay Stern | 32dbf80 | 2019-10-29 12:58:49 +0200 | [diff] [blame] | 82 | Cypress.Commands.add('clearSessionStorage', clearSessionStorage); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 83 | Cypress.Commands.add('setTestApiParamToGR', setTestApiParamToGR); |
| 84 | Cypress.Commands.add('setTestApiParamToVNF',setTestApiParamToVNF); |
| 85 | Cypress.Commands.add('buildReduxStateWithServiceRespone', buildReduxStateWithServiceRespone); |