-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b0de18
commit 69182ba
Showing
6 changed files
with
135 additions
and
13 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
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,19 @@ | ||
import { Asset } from "@chain-registry/types"; | ||
|
||
export const assetMock: Partial<Asset> = { | ||
name: "Ethereum", | ||
symbol: "ETH", | ||
logo_URIs: { | ||
svg: "https://example.com/eth-icon.png", | ||
}, | ||
}; | ||
|
||
export const assetMock2: Partial<Asset> = { | ||
name: "Bitcoin", | ||
symbol: "BTC", | ||
logo_URIs: { svg: "btc.svg" }, | ||
}; | ||
|
||
export const assetMockList: Array<Partial<Asset>> = [assetMock, assetMock2]; | ||
|
||
export const assetWithoutLogo: Partial<Asset> = { ...assetMock, logo_URIs: {} }; |
23 changes: 23 additions & 0 deletions
23
apps/namadillo/src/App/Transfer/__tests__/AssetCard.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,23 @@ | ||
import { Asset } from "@chain-registry/types"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { AssetCard } from "App/Transfer/AssetCard"; | ||
import { assetMock, assetWithoutLogo } from "App/Transfer/__mocks__/assets"; | ||
|
||
describe("Component: AssetCard", () => { | ||
it("should render asset name", () => { | ||
render(<AssetCard asset={assetMock as Asset} />); | ||
expect(screen.getByText("Ethereum")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should render asset logo if available", () => { | ||
render(<AssetCard asset={assetMock as Asset} />); | ||
const logo = screen.getByAltText("Ethereum logo"); | ||
expect(logo).toBeInTheDocument(); | ||
expect(logo).toHaveAttribute("src", assetMock.logo_URIs?.svg); | ||
}); | ||
|
||
it("should render placeholder if logo is not available", () => { | ||
render(<AssetCard asset={assetWithoutLogo as Asset} />); | ||
expect(screen.getByAltText(/logo not available/i)).toBeInTheDocument(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
apps/namadillo/src/App/Transfer/__tests__/ChainCard.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,18 @@ | ||
import { Chain } from "@chain-registry/types"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { ChainCard } from "App/Transfer/ChainCard"; | ||
import { randomChainMock } from "../__mocks__/chains"; | ||
|
||
describe("Component: ChainCard", () => { | ||
it("renders the chain's name", () => { | ||
render(<ChainCard chain={randomChainMock as Chain} />); | ||
expect(screen.getByText(randomChainMock.pretty_name!)).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders the chain's logo", () => { | ||
render(<ChainCard chain={randomChainMock as Chain} />); | ||
const logo = screen.getByAltText(`${randomChainMock.pretty_name!} logo`); | ||
expect(logo).toBeInTheDocument(); | ||
expect(logo).toHaveAttribute("src", randomChainMock.logo_URIs?.svg); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
apps/namadillo/src/App/Transfer/__tests__/SelectAssetModal.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 { Asset } from "@chain-registry/types"; | ||
import { fireEvent, render, screen, waitFor } from "@testing-library/react"; | ||
import { SelectAssetModal } from "App/Transfer/SelectAssetModal"; | ||
import { assetMockList } from "../__mocks__/assets"; | ||
|
||
describe("SelectAssetModal", () => { | ||
const onCloseMock = jest.fn(); | ||
const onSelectMock = jest.fn(); | ||
|
||
it("should render the modal title", () => { | ||
render( | ||
<SelectAssetModal | ||
onClose={onCloseMock} | ||
onSelect={onSelectMock} | ||
assets={assetMockList as Asset[]} | ||
/> | ||
); | ||
expect(screen.getByText("Select Asset")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should render all assets", () => { | ||
render( | ||
<SelectAssetModal | ||
onClose={onCloseMock} | ||
onSelect={onSelectMock} | ||
assets={assetMockList as Asset[]} | ||
/> | ||
); | ||
expect(screen.getByText("Bitcoin")).toBeInTheDocument(); | ||
expect(screen.getByText("Ethereum")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should filter assets based on search input", async () => { | ||
render( | ||
<SelectAssetModal | ||
onClose={onCloseMock} | ||
onSelect={onSelectMock} | ||
assets={assetMockList as Asset[]} | ||
/> | ||
); | ||
fireEvent.change(screen.getByPlaceholderText(/search/i, { exact: false }), { | ||
target: { value: "Bit" }, | ||
}); | ||
|
||
// Event is debounced | ||
waitFor(() => { | ||
expect(screen.getByText("Bitcoin")).toBeInTheDocument(); | ||
expect(screen.queryByText("Ethereum")).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it("should call onSelect and onClose when an asset is selected", () => { | ||
render( | ||
<SelectAssetModal | ||
onClose={onCloseMock} | ||
onSelect={onSelectMock} | ||
assets={assetMockList as Asset[]} | ||
/> | ||
); | ||
fireEvent.click(screen.getByText("Bitcoin")); | ||
expect(onSelectMock).toHaveBeenCalledWith(assetMockList[1]); | ||
expect(onCloseMock).toHaveBeenCalled(); | ||
}); | ||
}); |
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