test_that("plot_life_cycle works correctly", {
  mat_a <- mat_u + mat_f
  stages <- letters[seq_len(nrow(mat_a))]
  mat_a_na <- mat_a
  mat_a_na[1, 3] <- NA

  p1 <- plot_life_cycle(mat_a)
  p2 <- plot_life_cycle(mat_a, stages = stages)
  p3 <- plot_life_cycle(mat_a, stages = stages, title = "my_title")
  p4 <- plot_life_cycle(mat_a, node_order = 1:4)
  p5 <- plot_life_cycle(mat_a_na)

  expect_s3_class(p1, "grViz")
  expect_s3_class(p2, "grViz")
  expect_s3_class(p3, "grViz")
  expect_s3_class(p4, "grViz")
  expect_s3_class(p5, "grViz")
  expect_match(p1$x$diagram, "graph\\[overlap=false, margin=0, pad=0\\]")
  expect_false(grepl("x \\[style=invis\\]", p1$x$diagram))
  expect_false(grepl("labelloc=\"t\"", p1$x$diagram, fixed = TRUE))
  expect_true(grepl("labelloc=\"t\"", p3$x$diagram, fixed = TRUE))
  expect_true(grepl("\n  label=\"my_title\"", p3$x$diagram, fixed = TRUE))
})


test_that("plot_life_cycle warns and fails gracefully", {
  mat_a <- mat_u + mat_f
  colnames(mat_a) <- paste0("A", seq_len(nrow(mat_a)))
  rownames(mat_a) <- paste0("B", seq_len(nrow(mat_a)))
  # make rownames different from colnames
  stages <- dimnames(mat_a)[[1]]

  expect_message(plot_life_cycle(mat_a))
})

# Test failure with incorrect dimensions.
mat_a <- mat_u + mat_f

# wrong number of stages
expect_error(plot_life_cycle(mat_a, stages = c("A", "B", "C")))

# wrong number of entries in node_order
expect_error(plot_life_cycle(mat_a, node_order = 1:3))
