def test_js_on_click_executes(self, bokeh_model_page) -> None: button = Button(css_classes=['foo']) button.js_on_click(CustomJS(code=RECORD("clicked", "true"))) page = bokeh_model_page(button) button = page.driver.find_element_by_css_selector('.foo .bk-btn') button.click() results = page.results assert results == {'clicked': True} assert page.has_no_console_errors()
def test_js_on_click_executes(self, bokeh_model_page): button = Button(css_classes=['foo']) button.js_on_click(CustomJS(code=RECORD("clicked", "true"))) page = bokeh_model_page(button) button = page.driver.find_element_by_css_selector('.foo .bk-btn') button.click() results = page.results assert results == {'clicked': True} assert page.has_no_console_errors()
def test_callback_property_executes(self, bokeh_model_page): button = Button(css_classes=['foo']) button.callback = CustomJS(code=RECORD("clicked", "true")) page = bokeh_model_page(button) button = page.driver.find_element_by_class_name('foo') button.click() results = page.results assert results == {'clicked': True} assert page.has_no_console_errors()
def test_data_table_selected_highlighting(output_file_url, selenium, screenshot): # Create a DataTable and Button that sets a selection data = dict(x = list(range(10))) source = ColumnDataSource(data=data) columns = [TableColumn(field="x", title="X")] data_table = DataTable(source=source, columns=columns) button = Button(label="Click") button.callback = CustomJS(args=dict(source=source), code=""" source['selected']['1d'].indices = [1, 2] source.change.emit(); """) # Save the table and start the test save(column(data_table, button)) selenium.get(output_file_url) assert has_no_console_errors(selenium) # Click the button to select the rows button = selenium.find_element_by_class_name('bk-bs-btn') button.click() screenshot.assert_is_valid()
def test_updates_when_visibility_is_toggled(self, single_plot_page) -> None: source = ColumnDataSource(dict(x=[1, 2], y1=[0, 1], y2=[10, 11])) plot = Plot(plot_height=400, plot_width=400, x_range=DataRange1d(), y_range=DataRange1d(only_visible=True), min_border=0) plot.add_glyph(source, Circle(x='x', y='y1')) glyph = plot.add_glyph(source, Circle(x='x', y='y2')) code = RECORD("yrstart", "p.y_range.start", final=False) + RECORD( "yrend", "p.y_range.end") plot.add_tools( CustomAction(callback=CustomJS(args=dict(p=plot), code=code))) plot.toolbar_sticky = False button = Button(css_classes=['foo']) button.js_on_click( CustomJS(args=dict(glyph=glyph), code="glyph.visible=false")) page = single_plot_page(column(plot, button)) page.click_custom_action() results = page.results assert results['yrstart'] <= 0 assert results['yrend'] >= 11 button = page.driver.find_element_by_css_selector('.foo .bk-btn') button.click() page.click_custom_action() results = page.results assert results['yrstart'] <= 0 assert results['yrend'] < 5 assert page.has_no_console_errors()
def test_updates_when_visibility_is_toggled( self, single_plot_page: SinglePlotPage) -> None: source = ColumnDataSource(dict(x=[1, 2], y1=[0, 1], y2=[10, 11])) plot = Plot(height=400, width=400, x_range=DataRange1d(), y_range=DataRange1d(only_visible=True), min_border=0) plot.add_glyph(source, Circle(x='x', y='y1')) glyph = plot.add_glyph(source, Circle(x='x', y='y2')) code = RECORD("yrstart", "p.y_range.start", final=False) + RECORD( "yrend", "p.y_range.end") plot.tags.append( CustomJS(name="custom-action", args=dict(p=plot), code=code)) plot.toolbar_sticky = False button = Button() button.js_on_click( CustomJS(args=dict(glyph=glyph), code="glyph.visible=false")) page = single_plot_page(column(plot, button)) page.eval_custom_action() results = page.results assert results['yrstart'] <= 0 assert results['yrend'] >= 11 button = find_element_for(page.driver, button, ".bk-btn") button.click() page.eval_custom_action() results = page.results assert results['yrstart'] <= 0 assert results['yrend'] < 5 assert page.has_no_console_errors()