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

fix bug where govtable falls over if width_overwrite = NULL #111

Open
wants to merge 2 commits 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
5 changes: 4 additions & 1 deletion R/govTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ govTable <- function(inputId, df, caption, caption_size = "l",
}

#Change width of columns if requested
for(i in 1:length(width_overwrite)) {
if(!is.null(width_overwrite)){
for(i in 1:length(width_overwrite)) {
gov_table$children[[2]]$children[[1]][[3]][[1]][[i]]$attribs$class <-
paste0(
gov_table$children[[2]]$children[[1]][[3]][[1]][[i]]$attribs$class,
" govuk-!-width-", width_overwrite[i])
}
}


return(gov_table)
}

Expand Down
42 changes: 42 additions & 0 deletions tests/testthat/test-govTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ test_that("table works", {

example_data <- data.frame(Months, Bikes, Cars)

# test table with specified widths
table_check <- govTable(
"tab1", example_data, "Test", "l", num_col = c(2,3),
width_overwrite = c("one-half", "one-quarter", "one-quarter"))
Expand All @@ -25,4 +26,45 @@ test_that("table works", {
3
)

# test table with unspecified widths
table_check2 <- govTable(
"tab2", example_data, "Test", "l", num_col = c(2,3),
width_overwrite = NULL)

expect_identical(
table_check2$children[[2]]$children[[1]][[3]][[1]][[1]]$attribs$class,
"govuk-table__header"
)

expect_identical(
table_check2$children[[2]]$children[[1]][[3]][[1]][[2]]$attribs$class,
"govuk-table__header govuk-table__header--numeric"
)

expect_equal(
length(table_check2$children[[3]]),
3
)


# and if the argument isn't mentioned at all
table_check3 <- govTable(
"tab2", example_data, "Test", "l", num_col = c(2,3))

expect_identical(
table_check3$children[[2]]$children[[1]][[3]][[1]][[1]]$attribs$class,
"govuk-table__header"
)

expect_identical(
table_check3$children[[2]]$children[[1]][[3]][[1]][[2]]$attribs$class,
"govuk-table__header govuk-table__header--numeric"
)

expect_equal(
length(table_check3$children[[3]]),
3
)


})
Loading