context("grid")
test_that("test data_frame_to_css_grid_template_areas", {
areas_dataframe <- rbind(
c("header", "header", "header"),
c("menu", "main", "right1"),
c("menu", "main", "right2")
)
expect_equal(
data_frame_to_css_grid_template_areas(areas_dataframe),
"'header header header' 'menu main right1' 'menu main right2'"
)
areas_dataframe <- rbind(
c("a", "b"),
c("c", "d")
)
expect_equal(
data_frame_to_css_grid_template_areas(areas_dataframe),
"'a b' 'c d'"
)
})
test_that("test grid_container_css", {
expected_result <- paste(
"display: grid;",
"height: 100%;",
"grid-template-rows: 50% 50%;",
"grid-template-columns: 100px 2fr 1fr;",
"grid-template-areas: 'a a a' 'b b b';",
"{{ custom_style_grid_container }}"
)
expect_equal(
grid_container_css("'a a a' 'b b b'", c("50%", "50%"), c("100px", "2fr", "1fr")),
expected_result
)
})
test_that("test list_of_area_tags", {
expected_result <- list(
HTML('
'),
HTML('{{ main }}
'),
HTML('')
)
expect_equal(list_of_area_tags(c("header", "main", "footer")), expected_result)
expect_equal(list_of_area_tags(c()), list())
})
remove_whitespace <- function (string) gsub('[\n ]', '', as.character(string))
test_that("test grid_template", {
myGrid <- grid_template(default = list(
areas = rbind(
c("header", "header", "header"),
c("menu", "main", "right1"),
c("menu", "main", "right2")
),
rows_height = c("50px", "auto", "100px"),
cols_width = c("100px", "2fr", "1fr")
))
expected_template <- HTML('
{{ main }}
{{ right1 }}
{{ right2 }}
')
expected_area_names <- c("header", "menu", "main", "right1", "right2")
expect_equal(remove_whitespace(myGrid$template), remove_whitespace(expected_template))
expect_equal(myGrid$area_names, expected_area_names)
})
test_that("test grid_template with mobile version", {
myGrid <- grid_template(
default = list(
areas = rbind(
c("header", "header", "header"),
c("menu", "main", "right1"),
c("menu", "main", "right2")
),
rows_height = c("50px", "auto", "100px"),
cols_width = c("100px", "2fr", "1fr")
),
mobile = list(
areas = rbind(
"header",
"menu",
"main",
"right1",
"right2"
),
rows_height = c("50px", "50px", "auto", "100px", "100px"),
cols_width = c("100%")
)
)
expected_template <- HTML('
{{ main }}
{{ right1 }}
{{ right2 }}
')
expected_area_names <- c("header", "menu", "main", "right1", "right2")
expect_equal(remove_whitespace(myGrid$template), remove_whitespace(expected_template))
expect_equal(myGrid$area_names, expected_area_names)
})
test_that("test grid", {
simpleGrid <- grid_template(
default = list(
areas = rbind(c("a","b")),
rows_height = "100%",
cols_width = "50%", "50%"
)
)
gridHTML <- grid(simpleGrid,
id = "test_grid",
container_style = "",
area_styles = list(),
a = shiny::tags$div("hello"),
b = shiny::tags$div("world"))
expected_html <- HTML('
')
expect_equal(remove_whitespace(gridHTML), remove_whitespace(expected_html))
# Display mode
gridHTML <- grid(simpleGrid,
id = "test_grid",
container_style = "",
area_styles = list(),
display_mode = TRUE,
a = shiny::tags$div("hello"),
b = shiny::tags$div("world"))
expected_html <- HTML('
')
expect_equal(remove_whitespace(gridHTML), remove_whitespace(expected_html))
})