-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add market widget integration test
- Loading branch information
1 parent
278bf59
commit f7c14f5
Showing
20 changed files
with
913 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"ledger-live-desktop": minor | ||
--- | ||
|
||
Introduce integration tests for Market Widget |
64 changes: 64 additions & 0 deletions
64
...wArch/features/MarketPerformanceWidget/__integrations__/marketwidget.integration.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from "react"; | ||
import { render, screen, waitFor } from "tests/testUtils"; | ||
|
||
import { useMarketPerformanceWidget } from "../useMarketPerformanceWidget"; | ||
import { Order } from "../types"; | ||
import { MarketWidgetTest, FAKE_LIST } from "./shared"; | ||
|
||
jest.mock("../useMarketPerformanceWidget"); | ||
const mockedUseMarketPerformanceWidgetHook = useMarketPerformanceWidget as jest.Mock; | ||
|
||
jest.mock("@tanstack/react-query", () => { | ||
return { | ||
__esModule: true, | ||
...jest.requireActual("@tanstack/react-query"), | ||
}; | ||
}); | ||
|
||
describe("MarketPerformance Widget", () => { | ||
it("should display error screen when Component appears", async () => { | ||
mockedUseMarketPerformanceWidgetHook.mockReturnValue({ | ||
list: [], | ||
order: Order.asc, | ||
setOrder: jest.fn(), | ||
isLoading: false, | ||
hasError: true, | ||
range: "month", | ||
top: 0, | ||
enableNewFeature: true, | ||
}); | ||
|
||
render(<MarketWidgetTest />, { initialRoute: `/` }); | ||
|
||
expect(screen.getByTestId("error-container")).toBeVisible(); | ||
expect(screen.getByText("1M trend")).toBeVisible(); | ||
expect(screen.getByText("Sorry, we’re unable to load the trend")).toBeVisible(); | ||
}); | ||
it("should display V2 screen when FF new Feature is ON and go to market detail page of selected currency when clicking on it", async () => { | ||
mockedUseMarketPerformanceWidgetHook.mockReturnValue({ | ||
list: FAKE_LIST, | ||
order: Order.asc, | ||
setOrder: jest.fn(), | ||
isLoading: false, | ||
hasError: false, | ||
range: "month", | ||
top: 0, | ||
enableNewFeature: true, | ||
}); | ||
|
||
const { user } = render(<MarketWidgetTest />, { initialRoute: `/` }); | ||
|
||
expect(screen.getAllByTestId(/market-performance-widget-row/i).length).toEqual( | ||
FAKE_LIST.length, | ||
); | ||
|
||
const btc = screen.getByTestId("market-performance-widget-row-1"); | ||
expect(btc).toBeVisible(); | ||
await user.click(btc); | ||
|
||
await waitFor(() => expect(screen.getByTestId("market-coin-page-container")).toBeVisible()); | ||
|
||
expect(screen.getByText("Bitcoin")).toBeVisible(); | ||
expect(screen.getByText("BTC")).toBeVisible(); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
...ger-live-desktop/src/newArch/features/MarketPerformanceWidget/__integrations__/shared.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from "react"; | ||
import { Switch, Route, withRouter } from "react-router"; | ||
import MarketPerformanceWidget from ".."; | ||
import { ABTestingVariants } from "@ledgerhq/types-live"; | ||
import MarketCoin from "~/renderer/screens/market/MarketCoin"; | ||
import { MarketItemPerformer } from "@ledgerhq/live-common/market/utils/types"; | ||
|
||
export const FAKE_LIST: MarketItemPerformer[] = [ | ||
{ | ||
id: "bitcoin", | ||
name: "Bitcoin", | ||
ticker: "BTC", | ||
priceChangePercentage1h: 0.5, | ||
priceChangePercentage24h: 2.3, | ||
priceChangePercentage7d: 5.1, | ||
priceChangePercentage30d: 15.8, | ||
priceChangePercentage1y: 120.7, | ||
image: "https://path-to-bitcoin-image.com", | ||
price: 35000, | ||
ledgerIds: ["bitcoin"], | ||
}, | ||
{ | ||
id: "ethereum", | ||
name: "Ethereum", | ||
ticker: "ETH", | ||
priceChangePercentage1h: 0.3, | ||
priceChangePercentage24h: 1.7, | ||
priceChangePercentage7d: 3.9, | ||
priceChangePercentage30d: 10.5, | ||
priceChangePercentage1y: 85.3, | ||
image: "https://path-to-ethereum-image.com", | ||
price: 2500, | ||
ledgerIds: ["ethereum"], | ||
}, | ||
{ | ||
id: "ripple", | ||
name: "Ripple", | ||
ticker: "XRP", | ||
priceChangePercentage1h: 0.1, | ||
priceChangePercentage24h: 0.9, | ||
priceChangePercentage7d: 2.8, | ||
priceChangePercentage30d: 5.6, | ||
priceChangePercentage1y: 50.2, | ||
image: "https://path-to-ripple-image.com", | ||
price: 1.2, | ||
ledgerIds: ["ripple"], | ||
}, | ||
]; | ||
|
||
const MarketWidgetNavigation = () => ( | ||
<Switch> | ||
<Route | ||
exact | ||
path="/" | ||
render={() => <MarketPerformanceWidget variant={ABTestingVariants.variantA} />} | ||
/> | ||
<Route path="/market/:currencyId" render={() => <MarketCoin />} /> | ||
</Switch> | ||
); | ||
|
||
const MarketWidgetTestBase = () => <MarketWidgetNavigation />; | ||
|
||
export const MarketWidgetTest = withRouter(MarketWidgetTestBase); |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...erformanceWidget/components/Container.tsx → ...erformanceWidget/components/Container.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...rd/MarketPerformanceWidget/utils/index.ts → ...es/MarketPerformanceWidget/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
apps/ledger-live-desktop/tests/handlers/fixtures/market/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import mockedResponseBTC from "./mockedResponseBTC.json"; | ||
import mocketMarketList from "./mocketMarketList.json"; | ||
|
||
export const MarketMockedResponse = { | ||
bitcoinDetail: mockedResponseBTC, | ||
marketList: mocketMarketList, | ||
}; |
39 changes: 39 additions & 0 deletions
39
apps/ledger-live-desktop/tests/handlers/fixtures/market/mockedResponseBTC.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[ | ||
{ | ||
"id": "bitcoin", | ||
"ledgerIds": ["bitcoin"], | ||
"ticker": "btc", | ||
"name": "Bitcoin", | ||
"image": "https://proxycgassets.api.live.ledger.com/coins/images/1/large/bitcoin.png", | ||
"marketCap": 1853659311759, | ||
"marketCapRank": 1, | ||
"fullyDilutedValuation": 1965637466124, | ||
"totalVolume": 59569647143, | ||
"high24h": 94838, | ||
"low24h": 91375, | ||
"price": 93552, | ||
"priceChange24h": -257.298216683208, | ||
"priceChangePercentage1h": -0.40255063060877444, | ||
"priceChangePercentage24h": -0.27427661250417024, | ||
"priceChangePercentage7d": -0.30984911905827317, | ||
"priceChangePercentage30d": -3.4861595535989562, | ||
"priceChangePercentage1y": 118.89147816670156, | ||
"marketCapChange24h": -5358207120.227051, | ||
"marketCapChangePercentage24h": -0.28823, | ||
"circulatingSupply": 19803675, | ||
"totalSupply": 21000000, | ||
"maxSupply": 21000000, | ||
"allTimeHigh": 108135, | ||
"allTimeLow": 67.81, | ||
"allTimeHighDate": "2024-12-17T15:02:41.429Z", | ||
"allTimeLowDate": "2013-07-06T00:00:00Z", | ||
"sparkline": [ | ||
93904.34, 94180.71, 98540.01, 97744.89, 98500.26, 98166.15, 97972.34, 98116.91, 98322.234, | ||
99144.055, 98949.445, 98104.914, 95759.02, 95344.336, 96462.66, 95555.76, 95792.29, 96178.805, | ||
96120.68, 96461.414, 94017.74, 94505.445, 94248.84, 94372.445, 94337.37, 94463.18, 94745.09, | ||
94916.77, 94998.1, 94953.984, 94968.695, 94749.555, 93732.33, 93678.82, 93392.77, 93073.18, | ||
93686.19, 93614.766, 91960.47, 94197.09, 92369.18, 92286.9 | ||
], | ||
"updatedAt": "2024-12-31T10:19:36.410Z" | ||
} | ||
] |
Oops, something went wrong.