Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E tests. Changing fiat currency. #3513

Merged
merged 7 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions packages/e2e-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"simple-node-logger": "^21.8.12"
},
"dependencies": {
"axios": "^1.6.8",
"balanced-match": "^1.0.2",
"brace-expansion": "^1.1.11",
"concat-map": "^0.0.1",
Expand Down
15 changes: 14 additions & 1 deletion packages/e2e-tests/pages/walletCommonBase.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class WalletCommonBase extends BasePage {
locator: 'topBar:selectedWallet-availableBalance-text',
method: 'id',
};
walletFiatBalanceTextLocator = {
locator: 'topBar:selectedWallet-availableFiatBalance-text',
method: 'id',
};
// change wallet modal window
changeWalletDialogLocator = {
locator: 'changeWalletDialog-dialogWindow-modalWindow',
Expand Down Expand Up @@ -112,16 +116,25 @@ class WalletCommonBase extends BasePage {
// functions
async getSelectedWalletInfo() {
this.logger.info(`WalletCommonBase::getSelectedWalletInfo is called`);

await this.waitForElement(this.walletNameAndPlateNumberTextLocator);
const rawNameAndPlateText = await this.getText(this.walletNameAndPlateNumberTextLocator);
const [walletName, walletPlate] = rawNameAndPlateText.split('\n');

await this.waitForElement(this.walletBalanceTextLocator);
const rawBalanceText = await this.getText(this.walletBalanceTextLocator);
const [walletName, walletPlate] = rawNameAndPlateText.split('\n');
const adaBalance = Number(rawBalanceText.split(' ')[0]);

const rawFiatBalanceText = await this.getText(this.walletFiatBalanceTextLocator);
const [fiatBalanceStr, fiatCurrency] = rawFiatBalanceText.split(' ');
const fiatBalance = fiatBalanceStr === '-' ? 0 : Number(fiatBalanceStr);

const walletInfo = {
name: walletName,
plate: walletPlate,
balance: adaBalance,
fiatBalance,
fiatCurrency,
};
this.logger.info(
`WalletCommonBase::getSelectedWalletInfo::walletInfo is ${JSON.stringify(walletInfo)}`
Expand Down
79 changes: 79 additions & 0 deletions packages/e2e-tests/test/19_changingFiat.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import BasePage from '../pages/basepage.js';
import { customAfterEach } from '../utils/customHooks.js';
import TransactionsSubTab from '../pages/wallet/walletTab/walletTransactions.page.js';
import { testWallet1 } from '../utils/testWallets.js';
import { expect } from 'chai';
import { getTestLogger, roundUpCurrency } from '../utils/utils.js';
import { oneMinute } from '../helpers/timeConstants.js';
import { restoreWallet } from '../helpers/restoreWalletHelper.js';
import SettingsTab from '../pages/wallet/settingsTab/settingsTab.page.js';
import driversPoolsManager from '../utils/driversPool.js';
import GeneralSubTab from '../pages/wallet/settingsTab/generalSubTab.page.js';
import axios from 'axios';

const reqResponse = await axios.get('https://iohk-mainnet.yoroiwallet.com/api/price/ADA/current');
const prices = reqResponse.data.ticker.prices;

describe('Changing fiat currencies', function () {
this.timeout(2 * oneMinute);
let webdriver = null;
let logger = null;

before(function (done) {
webdriver = driversPoolsManager.getDriverFromPool();
logger = getTestLogger(this.test.parent.title);
done();
});

const testData = ['BRL', 'ETH', 'BTC', 'KRW', 'CNY', 'EUR', 'JPY', 'USD', 'ADA'];

it('Restore a 15-word wallet', async function () {
await restoreWallet(webdriver, logger, testWallet1);
const transactionsPage = new TransactionsSubTab(webdriver, logger);
const txPageIsDisplayed = await transactionsPage.isDisplayed();
expect(txPageIsDisplayed, 'The transactions page is not displayed').to.be.true;
});

for (const testDatum of testData) {
describe(`Changing fiat currency to ${testDatum}`, function () {
it('Open General settings', async function () {
const transactionsPage = new TransactionsSubTab(webdriver, logger);
await transactionsPage.goToSettingsTab();
const settingsPage = new SettingsTab(webdriver, logger);
await settingsPage.goToGeneralSubMenu();
});

it('Select currency', async function () {
const generalSubTab = new GeneralSubTab(webdriver, logger);
await generalSubTab.selectFiat(testDatum);
});

it('Check the selected currency is applied', async function () {
const generalSubTab = new GeneralSubTab(webdriver, logger);
await generalSubTab.goToWalletTab();
const walletInfo = await generalSubTab.getSelectedWalletInfo();
if (testDatum === 'ADA') {
expect(walletInfo.fiatBalance, 'Fiat balance is different').to.equal(0);
} else {
expect(walletInfo.fiatCurrency, 'Fiat currency is different').to.equal(testDatum);
const expectedFiatValue = roundUpCurrency(
prices[testDatum] * walletInfo.balance,
testDatum
);
expect(walletInfo.fiatBalance, 'Fiat balance is different').to.equal(expectedFiatValue);
}
});
});
}

afterEach(function (done) {
customAfterEach(this, webdriver, logger);
done();
});

after(function (done) {
const basePage = new BasePage(webdriver, logger);
basePage.closeBrowser();
done();
});
});
9 changes: 9 additions & 0 deletions packages/e2e-tests/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,12 @@ export const convertPrettyTimeToNormal = prettyTime => {
}
return `${hours}:${minutes}:00`;
};

export const roundUpCurrency = (value, fiatCurrency) => {
const cryptoFiats = ['ETH', 'BTC'];
if (cryptoFiats.includes(fiatCurrency)) {
return Number(parseFloat(value).toFixed(6));
} else {
return Number(parseFloat(value).toFixed(2));
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class AmountDisplay extends Component<Props> {
</div>
)}
{showFiat === true && (
<div className={styles.fiat}>
<div className={styles.fiat} id={id + '-availableFiatBalance-text'}>
{fiatDisplay || '-'} {currency || 'USD'}
</div>
)}
Expand Down
Loading