-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GIX-1980: Setup icp accounts with tokens table (#3775)
# Motivation When we migrate to the tokens page, we also want a similar view for the ICP accounts, subaccounts and hardware wallet accounts. In this PR, I introduce the TokensTable for NNS Accounts. # Changes * Render `TokensTable` in `NnsAccounts` depending on feature flag. * Expect an optional list of `UserTokenData` in `NnsAccounts`. * Hard code a list of `UserTokenData` in the Accounts route and pass it to `NnsAccounts`. # Tests * Add test in NnsAccounts.spec that the tokens table is there if feature flag is enabled. I added myself some TODOs comments to remember improving the test before adding more features here. * Add methods to NnsAccountsPo. * Add test in Accounts route to check that tokens table is rendered if flag is enabled. # Todos - [ ] Add entry to changelog (if necessary).
- Loading branch information
Showing
5 changed files
with
146 additions
and
43 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
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
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 |
---|---|---|
@@ -1,29 +1,71 @@ | ||
import { authStore } from "$lib/stores/auth.store"; | ||
import { OWN_CANISTER_ID_TEXT } from "$lib/constants/canister-ids.constants"; | ||
import { AppPath } from "$lib/constants/routes.constants"; | ||
import { overrideFeatureFlagsStore } from "$lib/stores/feature-flags.store"; | ||
import { page } from "$mocks/$app/stores"; | ||
import AccountsPage from "$routes/(app)/(u)/(accounts)/accounts/+page.svelte"; | ||
import { | ||
authStoreMock, | ||
mutableMockAuthStoreSubscribe, | ||
} from "$tests/mocks/auth.store.mock"; | ||
import { resetIdentity, setNoIdentity } from "$tests/mocks/auth.store.mock"; | ||
import { AccountsPo } from "$tests/page-objects/Accounts.page-object"; | ||
import { JestPageObjectElement } from "$tests/page-objects/jest.page-object"; | ||
import { render } from "@testing-library/svelte"; | ||
|
||
vi.mock("$lib/api/ckbtc-ledger.api"); | ||
vi.mock("$lib/api/sns-ledger.api"); | ||
|
||
describe("Accounts page", () => { | ||
vi.spyOn(authStore, "subscribe").mockImplementation( | ||
mutableMockAuthStoreSubscribe | ||
); | ||
const renderComponent = () => { | ||
const { container } = render(AccountsPage); | ||
return AccountsPo.under(new JestPageObjectElement(container)); | ||
}; | ||
|
||
beforeAll(() => { | ||
authStoreMock.next({ | ||
identity: undefined, | ||
}); | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
afterAll(() => { | ||
vi.clearAllMocks(); | ||
describe("not logged in", () => { | ||
beforeEach(() => { | ||
setNoIdentity(); | ||
}); | ||
|
||
it("should render sign-in if not logged in", () => { | ||
const { getByTestId } = render(AccountsPage); | ||
|
||
expect(getByTestId("login-button")).not.toBeNull(); | ||
}); | ||
}); | ||
|
||
it("should render sign-in if not logged in", () => { | ||
const { getByTestId } = render(AccountsPage); | ||
describe("logged in NNS Accounts", () => { | ||
beforeEach(() => { | ||
resetIdentity(); | ||
page.mock({ | ||
routeId: AppPath.Accounts, | ||
data: { universe: OWN_CANISTER_ID_TEXT }, | ||
}); | ||
}); | ||
|
||
describe("tokens flag enabled", () => { | ||
beforeEach(() => { | ||
overrideFeatureFlagsStore.setFlag("ENABLE_MY_TOKENS", true); | ||
}); | ||
|
||
it("renders tokens table for NNS accounts", async () => { | ||
const po = renderComponent(); | ||
|
||
const pagePo = po.getNnsAccountsPo(); | ||
expect(await pagePo.hasTokensTable()).toBe(true); | ||
}); | ||
}); | ||
|
||
describe("tokens flag disabled", () => { | ||
beforeEach(() => { | ||
overrideFeatureFlagsStore.setFlag("ENABLE_MY_TOKENS", false); | ||
}); | ||
|
||
expect(getByTestId("login-button")).not.toBeNull(); | ||
it("does not render tokens table for NNS accounts", async () => { | ||
const po = renderComponent(); | ||
|
||
const pagePo = po.getNnsAccountsPo(); | ||
expect(await pagePo.hasTokensTable()).toBe(false); | ||
}); | ||
}); | ||
}); | ||
}); |