|
| 1 | +from selenium.webdriver.support.select import Select |
| 2 | + |
| 3 | +app = """ |
| 4 | +library(dash) |
| 5 | +library(dashHtmlComponents) |
| 6 | +library(dashCoreComponents) |
| 7 | +
|
| 8 | +app <- Dash$new() |
| 9 | +
|
| 10 | +app$layout( |
| 11 | + htmlDiv(list( |
| 12 | + dccDropdown(options = list( |
| 13 | + list(label = "Red", value = "#FF0000"), |
| 14 | + list(label = "Green", value = "#00FF00"), |
| 15 | + list(label = "Blue", value = "#0000FF"), |
| 16 | + list(label = "Do nothing", value = "nothing") |
| 17 | + ), |
| 18 | + id = "color-selector"), |
| 19 | + htmlDiv(id='message-box', |
| 20 | + children='Please select a colour choice from the dropdown menu.') |
| 21 | + ) |
| 22 | + ) |
| 23 | +) |
| 24 | +
|
| 25 | +app$callback(output=list(id='message-box', property='children'), |
| 26 | + params=list( |
| 27 | + input(id='color-selector', property='value')), |
| 28 | + function(color) |
| 29 | + { |
| 30 | + if (color %in% c("#FF0000", "#00FF00", "#0000FF")) { |
| 31 | + msg <- sprintf("The hexadecimal representation of your last chosen colour is %s", |
| 32 | + color) |
| 33 | + return(msg) |
| 34 | + } else { |
| 35 | + return(dashNoUpdate()) |
| 36 | + } |
| 37 | + } |
| 38 | +) |
| 39 | +
|
| 40 | +app$run_server() |
| 41 | +""" |
| 42 | + |
| 43 | + |
| 44 | +def test_rsnu001_no_update(dashr): |
| 45 | + dashr.start_server(app) |
| 46 | + dashr.find_element("#color-selector").click() |
| 47 | + dashr.find_elements("div.VirtualizedSelectOption")[0].click() |
| 48 | + assert dashr.find_element("#message-box").text == "The hexadecimal representation of your last chosen colour is #FF0000" |
| 49 | + dashr.find_element("#color-selector").click() |
| 50 | + dashr.find_elements("div.VirtualizedSelectOption")[3].click() |
| 51 | + assert dashr.find_element("#message-box").text == "The hexadecimal representation of your last chosen colour is #FF0000" |
| 52 | + dashr.find_element("#color-selector").click() |
| 53 | + dashr.find_elements("div.VirtualizedSelectOption")[1].click() |
| 54 | + assert dashr.find_element("#message-box").text == "The hexadecimal representation of your last chosen colour is #00FF00" |
| 55 | + dashr.find_element("#color-selector").click() |
| 56 | + dashr.find_elements("div.VirtualizedSelectOption")[3].click() |
| 57 | + assert dashr.find_element("#message-box").text == "The hexadecimal representation of your last chosen colour is #00FF00" |
| 58 | + dashr.find_element("#color-selector").click() |
| 59 | + dashr.find_elements("div.VirtualizedSelectOption")[2].click() |
| 60 | + assert dashr.find_element("#message-box").text == "The hexadecimal representation of your last chosen colour is #0000FF" |
| 61 | + dashr.find_element("#color-selector").click() |
| 62 | + dashr.find_elements("div.VirtualizedSelectOption")[3].click() |
| 63 | + assert dashr.find_element("#message-box").text == "The hexadecimal representation of your last chosen colour is #0000FF" |
0 commit comments