File: test-page.R

package info (click to toggle)
r-cran-bslib 0.9.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,412 kB
  • sloc: javascript: 13,349; makefile: 33; sh: 23
file content (123 lines) | stat: -rw-r--r-- 2,303 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
library(htmltools)

# All page_*() functions are very thin wrappers around
# shiny::*Page() at the moment (except for page_navbar(), which
# which why we only have tests for page_navbar())

test_that("page_navbar()", {
  skip_if_not_installed("shiny")
  expect_snapshot(
    renderTags(
      page_navbar(
        title = div(h1("foo"), h2("bar"))
      )
    )$head,
    cran = TRUE
  )

  expect_snapshot(
    renderTags(
      page_navbar(
        title = "foo",
        window_title = "bar"
      )
    )$head,
    cran = TRUE
  )

  expect_snapshot(
    renderTags(
      page_sidebar(title = "foo")
    )$head,
    cran = TRUE
  )
})

test_that("page_sidebar()", {
  with_private_seed()

  expect_snapshot(
    renderTags(
      page_sidebar(
        title = "foo",
        window_title = "bar"
      )
    )$head,
    cran = TRUE
  )

  with_private_seed()

  expect_snapshot(
    renderTags(
      page_sidebar(
        "main",
        title = "Title",
        # Removes the {bsicons} icon
        sidebar = sidebar(open = "always"),
        "data-attr" = "here"
      )
    )$html,
    cran = TRUE
  )

  with_private_seed()

  skip_if_not_installed("bsicons", "0.1.0.9000")

  expect_snapshot(
    renderTags(
      page_sidebar(
        "main",
        title = "Title",
        sidebar = "side"
      )
    )$html,
    # Don't run on CRAN since the output depends on {bsicons}
    cran = FALSE
  )
})

test_that("save_html() works on components and pages with a custom theme", {
  withr::local_options(list(htmltools.dir.version = FALSE))

  withr::with_tempdir({
    save_html(
      card("A simple card"),
      "card.html"
    )
    expect_snapshot_file("card.html")
  })

  withr::with_tempdir({
    save_html(
      page(
        theme = bs_remove(bs_theme(), "bs3compat"),
        "A simple page without bs3compat dependencies"
      ),
      "modern-page.html"
    )
    expect_snapshot_file("modern-page.html")
  })
})

test_that("page_*() functions can handle trailing commas", {
  expect_no_error(
    page("foo", )
  )
  expect_no_error(
    page_fluid("foo", )
  )
  expect_no_error(
    page_fixed("foo", )
  )
  expect_no_error(
    page_fillable("foo", )
  )
  expect_no_error(
    page_sidebar("foo", )
  )
  expect_no_error(
    page_navbar(nav_panel("foo", "bar"), )
  )
})