diff --git a/e2e-tests/constants.ts b/e2e-tests/constants.ts index 51248a82..af1a31b7 100644 --- a/e2e-tests/constants.ts +++ b/e2e-tests/constants.ts @@ -1,4 +1,5 @@ import path from 'path'; +import {Page, Locator} from '@playwright/test' export const vaultPassword = '3hQqzYn4C7Y8rEZTVEZb'; export const twentyFourWordsSecretPhrase = @@ -109,6 +110,18 @@ export const NEW_VALIDATOR_FOR_STAKE = { export const URLS = { rpc: 'https://node.testnet.cspr.cloud/rpc' }; +export function createLocators(page: Page) { + return { + accountSwitcher: page.getByTestId('connection-status-modal'), + firstAccount: page.locator("span[type='bodySemiBold'].sc-iOeugr.hnMrar.sc-iJbNxu.bAimRi"), + CSPRtotalBalance: page.locator('span[type="CSPRBold"]'), + liquidBalance: page.locator('#layout-content-container > div > div.sc-gGvHcT.LEYqH > div > div.sc-hLBbgP.sc-kDvujY.bxIaNA.czrHSx > div.sc-hLBbgP.sc-kDvujY.nnmro.czrHSx > div.sc-hLBbgP.sc-kDvujY.sc-fmixVB.eJhjZ.czrHSx.jIbqvc > div:nth-child(1) > div > span.sc-iOeugr.fFyyCL'), + delegatedBalance: page.locator('//*[@id="layout-content-container"]/div/div[1]/div/div[2]/div[2]/div[2]/div[2]/div/span[1]'), + undelegatingBalance: page.locator('//*[@id="layout-content-container"]/div/div[1]/div/div[2]/div[2]/div[2]/div[3]/div/span[1]'), + totalBalanceUSD: page.locator('//span[@type="captionRegular" and @color="contentSecondary"]'), + threeDotsMenu: page.locator("//*[contains(@class, 'sc-eJDSGI') and contains(@class, 'bMCuLR')]") + }; +} export const RPC_RESPONSE = { success: { diff --git a/e2e-tests/fixtures.ts b/e2e-tests/fixtures.ts index c4eba6b3..9db8b134 100644 --- a/e2e-tests/fixtures.ts +++ b/e2e-tests/fixtures.ts @@ -212,6 +212,8 @@ export const popup = test.extend<{ createAccount: (newAccountName: string) => Promise; connectAccounts: () => Promise; addContact: () => Promise; + providePassword: (popupPage?: Page) => Promise; + passwordTimeout: (popupPage?: Page) => Promise; }>({ popupPage: async ({ extensionId, page }, use) => { await page.goto(`chrome-extension://${extensionId}/popup.html`); @@ -291,7 +293,37 @@ export const popup = test.extend<{ }; await use(addContact); - } -}); + }, + + +providePassword: async ({ page }, use) => { + const providePassword = async (popupPage?: Page) => { + const currentPage = popupPage || page; + + await currentPage + .getByPlaceholder('Password', { exact: true }) + .fill(vaultPassword); + await currentPage.getByRole('button', { name: 'Continue' }).click(); + }; + await use(providePassword); +}, + +passwordTimeout: async ({ page }, use) => { + const passwordTimeout = async (popupPage?: Page) => { + const currentPage = popupPage || page; + + await currentPage + .getByPlaceholder('Password', { exact: true }) + .fill('wrong password'); + + for (let i = 0; i < 5; i++) { + await currentPage.getByRole('button', { name: 'Continue' }).click(); + } + + }; + + await use(passwordTimeout); +} +}); export const popupExpect = popup.expect; diff --git a/e2e-tests/onboarding-flow/confirm-secret-phrase-flow.spec.ts b/e2e-tests/onboarding-flow/confirm-secret-phrase-flow.spec.ts index 44be77eb..ee88db22 100644 --- a/e2e-tests/onboarding-flow/confirm-secret-phrase-flow.spec.ts +++ b/e2e-tests/onboarding-flow/confirm-secret-phrase-flow.spec.ts @@ -1,5 +1,6 @@ import { onboardingExpect, onboarding } from '../fixtures'; import { DEFAULT_FIRST_ACCOUNT } from '../constants'; +import { createLocators } from '../constants'; onboarding.describe('Onboarding UI: confirm secret phrase flow', () => { onboarding( @@ -30,6 +31,26 @@ onboarding.describe('Onboarding UI: confirm secret phrase flow', () => { await onboardingExpect( page.getByText(DEFAULT_FIRST_ACCOUNT.accountName) ).toBeVisible(); + //Fresh account should have empty balances, no nft or deploy history + await onboardingExpect( + page.getByText("NFTs")).toBeVisible(); + + await page.getByText("NFTs").click(); + + await onboardingExpect( + await page.getByText("No NFT tokens")).toBeVisible(); + + await page.getByText("Deploys").click(); + + await onboardingExpect( + await page.getByText("No activity")).toBeVisible(); + + const locators = createLocators(page); + const accountSwitcher = locators.accountSwitcher; + const firstAccount = locators.firstAccount; + + // Perform actions and assertions + await accountSwitcher.click(); } ); diff --git a/e2e-tests/popup/settings/backup secret phrase.spec.ts b/e2e-tests/popup/settings/backup secret phrase.spec.ts new file mode 100644 index 00000000..9d0c3cec --- /dev/null +++ b/e2e-tests/popup/settings/backup secret phrase.spec.ts @@ -0,0 +1,111 @@ +import { + DEFAULT_FIRST_ACCOUNT, + DEFAULT_SECOND_ACCOUNT, + vaultPassword + } from '../../constants'; + import { popup, popupExpect } from '../../fixtures'; + + + //TODO + // add check to comparedisplayed phrase with the one used in onboarding + popup.describe('Popup UI: back up secret phrase', () => { + popup( + "should display a secret phrase after providing password and copy phrase", + async ({ popupPage, unlockVault, providePassword }) => { + await unlockVault(); + await popupPage.getByTestId('menu-open-icon').click(); + await popupPage.getByText('Back up your secret recovery phrase').click(); + await providePassword(); + + + await popupExpect( + popupPage.getByRole('heading', { name: 'Back up your secret recovery phrase' }) + ).toBeVisible(); + await popupPage.getByText('Click to reveal secret recovery phrase').click(); + await popupPage.getByText('Copy secret recovery phrase').click(); + + + + await popupExpect( + popupPage.getByText( + 'Copied to clipboard' + ) + ).toBeVisible(); + } + + ); + popup( + 'should display safety tips', + async ({ popupPage, unlockVault, providePassword }) => { + await unlockVault(); + await popupPage.getByTestId('menu-open-icon').click(); + await popupPage.getByText('Back up your secret recovery phrase').click(); + await providePassword(); + + + await popupExpect( + popupPage.getByRole('heading', { name: 'Back up your secret recovery phrase' }) + ).toBeVisible(); + + + await popupExpect( + popupPage.getByText( + 'Save a backup in multiple secure locations.' + ) + ).toBeVisible(); + + + await popupExpect( + popupPage.getByText( + 'Never share the phrase with anyone.' + ) + ).toBeVisible(); + + + await popupExpect( + popupPage.getByText( + 'Be careful of phishing! Casper Wallet will never spontaneously ask you for your secret recovery phrase.' + ) + ).toBeVisible(); + + + await popupExpect( + popupPage.getByText( + 'If you need to back up your secret recovery phrase again, you can find it in Settings.' + ) + ).toBeVisible(); + + + await popupExpect( + popupPage.getByText( + 'Casper Wallet cannot recover your secret recovery phrase! If you lose it, you may not be able to recover your funds.' + ) + ).toBeVisible(); + }) + + + popup( + "should timeout after providing wrong password 5 times", + async ({ popupPage, unlockVault, passwordTimeout }) => { + await unlockVault(); + + await popupPage.getByTestId('menu-open-icon').click(); + await popupPage.getByText('Back up your secret recovery phrase').click(); + + await passwordTimeout(); + + + await popupExpect( + popupPage.getByRole('heading', { name: 'Please wait before the next attempt to unlock your wallet' }) + ).toBeVisible(); + }) + }); + + + + + + + + + \ No newline at end of file