tests/testthat/test-browse-data.R

test_that("data_browser shows metrics, column info and sorts", {
  viewer <- data_browser(mtcars)
  pilot <- test_app(viewer, 110, 30)
  text <- pilot$screen_text()
  expect_match(text[[1]], "mtcars")
  expect_true(any(grepl("32 of 32 rows", text)))
  info <- pilot$query_one("#column-info")
  expect_identical(info$data$Type, "numeric")
  expect_identical(info$data$Missing, 0L)
  pilot$press("right")
  expect_identical(pilot$query_one("#info-panel")$border_title, "cyl")
  pilot$press("s")
  tbl <- pilot$query_one("#table")
  expect_identical(mtcars$cyl[tbl$view[[1]]], 4)
  pilot$press("s")
  expect_identical(mtcars$cyl[tbl$view[[1]]], 8)
  expect_true(any(grepl("sorted by cyl (desc)", pilot$screen_text(), fixed = TRUE)))
  pilot$press("enter")
  expect_true(inherits(pilot$app$screen, "ModalScreen"))
  pilot$press("escape", "r")
  expect_identical(tbl$view, seq_len(32))
})

test_that("data_browser searches across columns", {
  df <- data.frame(name = c("alpha", "beta", "gamma"), grp = factor(c("x", "y", "x")))
  pilot <- test_app(data_browser(df, title = "demo"), 90, 24)
  pilot$press("/")
  expect_identical(pilot$app$focused$id, "search")
  pilot$type("x")
  pilot$press("enter")
  expect_identical(pilot$query_one("#table")$view, c(1L, 3L))
  expect_true(any(grepl("2 of 3 rows", pilot$screen_text())))
  pilot$press("/", "escape")
  expect_identical(pilot$query_one("#table")$row_count, 3L)
  expect_identical(search_rows(df, ""), NULL)
  expect_identical(column_summary(df$grp, "grp")$`Top 1`, "x (2)")
})

Try the termr package in your browser

Any scripts or data that you put into this service are public.

termr documentation built on Oct. 21, 2026, 5:13 p.m.