|
| 1 | +from selenium.webdriver.support.select import Select |
| 2 | +import time |
| 3 | + |
| 4 | +app = """ |
| 5 | +library(dash) |
| 6 | +library(dashHtmlComponents) |
| 7 | +library(dashCoreComponents) |
| 8 | +
|
| 9 | +app <- Dash$new() |
| 10 | +
|
| 11 | +app$layout( |
| 12 | + htmlDiv(list( |
| 13 | + dccDropdown(options = list( |
| 14 | + list(label = "Red", value = "#FF0000"), |
| 15 | + list(label = "Green", value = "#00FF00"), |
| 16 | + list(label = "Blue", value = "#0000FF"), |
| 17 | + list(label = "Do nothing", value = "nothing") |
| 18 | + ), |
| 19 | + id = "color-selector"), |
| 20 | + htmlButton(children = "Select all the colors!", |
| 21 | + id = "multi-selector" |
| 22 | + ), |
| 23 | + htmlDiv(id='message-box', |
| 24 | + children='Please select a color choice from the dropdown menu.'), |
| 25 | + htmlDiv(id='message-box2', |
| 26 | + children=' ') |
| 27 | + ) |
| 28 | + ) |
| 29 | +) |
| 30 | +
|
| 31 | +app$callback(output=list(id='message-box2', property='children'), |
| 32 | + params=list( |
| 33 | + input(id='multi-selector', property='n_clicks')), |
| 34 | + function(n_clicks) |
| 35 | + { |
| 36 | + # if button has been clicked, n_clicks is numeric() |
| 37 | + # on first launch of callback at layout initialization, |
| 38 | + # value of n_clicks will be list(NULL), which is not |
| 39 | + # comparable using >, < or =; hence the is.numeric() |
| 40 | + # check |
| 41 | + if (is.numeric(n_clicks) && n_clicks >= 1) |
| 42 | + { |
| 43 | + # return a vector to ensure that the check for |
| 44 | + # class(x) == "no_update" isn't made for objects |
| 45 | + # where length(x) > 1 |
| 46 | + return(c("Multiple color values: ", |
| 47 | + "#FF0000, ", |
| 48 | + "#00FF00, ", |
| 49 | + "#0000FF ", |
| 50 | + "returned!") |
| 51 | + ) |
| 52 | + } |
| 53 | + } |
| 54 | +) |
| 55 | +
|
| 56 | +app$callback(output=list(id='message-box', property='children'), |
| 57 | + params=list( |
| 58 | + input(id='color-selector', property='value')), |
| 59 | + function(color) |
| 60 | + { |
| 61 | + if (color %in% c("#FF0000", "#00FF00", "#0000FF")) { |
| 62 | + msg <- sprintf("The hexadecimal representation of your last chosen color is %s", |
| 63 | + color) |
| 64 | + return(msg) |
| 65 | + } else { |
| 66 | + return(dashNoUpdate()) |
| 67 | + } |
| 68 | + } |
| 69 | +) |
| 70 | +
|
| 71 | +app$run_server() |
| 72 | +""" |
| 73 | + |
| 74 | + |
| 75 | +def test_rsnu001_no_update(dashr): |
| 76 | + dashr.start_server(app) |
| 77 | + dashr.find_element("#color-selector").click() |
| 78 | + dashr.find_elements("div.VirtualizedSelectOption")[0].click() |
| 79 | + dashr.wait_for_text_to_equal( |
| 80 | + "#message-box", |
| 81 | + "The hexadecimal representation of your last chosen color is #FF0000" |
| 82 | + ) |
| 83 | + dashr.find_element("#color-selector").click() |
| 84 | + dashr.find_elements("div.VirtualizedSelectOption")[3].click() |
| 85 | + time.sleep(1) |
| 86 | + assert dashr.find_element("#message-box").text == "The hexadecimal representation of your last chosen color is #FF0000" |
| 87 | + dashr.find_element("#color-selector").click() |
| 88 | + dashr.find_elements("div.VirtualizedSelectOption")[1].click() |
| 89 | + dashr.wait_for_text_to_equal( |
| 90 | + "#message-box", |
| 91 | + "The hexadecimal representation of your last chosen color is #00FF00" |
| 92 | + ) |
| 93 | + dashr.find_element("#color-selector").click() |
| 94 | + dashr.find_elements("div.VirtualizedSelectOption")[3].click() |
| 95 | + time.sleep(1) |
| 96 | + assert dashr.find_element("#message-box").text == "The hexadecimal representation of your last chosen color is #00FF00" |
| 97 | + dashr.find_element("#color-selector").click() |
| 98 | + dashr.find_elements("div.VirtualizedSelectOption")[2].click() |
| 99 | + dashr.wait_for_text_to_equal( |
| 100 | + "#message-box", |
| 101 | + "The hexadecimal representation of your last chosen color is #0000FF" |
| 102 | + ) |
| 103 | + dashr.find_element("#color-selector").click() |
| 104 | + dashr.find_elements("div.VirtualizedSelectOption")[3].click() |
| 105 | + time.sleep(1) |
| 106 | + assert dashr.find_element("#message-box").text == "The hexadecimal representation of your last chosen color is #0000FF" |
| 107 | + dashr.find_element("#multi-selector").click() |
| 108 | + dashr.wait_for_text_to_equal( |
| 109 | + "#message-box2", |
| 110 | + "Multiple color values: #FF0000, #00FF00, #0000FF returned!" |
| 111 | + ) |
0 commit comments