@@ -717,147 +717,157 @@ describe('Utils', () => {
717
717
} ) ;
718
718
719
719
describe ( 'painting the iframe' , ( ) => {
720
+ const defaultStyles = {
721
+ position : 'fixed' ,
722
+ left : '0%' ,
723
+ right : '0%' ,
724
+ top : '0%' ,
725
+ bottom : '0%' ,
726
+ zIndex : '9999' ,
727
+ width : '100%' ,
728
+ maxHeight : '95vh' ,
729
+ maxWidth : '100%'
730
+ } ;
731
+
732
+ const checkStyles = (
733
+ styles : CSSStyleDeclaration ,
734
+ overrides ?: Partial < typeof defaultStyles > & { height ?: string }
735
+ ) => {
736
+ Object . entries ( defaultStyles ) . forEach ( ( [ key , value ] ) => {
737
+ const styleValue = styles [ key as keyof typeof styles ] ;
738
+ expect ( styleValue ) . toBe (
739
+ overrides && key in overrides
740
+ ? overrides [ key as keyof typeof overrides ]
741
+ : value
742
+ ) ;
743
+ } ) ;
744
+ } ;
745
+
720
746
it ( 'should paint the iframe in the center of the screen' , async ( ) => {
721
- const iframe = await paintIFrame (
722
- mockMarkup ,
723
- DisplayPosition . Center ,
724
- false ,
725
- 'hi'
726
- ) ;
747
+ const iframe = await paintIFrame ( {
748
+ html : mockMarkup ,
749
+ position : DisplayPosition . Center ,
750
+ srMessage : 'hi'
751
+ } ) ;
727
752
jest . advanceTimersByTime ( 2000 ) ;
728
753
729
754
/* speed up time to past the setTimeout */
730
755
const styles = getComputedStyle ( iframe ) ;
731
- expect ( styles . position ) . toBe ( 'fixed' ) ;
732
- expect ( styles . left ) . toBe ( '0%' ) ;
733
- expect ( styles . right ) . toBe ( '0%' ) ;
734
- expect ( styles . top ) . toBe ( '0%' ) ;
735
- expect ( styles . bottom ) . toBe ( '0%' ) ;
736
- expect ( styles . zIndex ) . toBe ( '9999' ) ;
737
- expect ( styles . width ) . toBe ( '100%' ) ;
738
- expect ( styles . maxHeight ) . toBe ( '95vh' ) ;
756
+ checkStyles ( styles ) ;
757
+ } ) ;
758
+
759
+ it ( 'should paint the iframe with custom maxWidth' , async ( ) => {
760
+ const { Center, TopRight, BottomRight } = DisplayPosition ;
761
+ [ Center , TopRight , BottomRight ] . forEach ( async ( position ) => {
762
+ const iframe = await paintIFrame ( {
763
+ html : mockMarkup ,
764
+ position,
765
+ maxWidth : '350px'
766
+ } ) ;
767
+ jest . advanceTimersByTime ( 2000 ) ;
768
+ const styles = getComputedStyle ( iframe ) ;
769
+ expect ( styles . maxWidth ) . toBe ( '350px' ) ;
770
+ } ) ;
739
771
} ) ;
740
772
741
773
it ( 'should paint the iframe in the top-right of the screen' , async ( ) => {
742
- const iframe = await paintIFrame (
743
- mockMarkup ,
744
- DisplayPosition . TopRight ,
745
- false ,
746
- 'hi'
747
- ) ;
774
+ const iframe = await paintIFrame ( {
775
+ html : mockMarkup ,
776
+ position : DisplayPosition . TopRight ,
777
+ srMessage : 'hi'
778
+ } ) ;
748
779
jest . advanceTimersByTime ( 2000 ) ;
749
780
750
781
/* speed up time to past the setTimeout */
751
782
const styles = getComputedStyle ( iframe ) ;
752
- expect ( styles . position ) . toBe ( 'fixed' ) ;
753
- expect ( styles . left ) . toBe ( '' ) ;
754
- expect ( styles . right ) . toBe ( '0%' ) ;
755
- expect ( styles . top ) . toBe ( '0%' ) ;
756
- expect ( styles . bottom ) . toBe ( '' ) ;
757
- expect ( styles . zIndex ) . toBe ( '9999' ) ;
758
- expect ( styles . width ) . toBe ( '100%' ) ;
759
- expect ( styles . maxHeight ) . toBe ( '95vh' ) ;
783
+ checkStyles ( styles , { left : '' , bottom : '' } ) ;
760
784
} ) ;
761
785
762
786
it ( 'should paint the iframe in the bottom-right of the screen' , async ( ) => {
763
- const iframe = await paintIFrame (
764
- mockMarkup ,
765
- DisplayPosition . BottomRight ,
766
- false ,
767
- 'hi'
768
- ) ;
787
+ const iframe = await paintIFrame ( {
788
+ html : mockMarkup ,
789
+ position : DisplayPosition . BottomRight ,
790
+ srMessage : 'hi'
791
+ } ) ;
769
792
jest . advanceTimersByTime ( 2000 ) ;
770
793
771
794
/* speed up time to past the setTimeout */
772
795
const styles = getComputedStyle ( iframe ) ;
773
- expect ( styles . position ) . toBe ( 'fixed' ) ;
774
- expect ( styles . left ) . toBe ( '' ) ;
775
- expect ( styles . right ) . toBe ( '0%' ) ;
776
- expect ( styles . bottom ) . toBe ( '0%' ) ;
777
- expect ( styles . top ) . toBe ( '' ) ;
778
- expect ( styles . zIndex ) . toBe ( '9999' ) ;
779
- expect ( styles . width ) . toBe ( '100%' ) ;
780
- expect ( styles . maxHeight ) . toBe ( '95vh' ) ;
796
+ checkStyles ( styles , { left : '' , top : '' } ) ;
781
797
} ) ;
782
798
783
799
it ( 'should paint the iframe full-screen' , async ( ) => {
784
- const iframe = await paintIFrame (
785
- mockMarkup ,
786
- DisplayPosition . Full ,
787
- false ,
788
- ''
789
- ) ;
800
+ const iframe = await paintIFrame ( {
801
+ html : mockMarkup ,
802
+ position : DisplayPosition . Full
803
+ } ) ;
790
804
jest . advanceTimersByTime ( 2000 ) ;
791
805
792
806
/* speed up time to past the setTimeout */
793
807
const styles = getComputedStyle ( iframe ) ;
794
- expect ( styles . position ) . toBe ( 'fixed' ) ;
795
- expect ( styles . left ) . toBe ( '0%' ) ;
796
- expect ( styles . right ) . toBe ( '' ) ;
797
- expect ( styles . bottom ) . toBe ( '' ) ;
798
- expect ( styles . top ) . toBe ( '0%' ) ;
799
- expect ( styles . zIndex ) . toBe ( '9999' ) ;
800
- expect ( styles . height ) . toBe ( '100%' ) ;
801
- expect ( styles . width ) . toBe ( '100%' ) ;
802
- expect ( styles . maxHeight ) . toBe ( '' ) ;
808
+ checkStyles ( styles , {
809
+ right : '' ,
810
+ bottom : '' ,
811
+ height : '100%' ,
812
+ maxHeight : ''
813
+ } ) ;
803
814
} ) ;
804
815
805
816
it ( 'should paint TopRight iframes with custom offsets' , async ( ) => {
806
- const iframe = await paintIFrame (
807
- mockMarkup ,
808
- DisplayPosition . TopRight ,
809
- false ,
810
- '' ,
811
- '10px' ,
812
- '10px' ,
813
- '10px'
814
- ) ;
817
+ const iframe = await paintIFrame ( {
818
+ html : mockMarkup ,
819
+ position : DisplayPosition . TopRight ,
820
+ topOffset : '10px' ,
821
+ bottomOffset : '10px' ,
822
+ rightOffset : '10px'
823
+ } ) ;
815
824
jest . advanceTimersByTime ( 2000 ) ;
816
825
817
826
/* speed up time to past the setTimeout */
818
827
const styles = getComputedStyle ( iframe ) ;
819
- expect ( styles . position ) . toBe ( 'fixed' ) ;
820
- expect ( styles . left ) . toBe ( '' ) ;
821
- expect ( styles . right ) . toBe ( '10px' ) ;
822
- expect ( styles . bottom ) . toBe ( '' ) ;
823
- expect ( styles . top ) . toBe ( '10px' ) ;
824
- expect ( styles . zIndex ) . toBe ( '9999' ) ;
825
- expect ( styles . width ) . toBe ( '100%' ) ;
826
- expect ( styles . maxHeight ) . toBe ( '95vh' ) ;
828
+ checkStyles ( styles , {
829
+ left : '' ,
830
+ right : '10px' ,
831
+ bottom : '' ,
832
+ top : '10px'
833
+ } ) ;
827
834
} ) ;
828
835
829
836
it ( 'should paint BottomRight iframes with custom offsets' , async ( ) => {
830
- const iframe = await paintIFrame (
831
- mockMarkup ,
832
- DisplayPosition . BottomRight ,
833
- false ,
834
- '' ,
835
- '10px' ,
836
- '10px' ,
837
- '10px'
838
- ) ;
837
+ const iframe = await paintIFrame ( {
838
+ html : mockMarkup ,
839
+ position : DisplayPosition . BottomRight ,
840
+ topOffset : '10px' ,
841
+ bottomOffset : '10px' ,
842
+ rightOffset : '10px'
843
+ } ) ;
839
844
jest . advanceTimersByTime ( 2000 ) ;
840
845
841
846
/* speed up time to past the setTimeout */
842
847
const styles = getComputedStyle ( iframe ) ;
843
- expect ( styles . position ) . toBe ( 'fixed' ) ;
844
- expect ( styles . left ) . toBe ( '' ) ;
845
- expect ( styles . right ) . toBe ( '10px' ) ;
846
- expect ( styles . bottom ) . toBe ( '10px' ) ;
847
- expect ( styles . top ) . toBe ( '' ) ;
848
- expect ( styles . zIndex ) . toBe ( '9999' ) ;
849
- expect ( styles . width ) . toBe ( '100%' ) ;
850
- expect ( styles . maxHeight ) . toBe ( '95vh' ) ;
848
+ checkStyles ( styles , {
849
+ left : '' ,
850
+ right : '10px' ,
851
+ bottom : '10px' ,
852
+ top : ''
853
+ } ) ;
851
854
} ) ;
852
855
853
856
it ( 'should call srSpeak if screen reader text passed' , async ( ) => {
854
- await paintIFrame ( mockMarkup , DisplayPosition . Center , false , 'hi' ) ;
857
+ await paintIFrame ( {
858
+ html : mockMarkup ,
859
+ position : DisplayPosition . Center ,
860
+ srMessage : 'hi'
861
+ } ) ;
855
862
856
863
expect ( ( srSpeak as any ) . mock . calls . length ) . toBe ( 1 ) ;
857
864
} ) ;
858
865
859
866
it ( 'should not call srSpeak if no screen reader text passed' , async ( ) => {
860
- await paintIFrame ( mockMarkup , DisplayPosition . Center , false ) ;
867
+ await paintIFrame ( {
868
+ html : mockMarkup ,
869
+ position : DisplayPosition . Center
870
+ } ) ;
861
871
862
872
expect ( ( srSpeak as any ) . mock . calls . length ) . toBe ( 0 ) ;
863
873
} ) ;
@@ -869,6 +879,7 @@ describe('Utils', () => {
869
879
870
880
expect ( el . getAttribute ( 'aria-label' ) ) . toBe ( 'hello' ) ;
871
881
expect ( el . getAttribute ( 'role' ) ) . toBe ( 'button' ) ;
882
+ // eslint-disable-next-line no-script-url
872
883
expect ( el . getAttribute ( 'href' ) ) . toBe ( 'javascript:undefined' ) ;
873
884
} ) ;
874
885
0 commit comments