@@ -3,24 +3,40 @@ package virtualized
3
3
4
4
import org .scalatest ._
5
5
import japgolly .scalajs .react ._
6
+ import japgolly .scalajs .react .test ._
7
+ import japgolly .scalajs .react .vdom .html_<^ .{< => << , _ }
6
8
7
9
class AutoSizerSpec extends FlatSpec with Matchers with NonImplicitAssertions with TestUtils {
10
+ def children (s : Size ): VdomNode =
11
+ << .div(
12
+ ^ .width := s.width.px,
13
+ ^ .height := s.height.px,
14
+ << .span(" text" )
15
+ )
8
16
9
17
" AutoSizer" should
10
- " require width and dataKey" in {
11
- Column (Column .props(200 , " key" )).props.width should be (200 )
12
- Column (Column .props(200 , " key" )).props.dataKey should be (" key" )
18
+ " render" in {
19
+ val autoSizer = AutoSizer (AutoSizer .props(children = children))
20
+ ReactTestUtils .withRenderedIntoDocument(autoSizer) { m =>
21
+ val html =
22
+ """ <div style="overflow: visible; height: 0px; width: 0px;">
23
+ |<div style="width: 0px; height: 0px;">
24
+ |<span>text</span>
25
+ |</div>
26
+ |</div>""" .stripMargin.replaceAll(" [\n\r ]" , " " )
27
+ assert(m.outerHtmlScrubbed() == html)
28
+ }
13
29
}
14
30
it should " support disableWidth" in {
15
- AutoSizer (AutoSizer .props()).props.disableWidth.toOption should contain(false )
16
- AutoSizer (AutoSizer .props(disableWidth = true )).props.disableWidth.toOption should contain(true )
31
+ AutoSizer (AutoSizer .props(children = children )).props.disableWidth.toOption should contain(false )
32
+ AutoSizer (AutoSizer .props(children = children, disableWidth = true )).props.disableWidth.toOption should contain(true )
17
33
}
18
34
it should " support disableHeight" in {
19
- AutoSizer (AutoSizer .props()).props.disableHeight.toOption should contain(false )
20
- AutoSizer (AutoSizer .props(disableHeight = true )).props.disableHeight.toOption should contain(true )
35
+ AutoSizer (AutoSizer .props(children = children )).props.disableHeight.toOption should contain(false )
36
+ AutoSizer (AutoSizer .props(children = children, disableHeight = true )).props.disableHeight.toOption should contain(true )
21
37
}
22
38
it should " support onResize" in {
23
39
val size = Size (height = 10 , width = 20 )
24
- AutoSizer (AutoSizer .props(onResize = x => Callback .log(x))).props.onResize(size) should be(())
40
+ AutoSizer (AutoSizer .props(children = children, onResize = x => Callback .log(x))).props.onResize(size) should be(())
25
41
}
26
42
}
0 commit comments