Skip to content

Commit e8823b6

Browse files
authored
chore: setup unit tests (#30)
1 parent e5c244a commit e8823b6

File tree

5 files changed

+108
-4
lines changed

5 files changed

+108
-4
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414

1515
- name: git config
1616
run: |
17-
git config user.name "kanelloc-deploy"
18-
git config user.email "${{secrets.DEPLOY_EMAIL}}"
17+
git config user.name "${GITHUB_ACTOR}"
18+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
1919
2020
- run: >
2121
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@evilmartians/lefthook": "^1.2.2",
5858
"@react-native-community/eslint-config": "^3.0.2",
5959
"@release-it/conventional-changelog": "^5.0.0",
60+
"@testing-library/react-hooks": "^8.0.1",
6061
"@types/jest": "^28.1.2",
6162
"@types/react": "~17.0.21",
6263
"@types/react-native": "0.70.0",
@@ -72,6 +73,7 @@
7273
"react": "18.1.0",
7374
"react-native": "0.70.5",
7475
"react-native-builder-bob": "^0.20.0",
76+
"react-test-renderer": "^18.2.0",
7577
"release-it": "^15.0.0",
7678
"typescript": "^4.5.2"
7779
},

src/__tests__/index.test.tsx

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { renderHook } from '@testing-library/react-hooks';
2+
import { useAnimateNavbar } from '../hooks/useAnimateNavbar';
3+
import { HEADER_HEIGHT, IMG_HEADER_HEIGHT } from '../constants';
4+
import { Animated } from 'react-native';
5+
import { useRef } from 'react';
6+
7+
describe('useAnimatedNavbar basic tests', () => {
8+
it('should return starting points', () => {
9+
const { result } = renderHook(() => {
10+
const first = (IMG_HEADER_HEIGHT - HEADER_HEIGHT) * 0.75; // 157,5
11+
const scroll = useRef(new Animated.Value(first)).current;
12+
return useAnimateNavbar(scroll, IMG_HEADER_HEIGHT, HEADER_HEIGHT);
13+
});
14+
15+
const [headerOpacity, overflowHeaderOpacity] = result.current;
16+
17+
expect(JSON.stringify(headerOpacity)).toBe('0');
18+
expect(JSON.stringify(overflowHeaderOpacity)).toBe('1');
19+
});
20+
21+
it('should return ending points', () => {
22+
const { result } = renderHook(() => {
23+
const first = IMG_HEADER_HEIGHT - HEADER_HEIGHT; // 210
24+
const scroll = useRef(new Animated.Value(first)).current;
25+
return useAnimateNavbar(scroll, IMG_HEADER_HEIGHT, HEADER_HEIGHT);
26+
});
27+
28+
const [headerOpacity, overflowHeaderOpacity] = result.current;
29+
30+
expect(JSON.stringify(headerOpacity)).toBe('1');
31+
expect(JSON.stringify(overflowHeaderOpacity)).toBe('0');
32+
});
33+
34+
it('should return 50% of interpolation', () => {
35+
const { result } = renderHook(() => {
36+
const start = (IMG_HEADER_HEIGHT - HEADER_HEIGHT) * 0.75; // 157,5
37+
const end = IMG_HEADER_HEIGHT - HEADER_HEIGHT; // 210
38+
const diff = (end - start) / 2;
39+
40+
const scroll = useRef(new Animated.Value(end - diff)).current;
41+
return useAnimateNavbar(scroll, IMG_HEADER_HEIGHT, HEADER_HEIGHT);
42+
});
43+
44+
const [headerOpacity, overflowHeaderOpacity] = result.current;
45+
46+
expect(JSON.stringify(headerOpacity)).toBe('0.5');
47+
expect(JSON.stringify(overflowHeaderOpacity)).toBe('0.5');
48+
});
49+
50+
it('should return 80% of interpolation', () => {
51+
const { result } = renderHook(() => {
52+
const start = (IMG_HEADER_HEIGHT - HEADER_HEIGHT) * 0.75; // 157,5
53+
const end = IMG_HEADER_HEIGHT - HEADER_HEIGHT; // 210
54+
const diff = (end - start) * 0.8;
55+
56+
const scroll = useRef(new Animated.Value(end - diff)).current;
57+
return useAnimateNavbar(scroll, IMG_HEADER_HEIGHT, HEADER_HEIGHT);
58+
});
59+
60+
const [headerOpacity, overflowHeaderOpacity] = result.current;
61+
62+
expect(JSON.stringify(headerOpacity)).toBe('0.2');
63+
expect(JSON.stringify(overflowHeaderOpacity)).toBe('0.8');
64+
});
65+
});

