@@ -665,3 +665,174 @@ test('edge case: rerender appearance of inner virtual view', function() {
665
665
666
666
equal ( Ember . $ ( '#qunit-fixture' ) . text ( ) , 'test' ) ;
667
667
} ) ;
668
+
669
+ if ( Ember . FEATURES . isEnabled ( 'ember-htmlbars-inline-if-helper' ) ) {
670
+ test ( "`if` helper with inline form: renders the second argument when conditional is truthy" , function ( ) {
671
+ view = EmberView . create ( {
672
+ conditional : true ,
673
+ template : compile ( '{{if view.conditional "truthy" "falsy"}}' )
674
+ } ) ;
675
+
676
+ appendView ( view ) ;
677
+
678
+ equal ( view . $ ( ) . text ( ) , 'truthy' ) ;
679
+ } ) ;
680
+
681
+ test ( "`if` helper with inline form: renders the third argument when conditional is falsy" , function ( ) {
682
+ view = EmberView . create ( {
683
+ conditional : false ,
684
+ template : compile ( '{{if view.conditional "truthy" "falsy"}}' )
685
+ } ) ;
686
+
687
+ appendView ( view ) ;
688
+
689
+ equal ( view . $ ( ) . text ( ) , 'falsy' ) ;
690
+ } ) ;
691
+
692
+ test ( "`if` helper with inline form: can omit the falsy argument" , function ( ) {
693
+ view = EmberView . create ( {
694
+ conditional : true ,
695
+ template : compile ( '{{if view.conditional "truthy"}}' )
696
+ } ) ;
697
+
698
+ appendView ( view ) ;
699
+
700
+ equal ( view . $ ( ) . text ( ) , 'truthy' ) ;
701
+ } ) ;
702
+
703
+ test ( "`if` helper with inline form: can omit the falsy argument and renders nothing when conditional is falsy" , function ( ) {
704
+ view = EmberView . create ( {
705
+ conditional : false ,
706
+ template : compile ( '{{if view.conditional "truthy"}}' )
707
+ } ) ;
708
+
709
+ appendView ( view ) ;
710
+
711
+ equal ( view . $ ( ) . text ( ) , '' ) ;
712
+ } ) ;
713
+
714
+ test ( "`if` helper with inline form: truthy and falsy arguments are changed if conditional changes" , function ( ) {
715
+ view = EmberView . create ( {
716
+ conditional : true ,
717
+ template : compile ( '{{if view.conditional "truthy" "falsy"}}' )
718
+ } ) ;
719
+
720
+ appendView ( view ) ;
721
+
722
+ equal ( view . $ ( ) . text ( ) , 'truthy' ) ;
723
+
724
+ run ( function ( ) {
725
+ view . set ( 'conditional' , false ) ;
726
+ } ) ;
727
+
728
+ equal ( view . $ ( ) . text ( ) , 'falsy' ) ;
729
+ } ) ;
730
+
731
+ test ( "`if` helper with inline form: can use truthy param as binding" , function ( ) {
732
+ view = EmberView . create ( {
733
+ truthy : 'ok' ,
734
+ conditional : true ,
735
+ template : compile ( '{{if view.conditional view.truthy}}' )
736
+ } ) ;
737
+
738
+ appendView ( view ) ;
739
+
740
+ equal ( view . $ ( ) . text ( ) , 'ok' ) ;
741
+
742
+ run ( function ( ) {
743
+ view . set ( 'truthy' , 'yes' ) ;
744
+ } ) ;
745
+
746
+ equal ( view . $ ( ) . text ( ) , 'yes' ) ;
747
+ } ) ;
748
+
749
+ test ( "`if` helper with inline form: can use falsy param as binding" , function ( ) {
750
+ view = EmberView . create ( {
751
+ truthy : 'ok' ,
752
+ falsy : 'boom' ,
753
+ conditional : false ,
754
+ template : compile ( '{{if view.conditional view.truthy view.falsy}}' )
755
+ } ) ;
756
+
757
+ appendView ( view ) ;
758
+
759
+ equal ( view . $ ( ) . text ( ) , 'boom' ) ;
760
+
761
+ run ( function ( ) {
762
+ view . set ( 'falsy' , 'no' ) ;
763
+ } ) ;
764
+
765
+ equal ( view . $ ( ) . text ( ) , 'no' ) ;
766
+ } ) ;
767
+
768
+ test ( "`if` helper with inline form: raises when using more than three arguments" , function ( ) {
769
+ view = EmberView . create ( {
770
+ conditional : true ,
771
+ template : compile ( '{{if one two three four}}' )
772
+ } ) ;
773
+
774
+ expectAssertion ( function ( ) {
775
+ appendView ( view ) ;
776
+ } , 'If helper in inline form expects between two and three arguments' ) ;
777
+ } ) ;
778
+
779
+ test ( "`if` helper with inline form: raises when using less than two arguments" , function ( ) {
780
+ view = EmberView . create ( {
781
+ conditional : true ,
782
+ template : compile ( '{{if one}}' )
783
+ } ) ;
784
+
785
+ expectAssertion ( function ( ) {
786
+ appendView ( view ) ;
787
+ } , 'If helper in inline form expects between two and three arguments' ) ;
788
+ } ) ;
789
+
790
+ test ( "`if` helper with inline form: works when used in a sub expression" , function ( ) {
791
+ view = EmberView . create ( {
792
+ conditional : true ,
793
+ innerConditional : true ,
794
+ template : compile ( '{{if view.conditional (if view.innerConditional "truthy" )}}' )
795
+ } ) ;
796
+
797
+ appendView ( view ) ;
798
+
799
+ equal ( view . $ ( ) . text ( ) , 'truthy' ) ;
800
+ } ) ;
801
+
802
+ test ( "`if` helper with inline form: updates if condition changes in a sub expression" , function ( ) {
803
+ view = EmberView . create ( {
804
+ conditional : true ,
805
+ innerConditional : true ,
806
+ template : compile ( '{{if view.conditional (if view.innerConditional "innerTruthy" "innerFalsy")}}' )
807
+ } ) ;
808
+
809
+ appendView ( view ) ;
810
+
811
+ equal ( view . $ ( ) . text ( ) , 'innerTruthy' ) ;
812
+
813
+ run ( function ( ) {
814
+ view . set ( 'innerConditional' , false ) ;
815
+ } ) ;
816
+
817
+ equal ( view . $ ( ) . text ( ) , 'innerFalsy' ) ;
818
+ } ) ;
819
+
820
+ test ( "`if` helper with inline form: can use truthy param as binding in a sub expression" , function ( ) {
821
+ view = EmberView . create ( {
822
+ conditional : true ,
823
+ innerConditional : true ,
824
+ innerTruthy : "innerTruthy" ,
825
+ template : compile ( '{{if view.conditional (if view.innerConditional view.innerTruthy)}}' )
826
+ } ) ;
827
+
828
+ appendView ( view ) ;
829
+
830
+ equal ( view . $ ( ) . text ( ) , 'innerTruthy' ) ;
831
+
832
+ run ( function ( ) {
833
+ view . set ( 'innerTruthy' , 'innerOk' ) ;
834
+ } ) ;
835
+
836
+ equal ( view . $ ( ) . text ( ) , 'innerOk' ) ;
837
+ } ) ;
838
+ }
0 commit comments