fix value e2e

pull/4355/head
yann300 11 months ago
parent 7c5c00687c
commit 4fb76840c4
  1. 9
      apps/remix-ide-e2e/src/commands/validateValueInput.ts
  2. 10
      apps/remix-ide-e2e/src/helpers/init.ts
  3. 7
      apps/remix-ide-e2e/src/tests/runAndDeploy.test.ts
  4. 37
      libs/remix-ui/run-tab/src/lib/components/value.tsx

@ -5,9 +5,12 @@ class ValidateValueInput extends EventEmitter {
command (this: NightwatchBrowser, selector: string, valueTosSet: string, expectedValue: string) {
const browser = this.api
browser.perform((done) => {
browser.clearValue(selector)
.pause(2000)
.setValue(selector, valueTosSet).pause(2000)
browser
.clearValue(selector)
.execute((selector) => {
(document.querySelector(selector) as any).focus()
}, [selector], () => { })
.setValue(selector, valueTosSet)
.execute(function (selector) {
const elem = document.querySelector(selector) as HTMLInputElement
return elem.value

@ -40,12 +40,16 @@ export default function (browser: NightwatchBrowser, callback: VoidFunction, url
}})
.perform(() => {
browser.execute(function () {
(window as any).logs = []
(window as any).logs = [];
(console as any).browserLog = console.log;
(console as any).browserError = console.error
console.log = function () {
(window as any).logs.push(JSON.stringify(arguments))
(window as any).logs.push(JSON.stringify(arguments));
(console as any).browserLog(...arguments)
}
console.error = function () {
(window as any).logs.push(JSON.stringify(arguments))
(window as any).logs.push(JSON.stringify(arguments));
(console as any).browserError(...arguments)
}
})
})

@ -25,9 +25,10 @@ module.exports = {
'Should load run and deploy tab and check value validation #group1': function (browser: NightwatchBrowser) {
browser.waitForElementPresent('*[data-id="remixIdeSidePanel"]')
.assert.containsText('*[data-id="sidePanelSwapitTitle"]', 'DEPLOY & RUN TRANSACTIONS')
.validateValueInput('#value', '0000', '0')
.validateValueInput('#value', '', '0')
.validateValueInput('#value', 'dragon', '0')
.validateValueInput('*[data-id="dandrValue"]', '999', '999')
.validateValueInput('*[data-id="dandrValue"]', '0000', '0')
.validateValueInput('*[data-id="dandrValue"]', '1.3', '0') // no decimal
// .validateValueInput('*[data-id="dandrValue"]', 'dragon', '0') // only numbers
},
'Should sign message using account key #group2': function (browser: NightwatchBrowser) {

@ -6,49 +6,43 @@ import {CustomTooltip, isNumeric} from '@remix-ui/helper'
import {ValueProps} from '../types'
export function ValueUI(props: ValueProps) {
const [sendValue, setSendValue] = useState<string>(props.sendValue)
const inputValue = useRef<HTMLInputElement>({} as HTMLInputElement)
const inputValue = useRef<HTMLInputElement>({} as HTMLInputElement)
useEffect(() => {
sendValue !== props.sendValue && props.setSendValue(sendValue)
}, [sendValue])
useEffect(() => {
if(props.sendValue !== sendValue) {
setSendValue(props.sendValue)
if (props.sendValue !== inputValue.current.value) {
inputValue.current.value = props.sendValue
}
},[props.sendValue])
const validateInputKey = (e) => {
// preventing not numeric keys
// preventing 000 case
if (!isNumeric(e.key) || (e.key === '0' && !parseInt(inputValue.current.value) && inputValue.current.value.length > 0)) {
e.preventDefault()
}
}
const validateValue = (e) => {
console.log('validateValue', e.target.value)
const value = e.target.value
if (!value) {
// assign 0 if given value is
// - empty
return setSendValue('0')
inputValue.current.value = '0'
props.setSendValue('0')
return
}
let v
try {
v = new BN(value, 10)
setSendValue(v.toString(10))
props.setSendValue(v.toString(10))
} catch (e) {
// assign 0 if given value is
// - not valid (for ex 4345-54)
// - contains only '0's (for ex 0000) copy past or edit
setSendValue('0')
inputValue.current.value = '0'
props.setSendValue('0')
}
// if giveen value is negative(possible with copy-pasting) set to 0
if (v.lt(0)) setSendValue('0')
if (v.lt(0)) {
inputValue.current.value = '0'
props.setSendValue('0')
}
}
return (
@ -67,9 +61,8 @@ export function ValueUI(props: ValueProps) {
className="form-control udapp_gasNval udapp_col2"
id="value"
data-id="dandrValue"
onKeyPress={validateInputKey}
onChange={validateValue}
value={sendValue}
value={props.sendValue}
/>
</CustomTooltip>

Loading…
Cancel
Save