Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2676 from bandprotocol/cypress-setup
Browse files Browse the repository at this point in the history
Scan: Setup cypress with send testcase to scan
  • Loading branch information
pzshine committed Oct 2, 2020
2 parents 9e3d6ba + d32961d commit 18774ae
Show file tree
Hide file tree
Showing 17 changed files with 1,102 additions and 64 deletions.
53 changes: 35 additions & 18 deletions .github/workflows/scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,38 @@ jobs:
working-directory: ./scan

steps:
- name: Code Checkout
uses: actions/checkout@v2

- name: Cache node_modules
id: scan-node-modules-cache
uses: actions/cache@v1
with:
path: scan/node_modules
key: ${{ runner.OS }}-scan-test-${{ hashFiles('**/yarn.lock') }}

- name: Run yarn
if: steps.scan-node-modules-cache.outputs.cache-hit != 'true'
run: yarn
working-directory: ${{env.working-directory}}

- name: Run yarn test
run: yarn test
working-directory: ${{env.working-directory}}
- name: Code Checkout
uses: actions/checkout@v2

- name: Cache node_modules
id: scan-node-modules-cache
uses: actions/cache@v1
with:
path: scan/node_modules
key: ${{ runner.OS }}-scan-test-${{ hashFiles('**/yarn.lock') }}

- name: Yarn install deps with node_modules cache
run: |
yarn install --frozen-lockfile
if: steps.scan-node-modules-cache.outputs.cache-hit != 'true'
working-directory: ${{env.working-directory}}

- name: Run yarn build
run: yarn build
env:
RPC_URL: "https://d3n.bandprotocol.com/rest"
GRAPHQL_URL: "wss://d3n.bandprotocol.com/v1/graphql"
NETWORK: "GUANYU38"
working-directory: ${{env.working-directory}}

- name: Run install cypress
run: yarn cypress install
working-directory: ${{env.working-directory}}

- name: Run yarn test
run: yarn test
working-directory: ${{env.working-directory}}

