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

add-test-to-animint2 #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions tests/mytests.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
library("testthat")
library("animint2")
library("RSelenium")
library("XML")
source("helper-functions.R")
source("helper-HTML.R")
source("helper-plot-data.r")

tests_init()
tests_run(filter="renderer3-TestWorldBankTwoLayers")
tests_exit()

Copy link
Collaborator

Choose a reason for hiding this comment

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

please remove mytests.r file

tests_init("firefox")
tests_run(filter="renderer3-TestWorldBankTwoLayers")
tests_exit()
46 changes: 46 additions & 0 deletions tests/testthat/test-renderer3-TestWorldBankTwoLayers.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
acontext("TestWorldBankTwoLayers")

data(WorldBank, package="animint2")

# Filter the data for specific years
WorldBank1975 <- subset(WorldBank, year == 1975)
WorldBankBefore1975 <- subset(WorldBank, 1970 <= year & year <= 1975)

# Define income levels and colors
income.colors <- c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#FFFF33")
WorldBank$income <- factor(WorldBank$income,
levels = c("High income: nonOECD", "High income: OECD",
"Upper middle income", "Lower middle income",
"Low income", "Not classified"))
names(income.colors) <- levels(WorldBank$income)

# Create the scatter plot with one layer
scatter <- ggplot() +
scale_color_manual(values = income.colors) +
geom_point(
mapping = aes(x = life.expectancy, y = fertility.rate, color = income),
data = WorldBank1975
)

# Add the second layer for paths
two.layers <- scatter +
geom_path(
aes(
x = life.expectancy,
y = fertility.rate,
color = income,
group = country
),
data = WorldBankBefore1975
)

# Create an interactive plot
scatter_plot <- list(plot = two.layers)
animint(scatter_plot)

# Test that the visualization generates without warnings or errors
test_that("worldbank two-layers visualization generated without any warnings or errors", {
expect_no_warning({
info <- animint2HTML(scatter_plot)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this test does not use the renderer. please show that you understand how to inspect the output of the chromote renderer, and simulate interaction.

  • first add an expectation about info$html (maybe all of the regions are shown by default at first?)
  • then please use clickID() to simulate interaction (maybe with your legend?),
  • and then use getHTML() to get the HTML after the simulated interaction,
  • and then finally use another expectation about what the HTML looks like after interaction.

also this world bank data viz is not a very interesting test case, because you have no clickSelects/showSelected here. Instead can you write a test based on the animation example you created? https://busttech.github.io/deploy2/

})
})
Loading