-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix initial value of app color scheme
- Loading branch information
Showing
6 changed files
with
160 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import renderer from 'react-test-renderer'; | ||
import rn from 'react-native'; | ||
import { describe, it, expect } from '@jest/globals'; | ||
import React from 'react'; | ||
import type { RnColorScheme, TailwindFn } from '../'; | ||
import { create, useDeviceContext, useAppColorScheme } from '../'; | ||
|
||
jest.mock(`react-native`, () => ({ | ||
Platform: { OS: `ios` }, | ||
Appearance: { getColorScheme: () => `light` }, | ||
useColorScheme: () => `light`, | ||
useWindowDimensions: () => ({ width: 320, height: 640, fontScale: 1, scale: 2 }), | ||
})); | ||
|
||
const Test: React.FC<{ tw: TailwindFn; initial?: RnColorScheme }> = ({ tw, initial }) => { | ||
useDeviceContext(tw, { withDeviceColorScheme: true }); | ||
const [colorScheme] = useAppColorScheme(tw, initial); | ||
return ( | ||
<> | ||
{String(colorScheme)} | ||
{tw.prefixMatch(`dark`) ? `match:dark` : `no-match:dark`} | ||
</> | ||
); | ||
}; | ||
|
||
describe(`useAppColorScheme()`, () => { | ||
it(`should initialize to ambient color scheme, if no initializer`, () => { | ||
rn.Appearance.getColorScheme = () => `dark`; | ||
|
||
let component = renderer.create(<Test tw={create()} />); | ||
expect(component.toJSON()).toEqual([`dark`, `match:dark`]); | ||
|
||
rn.Appearance.getColorScheme = () => `light`; | ||
component = renderer.create(<Test tw={create()} />); | ||
expect(component.toJSON()).toEqual([`light`, `no-match:dark`]); | ||
|
||
rn.Appearance.getColorScheme = () => null; | ||
component = renderer.create(<Test tw={create()} />); | ||
expect(component.toJSON()).toEqual([`null`, `no-match:dark`]); | ||
|
||
rn.Appearance.getColorScheme = () => undefined; | ||
component = renderer.create(<Test tw={create()} />); | ||
expect(component.toJSON()).toEqual([`undefined`, `no-match:dark`]); | ||
}); | ||
|
||
it(`should initialize to explicitly passed color scheme when initializer provided`, () => { | ||
rn.Appearance.getColorScheme = () => `dark`; | ||
|
||
let component = renderer.create(<Test tw={create()} initial="light" />); | ||
expect(component.toJSON()).toEqual([`light`, `no-match:dark`]); | ||
|
||
rn.Appearance.getColorScheme = () => `light`; | ||
component = renderer.create(<Test tw={create()} initial="dark" />); | ||
expect(component.toJSON()).toEqual([`dark`, `match:dark`]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters