@@ -717,44 +717,63 @@ describe('BaseTable', () => {
717
717
let props ;
718
718
let wrapper ;
719
719
describe ( 'handleChangeSortDirection' , ( ) => {
720
- beforeEach ( ( ) => {
721
- props = createTestProps ( {
722
- onSortChange : jest . fn ( ) ,
723
- sortBy : 'id' ,
724
- sortDirection : 'ASC' ,
725
- } ) ;
726
- wrapper = shallow ( < BaseTable { ...props } /> ) ;
727
- } ) ;
728
- describe ( 'when previous direction was ASC' , ( ) => {
729
- beforeEach ( ( ) => {
730
- wrapper . instance ( ) . handleChangeSortDirection ( 'id' ) ;
731
- } ) ;
732
- it ( 'should call onSortChange with direction DESC' , ( ) => {
733
- expect ( props . onSortChange ) . toHaveBeenCalledWith ( 'id' , 'DESC' ) ;
734
- } ) ;
735
- } ) ;
736
- describe ( 'when previous direction was DESC' , ( ) => {
720
+ describe ( 'with `onSortChange`' , ( ) => {
737
721
beforeEach ( ( ) => {
738
722
props = createTestProps ( {
739
723
onSortChange : jest . fn ( ) ,
740
724
sortBy : 'id' ,
741
- sortDirection : 'DESC ' ,
725
+ sortDirection : 'ASC ' ,
742
726
} ) ;
743
727
wrapper = shallow ( < BaseTable { ...props } /> ) ;
744
728
} ) ;
745
- beforeEach ( ( ) => {
746
- wrapper . instance ( ) . handleChangeSortDirection ( 'id' ) ;
729
+ describe ( 'when previous direction was ASC' , ( ) => {
730
+ beforeEach ( ( ) => {
731
+ wrapper . instance ( ) . handleChangeSortDirection ( 'id' ) ;
732
+ } ) ;
733
+ it ( 'should call onSortChange with direction DESC' , ( ) => {
734
+ expect ( props . onSortChange ) . toHaveBeenCalledWith ( 'id' , 'DESC' ) ;
735
+ } ) ;
736
+ } ) ;
737
+ describe ( 'when previous direction was DESC' , ( ) => {
738
+ beforeEach ( ( ) => {
739
+ props = createTestProps ( {
740
+ onSortChange : jest . fn ( ) ,
741
+ sortBy : 'id' ,
742
+ sortDirection : 'DESC' ,
743
+ } ) ;
744
+ wrapper = shallow ( < BaseTable { ...props } /> ) ;
745
+ } ) ;
746
+ beforeEach ( ( ) => {
747
+ wrapper . instance ( ) . handleChangeSortDirection ( 'id' ) ;
748
+ } ) ;
749
+ it ( 'should call onSortChange with direction ASC' , ( ) => {
750
+ expect ( props . onSortChange ) . toHaveBeenCalledWith ( 'id' , 'ASC' ) ;
751
+ } ) ;
747
752
} ) ;
748
- it ( 'should call onSortChange with direction ASC' , ( ) => {
749
- expect ( props . onSortChange ) . toHaveBeenCalledWith ( 'id' , 'ASC' ) ;
753
+ describe ( 'when the sorted column changes' , ( ) => {
754
+ beforeEach ( ( ) => {
755
+ wrapper . instance ( ) . handleChangeSortDirection ( 'foo' ) ;
756
+ } ) ;
757
+ it ( 'should call onSortChange with direction ASC' , ( ) => {
758
+ expect ( props . onSortChange ) . toHaveBeenCalledWith ( 'foo' , 'ASC' ) ;
759
+ } ) ;
750
760
} ) ;
751
761
} ) ;
752
- describe ( 'when the sorted column changes' , ( ) => {
762
+
763
+ describe ( 'without `onSortChange`' , ( ) => {
753
764
beforeEach ( ( ) => {
754
- wrapper . instance ( ) . handleChangeSortDirection ( 'foo' ) ;
765
+ props = createTestProps ( {
766
+ onSortChange : null ,
767
+ sortBy : 'id' ,
768
+ sortDirection : 'ASC' ,
769
+ } ) ;
770
+ wrapper = shallow ( < BaseTable { ...props } /> ) ;
771
+
772
+ wrapper . instance ( ) . handleChangeSortDirection ( 'id' ) ;
755
773
} ) ;
756
- it ( 'should call onSortChange with direction ASC' , ( ) => {
757
- expect ( props . onSortChange ) . toHaveBeenCalledWith ( 'foo' , 'ASC' ) ;
774
+
775
+ it ( 'should not call onSortChange' , ( ) => {
776
+ expect ( props . onSortChange ) . toBe ( null ) ;
758
777
} ) ;
759
778
} ) ;
760
779
} ) ;
0 commit comments