Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# testthat (development version)

* `snapshot_review()` includes a reject button and only displays the file navigation and the skip button if there are multiple files to review (#2025).
* `test_dir()`, `test_file()`, `test_package()`, `test_check()`, `test_local()`, `source_file()` gain a `shuffle` argument uses `sample()` to randomly reorder the top-level expressions in each test file (#1942). This random reordering surfaces dependencies between tests and code outside of any test, as well as dependencies between tests. This helps you find and eliminate unintentional dependencies.
* `snapshot_accept(test)` now works when the test file name contains `.` (#1669).
* `local_mock()` and `with_mock()` have been deprecated because they are no longer permitted in R 4.5.
Expand Down
16 changes: 12 additions & 4 deletions R/snapshot-manage.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ review_app <- function(name, old_path, new_path, ...) {
ui <- shiny::fluidPage(
style = "margin: 0.5em",
shiny::fluidRow(
style = "display: flex",
style = "display: flex; margin-bottom: 0.5em",
shiny::div(
style = "flex: 1 1",
shiny::selectInput("cases", NULL, case_index, width = "100%")
if (n > 1) shiny::selectInput("cases", NULL, case_index, width = "100%")
),
shiny::div(
class = "btn-group",
style = "margin-left: 1em; flex: 0 0 auto",
shiny::actionButton("skip", "Skip"),
shiny::actionButton("reject", "Reject", class = "btn-danger"),
if (n > 1) shiny::actionButton("skip", "Skip"),
shiny::actionButton("accept", "Accept", class = "btn-success"),
)
),
Expand All @@ -90,11 +91,14 @@ review_app <- function(name, old_path, new_path, ...) {
)
)
server <- function(input, output, session) {
i <- shiny::reactive(as.numeric(input$cases))
i <- shiny::reactive(if (n == 1) 1L else as.numeric(input$cases))
output$diff <- diffviewer::visual_diff_render({
diffviewer::visual_diff(old_path[[i()]], new_path[[i()]])
})

# Can't skip if there's only one file to review
shiny::updateActionButton(session, "skip", disabled = (n <= 1))

# Handle buttons - after clicking update move input$cases to next case,
# and remove current case (for accept/reject). If no cases left, close app
shiny::observeEvent(input$reject, {
Expand Down Expand Up @@ -122,6 +126,10 @@ review_app <- function(name, old_path, new_path, ...) {
choices = case_index[!handled],
selected = i
)

n_left <- sum(!handled)
# Disable skip button if only one case remains
shiny::updateActionButton(session, "skip", disabled = (n_left <= 1))
}
next_case <- function() {
if (all(handled)) {
Expand Down
Loading