Skip to content

Refactor test-layer-positioning.R to eliminate code duplication#164

Merged
stemangiola merged 2 commits intofix-layersfrom
copilot/sub-pr-163
Jan 14, 2026
Merged

Refactor test-layer-positioning.R to eliminate code duplication#164
stemangiola merged 2 commits intofix-layersfrom
copilot/sub-pr-163

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

The test file contained duplicated dummy_df creation code in two test cases (lines 13-31 and 89-107), both constructing identical test data from GitHub issue #162.

Changes

  • Extracted create_issue_162_dummy_df() helper function to encapsulate shared test data
  • Updated both test cases to call the helper function instead of duplicating 19 lines of setup code
  • Reduces file from 117 to 104 lines while maintaining identical test behavior
# Helper function to create the dummy_df from GitHub issue #162
create_issue_162_dummy_df <- function() {
  tibble(
    row_id = c(
      "B cells", "Basophils", "Eosinophils", "Myeloid", "NK cells", "Neutrophils", "T cells",
      "B cells", "Basophils", "Eosinophils", "Myeloid", "NK cells", "Neutrophils", "T cells"
    ),
    col_id = c(rep("Control", 7), rep("Test", 7)),
    value = c(0.2000, -0.0180, 0.0983, 0.1930, 0.0934, 0.0529, -0.2090,
              0.0831, 0.00515, 0.0413, 0.0808, 0.0123, 0.0619, -0.1550),
    adj_p = c(5.81e-10, 2.72e-01, 4.46e-04, 1.44e-06, 6.43e-08, 1.08e-01, 7.65e-07,
              6.46e-02, 7.81e-01, 2.47e-01, 6.46e-02, 5.90e-01, 6.46e-02, 6.28e-03)
  ) %>% 
    mutate(col_id = fct_relevel(col_id, c("Control", "Test")))
}

test_that("layer_asterisk positions match matrix structure - using issue #162 dummy_df", {
  dummy_df <- create_issue_162_dummy_df()
  # ... rest of test
})

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Note

Streamlines test setup for layer positioning validations while keeping assertions and visuals intact.

  • Adds create_issue_162_dummy_df() helper in tests/testthat/test-layer-positioning.R
  • Replaces duplicated tibble construction in two tests with the helper (layer_asterisk position and visual tests)
  • No logic changes to tests; maintains same expectations and vdiffr snapshot, reducing duplication and lines of code

Written by Cursor Bugbot for commit 7c2bbcf. This will update automatically on new commits. Configure here.

Co-authored-by: stemangiola <7232890+stemangiola@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix positioning bug in layer_symbol and layer_text functions Refactor test-layer-positioning.R to eliminate code duplication Jan 14, 2026
Copilot AI requested a review from stemangiola January 14, 2026 10:11
@stemangiola stemangiola marked this pull request as ready for review January 14, 2026 10:21
@stemangiola stemangiola merged commit eb5f2d5 into fix-layers Jan 14, 2026
1 check 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

Comments