1import { resolveProps, setStrings } from '../withAndroidUserInterfaceStyle'; 2 3describe(resolveProps, () => { 4 it(`resolves no props`, () => { 5 expect(resolveProps({})).toStrictEqual({ 6 userInterfaceStyle: undefined, 7 }); 8 }); 9 10 it(`uses more specific key`, () => { 11 expect( 12 resolveProps({ 13 userInterfaceStyle: 'dark', 14 android: { 15 userInterfaceStyle: 'light', 16 }, 17 }) 18 ).toStrictEqual({ 19 userInterfaceStyle: 'light', 20 }); 21 }); 22}); 23 24describe(setStrings, () => { 25 function getAllProps() { 26 return resolveProps({ userInterfaceStyle: 'dark' }); 27 } 28 // TODO: Should we do validation on backgroundColor just for convenience? 29 it(`asserts an invalid color`, () => { 30 expect(() => 31 setStrings( 32 { resources: {} }, 33 resolveProps({ 34 // @ts-expect-error 35 userInterfaceStyle: '-bacon-', 36 }) 37 ) 38 ).toThrow(/expo-system-ui: Invalid userInterfaceStyle: "-bacon-"/); 39 }); 40 41 it(`sets all strings`, () => { 42 expect(setStrings({ resources: {} }, getAllProps())).toStrictEqual({ 43 resources: { 44 string: [ 45 { 46 $: { 47 name: 'expo_system_ui_user_interface_style', 48 translatable: 'false', 49 }, 50 _: 'dark', 51 }, 52 ], 53 }, 54 }); 55 }); 56 57 it(`sets no strings`, () => { 58 expect( 59 setStrings( 60 { 61 resources: { 62 string: [], 63 }, 64 }, 65 {} 66 ) 67 ).toStrictEqual({ 68 resources: { 69 string: [], 70 }, 71 }); 72 }); 73 it(`unsets string`, () => { 74 // Set all strings 75 const strings = setStrings({ resources: {} }, getAllProps()); 76 // Unset all strings 77 expect(setStrings(strings, resolveProps({}))).toStrictEqual({ 78 resources: { 79 string: [], 80 }, 81 }); 82 }); 83 it(`redefines duplicates`, () => { 84 // Set all strings 85 const strings = setStrings({ resources: {} }, { userInterfaceStyle: 'dark' }); 86 87 expect(strings.resources.string).toStrictEqual([ 88 { 89 $: { 90 name: 'expo_system_ui_user_interface_style', 91 translatable: 'false', 92 }, 93 // Test an initial value 94 _: 'dark', 95 }, 96 ]); 97 98 expect( 99 setStrings(strings, resolveProps({ userInterfaceStyle: 'light' })).resources.string 100 ).toStrictEqual([ 101 { 102 $: { name: 'expo_system_ui_user_interface_style', translatable: 'false' }, 103 // Test a redefined value 104 _: 'light', 105 }, 106 ]); 107 }); 108}); 109