- name: Run yarn integration-test
run: yarn integration-test
working-directory: ${{env.working-directory}}
1 change: 1 addition & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- (impv) [\#2689](https://github.com/bandprotocol/bandchain/pull/2689) Styled the top part of account index page
- (bugs) [\#2687](https://github.com/bandprotocol/bandchain/pull/2687) Fixed NaN number (Urgent)
- (impv) [\#2684](https://github.com/bandprotocol/bandchain/pull/2684) Adjust validator voted from 250 to 100
- (impv) [\#2676](https://github.com/bandprotocol/bandchain/pull/2676) Setup cypress to scan, added new sendToken testcase
- (bugs) [\#2673](https://github.com/bandprotocol/bandchain/pull/2673) Fixed sorting on moniker with emoji
- (impv) [\#2672](https://github.com/bandprotocol/bandchain/pull/2672) Hid the proposal desc from tx index page table
- (impv) [\#2671](https://github.com/bandprotocol/bandchain/pull/2671) Adjusted tooltip width and added webapi
Expand Down
6 changes: 6 additions & 0 deletions scan/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"baseUrl": "http://localhost:3000/",
"pluginsFile": false,
"fixturesFolder": false,
"defaultCommandTimeout": 10000
}
36 changes: 36 additions & 0 deletions scan/cypress/integration/send_action.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// <reference types="cypress" />

describe("Login", () => {
beforeEach(() => {
cy.visit("/");
});

it("Should have s address on account panel", () => {
cy.get('[id="connectButton"]').click();
cy.get('[id="mnemonicInput"]').type("s");
cy.get('[id="mnemonicConnectButton"] > button').click();
cy.get('[id="userInfoButton"]').click();
cy.get('[id="addressWrapper"] > a > span').should(
"contain",
"band1jrhuqrymzt4mnvgw8cvy3s9zhx3jj0dq30qpte"
);
});
});

describe("Send", () => {
it("Status should be Success", () => {
cy.get('[id="getFreeButton"] > button').click();
cy.get('[id="sendToken"] > button').wait(500).contains("Send").click();
cy.get('[id="recipientAddressInput"]')
.wait(1000)
.type("band1jrhuqrymzt4mnvgw8cvy3s9zhx3jj0dq30qpte")
.get('[id="sendAmountInput"]')
.type("2");
cy.get('[id="nextButton"]').contains("Next").click();
cy.get('[id="broadcastButton"]').click();
cy.get('[id="successMsgContainer"] > span').should(
"contain",
"Broadcast Transaction Success"
);
});
});
25 changes: 25 additions & 0 deletions scan/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions scan/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
16 changes: 13 additions & 3 deletions scan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"scripts": {
"build": "rm -rf dist/ && bsb -make-world && parcel build index.html --no-source-maps --no-cache",
"start": "bsb -make-world -w",
"test:dev": "yarn jest --coverage",
"test": "yarn build && yarn test:dev"
"test": "yarn jest --coverage",
"cy:run": "cypress run",
"serve:build": "serve -s dist -l 3000",
"integration-test": "start-server-and-test 'yarn run serve:build' http://localhost:3000 cy:run"
},
"dependencies": {
"@apollo/react-hooks": "^3.1.5",
Expand Down Expand Up @@ -53,12 +55,15 @@
"bs-platform": "^7.0.1",
"bsb-js": "^1.1.7",
"css-loader": "^4.3.0",
"cypress": "^5.2.0",
"html-webpack-plugin": "^4.5.0",
"parcel-bundler": "^1.12.4",
"style-loader": "^1.2.1",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
"webpack-dev-server": "^3.11.0",
"serve": "^11.3.0",
"start-server-and-test": "^1.11.0"
},
"customDistStructure": {
"config": {
Expand All @@ -71,5 +76,10 @@
".gif"
]
}
},
"jest": {
"testPathIgnorePatterns": [
"cypress"
]
}
}
2 changes: 2 additions & 0 deletions scan/src/components/EnhanceTxInput.re
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ let make =
~placeholder="",
~inputType="text",
~autoFocus=false,
~id,
) => {
let (status, setStatus) = React.useState(_ => Untouched);

Expand All @@ -101,6 +102,7 @@ let make =
<Text value=msg size=Text.Lg spacing={Text.Em(0.03)} nowrap=true block=true />
<div className={Styles.rightContainer(width)}>
<input
id
value={inputData.text}
className={Css.merge([Styles.input, code ? Styles.code : ""])}
placeholder
Expand Down
48 changes: 27 additions & 21 deletions scan/src/components/UserAccount.re
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module ConnectBtn = {
[@react.component]
let make = (~connect) => {
<div
id="connectButton"
className={Css.merge([
CssHelper.flexBox(~justify=`center, ~align=`center, ()),
CssHelper.clickable,
Expand Down Expand Up @@ -85,31 +86,35 @@ module FaucetBtn = {
let (isRequest, setIsRequest) = React.useState(_ => false);
isRequest
? <img src=Images.loadingCircles className=Styles.loading />
: <Button
px=20
py=5
variant=Button.Outline
onClick={_ => {
setIsRequest(_ => true);
let _ =
AxiosFaucet.request({address: address |> Address.toBech32, amount: 10_000_000})
|> Js.Promise.then_(_ => {
setIsRequest(_ => false);
Js.Promise.resolve();
});
();
}}>
<Text value="Get 10 Testnet BAND" weight=Text.Medium nowrap=true />
</Button>;
: <div id="getFreeButton">
<Button
px=20
py=5
variant=Button.Outline
onClick={_ => {
setIsRequest(_ => true);
let _ =
AxiosFaucet.request({address: address |> Address.toBech32, amount: 10_000_000})
|> Js.Promise.then_(_ => {
setIsRequest(_ => false);
Js.Promise.resolve();
});
();
}}>
<Text value="Get 10 Testnet BAND" weight=Text.Medium nowrap=true />
</Button>
</div>;
};
};

module SendBtn = {
[@react.component]
let make = (~send) => {
<Button px=20 py=5 onClick={_ => {send()}}>
<Text value="Send" weight=Text.Medium nowrap=true block=true />
</Button>;
<div id="sendToken">
<Button px=20 py=5 onClick={_ => {send()}}>
<Text value="Send" weight=Text.Medium nowrap=true block=true />
</Button>
</div>;
};
};

Expand All @@ -120,7 +125,7 @@ module Balance = {

<div className={CssHelper.flexBox(~justify=`spaceBetween, ())}>
<Text value="Balance" weight=Text.Medium />
<div className={CssHelper.flexBox()}>
<div className={CssHelper.flexBox()} id="bandBalance">
<Text
value={
switch (accountSub) {
Expand Down Expand Up @@ -156,13 +161,14 @@ let make = () => {
| Some({address}) =>
<div className={Css.merge([CssHelper.flexBox(~justify=`flexEnd, ()), Styles.container])}>
<div
id="userInfoButton"
className={Css.merge([CssHelper.flexBox(), CssHelper.clickable])}
onClick={_ => setShow(prev => !prev)}>
<div className=Styles.oval> <Icon name="fal fa-user" color=Colors.white /> </div>
<HSpacing size=Spacing.sm />
<Icon name="fas fa-caret-down" color=Colors.bandBlue />
</div>
<div className={Styles.profileCard(show)}>
<div className={Styles.profileCard(show)} id="addressWrapper">
<AddressRender address position=AddressRender.Text />
<VSpacing size={`px(16)} />
<div className=Styles.innerProfileCard>
Expand Down
3 changes: 2 additions & 1 deletion scan/src/components/modal/connect/ConnectWithMnemonic.re
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ let make = (~chainID) => {
<Text value="Enter Your Mnemonic" size=Text.Md weight=Text.Medium />
<VSpacing size=Spacing.sm />
<input
id="mnemonicInput"
autoFocus=true
value=mnemonic
className=Styles.inputBar
Expand All @@ -105,7 +106,7 @@ let make = (~chainID) => {
}
/>
<VSpacing size={`px(35)} />
<div className={CssHelper.flexBox(~justify=`flexEnd, ())}>
<div id="mnemonicConnectButton" className={CssHelper.flexBox(~justify=`flexEnd, ())}>
<Button px=20 py=8 onClick={_ => createMnemonic()}>
<Text value="Connect" weight=Text.Bold size=Text.Md color=Colors.white />
</Button>
Expand Down
1 change: 1 addition & 0 deletions scan/src/components/modal/submitTx/DelegateMsg.re
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ let make = (~address, ~validator, ~setMsgsOpt) => {
inputType="number"
code=true
autoFocus=true
id="delegateAmountInput"
/>;
| _ => <EnhanceTxInput.Loading msg="Delegate Amount (BAND)" width=300 />
}}
Expand Down
3 changes: 2 additions & 1 deletion scan/src/components/modal/submitTx/PreviewJsonStep.re
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ let make = (~rawTx, ~onBack, ~account: AccountContext.t) => {
</div>
<div
className=Styles.btn
id="broadcastButton"
onClick={_ => {
dispatchModal(DisableExit);
setState(_ => Signing);
Expand Down Expand Up @@ -192,7 +193,7 @@ let make = (~rawTx, ~onBack, ~account: AccountContext.t) => {
</div>
| Success(txHash) =>
<div className=Styles.resultContainer>
<div className=Styles.rFlex>
<div className=Styles.rFlex id="successMsgContainer">
<img src=Images.success2 className=Styles.resultIcon />
<HSpacing size=Spacing.md />
<Text value="Broadcast Transaction Success" weight=Text.Semibold />
Expand Down
1 change: 1 addition & 0 deletions scan/src/components/modal/submitTx/RedelegateMsg.re
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ let make = (~address, ~validator, ~setMsgsOpt) => {
inputType="number"
code=true
autoFocus=true
id="redelegateAmountInput"
/>;
| _ => <EnhanceTxInput.Loading msg="Amount (BAND)" width=300 />
}}
Expand Down
2 changes: 2 additions & 0 deletions scan/src/components/modal/submitTx/SendMsg.re
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ let make = (~address, ~receiver, ~setMsgsOpt) => {
parse=Parse.address
msg="Recipient Address"
code=true
id="recipientAddressInput"
placeholder="Insert recipient address"
autoFocus={
switch (toAddress.text) {
Expand Down Expand Up @@ -99,6 +100,7 @@ let make = (~address, ~receiver, ~setMsgsOpt) => {
| _ => true
}
}
id="sendAmountInput"
/>;
| _ => <EnhanceTxInput.Loading msg="Send Amount (BAND)" width=300 />
}}
Expand Down
2 changes: 2 additions & 0 deletions scan/src/components/modal/submitTx/SubmitTxModal.re
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ module SubmitTxStep = {
msg="Memo (optional)"
placeholder="Insert memo"
code=true
id="memoInput"
/>
<VSpacing size=Spacing.lg />
<VSpacing size=Spacing.md />
Expand All @@ -146,6 +147,7 @@ module SubmitTxStep = {
<VSpacing size=Spacing.lg />
<VSpacing size=Spacing.md />
<button
id="nextButton"
className=Styles.nextBtn
disabled={msgsOpt->Belt.Option.isNone}
onClick={_ => {
Expand Down
1 change: 1 addition & 0 deletions scan/src/components/modal/submitTx/UndelegateMsg.re
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ let make = (~address, ~validator, ~setMsgsOpt) => {
inputType="number"
code=true
autoFocus=true
id="undelegateAmountInput"
/>;
| _ => <EnhanceTxInput.Loading msg="Undelegate Amount (BAND)" width=300 />
}}
Expand Down
Loading

0 comments on commit 18774ae

Please sign in to comment.