Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: create wallet issues (#2570)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley committed Aug 3, 2020
1 parent 1c77d27 commit 4760f35
Show file tree
Hide file tree
Showing 11 changed files with 566 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ type SelectNetworkProps = {
name?: string;
value?: string;
id?: string;
disabled?: boolean;
onSelect?: (network?: NetworkData | null) => void;
};

export const itemToString = (item: Network | null) => item?.extra?.displayName || "";

export const SelectNetwork = ({ networks, placeholder, onSelect, name, id }: SelectNetworkProps) => {
export const SelectNetwork = ({ networks, placeholder, onSelect, name, id, disabled }: SelectNetworkProps) => {
const [items] = React.useState(() =>
networks.map((network) => {
const extended = getNetworkExtendedData({ coin: network.coin(), network: network.id() });
Expand Down Expand Up @@ -94,6 +95,7 @@ export const SelectNetwork = ({ networks, placeholder, onSelect, name, id }: Sel
<SelectNetworkInput
network={selectedItem}
suggestion={inputTypeAhead}
disabled={disabled}
{...getInputProps({
name,
placeholder,
Expand All @@ -114,9 +116,10 @@ export const SelectNetwork = ({ networks, placeholder, onSelect, name, id }: Sel
<ul {...getMenuProps()}>
{items.map((item, index) => (
<li
data-testid="SelectNetwork__NetworkIcon--container"
key={index}
className="inline-block pt-6 mr-6 cursor-pointer"
{...getItemProps({ item, index })}
{...getItemProps({ item, index, disabled })}
>
<NetworkIcon
coin={item.coin()}
Expand All @@ -136,4 +139,5 @@ export const SelectNetwork = ({ networks, placeholder, onSelect, name, id }: Sel
SelectNetwork.defaultProps = {
networks: [],
placeholder: "Enter a network name",
disabled: false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ exports[`SelectNetwork should render with networks 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="downshift-3-item-0"
role="option"
>
Expand All @@ -115,6 +116,7 @@ exports[`SelectNetwork should render with networks 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="downshift-3-item-1"
role="option"
>
Expand All @@ -138,6 +140,7 @@ exports[`SelectNetwork should render with networks 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="downshift-3-item-2"
role="option"
>
Expand Down
1 change: 1 addition & 0 deletions src/domains/profile/e2e/create-profile-action.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test("should create a profile and navigate to welcome screen", async (t) => {
await t.click(Selector("button").withExactText(translations().COMMON.COMPLETE));

// Check welcome with created profiles
await t.wait(1000); // TODO: the profile loading is async so we need to give it a moment
await t.expect(Selector("p").withText("John Doe").exists).ok();
await t.expect(Selector("p").withText("Anne Doe").exists).ok();
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ exports[`SendTransactionForm should render 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="SendTransactionForm__network-item-0"
role="option"
>
Expand All @@ -92,6 +93,7 @@ exports[`SendTransactionForm should render 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="SendTransactionForm__network-item-1"
role="option"
>
Expand All @@ -115,6 +117,7 @@ exports[`SendTransactionForm should render 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="SendTransactionForm__network-item-2"
role="option"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ exports[`Registration should render 1st step 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Registration__network-item-0"
role="option"
>
Expand All @@ -387,6 +388,7 @@ exports[`Registration should render 1st step 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Registration__network-item-1"
role="option"
>
Expand All @@ -410,6 +412,7 @@ exports[`Registration should render 1st step 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Registration__network-item-2"
role="option"
>
Expand Down Expand Up @@ -3377,6 +3380,7 @@ exports[`Registration should select registration type 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Registration__network-item-0"
role="option"
>
Expand All @@ -3400,6 +3404,7 @@ exports[`Registration should select registration type 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Registration__network-item-1"
role="option"
>
Expand All @@ -3423,6 +3428,7 @@ exports[`Registration should select registration type 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Registration__network-item-2"
role="option"
>
Expand Down Expand Up @@ -3963,6 +3969,7 @@ exports[`Registration should should go back 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Registration__network-item-0"
role="option"
>
Expand All @@ -3986,6 +3993,7 @@ exports[`Registration should should go back 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Registration__network-item-1"
role="option"
>
Expand All @@ -4009,6 +4017,7 @@ exports[`Registration should should go back 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Registration__network-item-2"
role="option"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ exports[`SendIPFSTransaction should render 1st step 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="SendIPFSTransaction__network-item-0"
role="option"
>
Expand All @@ -671,6 +672,7 @@ exports[`SendIPFSTransaction should render 1st step 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="SendIPFSTransaction__network-item-1"
role="option"
>
Expand All @@ -694,6 +696,7 @@ exports[`SendIPFSTransaction should render 1st step 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="SendIPFSTransaction__network-item-2"
role="option"
>
Expand Down
12 changes: 12 additions & 0 deletions src/domains/vote/pages/Votes/__snapshots__/Votes.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ exports[`Votes should render 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-0"
role="option"
>
Expand All @@ -328,6 +329,7 @@ exports[`Votes should render 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-1"
role="option"
>
Expand All @@ -351,6 +353,7 @@ exports[`Votes should render 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-2"
role="option"
>
Expand Down Expand Up @@ -781,6 +784,7 @@ exports[`Votes should select a delegate 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-0"
role="option"
>
Expand All @@ -804,6 +808,7 @@ exports[`Votes should select a delegate 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-1"
role="option"
>
Expand All @@ -827,6 +832,7 @@ exports[`Votes should select a delegate 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-2"
role="option"
>
Expand Down Expand Up @@ -2098,6 +2104,7 @@ exports[`Votes should select a network 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-0"
role="option"
>
Expand All @@ -2121,6 +2128,7 @@ exports[`Votes should select a network 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-1"
role="option"
>
Expand All @@ -2144,6 +2152,7 @@ exports[`Votes should select a network 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-2"
role="option"
>
Expand Down Expand Up @@ -3238,6 +3247,7 @@ exports[`Votes should select address 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-0"
role="option"
>
Expand All @@ -3261,6 +3271,7 @@ exports[`Votes should select address 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-1"
role="option"
>
Expand All @@ -3284,6 +3295,7 @@ exports[`Votes should select address 1`] = `
<li
aria-selected="false"
class="inline-block pt-6 mr-6 cursor-pointer"
data-testid="SelectNetwork__NetworkIcon--container"
id="Votes__network-item-2"
role="option"
>
Expand Down
47 changes: 43 additions & 4 deletions src/domains/wallet/pages/CreateWallet/CreateWallet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe("CreateWallet", () => {
bip39GenerateMock.mockRestore();
});

it("should render 1st step", () => {
it("should render 1st step", async () => {
const { result: form } = renderHook(() => useForm());
const { getByTestId, asFragment } = render(
<FormContext {...form.current}>
Expand All @@ -101,7 +101,11 @@ describe("CreateWallet", () => {
fireEvent.keyDown(selectAssetsInput, { key: "Enter", code: 13 });
});

expect(selectAssetsInput).toHaveAttribute("disabled");

expect(selectAssetsInput).toHaveValue("Ark");

await waitFor(() => expect(selectAssetsInput).not.toHaveAttribute("disabled"));
});

it("should render 2nd step", async () => {
Expand Down Expand Up @@ -189,6 +193,41 @@ describe("CreateWallet", () => {
expect(form.current.getValues()).toEqual({ name: "Test" });
});

it("should not allow quick swapping of networks", async () => {
const history = createMemoryHistory();
const createURL = `/profiles/${fixtureProfileId}/wallets/create`;
history.push(createURL);

const { queryAllByText, getAllByTestId, getByTestId, getByText, asFragment } = renderWithRouter(
<Route path="/profiles/:profileId/wallets/create">
<CreateWallet />
</Route>,
{
routes: [createURL],
history,
},
);

await waitFor(() => expect(getByTestId(`CreateWallet__first-step`)).toBeTruthy());
expect(asFragment()).toMatchSnapshot();

const continueButton = getByTestId("CreateWallet__continue-button");
const networkIcons = getAllByTestId("SelectNetwork__NetworkIcon--container");

fireEvent.click(networkIcons[0]); // click ARK
fireEvent.click(networkIcons[1]); // click DARK

expect(getByTestId("SelectNetworkInput__input")).toHaveAttribute("disabled");
for (const networkIcon of getAllByTestId("SelectNetwork__NetworkIcon--container")) {
expect(networkIcon).toHaveAttribute("disabled");
}
expect(continueButton).toHaveAttribute("disabled");

expect(getByTestId("NetworkIcon-ARK-mainnet")).toHaveClass("border-theme-success-200");

await waitFor(() => expect(continueButton).not.toHaveAttribute("disabled"));
});

it("should render", async () => {
const history = createMemoryHistory();
const createURL = `/profiles/${fixtureProfileId}/wallets/create`;
Expand Down Expand Up @@ -297,14 +336,14 @@ describe("CreateWallet", () => {

await waitFor(() => expect(getByTestId(`CreateWallet__fourth-step`)).toBeTruthy());

const historySpy = jest.spyOn(history, "push");
act(() => {
fireEvent.change(getByTestId("CreateWallet__wallet-name"), { target: { value: "Test Wallet" } });
fireEvent.click(getByTestId(`CreateWallet__save-button`));
});

await waitFor(() =>
expect(profile.wallets().values()[0].settings().get(WalletSetting.Alias)).toEqual("Test Wallet"),
);
await waitFor(() => expect(historySpy).toHaveBeenCalledWith(`/profiles/${profile?.id()}/dashboard`));
expect(profile.wallets().values()[0].settings().get(WalletSetting.Alias)).toEqual("Test Wallet");

expect(asFragment()).toMatchSnapshot();
});
Expand Down

0 comments on commit 4760f35

Please sign in to comment.