Skip to content
This repository was archived by the owner on Dec 13, 2019. It is now read-only.

[greenboard] Adds Deposit scenario #2135

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
94a74b8
.gitignore using extension symlink + user data dir
joelalejandro Aug 5, 2019
53cb5e3
excluding e2e.log from main .gitignore
joelalejandro Aug 5, 2019
7fb4215
moved chrome profile to local dir
joelalejandro Aug 5, 2019
6665b20
printing e2e logs to e2e.log
joelalejandro Aug 5, 2019
011893a
added StateCollector for handling LS
joelalejandro Aug 5, 2019
e01e7db
prepare by flow type, test order, login selectors
joelalejandro Aug 5, 2019
7235123
added login scenario
joelalejandro Aug 5, 2019
50bf3c6
cleaned up onboarding, added LS collector
joelalejandro Aug 5, 2019
82991f1
added balance check for login flow
joelalejandro Aug 5, 2019
b5a8ff4
clearing buffer on StateCollector is optional
joelalejandro Aug 5, 2019
e773097
disambiguated names for deposit/withdraw inputs
joelalejandro Aug 5, 2019
0535831
added clearInput() method
joelalejandro Aug 5, 2019
7a18de5
added support to detect Balance screen
joelalejandro Aug 5, 2019
fa16d2b
updated deposit/withdraw selectors
joelalejandro Aug 5, 2019
338dce6
added deposit test case
joelalejandro Aug 5, 2019
0462319
added LS collection
joelalejandro Aug 5, 2019
d1df1dd
generalized accountDepositForm automation
joelalejandro Aug 5, 2019
46f9db0
refactored StateCollector, fixed LS injection
joelalejandro Aug 7, 2019
a7c3f89
updated test:e2e:setup to use MM develop
joelalejandro Aug 7, 2019
45037f9
updated symbol names for inject/collect
joelalejandro Aug 7, 2019
e5bed18
Merge branch 'joel/e2e-login' of github.com:counterfactual/monorepo i…
joelalejandro Aug 7, 2019
3f5d1e7
updated to use new LS collector
joelalejandro Aug 7, 2019
a6f8203
waiting for channels-tree if coming from balance
joelalejandro Aug 7, 2019
8a90a0f
Merge branch 'master' of github.com:counterfactual/monorepo into joel…
joelalejandro Aug 7, 2019
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
47 changes: 47 additions & 0 deletions packages/greenboard/tests/deposit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
ACCOUNT_BALANCE_SELECTORS,
LAYOUT_HEADER_SELECTORS
} from "../utils/counterfactual-wallet-selectors";
import { TestBrowser } from "../utils/test-browser";
import { CounterfactualScreenName, MetamaskFlowType } from "../utils/types";

jest.setTimeout(100000);

let browser: TestBrowser;

beforeAll(async () => {
browser = new TestBrowser();
await browser.start();
await browser.prepare(MetamaskFlowType.ReturningUser);
});

it("logs in with an existing account, goes to /balance, makes a deposit", async () => {
const {
loginButton,
balanceContainer,
balanceText
} = LAYOUT_HEADER_SELECTORS;
const { depositAmountInput } = ACCOUNT_BALANCE_SELECTORS;

await browser.injectIntoMetamaskLocalStorage();
await browser.switchToWallet();
await browser.clickOnElement(loginButton);
await browser.signTransaction();
await browser.waitForLoginToBeFinished();
await browser.clickOnElement(balanceContainer);
await browser.waitForElement(depositAmountInput);
await browser.fillAccountDepositFormAndSubmit();

expect(await browser.getCurrentScreenName()).toEqual(
CounterfactualScreenName.Channels
);
expect(await browser.getTextFromElement(balanceText)).toEqual("0.2 ETH");
});

afterAll(async () => {
// We collect data again so the Withdraw scenario has a coherent
// Node state for an account with a balance of 0.2 ETH.
await browser.collectMetamaskLocalStorage();

await browser.closeBrowser();
});
14 changes: 13 additions & 1 deletion packages/greenboard/utils/counterfactual-wallet-selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const ACCOUNT_REGISTRATION_SELECTORS = {

export const ACCOUNT_DEPOSIT_SELECTORS = {
formTitle: By.css(".widget-header"),
amountInput: By.css("[data-test-selector='amount-input']"),
amountInput: By.css("[data-test-selector='deposit-amount-input']"),
proceedButton: By.css("[data-test-selector='deposit-button']")
};

Expand All @@ -21,5 +21,17 @@ export const LAYOUT_HEADER_SELECTORS = {
logoContainer: By.css(".header > .header-content > .logo-container"),
accountContainer: By.css("header > .header-content .account-container"),
userNameText: By.css("[data-test-selector='info-user'] .info-content"),
balanceContainer: By.css("[data-test-selector='info-balance']"),
balanceText: By.css("[data-test-selector='info-balance'] .info-content")
};

export const ACCOUNT_BALANCE_SELECTORS = {
depositAmountInput: By.css("[data-test-selector='deposit-amount-input']"),
depositProceedButton: By.css("[data-test-selector='deposit-button']"),
withdrawAmountInput: By.css("[data-test-selector='withdraw-amount-input']"),
withdrawProceedButton: By.css("[data-test-selector='withdraw-button']")
};

export const STATE_CHANNELS_SELECTORS = {
channelTreesContainer: By.css(".channel-trees")
};
43 changes: 39 additions & 4 deletions packages/greenboard/utils/test-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require("chromedriver");
import { resolve } from "path";
import {
Builder,
Key,
Locator,
until,
WebDriver,
Expand All @@ -17,7 +18,8 @@ import {
import {
ACCOUNT_DEPOSIT_SELECTORS,
ACCOUNT_REGISTRATION_SELECTORS,
LAYOUT_HEADER_SELECTORS
LAYOUT_HEADER_SELECTORS,
STATE_CHANNELS_SELECTORS
} from "./counterfactual-wallet-selectors";
import {
DEPOSIT_SELECTORS,
Expand All @@ -44,6 +46,15 @@ import {

export const EXTENSION_INSPECTOR = "chrome://inspect/#extensions";
export const LOCATOR_TIMEOUT = 10000;
export const DEPOSIT_TIMEOUT = 90000;

export const METAMASK_ETH_ADDRESS =
"0x212C90fdF90BbD5E9b352b9d2B086f2666CFEED6";
export const METAMASK_MNEMONIC =
"mistake cash photo pond little nerve neutral adapt item kite radar tray";
export const METAMASK_PASSWORD = "The Cake Is A Lie";
export const COUNTERFACTUAL_USER_USERNAME = "teapot";
export const COUNTERFACTUAL_USER_EMAIL_ADDRESS = "[email protected]";

export const METAMASK_ETH_ADDRESS =
"0x212C90fdF90BbD5E9b352b9d2B086f2666CFEED6";
Expand Down Expand Up @@ -471,14 +482,20 @@ export class TestBrowser {
* @todo Add check for texts "Transferring funds", "Collateralizing deposit".
*/
async fillAccountDepositFormAndSubmit() {
const { formTitle, proceedButton } = ACCOUNT_DEPOSIT_SELECTORS;
const { proceedButton } = ACCOUNT_DEPOSIT_SELECTORS;
const { logoContainer } = LAYOUT_HEADER_SELECTORS;
const { channelTreesContainer } = STATE_CHANNELS_SELECTORS;

await this.waitForElementToHaveText(formTitle, "Fund your account");
await this.clickOnElement(proceedButton);
await this.waitForElementToHaveText(proceedButton, "Check your wallet");
await this.confirmDeposit();
await this.waitForElement(logoContainer, 90000);
await this.waitForElement(logoContainer, DEPOSIT_TIMEOUT);

const currentScreen = await this.getCurrentScreenName();

if (currentScreen === CounterfactualScreenName.Balance) {
await this.waitForElement(channelTreesContainer, DEPOSIT_TIMEOUT);
}
}

/**
Expand All @@ -505,6 +522,10 @@ export class TestBrowser {
return CounterfactualScreenName.Channels;
}

if (url.includes("balance")) {
return CounterfactualScreenName.Balance;
}

return CounterfactualScreenName.Welcome;
}

Expand Down Expand Up @@ -608,9 +629,23 @@ export class TestBrowser {
* @param selector
*/
async typeOnInput(selector: Locator, value: string) {
await this.clearInput(selector);
await this.getElement(selector).sendKeys(value);
}

/**
* Clears an input's value by selecting all text and pressing
* the BACKSPACE key.
*
* @param selector
*/
async clearInput(selector: Locator) {
await this.getElement(selector).sendKeys(
Key.chord(Key.CONTROL, "A"),
Key.BACK_SPACE
);
}

/**
* Returns the text contained in an element found by the selector.
*
Expand Down
7 changes: 6 additions & 1 deletion packages/greenboard/utils/test-sequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* Keep in mind that if you create a new scenario, you'll need to include it
* on this list, otherwise it won't be executed.
*/
const testSequence = ["tests/onboarding.spec.ts", "tests/login.spec.ts"];
const testSequence = [
"tests/onboarding.spec.ts",
"tests/login.spec.ts",
"tests/deposit.spec.ts"
];

// Import the default test sequencer.
const Sequencer = require("@jest/test-sequencer").default;
Expand All @@ -15,6 +19,7 @@ module.exports = class extends Sequencer {
* Sorts the tests by order of appearance in the `testSequence` array.
*/
sort(tests) {
// TODO: Add the ability to run tests in dependency order.
return testSequence.map(testName =>
tests.find(test => test.path.endsWith(testName))
);
Expand Down
3 changes: 2 additions & 1 deletion packages/greenboard/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const enum CounterfactualScreenName {
Welcome = "welcome",
OnboardingRegistration = "onboarding:register",
OnboardingDeposit = "onboarding:deposit",
Channels = "channels"
Channels = "channels",
Balance = "balance"
}

export type StringHashMap = { [key: string]: string };
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class AccountDeposit extends React.Component<
className="input--balance"
type="number"
units={nodeAddresses}
name="amount"
name="deposit-amount"
min={0.02}
max={Number(ethereumBalance)}
value={formatEther(amount)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class AccountWithdraw extends React.Component<
className="input--balance"
type="number"
units={nodeAddresses}
name="amount"
name="withdraw-amount"
min={0.02}
max={Number(ethereumBalance)}
value={formatEther(amount)}
Expand All @@ -139,7 +139,7 @@ export class AccountWithdraw extends React.Component<
<div className="error">Ups! something broke</div>
) : null}
<FormButton
name="deposit"
name="withdraw"
type="button"
className="button"
spinner={loading}
Expand Down