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

Merged
merged 12 commits into from
Dec 27, 2024
Merged

Conversation

Meghansaha
Copy link
Contributor

@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.

tests/testthat/test-theme_elements_gtsummary.R Outdated Show resolved Hide resolved
tests/testthat/test-theme_elements_gtsummary.R Outdated Show resolved Hide resolved
tests/testthat/test-theme_elements_gtsummary.R Outdated Show resolved Hide resolved
tests/testthat/test-theme_elements_gtsummary.R Outdated Show resolved Hide resolved
tests/testthat/test-theme_elements_gtsummary.R Outdated Show resolved Hide resolved
tests/testthat/test-theme_elements_gtsummary.R Outdated Show resolved Hide resolved
# 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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that I'm understanding the print engine thing a bit better, I reverted back to the original test I tried to do when I first started. I can change it to a snapshot if you'd prefer that?

tests/testthat/test-theme_elements_gtsummary.R Outdated Show resolved Hide resolved
tests/testthat/test-theme_elements_gtsummary.R Outdated Show resolved Hide resolved
tests/testthat/test-theme_elements_gtsummary.R Outdated Show resolved Hide resolved
Copy link
Contributor Author

@Meghansaha Meghansaha left a comment

Choose a reason for hiding this comment

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

addressed your comments. Let me know if something's not right, or if I missed anything!

test_that("pkgwide-str:language works", {

# Test that the CI has the correct pattern somewhere#
expect_snapshot(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was trying to test that translated columns names were returned. Not sure why I did this either, so changed it!

# 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
Contributor Author

Choose a reason for hiding this comment

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

Now that I'm understanding the print engine thing a bit better, I reverted back to the original test I tried to do when I first started. I can change it to a snapshot if you'd prefer that?

tests/testthat/test-theme_elements_gtsummary.R Outdated Show resolved Hide resolved
@Meghansaha Meghansaha requested a review from ddsjoberg December 3, 2024 01:21
Comment on lines 68 to 79
## pkgwide-lgl:quiet------------------------------------------------------------
test_that("pkgwide-lgl:quiet works", {

# Test that the lgl value can be found#
expect_silent(
with_gtsummary_theme(
x = my_theme_2,
expr = get_theme_element("pkgwide-lgl:quiet")
)
)
}
)
Copy link
Owner

Choose a reason for hiding this comment

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

These quiet arguments have been deprecated, so I am going to go ahead and delete this section. Sorry!

@ddsjoberg
Copy link
Owner

Thanks @Meghansaha for the contribution!!

I did a little cleaning up, ie one testthat chunk per theme element that we're testing, within that chunk adding a test for every place that theme element is used in the package (this actually found a mistake where it wasn't being applied 😱 ).

I did delete a couple of tests that would have taken me too long to comprehensively test, but we can add those back in other PRs.

Thanks again!

@ddsjoberg ddsjoberg merged commit 1c21e9c into ddsjoberg:main Dec 27, 2024
7 checks passed
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