Skip to content

Commit

Permalink
splitting tests and reverting wordlist.
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikeya committed Aug 8, 2023
1 parent 9d370c1 commit a90c023
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
10 changes: 8 additions & 2 deletions R/plot_with_settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,20 @@ plot_with_settings_srv <- function(id,
p_height <- reactive(`if`(!is.null(input$height), input$height, height[1]))
p_width <- reactive(`if`(!is.null(input$width), input$width, default_slider_width()[1]))
output$plot_main <- renderPlot(
apply_plot_modifications(plot_obj = plot_r(), plot_type = plot_type(), dbclicking = dblclicking, ranges = ranges),
apply_plot_modifications(plot_obj = plot_r(),
plot_type = plot_type(),
dbclicking = dblclicking,
ranges = ranges),
res = get_plot_dpi(),
height = p_height,
width = p_width
)

output$plot_modal <- renderPlot(
apply_plot_modifications(plot_obj = plot_r(), plot_type = plot_type(), dbclicking = dblclicking, ranges = ranges),,
apply_plot_modifications(plot_obj = plot_r(),
plot_type = plot_type(),
dbclicking = dblclicking,
ranges = ranges),
res = get_plot_dpi(),
height = reactive(input$height_in_modal),
width = reactive(input$width_in_modal)
Expand Down
2 changes: 0 additions & 2 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ funder
pre
repo
shinyServer
gg
ggplot
38 changes: 26 additions & 12 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,39 @@ testthat::test_that("get_bs_version", {
testthat::expect_identical(get_bs_version(), "3")
})

test_that("apply_plot_modifications correctly modifies plot objects", {
# Create a sample ggplot2 plot object
ggplot_obj <- ggplot2::ggplot(data = iris, ggplot2::aes(x = Sepal.Length, y = Sepal.Width)) +
ggplot2::geom_point()
# Create a sample ggplot2 plot object
ggplot_obj <- ggplot2::ggplot(data = iris, ggplot2::aes(x = Sepal.Length, y = Sepal.Width)) +
ggplot2::geom_point()

# Test case 1: Modify ggplot object with dblclicking enabled
modified_ggplot <- apply_plot_modifications(ggplot_obj, "gg", TRUE, list(x = c(4, 7), y = c(2, 4)))
test_that("apply_plot_modifications, Modify ggplot object with dblclicking enabled", {
modified_ggplot <- apply_plot_modifications(plot_obj = ggplot_obj,
plot_type = "gg",
dblclicking = TRUE,
ranges = list(x = c(4, 7), y = c(2, 4)))
expect_true(identical(class(modified_ggplot), class(ggplot_obj)))
})

# Test case 2: Modify ggplot object with dblclicking disabled
modified_ggplot <- apply_plot_modifications(ggplot_obj, "gg", FALSE, list(x = c(4, 7), y = c(2, 4)))
test_that("apply_plot_modifications, Modify ggplot object with dblclicking disabled", {
modified_ggplot <- apply_plot_modifications(plot_obj = ggplot_obj,
plot_type = "gg",
dblclicking = FALSE,
ranges = list(x = c(4, 7), y = c(2, 4)))
expect_true(identical(class(modified_ggplot), class(ggplot_obj)))
})

# Test case 3: Modify grob object
test_that("apply_plot_modifications, Modify grob object", {
grob_obj <- grid::rectGrob()
modified_grob <- apply_plot_modifications(grob_obj, "grob", TRUE, list(x = c(0, 1), y = c(0, 1)))
modified_grob <- apply_plot_modifications(plot_obj = grob_obj,
plot_type = "grob",
dblclicking = TRUE,
ranges = list(x = c(0, 1), y = c(0, 1)))
expect_null(modified_grob)
})

# Test case 4: Do not modify plot object
unchanged_plot <- apply_plot_modifications(ggplot_obj, "other_type", TRUE, list(x = c(4, 7), y = c(2, 4)))
test_that("apply_plot_modifications, Do not modify plot object", {
unchanged_plot <- apply_plot_modifications(plot_obj = ggplot_obj,
plot_type = "other_type",
dblclicking = TRUE,
ranges = list(x = c(4, 7), y = c(2, 4)))
expect_true(identical(unchanged_plot, ggplot_obj))
})

0 comments on commit a90c023

Please sign in to comment.