Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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).
* New `snapshot_download_gh()` makes it easy to get snapshots off GitHub and into your local package (#1779).
* New `local_mocked_s3_method()`, `local_mocked_s4_method()`, and `local_mocked_r6_class()` allow you to mock S3 and S4 methods and R6 classes (#1892, #1916)
* `expect_snapshot_file(name=)` must have a unique file path. If a snapshot file attempts to be saved with a duplicate `name`, an error will be thrown. (#1592)
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