1313import type { I18nManagerConstants } from '../NativeI18nManager' ;
1414
1515const mockGetConstants : JestMockFn < [ ] , I18nManagerConstants > = jest . fn ( ) ;
16+ const mockForceRTL : JestMockFn < [ boolean ] , ?boolean > = jest . fn ( ) ;
1617
1718jest . mock ( '../NativeI18nManager' , ( ) => ( {
1819 __esModule : true ,
1920 default : {
2021 getConstants : ( ) => mockGetConstants ( ) ,
21- forceRTL : jest . fn ( ) ,
22+ forceRTL : ( forceRTL : boolean ) => mockForceRTL ( forceRTL ) ,
2223 } ,
2324} ) ) ;
2425
2526describe ( 'I18nManager' , ( ) => {
2627 beforeEach ( ( ) => {
2728 jest . resetModules ( ) ;
29+ mockGetConstants . mockReset ( ) ;
30+ mockForceRTL . mockReset ( ) ;
2831 } ) ;
2932
3033 it ( 'does not swap left and right styles when native does not send the constant' , ( ) => {
@@ -43,4 +46,31 @@ describe('I18nManager', () => {
4346
4447 expect ( I18nManager . getConstants ( ) . doLeftAndRightSwapInRTL ) . toBe ( true ) ;
4548 } ) ;
49+
50+ it ( 'updates isRTL when forceRTL returns a boolean' , ( ) => {
51+ mockGetConstants . mockReturnValue ( { isRTL : false } ) ;
52+ mockForceRTL . mockImplementation ( forceRTL => forceRTL ) ;
53+ const I18nManager = require ( '../I18nManager' ) . default ;
54+
55+ I18nManager . forceRTL ( true ) ;
56+
57+ expect ( mockForceRTL ) . toHaveBeenCalledWith ( true ) ;
58+ expect ( mockGetConstants ) . toHaveBeenCalledTimes ( 1 ) ;
59+ expect ( I18nManager . isRTL ) . toBe ( true ) ;
60+ expect ( I18nManager . getConstants ( ) ) . toEqual ( {
61+ doLeftAndRightSwapInRTL : false ,
62+ isRTL : true ,
63+ } ) ;
64+ } ) ;
65+
66+ it ( 'keeps isRTL when forceRTL returns nothing on older native binaries' , ( ) => {
67+ mockGetConstants . mockReturnValue ( { isRTL : false } ) ;
68+ mockForceRTL . mockReturnValue ( undefined ) ;
69+ const I18nManager = require ( '../I18nManager' ) . default ;
70+
71+ I18nManager . forceRTL ( true ) ;
72+
73+ expect ( mockForceRTL ) . toHaveBeenCalledWith ( true ) ;
74+ expect ( I18nManager . isRTL ) . toBe ( false ) ;
75+ } ) ;
4676} ) ;
0 commit comments