Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
12 changes: 12 additions & 0 deletions inst/emptystate.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ function hideEmptyState(message) {
resizeObserver.unobserve(elementToReplace);
}

function shiny_emptystate_updatePosition(id){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the name of the function to follow camel case, instead of a weird hybrid. updateElementPosition should work here.

const elementWithEmptyState = findElementById(id);
const emptyStateContainer = elementWithEmptyState.querySelector(".empty-state-container");

const parentElement = emptyStateContainer.parentElement;
emptyStateContainer.style.height = parentElement.offsetHeight + "px";
emptyStateContainer.style.width = parentElement.offsetWidth + "px";
emptyStateContainer.style.left = parentElement.offsetLeft + "px";
emptyStateContainer.style.top = parentElement.offsetTop + "px";
}


$(function() {
Shiny.addCustomMessageHandler("showEmptyState", showEmptyState)
Shiny.addCustomMessageHandler("hideEmptyState", hideEmptyState)
Expand Down
43 changes: 43 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,46 @@ test_app <- function() {
}
)
}

test_slider_app <- function() {
shiny::shinyApp(
ui = shiny::fillPage(
use_empty_state(),
shiny::actionButton(
"toggle_pannel",
"Toggle panel",
class = "btn btn-primary",
onClick = "$('#container1').toggle(anim = 'slide',
function(){shiny_emptystate_updatePosition('container2')});"
),
shiny::div(
style = "width: 300px",
class = "d-flex flex-column gap-5",
shiny::div(
id = "container1",
shiny::div(
shiny::h1("Card 1"),
"Card content"
)
),
shiny::div(
id = "container2",
shiny::div(
shiny::h1("Card 2"),
"Card content"
)
)
)
),
server = function(input, output) {
empty_state_content <- shiny::div(
"This is example empty state content"
)
empty_state_manager <- EmptyStateManager$new(
id = "container2",
html_content = empty_state_content
)
empty_state_manager$show()
}
)
}
8 changes: 8 additions & 0 deletions tests/testthat/test-empty_state.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ describe("EmptyStateManager", {
expect_null(app$get_html(selector = ".empty-state-content"))
app$stop()
})

it("checks the empty state component follows slider from id", {
app <- shinytest2::AppDriver$new(test_slider_app(), name = "slide_tag")
app$expect_values()
app$click("toggle_pannel")
app$expect_values()
app$stop()
})
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is useless.

  1. You have not included the snapshots generated by app$expected_values(), so the tests are not run against the reference, they only generate references.
  2. Even with the snapshots, this test only verifies the values of inputs and outputs, which means that the only thing that you test is if the button was clicked. You are not testing the position of the empty state container.


describe("use_empty_state()", {
Expand Down