-
-
Notifications
You must be signed in to change notification settings - Fork 144
Conversation
dash_core_components/Location.py
Outdated
@@ -32,7 +32,7 @@ def __init__(self, id=Component.REQUIRED, pathname=Component.UNDEFINED, search=C | |||
_locals.update(kwargs) # For wildcard attrs | |||
args = {k: _locals[k] for k in _explicit_args if k != 'children'} | |||
|
|||
for k in [u'id']: | |||
for k in ['id']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this is happening to be honest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That the dash generate component, I think I generated from py3 and it added that unicode, I regened from py2 and they were gone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok! That's probably fine then!
test/unit/Input.test.js
Outdated
expect(input.props().value).toBeDefined(); | ||
expect(input.props().value).toEqual(defaultProps.value); | ||
|
||
// test if id is in the actual HTML string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value, not id
test/unit/Input.test.js
Outdated
// props, if dash-renderer is not informed of prop updates | ||
input.setProps({value: 'initial value'}); | ||
|
||
expect(input.find('input').getNode().value).toEqual('new value'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain what is being tested here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! In some cases, dash-renderer
will need to re-render the entire layout. It will, at that point, push the props in the components it wants to render. If, Dash isn't informed of any prop updates (in the case were setProps()
is not being used, but the component's internal state is) then it will push in the old prop, or the initial prop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm. There's one outstanding comment left where it's written 'id' instead of 'value'. Otherwise looks fine.
@valentijnnieman this fix #362, can you add this test to test_integration: def test_input_lose_focus(self):
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Input(
id='input',
value='initial value'
),
dcc.Input(id='input-2'),
html.Div(
html.Div([
1.5,
None,
'string',
html.Div(id='output-1')
])
)
])
@app.callback(Output('output-1', 'children'), [Input('input', 'value')])
def update_output(value):
return value
self.startServer(app)
self.wait_for_text_to_equal('#output-1', 'initial value')
input1 = self.wait_for_element_by_css_selector('#input')
input1.clear()
clicker = self.wait_for_element_by_css_selector('#input-2')
clicker.send_keys('bad')
input1.send_keys('hello world')
time.sleep(1)
self.assertEqual('hello world', input1.get_attribute('value')) 💃 |
@T4rk1n Sorry, I'm not sure what this test is testing, could you explain? I ask because I want to try to split up tests into (1) Unit tests that go into |
It's an integration test for a bug introduced by n_blur and setState in componentWillReceiveProps, when the component lost focus it would prepend the value with the initial value. So I wrote this test that change the focus to another input and assert the first input is still the same value, it failed with the dcc version on master. |
@T4rk1n In that case, the behaviour of new props and |
Testing time used to be not so slow, I investigated and found a few issues. Dropped the test time from ~8:30 avg to ~4:30.. The test is already written and proven to fail, it only adds at most a couple seconds. I've been hunting this bug for two weeks, finally found the culprit and wrote the test with failing behavior with the intention to fix it, was out of idea and noticed you changed things here so I tried and it passed. I'd prefer not having to rewrite it, so I'll merge master after this PR on the failing branch and add it in another PR. Have yet to take a good look at the new unit tests, I don't know much about jest/enzyme. They look good at first glance with the mocked setProps. |
@T4rk1n Yeah the time isn't really that much of an issue for me, it's more that I think that what you're testing in your test is already covered in the unit tests now. I want to really start dividing tests between unit and integration, testing the behaviour of the component in the unit tests and the integration with Dash in the integration tests. That way, we can more easily do test driven development, writing unit tests that fail and make them pass, then assert that the behaviour in Dash stays the same later in the integration tests. It's just a lot easier to do that as opposed to make a change to the code, do a build:js and build:py, and then fire up the Selenium tests each time to make sure it works. With Jest you're testing the |
CHANGELOG.md
Outdated
## [0.36.0] - 2018-11-01 | ||
### Fixed | ||
### Fixe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The d
is gone!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the d
gone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I unno!
src/components/Input.react.js
Outdated
setProps({value: e.target.value}); | ||
} | ||
const newValue = e.target.value; | ||
if (((min || max) && newValue < min) || newValue > max) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check is wrong. 0
is falsy and max is compared always
test/unit/Input.test.js
Outdated
test('Input can not be updated lower than props.min', () => { | ||
input | ||
.find('input') | ||
.simulate('change', {target: {value: props.min - 1}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, these tests are incorrect in so far as they are sending a number to the component when an actual onchange event would send a string
test/unit/Input.test.js
Outdated
input = mount(<Input type="number" value={0} />); | ||
}); | ||
test('Input can be updated', () => { | ||
input.find('input').simulate('change', {target: {value: -1}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it a string
test/unit/Input.test.js
Outdated
test('Input can be updated', () => { | ||
input.find('input').simulate('change', {target: {value: -1}}); | ||
expect(Number(input.find('input').getNode().value)).toEqual(-1); | ||
input.find('input').simulate('change', {target: {value: 100}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it a string
edit:
This PR is becoming much bigger than expected, apologies in advance if the commit history or comments are not super clear.
This updates the
Input
component with a newdebounce
prop that determines whensetProps
is called, should fix #169. It also adds a bunch of unit tests, and fixes an issue where props coming fromdash-renderer
would overwrite the current state of the input. That last bug is more common than we think - components that usestate
as well assetProps
get out of sync often.Here's an example app with the new
debounce
prop:It also fixes #292 by fixing the
step
prop and #173 by not updating value if <min
or >max
.Also renamed a couple of props that weren't being picked up by React, similarly to #348.