stake.steps.ts
1 import { doCloseModal } from './main.steps'; 2 3 type SkipType = { 4 set: (val: boolean) => void; 5 get: () => boolean; 6 }; 7 8 /** 9 * This skip all test steps if previous one was failed 10 */ 11 const skipSetup = ({ skip, updateSkipStatus }: { skip: SkipType; updateSkipStatus: boolean }) => { 12 before(function () { 13 if (skip.get()) { 14 this.skip(); 15 } 16 }); 17 afterEach(function onAfterEach() { 18 if ((this.currentTest as Mocha.Test).state === 'failed' && updateSkipStatus) { 19 skip.set(true); 20 } 21 }); 22 }; 23 24 const waitStakedAmount = (assetName: string, checkAmount: string) => { 25 cy.get(`[data-cy="stakedBox_${assetName}"]`) 26 .find(`[data-cy="amountNative"]`) 27 .then(($amount) => { 28 cy.waitUntil(() => $amount.text() == checkAmount, { 29 errorMsg: "staked amount wasn't updated", 30 timeout: 70000, 31 interval: 500, 32 }); 33 }); 34 }; 35 36 export const stake = ( 37 { 38 asset, 39 amount, 40 checkAmount, 41 tabValue, 42 hasApproval, 43 changeApproval, 44 }: { 45 asset: { fullName: string; shortName: string; address: string }; 46 amount: number; 47 checkAmount: string; 48 tabValue: string; 49 hasApproval: boolean; 50 changeApproval: boolean; 51 }, 52 skip: SkipType, 53 updateSkipStatus = false 54 ) => { 55 const _shortName = asset.shortName; 56 const _actionName = 'Stake'; 57 58 return describe(`Stake ${_shortName}`, () => { 59 skipSetup({ skip, updateSkipStatus }); 60 it(`Open staking page`, () => { 61 if (asset.shortName === 'GHO') cy.wait(5000); 62 cy.get(`button[value="${tabValue}"]`).then(($clickable) => { 63 if ($clickable.prop('disabled')) return; 64 $clickable.click(); 65 }); 66 }); 67 it(`Open stake modal`, () => { 68 cy.get(`button[data-cy="stakeBtn_${asset.shortName}"]`).should('not.be.disabled').click(); 69 }); 70 it(`Set amount`, () => { 71 cy.setAmount(amount, false); 72 if (!hasApproval && changeApproval) { 73 cy.get('[data-cy=Modal]') 74 .find('[data-cy=approveButtonChange]') 75 .click() 76 .get('[data-cy=approveOption_Transaction]') 77 .click(); 78 } 79 cy.wait(2000); 80 cy.doConfirm(hasApproval, _actionName); 81 }); 82 doCloseModal(); 83 it(`Check staked amount`, () => { 84 waitStakedAmount(asset.shortName, checkAmount); 85 cy.get(`[data-cy="stakedBox_${asset.shortName}"]`) 86 .find(`[data-cy="amountNative"]`) 87 .should('have.text', checkAmount); 88 cy.get(`[data-cy="stakedBox_${asset.shortName}"]`) 89 .find(`[data-cy="amountUSD"]`) 90 .should('not.have.text', '$ 0'); 91 // skip while tenderly issue 92 // cy.get(`[data-cy="rewardBox_${asset.shortName}"]`) 93 // .find(`[data-cy="amountNative"]`) 94 // .should('not.have.text', '0'); 95 // cy.get(`[data-cy="rewardBox_${asset.shortName}"]`) 96 // .find(`[data-cy="amountUSD"]`) 97 // .should('not.have.text', ' $0'); 98 }); 99 }); 100 }; 101 102 export const claimReward = ( 103 { 104 asset, 105 }: { 106 asset: { fullName: string; shortName: string; address: string }; 107 }, 108 skip: SkipType, 109 updateSkipStatus = false 110 ) => { 111 const _shortName = asset.shortName; 112 const _actionName = `STAKE ${asset.shortName}`; 113 114 return describe(`Claim reward for ${_shortName}`, () => { 115 skipSetup({ skip, updateSkipStatus }); 116 it(`Open claim popup`, () => { 117 cy.get(`[data-cy="claimBtn_${asset.shortName}"]`).click(); 118 }); 119 it(`Confirm`, () => { 120 cy.wait(2000); 121 cy.get('[data-cy=Modal]').find('button:contains("Max")').click(); 122 cy.doConfirm(true, _actionName); 123 }); 124 doCloseModal(); 125 }); 126 }; 127 128 export const activateCooldown = ( 129 { 130 asset, 131 }: { 132 asset: { fullName: string; shortName: string; address: string }; 133 }, 134 skip: SkipType, 135 updateSkipStatus = false 136 ) => { 137 const _shortName = asset.shortName; 138 const _actionName = `Cooldown to unstake`; 139 140 return describe(`Activate cooldown ${_shortName}`, () => { 141 skipSetup({ skip, updateSkipStatus }); 142 it(`open activate cooldown`, () => { 143 cy.get(`[data-cy="coolDownBtn_${asset.shortName}"]`).click(); 144 }); 145 it(`Confirm`, () => { 146 cy.get(`[data-cy="cooldownAcceptCheckbox"]`).click(); 147 cy.doConfirm(true, _actionName); 148 }); 149 doCloseModal(); 150 it(`Check cooldown activation`, () => { 151 cy.get(`[data-cy="awaitCoolDownBtn_${asset.shortName}"]`, { 152 timeout: 70000, 153 }).should('be.visible', { timeout: 50000 }); 154 }); 155 }); 156 }; 157 158 export const reCallCooldown = ( 159 { 160 asset, 161 }: { 162 asset: { fullName: string; shortName: string; address: string }; 163 }, 164 skip: SkipType, 165 updateSkipStatus = false 166 ) => { 167 const _shortName = asset.shortName; 168 const _actionName = `Cooldown to unstake`; 169 170 return describe(`Stake ${_shortName}`, () => { 171 skipSetup({ skip, updateSkipStatus }); 172 it(`open reactivate cooldown`, () => { 173 cy.get(`[data-cy="reCoolDownBtn_${asset.shortName}"]`).click(); 174 }); 175 it(`Confirm`, () => { 176 cy.get(`[data-cy="cooldownAcceptCheckbox"]`).click(); 177 cy.doConfirm(true, _actionName); 178 }); 179 doCloseModal(); 180 it(`Check recooldown button is hidden`, () => { 181 cy.get(`[data-cy="reCoolDownBtn_${asset.shortName}"]`, { timeout: 70000 }).should( 182 'not.exist', 183 { timeout: 50000 } 184 ); 185 }); 186 }); 187 }; 188 189 export const reStake = ( 190 { 191 asset, 192 }: { 193 asset: { fullName: string; shortName: string; address: string }; 194 }, 195 skip: SkipType, 196 updateSkipStatus = false 197 ) => { 198 const _shortName = asset.shortName; 199 const _actionName = `STAKE ${asset.shortName}`; 200 201 return describe(` Re Stake ${_shortName}`, () => { 202 skipSetup({ skip, updateSkipStatus }); 203 it(`Open claim popup`, () => { 204 cy.get(`[data-cy="restakeBtn_${asset.shortName}"]`).click(); 205 }); 206 it(`Confirm`, () => { 207 cy.wait(2000); 208 cy.get('[data-cy=Modal]').find('button:contains("Max")').click(); 209 cy.doConfirm(true, _actionName); 210 }); 211 doCloseModal(); 212 }); 213 };