Skip to content

Commit

Permalink
Add several testthat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rich-iannone committed Apr 8, 2019
1 parent c496adf commit 31eff6d
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 26 deletions.
26 changes: 0 additions & 26 deletions tests/testthat/test-cols_label.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,3 @@ test_that("the function `cols_label()` works correctly", {
gt(tbl) %>%
cols_label(col_a = "col_1"))
})

test_that("all column labels can be entirely hidden from view", {

# Expect that the option `column_labels.hidden = TRUE` will
# remove the expected node with the classes of `gt_col_heading`
# and `gt_right` (i.e., the column labels)
expect_length(
tbl %>%
gt() %>%
tab_options(column_labels.hidden = TRUE) %>%
render_as_html() %>%
xml2::read_html() %>%
selection_text("[class='gt_col_heading gt_right']"),
0)

# Expect that not hiding the column labels yields a length
# four vector when using the same search
expect_length(
tbl %>%
gt() %>%
render_as_html() %>%
xml2::read_html() %>%
selection_text("[class='gt_col_heading gt_right']"),
4)
})

114 changes: 114 additions & 0 deletions tests/testthat/test-tab_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,117 @@ test_that("the `opts_df` getter/setter both function properly", {
opts_df_get(option = "footnote_font_size") %>%
expect_equal("60%")
})

test_that("all column labels can be entirely hidden from view", {

# Expect that the option `column_labels.hidden = TRUE` will
# remove the expected node with the classes of `gt_col_heading`
# and `gt_right` (i.e., the column labels)
expect_length(
tbl %>%
gt() %>%
tab_options(column_labels.hidden = TRUE) %>%
render_as_html() %>%
xml2::read_html() %>%
selection_text("[class='gt_col_heading gt_right']"),
0)

# Expect that not hiding the column labels yields a length
# four vector when using the same search
expect_length(
tbl %>%
gt() %>%
render_as_html() %>%
xml2::read_html() %>%
selection_text("[class='gt_col_heading gt_right']"),
4)
})

test_that("the row striping options work correctly", {

# Expect that the option `row.striping.include_stub = FALSE`
# will result in no CSS class combinations of `gt_stub` and
# `gt_striped`
expect_length(
tbl %>%
gt() %>%
tab_options(row.striping.include_stub = FALSE) %>%
render_as_html() %>%
xml2::read_html() %>%
selection_text("[class='gt_row gt_stub gt_left gt_striped']"),
0)

# Expect that the option `row.striping.include_stub = TRUE` will
# result in a particular class combination for every second
# stub cell (includes `gt_striped`)
expect_length(
tbl %>%
gt() %>%
tab_options(row.striping.include_stub = TRUE) %>%
render_as_html() %>%
xml2::read_html() %>%
selection_text("[class='gt_row gt_stub gt_left gt_striped']"),
5)

# Expect that the option `row.striping.include_table_body = TRUE` will
# result in a particular class combination for every second
# stub cell (includes `gt_striped`)
expect_length(
tbl %>%
gt() %>%
tab_options(row.striping.include_table_body = TRUE) %>%
render_as_html() %>%
xml2::read_html() %>%
selection_text("[class='gt_row gt_right gt_striped']"),
20)

# Expect that the options `row.striping.include_table_body = TRUE`
# and `row.striping.include_stub = TRUE` will result in cells that
# have either of two class combinations for every second stub cell
# (both include `gt_striped`)
expect_length(
c(
tbl %>%
gt() %>%
tab_options(
row.striping.include_stub = TRUE,
row.striping.include_table_body = TRUE) %>%
render_as_html() %>%
xml2::read_html() %>%
selection_text("[class='gt_row gt_stub gt_left gt_striped']"),
tbl %>%
gt() %>%
tab_options(
row.striping.include_stub = TRUE,
row.striping.include_table_body = TRUE) %>%
render_as_html() %>%
xml2::read_html() %>%
selection_text("[class='gt_row gt_right gt_striped']")
),
25)

# Expect that the options `row.striping.include_table_body = FALSE`
# and `row.striping.include_stub = FALSE` will result in cells that
# have neither of two class combinations in every second stub cell
# (with `gt_striped`)
expect_length(
c(
tbl %>%
gt() %>%
tab_options(
row.striping.include_stub = FALSE,
row.striping.include_table_body = FALSE) %>%
render_as_html() %>%
xml2::read_html() %>%
selection_text("[class='gt_row gt_stub gt_left gt_striped']"),
tbl %>%
gt() %>%
tab_options(
row.striping.include_stub = FALSE,
row.striping.include_table_body = FALSE) %>%
render_as_html() %>%
xml2::read_html() %>%
selection_text("[class='gt_row gt_right gt_striped']")
),
0)
})

0 comments on commit 31eff6d

Please sign in to comment.