-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/docs-website
- Loading branch information
Showing
16 changed files
with
899 additions
and
3,914 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
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
2 changes: 1 addition & 1 deletion
2
src/utils/breakpoints.spec.ts → src/__tests__/breakpoints.spec.ts
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,158 @@ | ||
import React from 'react' | ||
import { StyleSheet } from 'react-native' | ||
import type { ViewStyle } from 'react-native' | ||
import { renderHook } from '@testing-library/react-hooks' | ||
import { createUnistyles } from '../createUnistyles' | ||
import { UnistylesTheme } from '../UnistylesTheme' | ||
import type { CustomNamedStyles } from '../types' | ||
|
||
jest.mock('../hooks', () => ({ | ||
useDimensions: jest.fn(() => ({ | ||
width: 500, | ||
height: 1000 | ||
})) | ||
})) | ||
|
||
describe('createUnistyles', () => { | ||
describe('createStyleSheet', () => { | ||
it('should work exactly the same like StyleSheet.create', () => { | ||
const breakpoints = { | ||
xs: 0 | ||
} | ||
const { createStyleSheet } = createUnistyles(breakpoints) | ||
|
||
const styles = { | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center' | ||
}, | ||
text: { | ||
fontWeight: 'bold', | ||
fontSize: 32 | ||
} | ||
} as const | ||
|
||
expect(createStyleSheet(styles)).toEqual(StyleSheet.create(styles)) | ||
}) | ||
|
||
it('should inject the theme to the createStyleSheet', () => { | ||
const theme = { | ||
colors: { | ||
barbie: '#ff9ff3', | ||
oak: '#1dd1a1', | ||
sky: '#48dbfb', | ||
fog: '#c8d6e5', | ||
aloes: '#00d2d3' | ||
} | ||
} | ||
const breakpoints = { | ||
xs: 0 | ||
} | ||
const { useStyles, createStyleSheet } = createUnistyles<typeof breakpoints, typeof theme>(breakpoints) | ||
const stylesheet = createStyleSheet(theme => ({ | ||
container: { | ||
backgroundColor: theme.colors.barbie | ||
} | ||
})) | ||
const { result } = renderHook(() => useStyles(stylesheet), { | ||
// @ts-ignore | ||
wrapper: ({ children }) => ( | ||
<UnistylesTheme theme={theme}> | ||
{children} | ||
</UnistylesTheme> | ||
) | ||
}) | ||
|
||
expect(result.current.theme).toEqual(theme) | ||
expect(result.current.styles).not.toBe(Function) | ||
expect(result.current.styles.container.backgroundColor).toEqual(theme.colors.barbie) | ||
}) | ||
}) | ||
|
||
describe('useStyles', () => { | ||
it('should return empty object for optional stylesheet', () => { | ||
const breakpoints = { | ||
xs: 0 | ||
} | ||
const { useStyles } = createUnistyles(breakpoints) | ||
const { result } = renderHook(() => useStyles()) | ||
|
||
expect(result.current.styles).toEqual({}) | ||
expect(result.current.theme).toEqual({}) | ||
}) | ||
|
||
it ('should choose single value from breakpoints', () => { | ||
const breakpoints = { | ||
xs: 0, | ||
sm: 200, | ||
md: 500, | ||
lg: 1000 | ||
} | ||
|
||
const { useStyles, createStyleSheet } = createUnistyles(breakpoints) | ||
const stylesheet = createStyleSheet({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: { | ||
xs: 'row', | ||
md: 'column' | ||
} | ||
} | ||
}) | ||
const { result } = renderHook(() => useStyles(stylesheet)) | ||
|
||
expect(result.current.styles.container.alignItems).toEqual('column') | ||
}) | ||
|
||
it ('should choose single value from media queries', () => { | ||
const breakpoints = { | ||
xs: 0 | ||
} | ||
|
||
const { useStyles, createStyleSheet } = createUnistyles(breakpoints) | ||
const stylesheet = createStyleSheet({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: { | ||
xs: 'row', | ||
':w[300, 490]': 'column', | ||
':w[491]': 'row' | ||
} | ||
} | ||
}) | ||
const { result } = renderHook(() => useStyles(stylesheet as CustomNamedStyles<typeof stylesheet, typeof breakpoints>)) | ||
|
||
expect(result.current.styles.container.alignItems).toEqual('row') | ||
}) | ||
|
||
it ('should choose wrap dynamic functions in Proxy', () => { | ||
const breakpoints = { | ||
xs: 0 | ||
} | ||
|
||
const { useStyles, createStyleSheet } = createUnistyles<typeof breakpoints, {}>(breakpoints) | ||
const stylesheet = createStyleSheet({ | ||
container: (flex: number) => ({ | ||
flex, | ||
justifyContent: 'center', | ||
alignItems: { | ||
xs: 'row', | ||
':w[300, 490]': 'column', | ||
':w[491]': 'row' | ||
} | ||
}) | ||
}) | ||
const { result } = renderHook(() => useStyles(stylesheet as CustomNamedStyles<typeof stylesheet, typeof breakpoints>)) | ||
|
||
expect(result.current.styles.container).toBeInstanceOf(Function) | ||
expect((result.current.styles.container as (flex: number) => ViewStyle)(2)).toEqual({ | ||
flex: 2, | ||
justifyContent: 'center', | ||
alignItems: 'row' | ||
}) | ||
}) | ||
}) | ||
}) |
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
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
Oops, something went wrong.