|
| 1 | +/* |
| 2 | + * mobile checkboxradio unit tests |
| 3 | + */ |
| 4 | +(function($){ |
| 5 | + module( 'vertical controlgroup', { |
| 6 | + setup: function() { |
| 7 | + this.vcontrolgroup = $( "#vertical-controlgroup" ); |
| 8 | + this.vcontrolgroup.find( ".ui-btn" ).show(); |
| 9 | + this.vcontrolgroup.controlgroup("refresh"); |
| 10 | + } |
| 11 | + }); |
| 12 | + |
| 13 | + test( "vertical controlgroup classes", function() { |
| 14 | + var buttons = this.vcontrolgroup.find( ".ui-btn" ), |
| 15 | + middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}), |
| 16 | + length = buttons.length; |
| 17 | + |
| 18 | + ok( buttons.first().hasClass( "ui-corner-top" ), "first button should have class 'ui-corner-top'" ); |
| 19 | + ok( !middlebuttons.hasClass( "ui-corner-top" ), "middle buttons should not have class 'ui-corner-top'" ); |
| 20 | + ok( !middlebuttons.hasClass( "ui-corner-bottom" ), "middle buttons should not have class 'ui-corner-bottom'" ); |
| 21 | + ok( buttons.last().hasClass( "ui-corner-bottom"), "last button should have class 'ui-corner-bottom'" ); |
| 22 | + }); |
| 23 | + |
| 24 | + test( "vertical controlgroup after first button was hidden", function() { |
| 25 | + //https://github.com/jquery/jquery-mobile/issues/1929 |
| 26 | + |
| 27 | + //We hide the first button and refresh |
| 28 | + this.vcontrolgroup.find( ".ui-btn" ).first().hide(); |
| 29 | + this.vcontrolgroup.controlgroup("refresh"); |
| 30 | + |
| 31 | + var buttons = this.vcontrolgroup.find( ".ui-btn" ).filter( ":visible" ), |
| 32 | + middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}), |
| 33 | + length = buttons.length; |
| 34 | + |
| 35 | + ok( buttons.first().hasClass( "ui-corner-top" ), "first visible button should have class 'ui-corner-top'" ); |
| 36 | + ok( !middlebuttons.hasClass( "ui-corner-top" ), "middle buttons should not have class 'ui-corner-top'" ); |
| 37 | + ok( !middlebuttons.hasClass( "ui-corner-bottom" ), "middle buttons should not have class 'ui-corner-bottom'" ); |
| 38 | + ok( buttons.last().hasClass( "ui-corner-bottom"), "last visible button should have class 'ui-corner-bottom'" ); |
| 39 | + }); |
| 40 | + |
| 41 | + test( "vertical controlgroup after last button was hidden", function() { |
| 42 | + //https://github.com/jquery/jquery-mobile/issues/1929 |
| 43 | + |
| 44 | + //We hide the last button and refresh |
| 45 | + this.vcontrolgroup.find( ".ui-btn" ).last().hide(); |
| 46 | + this.vcontrolgroup.controlgroup("refresh"); |
| 47 | + |
| 48 | + var buttons = this.vcontrolgroup.find( ".ui-btn" ).filter( ":visible" ), |
| 49 | + middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}), |
| 50 | + length = buttons.length; |
| 51 | + |
| 52 | + ok( buttons.first().hasClass( "ui-corner-top" ), "first visible button should have class 'ui-corner-top'" ); |
| 53 | + ok( !middlebuttons.hasClass( "ui-corner-top" ), "middle buttons should not have class 'ui-corner-top'" ); |
| 54 | + ok( !middlebuttons.hasClass( "ui-corner-bottom" ), "middle buttons should not have class 'ui-corner-bottom'" ); |
| 55 | + ok( buttons.last().hasClass( "ui-corner-bottom"), "last visible button should have class 'ui-corner-bottom'" ); |
| 56 | + }); |
| 57 | + |
| 58 | + module( 'horizontal controlgroup', { |
| 59 | + setup: function() { |
| 60 | + this.hcontrolgroup = $( "#horizontal-controlgroup" ); |
| 61 | + this.hcontrolgroup.find( ".ui-btn" ).show(); |
| 62 | + this.hcontrolgroup.controlgroup("refresh"); |
| 63 | + } |
| 64 | + }); |
| 65 | + |
| 66 | + test( "horizontal controlgroup classes", function() { |
| 67 | + var buttons = this.hcontrolgroup.find( ".ui-btn" ), |
| 68 | + middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}), |
| 69 | + length = buttons.length; |
| 70 | + |
| 71 | + ok( buttons.first().hasClass( "ui-corner-left" ), "first button should have class 'ui-corner-left'" ); |
| 72 | + ok( !middlebuttons.hasClass( "ui-corner-left" ), "middle buttons should not have class 'ui-corner-left'" ); |
| 73 | + ok( !middlebuttons.hasClass( "ui-corner-right" ), "middle buttons should not have class 'ui-corner-right'" ); |
| 74 | + ok( buttons.last().hasClass( "ui-corner-right"), "last button should have class 'ui-corner-right'" ); |
| 75 | + }); |
| 76 | + |
| 77 | + test( "horizontal controlgroup after first button was hidden", function() { |
| 78 | + //We hide the first button and refresh |
| 79 | + this.hcontrolgroup.find( ".ui-btn" ).first().hide(); |
| 80 | + this.hcontrolgroup.controlgroup("refresh"); |
| 81 | + |
| 82 | + var buttons = this.hcontrolgroup.find( ".ui-btn" ).filter( ":visible" ), |
| 83 | + middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}), |
| 84 | + length = buttons.length; |
| 85 | + |
| 86 | + ok( buttons.first().hasClass( "ui-corner-left" ), "first visible button should have class 'ui-corner-left'" ); |
| 87 | + ok( !middlebuttons.hasClass( "ui-corner-left" ), "middle buttons should not have class 'ui-corner-left'" ); |
| 88 | + ok( !middlebuttons.hasClass( "ui-corner-right" ), "middle buttons should not have class 'ui-corner-right'" ); |
| 89 | + ok( buttons.last().hasClass( "ui-corner-right"), "last visible button should have class 'ui-corner-right'" ); |
| 90 | + }); |
| 91 | + |
| 92 | + test( "horizontal controlgroup after last button was hidden", function() { |
| 93 | + //We hide the last button and refresh |
| 94 | + this.hcontrolgroup.find( ".ui-btn" ).last().hide(); |
| 95 | + this.hcontrolgroup.controlgroup("refresh"); |
| 96 | + |
| 97 | + var buttons = this.hcontrolgroup.find( ".ui-btn" ).filter( ":visible" ), |
| 98 | + middlebuttons = buttons.filter(function(index) { return index > 0 && index < (length-1)}), |
| 99 | + length = buttons.length; |
| 100 | + |
| 101 | + ok( buttons.first().hasClass( "ui-corner-left" ), "first visible button should have class 'ui-corner-left'" ); |
| 102 | + ok( !middlebuttons.hasClass( "ui-corner-left" ), "middle buttons should not have class 'ui-corner-left'" ); |
| 103 | + ok( !middlebuttons.hasClass( "ui-corner-right" ), "middle buttons should not have class 'ui-corner-right'" ); |
| 104 | + ok( buttons.last().hasClass( "ui-corner-right"), "last visible button should have class 'ui-corner-right'" ); |
| 105 | + }); |
| 106 | + |
| 107 | + |
| 108 | +})(jQuery); |
0 commit comments