-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Theme element unit tests #2081
base: main
Are you sure you want to change the base?
Theme element unit tests #2081
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Meghansaha for the PR!!! I left a few comments to address.
) | ||
|
||
# Set the theme | ||
set_gtsummary_theme(my_theme_1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of setting a theme in semi-open code, let's use with_gtsummary_theme()
, because it's well-confined to the operations that are called within it.
# Test that the p-value has 3 digits# | ||
expect_true( | ||
inline_text(gts_1, variable = age, column = "p.value") |> | ||
grepl(pattern = "p=0.\\d{3}", x = _) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be easier to read as an expect_equal()
. Can we update to avoid the regex pattern matching?
grepl(pattern = "p=0.\\d{3}", x = _) | ||
) | ||
# Reset the theming# | ||
reset_gtsummary_theme() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we're now using with_gtsummary_theme()
, we can remove this
) | ||
|
||
# Set the theme | ||
set_gtsummary_theme(my_theme_2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use with_gtsummary_theme()
as above
test_that("pkgwide-fn:pvalue_fun works", { | ||
|
||
# Test that the p-value has the correct digits and prefix# | ||
expect_true( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above, let's use expect_equal()
# This only works when a theme is set explicitly | ||
# And not when it is just temporarily set with 'with_gtsummary_theme' | ||
# Is this intentional behavior? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conversion happens in the print method, which doesn't run until we print. So you can update the above code with
with_gtsummary_theme(
my_theme_4,
trial |>
dplyr::select(death, trt) |>
tbl_summary(by = trt)
) |>
print()
# This only works when a theme is set explicitly | ||
# And not when it is just temporarily set with 'with_gtsummary_theme' | ||
# Is this intentional behavior? | ||
expect_true(grepl("|:-", gts_4) |> any()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be easier to read as a snapshot test
expect_true(grepl("|:-", gts_4) |> any()) | ||
|
||
# Reset the theme | ||
reset_gtsummary_theme() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove this
) | ||
|
||
## pkgwide-str:theme_name------------------------------------------------------- | ||
test_that("pkgwide-str:theme_name works", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may be able to test this with with_gtsummary_theme()
. can you try to update to not directly call the theme?
|
||
|
||
## pkgwide-fun:pre_conversion--------------------------------------------------- | ||
test_that("pkgwide-fun:pre_conversion works", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apply the changes listed above to this code chunk as well, please.
What changes are proposed in this pull request?
Added unit test coverage for pkgwide theme elements
If there is an GitHub issue associated with this pull request, please provide link.
#1959
Reviewer Checklist (if item does not apply, mark is as complete)
pkgdown::build_site()
. Check the R console for errors, and review the rendered website.devtools::test_coverage()
usethis::use_spell_check()
runs with no spelling errors in documentationWhen the branch is ready to be merged into master:
NEWS.md
with the changes from this pull request under the heading "# gtsummary (development version)
". If there is an issue associated with the pull request, reference it in parentheses at the end update (seeNEWS.md
for examples).usethis::use_version(which = "dev")
usethis::use_spell_check()
again