@@ -7,60 +7,34 @@ var vows = require("vows"),
77var suite = vows . describe ( "d3.selectAll" ) ;
88
99suite . addBatch ( {
10- "style " : {
10+ "selectAll " : {
1111 topic : function ( ) {
12- return d3 . select ( "body" ) . selectAll ( "div" ) . data ( d3 . range ( 2 ) ) . enter ( ) . append ( "div" ) ;
13- } ,
14- "can set a property as a string" : function ( div ) {
15- div . style ( "background-color" , "red" ) ;
16- assert . equal ( div [ 0 ] [ 0 ] . style [ "background-color" ] , "red" ) ;
17- assert . equal ( div [ 0 ] [ 1 ] . style [ "background-color" ] , "red" ) ;
18- } ,
19- "can set a property as a number" : function ( div ) {
20- div . style ( "opacity" , .5 ) ;
21- assert . equal ( div [ 0 ] [ 0 ] . style [ "opacity" ] , ".5" ) ;
22- assert . equal ( div [ 0 ] [ 1 ] . style [ "opacity" ] , ".5" ) ;
23- } ,
24- "can set a property as a function" : function ( div ) {
25- div . style ( "background-color" , d3 . interpolateRgb ( "orange" , "yellow" ) ) ;
26- assert . equal ( div [ 0 ] [ 0 ] . style [ "background-color" ] , "rgb(255,165,0)" ) ;
27- assert . equal ( div [ 0 ] [ 1 ] . style [ "background-color" ] , "rgb(255,255,0)" ) ;
28- } ,
29- "can get a property value" : function ( div ) {
30- div [ 0 ] [ 0 ] . style . setProperty ( "background-color" , "green" , "" ) ;
31- assert . equal ( div . style ( "background-color" ) , "green" ) ;
32- } ,
33- "observes the specified priority" : function ( div ) {
34- div . style ( "background-color" , "blue" , "important" ) ;
35- assert . equal ( div [ 0 ] [ 0 ] . style . getPropertyPriority ( "background-color" ) , "important" ) ;
36- assert . equal ( div [ 0 ] [ 1 ] . style . getPropertyPriority ( "background-color" ) , "important" ) ;
37- }
38- }
39- } ) ;
40-
41- suite . addBatch ( {
42- "attr" : {
43- topic : function ( ) {
44- return d3 . select ( "body" ) . selectAll ( "div" ) ;
45- } ,
46- "can set an attribute as a string" : function ( div ) {
47- div . attr ( "bgcolor" , "red" ) ;
48- assert . equal ( div [ 0 ] [ 0 ] . getAttribute ( "bgcolor" ) , "red" ) ;
49- assert . equal ( div [ 0 ] [ 1 ] . getAttribute ( "bgcolor" ) , "red" ) ;
50- } ,
51- "can set an attribute as a number" : function ( div ) {
52- div . attr ( "opacity" , 0.4 ) ;
53- assert . equal ( div [ 0 ] [ 0 ] . getAttribute ( "opacity" ) , "0.4" ) ;
54- assert . equal ( div [ 0 ] [ 1 ] . getAttribute ( "opacity" ) , "0.4" ) ;
55- } ,
56- "can set an attribute as a function" : function ( div ) {
57- div . attr ( "bgcolor" , d3 . interpolateRgb ( "brown" , "steelblue" ) ) ;
58- assert . equal ( div [ 0 ] [ 0 ] . getAttribute ( "bgcolor" ) , "rgb(165,42,42)" ) ;
59- assert . equal ( div [ 0 ] [ 1 ] . getAttribute ( "bgcolor" ) , "rgb(70,130,180)" ) ;
60- } ,
61- "can get an attribute value" : function ( div ) {
62- div [ 0 ] [ 0 ] . setAttribute ( "bgcolor" , "purple" ) ;
63- assert . equal ( div . attr ( "bgcolor" ) , "purple" ) ;
12+ var body = d3 . select ( "body" ) . html ( "" ) ;
13+ body . append ( "span" ) . attr ( "class" , "f00" ) . attr ( "id" , "b4r" ) . attr ( "name" , "b4z" ) ;
14+ body . append ( "div" ) . attr ( "class" , "foo" ) . attr ( "id" , "bar" ) . attr ( "name" , "baz" ) ;
15+ return body ;
16+ } ,
17+ "selects by element name" : function ( ) {
18+ var div = d3 . selectAll ( "div" ) ;
19+ assert . equal ( div [ 0 ] [ 0 ] . tagName , "DIV" ) ;
20+ } ,
21+ "selects by class name" : function ( ) {
22+ var div = d3 . selectAll ( ".foo" ) ;
23+ assert . equal ( div [ 0 ] [ 0 ] . className , "foo" ) ;
24+ } ,
25+ "selects by id" : function ( ) {
26+ var div = d3 . select ( "div#bar" ) ;
27+ assert . equal ( div [ 0 ] [ 0 ] . id , "bar" ) ;
28+ } ,
29+ "selects by attribute value" : function ( ) {
30+ var div = d3 . selectAll ( "[name=baz]" ) ;
31+ assert . equal ( div [ 0 ] [ 0 ] . getAttribute ( "name" ) , "baz" ) ;
32+ } ,
33+ "selects by array" : function ( ) {
34+ var div = d3 . selectAll ( [ document . body . lastChild ] ) ;
35+ assert . isTrue ( div [ 0 ] [ 0 ] === document . body . lastChild ) ;
36+ assert . length ( div , 1 ) ;
37+ assert . length ( div [ 0 ] , 1 ) ;
6438 }
6539 }
6640} ) ;
0 commit comments