Skip to content

Commit 87341c2

Browse files
committed
test(appearanceHelper): added test
1 parent 1b0cd55 commit 87341c2

File tree

8 files changed

+71
-22
lines changed

8 files changed

+71
-22
lines changed

babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ['module:metro-react-native-babel-preset'],
3+
};

package.json

+16-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"w:build": "lerna run prepare",
2323
"w:test": "lerna run test",
2424
"lerna:remove": "sh -c 'lerna exec \"yarn remove ${0}\" ${1}'",
25-
"test": "jest .",
25+
"test": "jest",
2626
"reset": "find . -type dir -name node_modules | xargs rm -rf",
2727
"lint": "yarn lint:eslint && yarn lint:prettier",
2828
"fix": "yarn fix:eslint && yarn fix:prettier",
@@ -32,31 +32,45 @@
3232
"fix:prettier": "prettier --write sample/src/**.{ts,tsx} packages/**/src/**/*.{ts,tsx}"
3333
},
3434
"devDependencies": {
35+
"@testing-library/react-native": "^9.0.0",
3536
"@trivago/prettier-plugin-sort-imports": "^3.1.1",
3637
"@types/jest": "^27.4.0",
3738
"@typescript-eslint/eslint-plugin": "^5.9.1",
3839
"@typescript-eslint/parser": "^5.9.1",
40+
"babel-jest": "^27.4.6",
3941
"del-cli": "^4.0.1",
4042
"esbuild": "^0.14.11",
4143
"eslint": "^8.6.0",
4244
"eslint-config-prettier": "^8.3.0",
4345
"jest": "^27.4.7",
4446
"lerna": "^4.0.0",
4547
"metro-minify-esbuild": "^0.1.0",
48+
"metro-react-native-babel-preset": "^0.66.2",
4649
"prettier": "^2.5.1",
50+
"react": "16.x",
51+
"react-native": "0.63.x",
4752
"react-native-builder-bob": "^0.18.2",
4853
"react-native-monorepo-tools": "^1.1.4",
54+
"react-test-renderer": "^17.0.2",
4955
"typescript": "^4.5.4"
5056
},
5157
"dependencies": {},
5258
"jest": {
5359
"testEnvironment": "node",
60+
"moduleFileExtensions": [
61+
"ts",
62+
"tsx",
63+
"js",
64+
"jsx",
65+
"json"
66+
],
5467
"testPathIgnorePatterns": [
5568
"/node_modules/"
5669
],
5770
"testRegex": "/__tests__/.*\\.(test|spec)\\.(js|tsx?)$",
5871
"moduleNameMapper": {
5972
"@sendbird/([^/]+)": "<rootDir>/packages/$1/src"
60-
}
73+
},
74+
"preset": "react-native"
6175
}
6276
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
it.todo('write a test');
1+
import appearanceHelperFactory from '../utils/appearanceHelper';
2+
3+
describe('utils', function () {
4+
it('appearanceHelperFactory', function () {
5+
const helper = appearanceHelperFactory('light');
6+
expect(typeof helper['select']).toBe('function');
7+
8+
const selected1 = helper.select({ light: 'light-value', dark: 'dark-value', default: 'default-value' });
9+
const selected2 = helper.select({ light: undefined, dark: 'dark-value' });
10+
const selected3 = helper.select({ light: undefined, dark: undefined, default: 'default-value' });
11+
12+
expect(selected1).toBe('light-value');
13+
expect(selected1).not.toBe('dark-value');
14+
expect(selected1).not.toBe('default-value');
15+
16+
expect(selected2).toBe('dark-value');
17+
expect(selected2).not.toBeUndefined();
18+
expect(selected2).not.toBe('light-value');
19+
20+
expect(selected3).toBe('default-value');
21+
expect(selected3).not.toBeUndefined();
22+
expect(selected3).not.toBe('light-value');
23+
24+
try {
25+
helper.select({});
26+
} catch (err) {
27+
expect(err).not.toBeUndefined();
28+
}
29+
});
30+
});

packages/uikit-react-native/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ export type UIKitColors = {
6060
};
6161

6262
export interface AppearanceHelper {
63-
select<T>(options: { light: T; dark: T; default?: T }): T;
63+
select<T>(options: { light?: T; dark?: T; default?: T }): T;
6464
}

