@@ -2,13 +2,12 @@ import { select } from 'd3-selection';
22import SvgChart from './SvgChart.js' ;
33
44describe ( 'SvgChart' , ( ) => {
5- let element , $element , $svg , chart ;
5+ let element , $element , chart ;
66
77 beforeEach ( ( ) => {
88 element = document . body . appendChild ( document . createElement ( 'div' ) ) ;
99 chart = new SvgChart ( element , null ) ;
1010 $element = select ( element ) ;
11- $svg = $element . select ( 'svg' ) ;
1211 } ) ;
1312
1413 describe ( 'new SvgChart(element, options)' , ( ) => {
@@ -68,39 +67,50 @@ describe('SvgChart', () => {
6867
6968 describe ( '.width(width)' , ( ) => {
7069 it ( 'should return <svg> width when called without argument' , ( ) => {
71- const w = $ svg. attr ( 'width' ) ;
70+ const w = chart . svg . attr ( 'width' ) ;
7271 expect ( chart . width ( ) ) . to . equal ( + w ) ;
7372 } ) ;
7473 it ( 'should set <svg> width when called with Number as the first argument' , ( ) => {
7574 chart
7675 . width ( 300 )
7776 . updateDimensionNow ( ) ;
78- expect ( + $ svg. attr ( 'width' ) ) . to . equal ( 300 ) ;
77+ expect ( + chart . svg . attr ( 'width' ) ) . to . equal ( 300 ) ;
7978 } ) ;
8079 } ) ;
8180
8281 describe ( '.height(height)' , ( ) => {
8382 it ( 'should return <svg> height when called without argument' , ( ) => {
84- const w = $ svg. attr ( 'height' ) ;
83+ const w = chart . svg . attr ( 'height' ) ;
8584 expect ( chart . height ( ) ) . to . equal ( + w ) ;
8685 } ) ;
8786 it ( 'should set <svg> height when called with Number as the first argument' , ( ) => {
8887 chart
8988 . height ( 300 )
9089 . updateDimensionNow ( ) ;
91- expect ( + $svg . attr ( 'height' ) ) . to . equal ( 300 ) ;
90+ expect ( + chart . svg . attr ( 'height' ) ) . to . equal ( 300 ) ;
91+ } ) ;
92+ it ( 'should override line-height and set <svg> height correctly' , ( ) => {
93+ const element2 = document . body . appendChild ( document . createElement ( 'div' ) ) ;
94+ element2 . style . lineHeight = 1 ;
95+ const chart2 = new SvgChart ( element2 ) ;
96+ chart2
97+ . height ( 300 )
98+ . updateDimensionNow ( ) ;
99+ expect ( + chart2 . svg . attr ( 'height' ) ) . to . equal ( 300 ) ;
100+ expect ( + chart2 . container . node ( ) . clientHeight ) . to . equal ( 300 ) ;
101+ expect ( + element2 . style . lineHeight ) . to . equal ( 0 ) ;
92102 } ) ;
93103 } ) ;
94104
95105 describe ( '.dimension(dimension)' , ( ) => {
96106 it ( 'should return an array [width, height] when called without argument' , ( ) => {
97- const dim = [ + $ svg. attr ( 'width' ) , + $ svg. attr ( 'height' ) ] ;
107+ const dim = [ + chart . svg . attr ( 'width' ) , + chart . svg . attr ( 'height' ) ] ;
98108 expect ( chart . dimension ( ) ) . to . deep . equal ( dim ) ;
99109 } ) ;
100110 it ( 'should set width and height of the <svg> when called with an array [width, height] as the first argument' , done => {
101111 chart . dimension ( [ 118 , 118 ] ) ;
102112 setTimeout ( ( ) => {
103- expect ( [ + $ svg. attr ( 'width' ) , + $ svg. attr ( 'height' ) ] ) . to . deep . equal ( [ 118 , 118 ] ) ;
113+ expect ( [ + chart . svg . attr ( 'width' ) , + chart . svg . attr ( 'height' ) ] ) . to . deep . equal ( [ 118 , 118 ] ) ;
104114 done ( ) ;
105115 } , 0 ) ;
106116 } ) ;
0 commit comments