11describe ( 'GridColumn factory' , function ( ) {
2- var $q , $scope , cols , grid , gridCol , Grid , GridColumn , gridClassFactory , GridRenderContainer , uiGridConstants , $httpBackend ;
2+ var $q , $scope , cols , grid , Grid , GridColumn , gridClassFactory , GridRenderContainer , uiGridConstants , $httpBackend ;
33
44 beforeEach ( module ( 'ui.grid' ) ) ;
55
@@ -65,8 +65,7 @@ describe('GridColumn factory', function () {
6565
6666 describe ( 'should not update sort when updating a column, but visible flag does update' , function ( ) {
6767 beforeEach ( function ( complete ) {
68- var sort = { priority : 0 , direction : 'asc' } ;
69- grid . options . columnDefs [ 0 ] . sort = sort ;
68+ grid . options . columnDefs [ 0 ] . sort = { priority : 0 , direction : 'asc' } ;
7069 grid . options . columnDefs [ 0 ] . visible = false ;
7170 buildCols ( complete ) ;
7271 } ) ;
@@ -79,8 +78,7 @@ describe('GridColumn factory', function () {
7978
8079 describe ( 'should update everything but term when updating filters' , function ( ) {
8180 beforeEach ( function ( complete ) {
82- var filter = { term : 'x' , placeholder : 'placeholder' , type : uiGridConstants . filter . SELECT , selectOptions : [ { value : 1 , label : "male" } ] } ;
83- grid . options . columnDefs [ 0 ] . filter = filter ;
81+ grid . options . columnDefs [ 0 ] . filter = { term : 'x' , placeholder : 'placeholder' , type : uiGridConstants . filter . SELECT , selectOptions : [ { value : 1 , label : "male" } ] } ;
8482 buildCols ( complete ) ;
8583 } ) ;
8684
@@ -92,8 +90,7 @@ describe('GridColumn factory', function () {
9290
9391 describe ( 'should update everything but term when updating filters' , function ( ) {
9492 beforeEach ( function ( complete ) {
95- var filters = [ { term : 'x' , placeholder : 'placeholder' , type : uiGridConstants . filter . SELECT , selectOptions : [ { value : 1 , label : "male" } ] } ] ;
96- grid . options . columnDefs [ 0 ] . filters = filters ;
93+ grid . options . columnDefs [ 0 ] . filters = [ { term : 'x' , placeholder : 'placeholder' , type : uiGridConstants . filter . SELECT , selectOptions : [ { value : 1 , label : "male" } ] } ] ;
9794 buildCols ( complete ) ;
9895 } ) ;
9996
@@ -103,7 +100,6 @@ describe('GridColumn factory', function () {
103100 } ) ;
104101
105102
106-
107103 it ( 'should obey columnDef sort spec' , function ( ) {
108104 // ... TODO(c0bra)
109105 } ) ;
@@ -115,15 +111,13 @@ describe('GridColumn factory', function () {
115111 } ) ;
116112
117113 it ( 'should add an incrementing number to column names when they have the same field and no name' , function ( ) {
118- var cols = [
114+ grid . options . columnDefs = [
119115 { field : 'age' } ,
120116 { field : 'name' } ,
121117 { field : 'name' } ,
122118 { field : 'name' }
123119 ] ;
124120
125- grid . options . columnDefs = cols ;
126-
127121 buildCols ( ) ;
128122
129123 expect ( grid . columns [ 0 ] . name ) . toEqual ( 'age' ) ;
@@ -133,34 +127,29 @@ describe('GridColumn factory', function () {
133127 } ) ;
134128
135129 it ( 'should not change the displayNames if they are provided' , function ( ) {
136- var cols = [
130+ grid . options . columnDefs = [
137131 { field : 'age' } ,
138132 { field : 'name' , displayName :'First Name' } ,
139133 { field : 'name' , displayName :'First Name' } ,
140134 { field : 'name' , displayName :'First Name' }
141135 ] ;
142136
143- grid . options . columnDefs = cols ;
144-
145137 buildCols ( ) ;
146138
147139 expect ( grid . columns [ 0 ] . displayName ) . toEqual ( 'Age' ) ;
148140 expect ( grid . columns [ 1 ] . displayName ) . toEqual ( 'First Name' ) ;
149141 expect ( grid . columns [ 2 ] . displayName ) . toEqual ( 'First Name' ) ;
150142 expect ( grid . columns [ 3 ] . displayName ) . toEqual ( 'First Name' ) ;
151-
152143 } ) ;
153144
154145 it ( 'should account for existing incremented names' , function ( ) {
155- var cols = [
146+ grid . options . columnDefs = [
156147 { field : 'age' } ,
157148 { field : 'name' } ,
158149 { field : 'name' , name : 'name3' } ,
159150 { field : 'name' }
160151 ] ;
161152
162- grid . options . columnDefs = cols ;
163-
164153 buildCols ( ) ;
165154
166155 expect ( grid . columns [ 0 ] . name ) . toEqual ( 'age' ) ;
@@ -622,6 +611,29 @@ describe('GridColumn factory', function () {
622611 expect ( updateCol ( col , colDef ) ) . toThrow ( ) ;
623612 } ) ;
624613
614+ describe ( 'displayName' , function ( ) {
615+ it ( 'should allow the user to set the displayName to an empty string or null value' , function ( ) {
616+ colDef . displayName = '' ;
617+ col . updateColumnDef ( colDef ) ;
618+ expect ( col . displayName ) . toEqual ( '' ) ;
619+
620+ colDef . displayName = null ;
621+ col . updateColumnDef ( colDef ) ;
622+ expect ( col . displayName ) . toBeNull ( ) ;
623+ } ) ;
624+ it ( 'should allow the user to enter whatever displayName they desire' , function ( ) {
625+ colDef . displayName = 'Test' ;
626+ col . updateColumnDef ( colDef ) ;
627+ expect ( col . displayName ) . toEqual ( colDef . displayName ) ;
628+ } ) ;
629+ it ( 'should generate a displayName based on the name attribute if the user does not define it' , function ( ) {
630+ colDef . displayName = undefined ;
631+ colDef . name = 'mockName' ;
632+ col . updateColumnDef ( colDef ) ;
633+ expect ( col . displayName ) . toEqual ( 'Mock Name' ) ;
634+ } ) ;
635+ } ) ;
636+
625637 describe ( 'cellTooltip' , function ( ) {
626638 it ( 'should be set to false when it is undefined' , function ( ) {
627639 colDef . cellTooltip = undefined ;
0 commit comments