Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
♻️ simplifies test_callbacks_generating_children
Browse files Browse the repository at this point in the history
  • Loading branch information
byron committed Apr 1, 2019
1 parent 0958494 commit a51bf89
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,33 +310,24 @@ def update_input(value):

self.startServer(app)

output = self.driver.find_element_by_id('output')
output_html = output.get_attribute('innerHTML')

wait_for(lambda: call_count.value == 1)

# Adding new children to the layout should
# call the callbacks immediately to set
# the correct initial state
wait_for(
lambda: (
self.driver.find_element_by_id('output')
.get_attribute('innerHTML') in ['''
<div>
{}
<div id="sub-output-1">
sub input initial value
</div>
</div>'''.replace('\n', '').replace(' ', '').format(input)
for input in [
# html attributes are unordered, so include both versions
'<input id="sub-input-1" value="sub input initial value">',
'<input value="sub input initial value" id="sub-input-1">'
]
]
),
lambda: self.driver.find_element_by_id('output').get_attribute('innerHTML')
pad_input, pad_div = BeautifulSoup(
self.driver.find_element_by_css_selector(
'#_dash-app-content').get_attribute('innerHTML'),
'lxml').select_one('#output > div').contents

self.assertTrue(
pad_input.attrs == {'id': 'sub-input-1', 'value': 'sub input initial value'}
and pad_input.name == 'input',
"pad input is correctly rendered")

self.assertTrue(
pad_div.text == pad_input.attrs['value']
and pad_div.get('id') == 'sub-output-1',
"the sub-output-1 content reflects to sub-input-1 value"
)

self.percy_snapshot(name='callback-generating-function-1')

# the paths should include these new output IDs
Expand All @@ -362,12 +353,15 @@ def update_input(value):

# editing the input should modify the sub output
sub_input = self.driver.find_element_by_id('sub-input-1')
sub_input.send_keys('a')

sub_input.send_keys('deadbeef')
self.wait_for_text_to_equal(
'#sub-output-1',
'sub input initial valuea')
pad_input.attrs['value'] + 'deadbeef')

self.assertEqual(call_count.value, 2)
self.assertEqual(
call_count.value, len('deadbeef') + 1,
"the total updates is initial one + the text input changes")

self.request_queue_assertions(call_count.value + 1)
self.percy_snapshot(name='callback-generating-function-2')
Expand Down Expand Up @@ -1752,7 +1746,7 @@ def update_output(value):

self.wait_for_text_to_equal('#output-1', 'fire request hooks')
self.wait_for_text_to_equal('#output-pre', 'request_pre changed this text!')
self.wait_for_text_to_equal('#output-pre-payload', '{"output":"output-1.children","changedPropIds":["input.value"],"inputs":[{"id":"input","property":"value","value":"fire request hooks"}]}')
self.wait_for_text_to_equal('#output-pre-payload', '{"output":"output-1.children","changedProning: unclosed <socket.socket fd=4ds":["input.value"],"inputs":[{"id":"input","property":"value","value":"fire request hooks"}]}')
self.wait_for_text_to_equal('#output-post', 'request_post changed this text!')
self.wait_for_text_to_equal('#output-post-payload', '{"output":"output-1.children","changedPropIds":["input.value"],"inputs":[{"id":"input","property":"value","value":"fire request hooks"}]}')
self.wait_for_text_to_equal('#output-post-response', '{"props":{"children":"fire request hooks"}}')
Expand Down

0 comments on commit a51bf89

Please sign in to comment.