From 06f9c74d5ada56185620d4bf258196429e324fdd Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Thu, 13 Jul 2023 13:36:19 -0400 Subject: [PATCH 1/2] tests(313): Fix bslib full screen card selector --- .../tests/testthat/test-313-bslib-card-tab-focus.R | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/inst/apps/313-bslib-card-tab-focus/tests/testthat/test-313-bslib-card-tab-focus.R b/inst/apps/313-bslib-card-tab-focus/tests/testthat/test-313-bslib-card-tab-focus.R index ab8f25b3ab..05ed9039e6 100644 --- a/inst/apps/313-bslib-card-tab-focus/tests/testthat/test-313-bslib-card-tab-focus.R +++ b/inst/apps/313-bslib-card-tab-focus/tests/testthat/test-313-bslib-card-tab-focus.R @@ -34,14 +34,20 @@ expect_focus <- function(app, selector) { expect_card_full_screen <- function(app, id) { id <- sub("^#", "", id) app$wait_for_js('document.body.matches(".bslib-has-full-screen")') + # The expected card is expanded in full screen mode expect_equal( - app$get_js('document.querySelector(".bslib-full-screen").id'), - id + app$get_js(sprintf( + "document.getElementById('%s').getAttribute('data-full-screen')", + id + )), + "true" ) + # Only one card is expanded to full screen expect_equal( - app$get_js("document.querySelectorAll('.bslib-full-screen').length"), + app$get_js("document.querySelectorAll('.bslib-card[data-full-screen=\"true\"]').length"), 1 ) + # The overlay (behind card and above UI) is present expect_equal( app$get_js("document.querySelectorAll('#bslib-full-screen-overlay').length"), 1 @@ -62,7 +68,7 @@ expect_card_full_screen <- function(app, id) { expect_no_full_screen <- function(app) { app$wait_for_js('!document.body.matches(".bslib-has-full-screen")') expect_equal( - app$get_js("document.querySelectorAll('.bslib-full-screen').length"), + app$get_js("document.querySelectorAll('.bslib-card[data-full-screen=\"true\"]').length"), 0 ) invisible(app) From e959577849195cd04d924bc295134c8d9d111185 Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Thu, 13 Jul 2023 13:42:59 -0400 Subject: [PATCH 2/2] tests(313): Also test that full-screen attribute returns to false --- .../tests/testthat/test-313-bslib-card-tab-focus.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/inst/apps/313-bslib-card-tab-focus/tests/testthat/test-313-bslib-card-tab-focus.R b/inst/apps/313-bslib-card-tab-focus/tests/testthat/test-313-bslib-card-tab-focus.R index 05ed9039e6..58a2268c30 100644 --- a/inst/apps/313-bslib-card-tab-focus/tests/testthat/test-313-bslib-card-tab-focus.R +++ b/inst/apps/313-bslib-card-tab-focus/tests/testthat/test-313-bslib-card-tab-focus.R @@ -65,12 +65,22 @@ expect_card_full_screen <- function(app, id) { invisible(app) } -expect_no_full_screen <- function(app) { +expect_no_full_screen <- function(app, id = NULL) { app$wait_for_js('!document.body.matches(".bslib-has-full-screen")') expect_equal( app$get_js("document.querySelectorAll('.bslib-card[data-full-screen=\"true\"]').length"), 0 ) + if (is.null(id)) return(invisible(app)) + + expect_equal( + app$get_js(sprintf( + "document.getElementById('%s').getAttribute('data-full-screen')", + id + )), + "false" + ) + invisible(app) } @@ -174,7 +184,7 @@ test_that("fullscreen card without internal focusable elements", { # Exit full screen key_press("Enter") - expect_no_full_screen(app) + expect_no_full_screen(app, id = "card-no-inputs") }) # Test enter/exit methods ------------------------------------------