tests/testthat/test-div.R

testthat::context("divs")

test_css <- htmltools::css(marginLeft='auto',marginRight='auto')

testthat::describe('slick div types',{
  
  it('img default',{
    testthat::expect_equal(
      slick_div($uri[1]),
      list(htmltools::img(src =  as.character($uri[1]), style = test_css))
    )
  })
  
  it('img vector',{
    testthat::expect_equal(
      slick_div($uri[c(1,2)]),
      lapply($uri[c(1,2)], function(x,css) htmltools::img(src =  x, style = css),css = test_css)
    )
  })
  
  it('img file',{
    testthat::expect_equal(
      slick_div('../assets/img1.png'),
      list(htmltools::img(src =  readImage('../assets/img1.png'), style = test_css))
    )
  })
  
  it('img link',{
    testthat::expect_equal(
      slick_div($uri[1],links = $player_home[1]),
      list(
        htmltools::a(
          htmltools::img(src =  $uri[1], style = test_css),
          href = $player_home[1], target="_blank"
        ))
    )
  })
  
  it('p',{
    testthat::expect_equal(
      slick_div('1234',type = 'p'),
      list(htmltools::p('1234', style = test_css))
    )
  })
  
  it('iframe',{
    testthat::expect_equal(
      slick_div('1234',type = 'iframe'),
      list(htmltools::tags$iframe(srcdoc = '1234', style = test_css))
    )
  })
  
})

testthat::describe('slick list',{
  
  it('dots',{
    testthat::expect_equal(
      slick_list(slick_div($uri[1],type = 'img'),
                 slick_div($uri[2],type = 'img')
                ),
      htmltools::tagList(
        list(htmltools::div(
          list(htmltools::img(src =  as.character($uri[1]), style = test_css))
          ),
        htmltools::div(
          list(htmltools::img(src =  as.character($uri[2]), style = test_css))
          )
        )
      )
    )
  })
  
  it('list',{
    testthat::expect_equal(
      slick_list(list(slick_div($uri[1],type = 'img'),
                 slick_div($uri[2],type = 'img'))
      ),
      htmltools::tagList(
        list(htmltools::div(
          list(htmltools::img(src =  as.character($uri[1]), style = test_css))
        ),
        htmltools::div(
          list(htmltools::img(src =  as.character($uri[2]), style = test_css))
        )
        )
      )
    )
  })
})

testthat::describe('slick outer div',{
  it('wrap div',{
    testthat::expect_equal(
      {set.seed(123)
      outer_div(slick_div($uri[1]),id = '123')},
      readRDS('../assets/outer_div.Rds')
    )
  })
})

Try the slickR package in your browser

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

slickR documentation built on Dec. 28, 2022, 2:41 a.m.