packages/uikit-react-native/src/utils/appearanceHelper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { AppearanceHelper, UIKitAppearance } from '../types';
88
* */
99
const appearanceHelperFactory = (appearance: UIKitAppearance): AppearanceHelper => ({
1010
select(options) {
11-
const value = options[appearance ?? 'default'] ?? options['light'] ?? options['dark'];
11+
const value = options[appearance ?? 'default'] ?? options['light'] ?? options['dark'] ?? options['default'];
1212
if (!value) throw Error('Not provided any selectable appearance values');
1313
return value;
1414
},

sample/__tests__/App-test.tsx

-13
This file was deleted.

sample/src/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const HomeScreen: React.FC = () => {
1515
const navigation = useNavigation<{ navigate: (route: string) => void }>();
1616
return (
1717
<SafeAreaView>
18-
<ScrollView>
18+
<ScrollView style={{ paddingVertical: 12 }}>
1919
{screenMap.map(([name]) => {
2020
return (
2121
<TouchableOpacity key={name} style={styles.btn} onPress={() => navigation.navigate(name)}>
@@ -54,7 +54,7 @@ const styles = StyleSheet.create({
5454
alignItems: 'center',
5555
justifyContent: 'center',
5656
borderRadius: 12,
57-
marginVertical: 12,
57+
marginBottom: 12,
5858
},
5959
btnTitle: {
6060
color: 'white',

yarn.lock

+18-2
Original file line numberDiff line numberDiff line change
@@ -2911,6 +2911,13 @@
29112911
dependencies:
29122912
"@sinonjs/commons" "^1.7.0"
29132913

2914+
"@testing-library/react-native@^9.0.0":
2915+
version "9.0.0"
2916+
resolved "https://registry.yarnpkg.com/@testing-library/react-native/-/react-native-9.0.0.tgz#e9c63411e93d2e8e70d744b12aeb78c58025c5fc"
2917+
integrity sha512-UE3FWOsDUr+2l3Pg6JTpn2rV5uzYsxIus6ZyN1uMOTmn30bIuBBDDlWQtdWGJx92YcY4xgJA4vViCEKv7wVzJA==
2918+
dependencies:
2919+
pretty-format "^27.0.0"
2920+
29142921
"@tootallnate/once@1":
29152922
version "1.1.2"
29162923
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
@@ -10390,7 +10397,7 @@ react-native-screens@^3.10.2:
1039010397
react-freeze "^1.0.0"
1039110398
warn-once "^0.1.0"
1039210399

10393-
10400+
1039410401
version "0.63.4"
1039510402
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.63.4.tgz#2210fdd404c94a5fa6b423c6de86f8e48810ec36"
1039610403
integrity sha512-I4kM8kYO2mWEYUFITMcpRulcy4/jd+j9T6PbIzR0FuMcz/xwd+JwHoLPa1HmCesvR1RDOw9o4D+OFLwuXXfmGw==
@@ -10473,7 +10480,7 @@ react-shallow-renderer@^16.13.1:
1047310480
object-assign "^4.1.1"
1047410481
react-is "^16.12.0 || ^17.0.0"
1047510482

10476-
10483+
[email protected], react-test-renderer@^17.0.2:
1047710484
version "17.0.2"
1047810485
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-17.0.2.tgz#4cd4ae5ef1ad5670fc0ef776e8cc7e1231d9866c"
1047910486
integrity sha512-yaQ9cB89c17PUb0x6UfWRs7kQCorVdHlutU1boVPEsB8IDZH6n9tHxMacc3y0JoXOJUsZb/t/Mb8FUWMKaM7iQ==
@@ -10492,6 +10499,15 @@ [email protected]:
1049210499
object-assign "^4.1.1"
1049310500
prop-types "^15.6.2"
1049410501

10502+
10503+
version "16.14.0"
10504+
resolved "https://registry.yarnpkg.com/react/-/react-16.14.0.tgz#94d776ddd0aaa37da3eda8fc5b6b18a4c9a3114d"
10505+
integrity sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==
10506+
dependencies:
10507+
loose-envify "^1.1.0"
10508+
object-assign "^4.1.1"
10509+
prop-types "^15.6.2"
10510+
1049510511
1049610512
version "17.0.2"
1049710513
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"

0 commit comments

Comments
 (0)