Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

LIVE-448 - Add playwright test suite for market page #4704

Closed
wants to merge 6 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/renderer/screens/market/CountervalueSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function CounterValueSelect({
<>
<Track onUpdate event="MarketCounterValueSelect" counterValue={cvOption && cvOption.value} />
<Dropdown
data-test-id="market-counter-value-select"
label={t("market.currency")}
name="currency"
menuPortalTarget={document.body}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ function MarkeCoinChartComponent({
)}
</Flex>
</Flex>
<Bar onTabChange={setRange} initialActiveIndex={activeRangeIndex}>
<Bar
data-test-id="market-coin-range-select"
onTabChange={setRange}
initialActiveIndex={activeRangeIndex}
>
{ranges.map(key => (
<Text color="inherit" variant="small" key={key}>
{t(`market.range.${key}`)}
Expand Down
12 changes: 9 additions & 3 deletions src/renderer/screens/market/MarketCoinScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export default function MarketCoinScreen() {
<Flex pl={3} flexDirection="column" alignItems="left" pr={16}>
<Flex flexDirection="row" alignItems="center">
<Title>{name}</Title>
<StarContainer onClick={toggleStar}>
<StarContainer data-test-id="market-coin-star-button" onClick={toggleStar}>
<Icon name={isStarred > 0 ? "StarSolid" : "Star"} size={18} />
</StarContainer>
</Flex>
Expand All @@ -221,19 +221,25 @@ export default function MarketCoinScreen() {
{internalCurrency && (
<>
{availableOnBuy && (
<Button variant="shade" mr={1} onClick={onBuy}>
<Button
data-test-id="market-coin-buy-button"
variant="shade"
mr={1}
onClick={onBuy}
>
{t("accounts.contextMenu.buy")}
</Button>
)}
{availableOnSwap && (
<Button variant="shade" onClick={onSwap}>
<Button data-test-id="market-coin-swap-button" variant="shade" onClick={onSwap}>
{t("accounts.contextMenu.swap")}
</Button>
)}
</>
)}
<Flex justifyContent="flex-end" ml={4}>
<CounterValueSelect
data-test-id="market-coin-counter-value-select"
counterCurrency={counterCurrency}
setCounterCurrency={setCounterCurrency}
supportedCounterCurrencies={supportedCounterCurrencies}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/screens/market/MarketList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ function MarketList({
<TableCell disabled>{t("market.marketList.last7d")}</TableCell>
)}
<TableCell
data-test-id="market-star-button"
disabled={starredMarketCoins.length <= 0 && starred.length <= 0}
onClick={toggleStarredAccounts}
>
Expand Down
17 changes: 13 additions & 4 deletions src/renderer/screens/market/MarketRowItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function MarketRowItem({
<TableCell loading />
</TableRow>
) : (
<TableRow onClick={onCurrencyClick}>
<TableRow data-test-id={`market-${currency?.ticker}-row`} onClick={onCurrencyClick}>
<TableCell>{currency?.marketcapRank ?? "-"}</TableCell>
<TableCell>
<CryptoCurrencyIconWrapper>
Expand All @@ -168,12 +168,21 @@ function MarketRowItem({
{currency.internalCurrency && (
<>
{availableOnBuy && (
<Button variant="shade" mr={1} onClick={onBuy}>
<Button
data-test-id={`market-${currency?.ticker}-buy-button`}
variant="shade"
mr={1}
onClick={onBuy}
>
{t("accounts.contextMenu.buy")}
</Button>
)}
{availableOnSwap && (
<Button variant="shade" onClick={onSwap}>
<Button
data-test-id={`market-${currency?.ticker}-swap-button`}
variant="shade"
onClick={onSwap}
>
{t("accounts.contextMenu.swap")}
</Button>
)}
Expand Down Expand Up @@ -214,7 +223,7 @@ function MarketRowItem({
)}
</TableCell>
)}
<TableCell onClick={onStarClick}>
<TableCell data-test-id={`market-${currency?.ticker}-star-button`} onClick={onStarClick}>
<Icon name={isStarred ? "StarSolid" : "Star"} size={18} />
</TableCell>
</TableRow>
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/screens/market/SideDrawerFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ export default function SideDrawerFilter({

return (
<>
<Button Icon={Icons.FiltersRegular} variant="shade" outline onClick={openDrawer} />
<Button
data-test-id="market-filter-drawer-button"
Icon={Icons.FiltersRegular}
variant="shade"
outline
onClick={openDrawer}
/>
<SideDrawer
isOpen={isOpen}
onRequestClose={closeDrawer}
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/screens/market/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ export default function Market() {
<Title>{t("market.title")}</Title>
<Flex flexDirection="row" pr="6px" my={2} alignItems="center" justifyContent="space-between">
<SearchContainer>
<SearchInput value={search} onChange={updateSearch} placeholder={t("common.search")} />
<SearchInput
data-test-id="market-search-input"
value={search}
onChange={updateSearch}
placeholder={t("common.search")}
/>
</SearchContainer>
<Flex flexDirection="row" alignItems="center" justifyContent="flex-end">
<Flex width="290px" justifyContent="flex-end" ml={3}>
Expand All @@ -122,6 +127,7 @@ export default function Market() {
</Flex>
<Flex mx={3}>
<Dropdown
data-test-id="market-range-select"
label={t("market.rangeLabel")}
menuPortalTarget={document.body}
onChange={updateTimeRange}
Expand Down
6 changes: 6 additions & 0 deletions tests/models/Layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class Layout {
readonly inputWarning: Locator;
readonly drawerCollapseButton: Locator;
readonly drawerPortfolioButton: Locator;
readonly drawerMarketButton: Locator;
readonly drawerAccountsButton: Locator;
readonly drawerDiscoverButton: Locator;
readonly drawerSendButton: Locator;
Expand Down Expand Up @@ -36,6 +37,7 @@ export class Layout {
// drawer
this.drawerCollapseButton = page.locator("data-test-id=drawer-collapse-button");
this.drawerPortfolioButton = page.locator("data-test-id=drawer-dashboard-button");
this.drawerMarketButton = page.locator('data-test-id=drawer-market-button');
this.drawerAccountsButton = page.locator("data-test-id=drawer-accounts-button");
this.drawerDiscoverButton = page.locator("data-test-id=drawer-catalog-button");
this.drawerSendButton = page.locator("data-test-id=drawer-send-button");
Expand Down Expand Up @@ -69,6 +71,10 @@ export class Layout {
await this.drawerPortfolioButton.click();
}

async goToMarket() {
await this.drawerMarketButton.click();
}

async goToAccounts() {
await this.drawerAccountsButton.click();
}
Expand Down
27 changes: 27 additions & 0 deletions tests/models/MarketCoinPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Page, Locator } from "@playwright/test";

export class MarketCoinPage {
readonly page: Page;
readonly buyButton: Locator;
readonly swapButton: Locator;
readonly counterValueSelect: Locator;
readonly marketRangeSelect: Locator;
readonly starFilterButton: Locator;

constructor(page: Page) {
this.page = page;
this.buyButton = page.locator("data-test-id=market-coin-buy-button");
this.swapButton = page.locator("data-test-id=market-coin-swap-button");
this.counterValueSelect = page.locator("data-test-id=market-coin-counter-value-select");
this.marketRangeSelect = page.locator("data-test-id=market-coin-range-select");
this.starFilterButton = page.locator("data-test-id=market-coin-star-button");
}

async openBuyPage() {
await this.buyButton.click();
}

async openSwapPage() {
await this.swapButton.click();
}
}
37 changes: 37 additions & 0 deletions tests/models/MarketPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Page, Locator } from "@playwright/test";

export class MarketPage {
readonly page: Page;
readonly searchInput: Locator;
readonly counterValueSelect: Locator;
readonly marketRangeSelect: Locator;
readonly filterDrawerButton: Locator;
readonly starFilterButton: Locator;

constructor(page: Page) {
this.page = page;
this.searchInput = page.locator("data-test-id=market-search-input");
this.counterValueSelect = page.locator("data-test-id=market-counter-value-select");
this.marketRangeSelect = page.locator("data-test-id=market-range-select");
this.filterDrawerButton = page.locator("data-test-id=market-filter-drawer-button");
this.starFilterButton = page.locator("data-test-id=market-star-button");
}

async search(query: string) {
await this.searchInput.fill(query);
}

async openFilterDrawer() {
await this.filterDrawerButton.click();
}

async openCoinPage(ticker: string) {
const coinRow = this.page.locator(`data-test-id=market-${ticker}-row`);
await coinRow.click();
}

async openBuyPage(ticker: string) {
const buyButton = this.page.locator(`data-test-id=market-${ticker}-buy-button`);
await buyButton.click();
}
}
Binary file modified tests/specs/firmwareupdate.spec.ts-snapshots/modal-closed-win32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions tests/specs/market.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { expect } from "@playwright/test";

import test from "../fixtures/common";
import { MarketPage } from "../models/MarketPage";
import { Layout } from "../models/Layout";
import { MarketCoinPage } from "../models/MarketCoinPage";

test.use({ userdata: "skip-onboarding" });

test("Market", async ({ page }) => {
const marketPage = new MarketPage(page);
const marketCoinPage = new MarketCoinPage(page);
const layout = new Layout(page);

await test.step("go to market", async () => {
await layout.goToMarket();
expect(await page.screenshot()).toMatchSnapshot("market-page.png");
});

await test.step("go to market -> bitcoin", async () => {
await marketPage.openCoinPage("btc");
expect(await page.screenshot()).toMatchSnapshot("market-btc-page.png");
});

await test.step("go to market -> bitcoin -> buy", async () => {
await marketCoinPage.openBuyPage();
expect(await page.screenshot()).toMatchSnapshot("market-btc-buy-page.png");
});

await test.step("go to market", async () => {
await layout.goToMarket();
expect(await page.screenshot()).toMatchSnapshot("market-page.png");
});

await test.step("go to market -> buy bitcoin", async () => {
await marketPage.openBuyPage("btc");
expect(await page.screenshot()).toMatchSnapshot("market-btc-buy-page.png");
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.