yarn.lock

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,13 @@
10451045
dependencies:
10461046
regenerator-runtime "^0.13.11"
10471047

1048+
"@babel/runtime@^7.12.5":
1049+
version "7.20.13"
1050+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.20.13.tgz#7055ab8a7cff2b8f6058bf6ae45ff84ad2aded4b"
1051+
integrity sha512-gt3PKXs0DBoL9xCvOIIZ2NEqAGZqHjAnmVbfQtB620V0uReIQutpel14KcneZuer7UioY8ALKZ7iocavvzTNFA==
1052+
dependencies:
1053+
regenerator-runtime "^0.13.11"
1054+
10481055
"@babel/template@^7.0.0", "@babel/template@^7.18.10", "@babel/template@^7.20.7", "@babel/template@^7.3.3":
10491056
version "7.20.7"
10501057
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.20.7.tgz#a15090c2839a83b02aa996c0b4994005841fd5a8"
@@ -2044,6 +2051,14 @@
20442051
dependencies:
20452052
defer-to-connect "^2.0.1"
20462053

2054+
"@testing-library/react-hooks@^8.0.1":
2055+
version "8.0.1"
2056+
resolved "https://registry.yarnpkg.com/@testing-library/react-hooks/-/react-hooks-8.0.1.tgz#0924bbd5b55e0c0c0502d1754657ada66947ca12"
2057+
integrity sha512-Aqhl2IVmLt8IovEVarNDFuJDVWVvhnr9/GCU6UUnrYXwgDFF9h2L2o2P9KBni1AST5sT6riAyoukFLyjQUgD/g==
2058+
dependencies:
2059+
"@babel/runtime" "^7.12.5"
2060+
react-error-boundary "^3.1.0"
2061+
20472062
"@tootallnate/once@1":
20482063
version "1.1.2"
20492064
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
@@ -7825,7 +7840,14 @@ [email protected]:
78257840
shell-quote "^1.6.1"
78267841
ws "^7"
78277842

7828-
"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.0.0:
7843+
react-error-boundary@^3.1.0:
7844+
version "3.1.4"
7845+
resolved "https://registry.yarnpkg.com/react-error-boundary/-/react-error-boundary-3.1.4.tgz#255db92b23197108757a888b01e5b729919abde0"
7846+
integrity sha512-uM9uPzZJTF6wRQORmSrvOIgt4lJ9MC1sNgEOj2XGsDTRE4kmpWxg7ENK9EWNKJRMAOY9z0MuF4yIfl6gp4sotA==
7847+
dependencies:
7848+
"@babel/runtime" "^7.12.5"
7849+
7850+
"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.0.0, react-is@^18.2.0:
78297851
version "18.2.0"
78307852
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
78317853
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==
@@ -7933,6 +7955,15 @@ react-shallow-renderer@^16.15.0:
79337955
object-assign "^4.1.1"
79347956
react-is "^16.12.0 || ^17.0.0 || ^18.0.0"
79357957

7958+
react-test-renderer@^18.2.0:
7959+
version "18.2.0"
7960+
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-18.2.0.tgz#1dd912bd908ff26da5b9fca4fd1c489b9523d37e"
7961+
integrity sha512-JWD+aQ0lh2gvh4NM3bBM42Kx+XybOxCpgYK7F8ugAlpaTSnWsX+39Z4XkOykGZAHrjwwTZT3x3KxswVWxHPUqA==
7962+
dependencies:
7963+
react-is "^18.2.0"
7964+
react-shallow-renderer "^16.15.0"
7965+
scheduler "^0.23.0"
7966+
79367967
79377968
version "18.1.0"
79387969
resolved "https://registry.yarnpkg.com/react/-/react-18.1.0.tgz#6f8620382decb17fdc5cc223a115e2adbf104890"
@@ -8389,6 +8420,13 @@ scheduler@^0.22.0:
83898420
dependencies:
83908421
loose-envify "^1.1.0"
83918422

8423+
scheduler@^0.23.0:
8424+
version "0.23.0"
8425+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.0.tgz#ba8041afc3d30eb206a487b6b384002e4e61fdfe"
8426+
integrity sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==
8427+
dependencies:
8428+
loose-envify "^1.1.0"
8429+
83928430
semver-diff@^4.0.0:
83938431
version "4.0.0"
83948432
resolved "https://registry.yarnpkg.com/semver-diff/-/semver-diff-4.0.0.tgz#3afcf5ed6d62259f5c72d0d5d50dffbdc9680df5"

0 commit comments

Comments
 (0)