-
Notifications
You must be signed in to change notification settings - Fork 36
/
stakingPageAssert.ts
181 lines (156 loc) · 8.2 KB
/
stakingPageAssert.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import StakingPage from '../elements/staking/stakingPage';
import { TestnetPatterns } from '../support/patterns';
import webTester from '../actor/webTester';
import StakingInfoComponent from '../elements/staking/stakingInfoComponent';
import { t } from '../utils/translationService';
import { StakePoolListItem } from '../elements/staking/StakePoolListItem';
import StakingSuccessDrawer from '../elements/staking/StakingSuccessDrawer';
import { Logger } from '../support/logger';
import StakingExtendedPageObject from '../pageobject/stakingExtendedPageObject';
import { sortColumnContent } from '../utils/stakePoolListContent';
import { expect } from 'chai';
import { StakePool } from '../data/expectedStakePoolsData';
import StakingPasswordDrawer from '../elements/staking/StakingPasswordDrawer';
import StakingErrorDrawer from '../elements/staking/StakingErrorDrawer';
import { browser } from '@wdio/globals';
class StakingPageAssert {
assertStakePoolSwitched = async (stakePoolName: string) => {
await browser.waitUntil(async () => (await StakingInfoComponent.poolName.getText()) === stakePoolName, {
timeout: 180_000,
interval: 2000,
timeoutMsg: 'failed while waiting for stake Pool Switch'
});
};
assertSeeCurrentlyStakingComponent = async (
expectedStakePool: StakePool,
mode: 'extended' | 'popup',
noMetaDataPool = false
) => {
expect(await StakingInfoComponent.title.getText()).to.equal(await t('browserView.staking.stakingInfo.title'));
await StakingInfoComponent.poolLogo.waitForDisplayed();
expect(await StakingInfoComponent.poolName.getText()).to.equal(expectedStakePool.name);
noMetaDataPool
? expect(await StakingInfoComponent.poolTicker.getText()).to.contain(expectedStakePool.poolId.slice(0, 6))
: expect(await StakingInfoComponent.poolTicker.getText()).to.equal(expectedStakePool.ticker);
expect(await StakingInfoComponent.statsApy.title.getText()).to.equal(
await t('browserView.staking.stakingInfo.stats.ros')
);
expect(await StakingInfoComponent.statsApy.value.getText()).to.match(TestnetPatterns.PERCENT_DOUBLE_REGEX);
expect(await StakingInfoComponent.statsFee.title.getText()).to.equal(
await t('browserView.staking.stakingInfo.stats.Fee')
);
expect(await StakingInfoComponent.statsFee.value.getText()).to.match(TestnetPatterns.ADA_LITERAL_VALUE_REGEX);
expect(await StakingInfoComponent.statsMargin.title.getText()).to.equal(
await t('browserView.staking.stakingInfo.stats.Margin')
);
expect(await StakingInfoComponent.statsMargin.value.getText()).to.match(TestnetPatterns.PERCENT_DOUBLE_REGEX);
if (mode === 'extended') {
expect(await StakingInfoComponent.statsTotalRewards.title.getText()).to.equal(
await t('browserView.staking.stakingInfo.totalRewards.title')
);
expect(await StakingInfoComponent.statsTotalRewards.value.getText()).to.match(
TestnetPatterns.ADA_LITERAL_VALUE_REGEX_OR_0
);
}
expect(await StakingInfoComponent.statsTotalStaked.title.getText()).to.equal(
await t('browserView.staking.stakingInfo.totalStaked.title')
);
expect(await StakingInfoComponent.statsTotalStaked.value.getText()).to.match(
TestnetPatterns.ADA_LITERAL_VALUE_REGEX
);
expect(await StakingInfoComponent.statsLastReward.title.getText()).to.equal(
await t('browserView.staking.stakingInfo.lastReward.title')
);
expect(await StakingInfoComponent.statsLastReward.value.getText()).to.match(
TestnetPatterns.ADA_LITERAL_VALUE_REGEX
);
};
assertStakingSuccessDrawer = async (process: 'Initial' | 'Switching', mode: 'extended' | 'popup') => {
await StakingSuccessDrawer.drawerHeaderCloseButton.waitForDisplayed();
if (mode === 'extended') {
await StakingSuccessDrawer.drawerNavigationTitle.waitForDisplayed();
expect(await StakingSuccessDrawer.drawerNavigationTitle.getText()).to.equal(
await t('browserView.staking.details.titleSecond')
);
}
await StakingSuccessDrawer.resultIcon.waitForDisplayed();
await StakingSuccessDrawer.resultTitle.waitForDisplayed();
expect(await StakingSuccessDrawer.resultTitle.getText()).to.equal(
process === 'Initial'
? await t('browserView.staking.details.success.title')
: await t('browserView.staking.details.switchedPools.title')
);
await StakingSuccessDrawer.resultSubtitle.waitForDisplayed();
// TODO: uncomment when LW-4864 is resolved
// expect(await StakingSuccessDrawer.resultSubtitle.getText()).to.equal(
// process === 'Initial'
// ? await t('browserView.staking.details.success.subTitle')
// : await t('browserView.staking.details.switchedPools.subTitle')
// );
await StakingSuccessDrawer.closeButton.waitForDisplayed();
expect(await StakingSuccessDrawer.closeButton.getText()).to.equal(await t('general.button.close'));
};
assertSeeSingleSearchResult = async () => {
await browser.waitUntil(async () => (await StakingPage.counter.getText()) === '(1)', {
timeout: 20_000,
timeoutMsg: 'failed while waiting for single search result'
});
};
assertStakePoolItemsOrder = async (columnName: string, order: string) => {
const stakePoolListItem = new StakePoolListItem();
await webTester.waitUntilSeeElement(stakePoolListItem.container(), 60_000);
const columnContent: string[] = await StakingExtendedPageObject.extractColumnContent(columnName);
Logger.log(`EXTRACTED DATA: ${columnContent}`);
const sortedColumnContent = await sortColumnContent(columnContent, columnName, order);
Logger.log(`SORTED DATA: ${sortedColumnContent}`);
expect(columnContent).to.not.be.empty;
expect(columnContent).to.deep.equal(sortedColumnContent);
};
assertSeeStakingPasswordDrawer = async () => {
await StakingPasswordDrawer.title.waitForDisplayed();
expect(await StakingPasswordDrawer.title.getText()).to.equal(
await t('browserView.staking.details.confirmation.title')
);
await StakingPasswordDrawer.subtitle.waitForDisplayed();
expect(await StakingPasswordDrawer.subtitle.getText()).to.equal(
await t('browserView.transaction.send.enterWalletPasswordToConfirmTransaction')
);
await StakingPasswordDrawer.passwordInputContainer.waitForDisplayed();
await StakingPasswordDrawer.confirmButton.waitForDisplayed();
expect(await StakingPasswordDrawer.confirmButton.getText()).to.equal(await t('general.button.confirm'));
};
assertSeeStakingError = async () => {
await StakingErrorDrawer.icon.waitForDisplayed();
await StakingErrorDrawer.title.waitForDisplayed();
expect(await StakingErrorDrawer.title.getText()).to.equal(await t('browserView.staking.details.fail.title'));
await StakingErrorDrawer.description.waitForDisplayed();
expect(await StakingErrorDrawer.description.getText()).to.equal(
await t('browserView.staking.details.fail.description')
);
await StakingErrorDrawer.retryButton.waitForDisplayed();
expect(await StakingErrorDrawer.retryButton.getText()).to.equal(
await t('browserView.staking.details.fail.btn.retry')
);
await StakingErrorDrawer.closeButton.waitForDisplayed();
expect(await StakingErrorDrawer.closeButton.getText()).to.equal(
await t('browserView.staking.details.fail.btn.close')
);
};
async assertSeeTickerInCostColumn(expectedTicker: 'ADA' | 'tADA') {
const regex = expectedTicker === 'ADA' ? /[^t]ADA/g : /tADA/g;
const tickerList = await StakingPage.stakePoolListCostList.map(async (stakePoolListCost) =>
String(((await stakePoolListCost.getText()) as string).match(regex))
);
this.assertTickerInList(expectedTicker, tickerList);
}
async assertSeeTickerInCurrentStakedPool(expectedTicker: 'ADA' | 'tADA') {
const regex = expectedTicker === 'ADA' ? /[^t]ADA/g : /tADA/g;
const tickerList = (await StakingPage.getStatsTickers()).map((ticker) => String(ticker.match(regex)));
this.assertTickerInList(expectedTicker, tickerList);
}
assertTickerInList(expectedTicker: 'ADA' | 'tADA', tickerList: string[]) {
if (expectedTicker === 'ADA') tickerList = tickerList.map((ticker) => ticker.trim().slice(-3));
expect(tickerList.every((ticker) => ticker === expectedTicker)).to.be.true;
}
}
export default new StakingPageAssert();