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

Commit

Permalink
Merge pull request MetaMask#229 from poanetwork/bool-select
Browse files Browse the repository at this point in the history
(Feature) Select input for Boolean type for contract type acc
  • Loading branch information
vbaranov committed Dec 26, 2018
2 parents 42936f2 + 42f2af1 commit 67466de
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 29 deletions.
76 changes: 63 additions & 13 deletions old-ui/app/components/send/send-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class SendTransactionField extends Component {
this.state = {
val: props.defaultValue,
}
this.timerID = null
}

static propTypes = {
Expand All @@ -40,18 +39,57 @@ class SendTransactionField extends Component {
placeholder={this.props.placeholder}
value={this.state.val}
disabled={this.props.disabled}
onChange={e => {
onChange={(e) => {
this.setState({
val: e.target.value,
})
this.props.onChange(e)
this.props.onChange(e.target.value)
}}
style={{ marginTop: '5px' }}
/>
)
}
}

class SendTransactionInputSelect extends Component {
constructor (props) {
super(props)
this.state = {
val: props.defaultValue,
}
}

static propTypes = {
defaultValue: PropTypes.string,
value: PropTypes.string,
onChange: PropTypes.func,
}

render () {
return (
<Select
clearable={false}
value={this.state.val}
options={[{
label: 'false',
value: 'false',
}, {
label: 'true',
value: 'true',
}]}
onChange={(opt) => {
this.setState({
val: opt.value,
})
this.props.onChange(opt.value)
}
}
style={{ marginTop: '5px' }}
/>
)
}
}

class SendTransactionScreen extends PersistentForm {
constructor (props) {
super(props)
Expand All @@ -71,6 +109,7 @@ class SendTransactionScreen extends PersistentForm {
copyDisabled: true,
}

this.timerID = null
PersistentForm.call(this)
}

Expand Down Expand Up @@ -184,16 +223,27 @@ class SendTransactionScreen extends PersistentForm {
})
}
}
const field = (
<SendTransactionField
key={Math.random()}
ind={ind}
disabled={!isInput}
placeholder={params.type}
defaultValue={defaultValue}
onChange={e => isInput ? this.handleInputChange(e.target.value, params.type, ind) : null}
/>
)
let field
if (params.type === 'bool' && isInput) {
field = (
<SendTransactionInputSelect
ind={ind}
defaultValue={defaultValue}
onChange={val => this.handleInputChange(val, params.type, ind)}
/>
)
} else {
field = (
<SendTransactionField
key={Math.random()}
ind={ind}
disabled={!isInput}
placeholder={params.type}
defaultValue={defaultValue}
onChange={val => isInput ? this.handleInputChange(val, params.type, ind) : null}
/>
)
}
const fieldObj = (
<div key={`method_label_container_${ind}`}>
{label}
Expand Down
1 change: 1 addition & 0 deletions test/e2e/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ async function verboseReportOnFailure ({ browser, driver, title }) {
const htmlSource = await driver.getPageSource()
await fs.writeFile(`${filepathBase}-dom.html`, htmlSource)
}

37 changes: 21 additions & 16 deletions test/e2e/metamask.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ describe('Metamask popup page', async function () {
})
})
describe('Check output for data type : BOOLEAN', () => {

it("Select method 'returnBoolean'", async function () {
const field = await waitUntilShowUp(screens.executeMethod.selectArrow)
await field.click()
Expand All @@ -542,11 +541,14 @@ describe('Metamask popup page', async function () {
assert.equal(list.length, 22, "drop down menu isn't displayed")
})

it('Fill out input parameter field, value is TRUE', async function () {
await waitUntilShowUp(screens.executeMethod.fieldParameter)
const fields = await driver.findElements(screens.executeMethod.fieldParameter)
assert.notEqual(fields[0], false, "field parameter#1 isn't displayed")
await fields[0].sendKeys('true')
it('Select value TRUE from dropdown menu', async function () {
const arrows = await driver.findElements(screens.executeMethod.selectArrow)
await arrows[1].click()
await waitUntilShowUp(screens.executeMethod.items)
const list = await driver.findElements(screens.executeMethod.items)
assert.equal(await list[1].getText(), 'true', 'TRUE menu item: incorrect text')
assert.equal(list.length, 2, "drop down menu isn't displayed")
await list[1].click()
})

it("Click button 'Call data' ", async function () {
Expand All @@ -560,16 +562,19 @@ describe('Metamask popup page', async function () {
await delay(3000)
await waitUntilShowUp(screens.executeMethod.fieldOutput)
const fields = await driver.findElements(screens.executeMethod.fieldOutput)
assert.notEqual(fields[1], false, "field 'Output' isn't displayed")
const text = await waitUntilHasValue(fields[1])
assert.notEqual(fields[0], false, "field 'Output' isn't displayed")
const text = await waitUntilHasValue(fields[0])
assert.equal(text, 'true', 'incorrect value was returned')
})
it('Fill out input parameter field, value is FALSE ', async function () {
await waitUntilShowUp(screens.executeMethod.fieldParameter)
const fields = await driver.findElements(screens.executeMethod.fieldParameter)
assert.notEqual(fields[0], false, "field parameter#1 isn't displayed")
await clearField(fields[0])
await fields[0].sendKeys('false')

it('Select value FALSE from dropdown menu', async function () {
const arrows = await driver.findElements(screens.executeMethod.selectArrow)
await arrows[1].click()
await waitUntilShowUp(screens.executeMethod.items)
const list = await driver.findElements(screens.executeMethod.items)
assert.equal(await list[0].getText(), 'false', 'FALSE menu item: incorrect text')
assert.equal(list.length, 2, "drop down menu isn't displayed")
await list[0].click()
})

it("Click button 'Call data' ", async function () {
Expand All @@ -583,8 +588,8 @@ describe('Metamask popup page', async function () {
await delay(3000)
await waitUntilShowUp(screens.executeMethod.fieldOutput)
const fields = await driver.findElements(screens.executeMethod.fieldOutput)
assert.notEqual(fields[1], false, "field 'Output' isn't displayed")
const text = await waitUntilHasValue(fields[1])
assert.notEqual(fields[0], false, "field 'Output' isn't displayed")
const text = await waitUntilHasValue(fields[0])
assert.equal(text, 'false', 'incorrect value was returned')
})
it('icon copy cliboard is displayed and clickable', async function () {
Expand Down

0 comments on commit 67466de

Please sign in to comment.