Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion inst/draggable-buckets/draggable-buckets.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ $.extend(draggableBuckets, {

subscribe: function (el, callback) {
if (this.observers === undefined) this.observers = {};
this.observers[el] = new MutationObserver(callback);
this.observers[el] = new MutationObserver(function () {
callback({ priority: "event" });
});
this.observers[el].observe(el, {
subtree: true,
childList: true,
Expand Down
104 changes: 104 additions & 0 deletions tests/testthat/test-draggable_buckets.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
app_driver_db <- function(input_id, label, elements = character(), buckets) {
ui <- bslib::page_fluid(
draggable_buckets(
input_id = input_id,
label = label,
elements = elements,
buckets = buckets
)
)

shinytest2::AppDriver$new(
shiny::shinyApp(ui, function(input, output) {})
)
}

testthat::test_that(
"e2e: teal.widgets::draggable_buckets: initializes without input",
{
skip_if_too_deep(5)
app_driver <- app_driver_db(
input_id = "id",
label = "Choices",
elements = c("a", "b"),
buckets = c("bucket1", "bucket2")
)
app_driver$wait_for_idle(timeout = default_idle_timeout)
testthat::expect_true(is_visible("#id.draggableBuckets.shiny-bound-input", app_driver))
testthat::expect_identical(
app_driver$get_value(input = "id"),
list(
"bucket1" = list(),
"bucket2" = list()
)
)
app_driver$stop()
}
)

testthat::test_that(
"e2e: teal.widgets::draggable_buckets: initializes with default inputs",
{
skip_if_too_deep(5)
app_driver <- app_driver_db(
input_id = "id",
label = "Choices",
elements = character(),
buckets = list(
"Ref" = "B: Placebo",
"Comp" = c("A: Drug X", "C: Combination")
)
)
app_driver$wait_for_idle(timeout = default_idle_timeout)
values <- app_driver$get_value(input = "id")
testthat::expect_identical(
app_driver$get_value(input = "id"),
list(
"Ref" = list("B: Placebo"),
"Comp" = list("A: Drug X", "C: Combination")
)
)
app_driver$stop()
}
)

testthat::test_that(
"e2e: teal.widgets::draggable_buckets: moving elements between buckets updates input",
{
skip_if_too_deep(5)
app_driver <- app_driver_db(
input_id = "id",
label = "Choices",
elements = character(),
buckets = list(
"Ref" = "B: Placebo",
"Comp" = c("A: Drug X", "C: Combination")
)
)
app_driver$wait_for_idle(timeout = default_idle_timeout)
app_driver$run_js(
"
// Find the buckets
var widget = document.getElementById('id');
var buckets = widget.querySelectorAll('.bucket');
var refBucket = Array.from(buckets).find(b => b.dataset.label === 'Ref');
var compBucket = Array.from(buckets).find(b => b.dataset.label === 'Comp');
// Find element 'A: Drug X' in compBucket
var element = Array.from(compBucket.querySelectorAll('.element')).find(e => e.textContent.trim() === 'A: Drug X');
// Move it to refBucket
refBucket.appendChild(element);
"
)
app_driver$wait_for_idle(timeout = default_idle_timeout)
testthat::expect_identical(
app_driver$get_value(input = "id")$Ref,
list("B: Placebo", "A: Drug X")
)

testthat::expect_identical(
app_driver$get_value(input = "id")$Comp,
list("C: Combination")
)
app_driver$stop()
}
)
23 changes: 0 additions & 23 deletions tests/testthat/test-draggable_buckets_ui.R

This file was deleted.

14 changes: 0 additions & 14 deletions tests/testthat/test-optionalSelectInput_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,9 @@ testthat::test_that(
testthat::expect_equal(gv$output[[i]], output[[i]])
}

# app_driver$click(
# selector = "body > div.container-fluid > bslib-layout-columns > div:nth-child(2) span.bs-select-clear-selected"
# )

# app_driver$get_value(output = "c2_out") %>%
# testthat::expect_equal("NULL")

# app_driver$get_value(input = "c2") %>%
# testthat::expect_equal(NULL)

# app_driver$get_text("#c2_input .filter-option-inner-inner") |>
# testthat::expect_equal("- Nothing selected -")

# Check allow clear behavior on c2 input where multiple is FALSE
allow_clear_selector <- "#c2_input span.bs-select-clear-selected"
app_driver$click(selector = allow_clear_selector)
app_driver$wait_for_idle(duration = default_idle_timeout)
testthat::expect_equal(app_driver$get_value(output = "c2_out"), "NULL")
testthat::expect_equal(app_driver$get_value(input = "c2"), NULL)
testthat::expect_equal(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-verbatim_popup_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ testthat::test_that(
"Copy to Clipboard"
)
testthat::expect_equal(
app_driver$get_text(".modal-footer button:nth-of-type(2)"),
app_driver$get_text(".modal-footer button:nth-of-type(1)"),
"Dismiss"
)

Expand Down
Loading