Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Meghansaha
Copy link

@Meghansaha Meghansaha commented Nov 25, 2024

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)

  • PR branch has pulled the most recent updates from main branch.
  • If a bug was fixed, a unit test was added.
  • Run pkgdown::build_site(). Check the R console for errors, and review the rendered website.
  • Code coverage is suitable for any new functions/features: devtools::test_coverage()
  • usethis::use_spell_check() runs with no spelling errors in documentation
  • All GitHub Action workflows pass with a ✅

When the branch is ready to be merged into master:

  • Update 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 (see NEWS.md for examples).
  • Increment the version number using usethis::use_version(which = "dev")
  • Run usethis::use_spell_check() again
  • Approve Pull Request
  • Merge the PR. Please use "Squash and merge".

Copy link
Owner

@ddsjoberg ddsjoberg left a 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)
Copy link
Owner

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 = _)
Copy link
Owner

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()
Copy link
Owner

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)
Copy link
Owner

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(
Copy link
Owner

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()

Comment on lines +155 to +157
# 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?
Copy link
Owner

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())
Copy link
Owner

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()
Copy link
Owner

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", {
Copy link
Owner

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", {
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants