File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -1571,6 +1571,48 @@ describe('Schema form',function(){
15711571 } ) ;
15721572 } ) ;
15731573
1574+ it ( 'should sort select options by enum' , function ( ) {
1575+
1576+ inject ( function ( $compile , $rootScope ) {
1577+ var scope = $rootScope . $new ( ) ;
1578+ scope . person = { } ;
1579+
1580+ scope . schema = {
1581+ "type" : "object" ,
1582+ "properties" : {
1583+ "thing" : {
1584+ "type" : "string" ,
1585+ "title" : "Thing" ,
1586+ "enum" : [
1587+ // Intentionally non-alphabetical
1588+ // https://github.com/Textalk/angular-schema-form/issues/82
1589+ // https://github.com/Textalk/angular-schema-form/issues/83
1590+ "b" ,
1591+ "a"
1592+ ] ,
1593+ "enumNames" : {
1594+ // Intentionally not the same order as the `enum`
1595+ "a" : "The A" ,
1596+ "b" : "The B"
1597+ }
1598+ }
1599+ }
1600+ } ;
1601+
1602+ scope . form = [ "*" ] ;
1603+
1604+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person"></form>' ) ;
1605+
1606+ $compile ( tmpl ) ( scope ) ;
1607+ $rootScope . $apply ( ) ;
1608+
1609+ console . log ( tmpl ) ;
1610+
1611+ tmpl . children ( ) . eq ( 0 ) . find ( 'select' ) . eq ( 0 ) . find ( 'option' ) . eq ( 0 ) . text ( ) . trim ( ) . should . be . eq ( '' ) ;
1612+ tmpl . children ( ) . eq ( 0 ) . find ( 'select' ) . eq ( 0 ) . find ( 'option' ) . eq ( 1 ) . text ( ) . trim ( ) . should . be . eq ( 'The B' ) ;
1613+ tmpl . children ( ) . eq ( 0 ) . find ( 'select' ) . eq ( 0 ) . find ( 'option' ) . eq ( 2 ) . text ( ) . trim ( ) . should . be . eq ( 'The A' ) ;
1614+ } ) ;
1615+ } ) ;
15741616
15751617 } ) ;
15761618
You can’t perform that action at this time.
0 commit comments