From 88d579a19783143bb09ef935eefce6b9c02ae89e Mon Sep 17 00:00:00 2001 From: John Haupenthal Date: Fri, 10 May 2024 21:43:33 -0700 Subject: [PATCH] chore: remove jest tests --- __tests__/components/LazyChild.test.tsx | 154 ------------------- __tests__/components/LazyScrollView.test.tsx | 101 ------------ 2 files changed, 255 deletions(-) delete mode 100644 __tests__/components/LazyChild.test.tsx delete mode 100644 __tests__/components/LazyScrollView.test.tsx diff --git a/__tests__/components/LazyChild.test.tsx b/__tests__/components/LazyChild.test.tsx deleted file mode 100644 index ef51bd6..0000000 --- a/__tests__/components/LazyChild.test.tsx +++ /dev/null @@ -1,154 +0,0 @@ -import { - act, - cleanup, - fireEvent, - render, - screen, -} from '@testing-library/react-native'; -import React from 'react'; -import { ScrollView, Text, View } from 'react-native'; -import Animated from 'react-native-reanimated'; -import { LazyChild } from '../../src/components/LazyChild'; -import { LazyScrollView } from '../../src/components/LazyScrollView'; - -describe('LazyChild', () => { - const onThresholdPassOne = jest.fn(); - const onThresholdPassTwo = jest.fn(); - const onThresholdPassThree = jest.fn(); - const HEIGHT = 400; - const SMALL_HEIGHT = 100; - const CONTENT_HEIGHT = HEIGHT * 2 + SMALL_HEIGHT; - - function Child({ onThresholdPass }: { onThresholdPass: () => void }) { - return ( - - - I am a child - - - ); - } - - function Screen({ offset }: { offset?: number }) { - return ( - - - - - - ); - } - - const fireOnLayouts = () => { - fireEvent(screen.UNSAFE_queryAllByType(Animated.View)[0], 'layout', { - nativeEvent: { - layout: { - height: HEIGHT, - y: 0, - }, - }, - }); - - fireEvent(screen.UNSAFE_queryAllByType(Animated.View)[1], 'layout', { - nativeEvent: { - layout: { - height: HEIGHT, - y: HEIGHT, - }, - }, - }); - - fireEvent(screen.UNSAFE_queryAllByType(Animated.View)[2], 'layout', { - nativeEvent: { - layout: { - height: SMALL_HEIGHT, - y: HEIGHT * 2, - }, - }, - }); - - fireEvent(screen.UNSAFE_queryByType(ScrollView), 'layout', { - nativeEvent: { - layout: { - height: HEIGHT, - }, - }, - }); - }; - - const fireScroll = (toValue: number) => { - fireEvent.scroll(screen.UNSAFE_queryByType(ScrollView), { - nativeEvent: { - contentOffset: { - y: toValue, - }, - contentSize: { - height: CONTENT_HEIGHT, - }, - }, - }); - }; - - afterEach(() => { - onThresholdPassOne.mockClear(); - onThresholdPassTwo.mockClear(); - onThresholdPassThree.mockClear(); - cleanup(); - }); - - it('calls onThresholdPass for children in view on render after layout', () => { - const { update } = render(); - - act(() => { - fireOnLayouts(); - }); - - update(); - - expect(onThresholdPassOne).toHaveBeenCalledTimes(1); - expect(onThresholdPassTwo).toHaveBeenCalledTimes(0); - expect(onThresholdPassThree).toHaveBeenCalledTimes(0); - }); - - it('calls onThresholdPass for ChildTwo when threshold is passed', () => { - const { update } = render(); - - act(() => { - fireOnLayouts(); - fireScroll(1); - }); - - update(); - - expect(onThresholdPassOne).toHaveBeenCalledTimes(1); - expect(onThresholdPassTwo).toHaveBeenCalledTimes(1); - expect(onThresholdPassThree).toHaveBeenCalledTimes(0); - }); - - it('calls onThresholdPass for ChildThree when end of scrollview is reached', () => { - const aboveThirdChild = -SMALL_HEIGHT - 10; - const fullContentScroll = HEIGHT + SMALL_HEIGHT; - const { update } = render(); - - act(() => { - fireOnLayouts(); - fireScroll(fullContentScroll - 10); - }); - - update(); - - expect(onThresholdPassOne).toHaveBeenCalledTimes(1); - expect(onThresholdPassTwo).toHaveBeenCalledTimes(1); - expect(onThresholdPassThree).toHaveBeenCalledTimes(0); - - act(() => { - fireScroll(fullContentScroll); - }); - - update(); - - expect(onThresholdPassOne).toHaveBeenCalledTimes(1); - expect(onThresholdPassTwo).toHaveBeenCalledTimes(1); - expect(onThresholdPassThree).toHaveBeenCalledTimes(1); - }); -}); diff --git a/__tests__/components/LazyScrollView.test.tsx b/__tests__/components/LazyScrollView.test.tsx deleted file mode 100644 index 6d6d6b4..0000000 --- a/__tests__/components/LazyScrollView.test.tsx +++ /dev/null @@ -1,101 +0,0 @@ -import { - act, - cleanup, - fireEvent, - render, - screen, -} from '@testing-library/react-native'; -import React from 'react'; -import { ScrollView, Text, View } from 'react-native'; -import { LazyScrollView } from '../../src/components/LazyScrollView'; -import { useAnimatedContext } from '../../src/context/AnimatedContext'; - -describe('LazyScrollView', () => { - const SCROLLVIEW_HEIGHT = 300; - - function Child() { - const { triggerValue } = useAnimatedContext(); - return ( - - {`Trigger Scroll:${triggerValue.value}`} - - ); - } - - function Screen({ offset }: { offset?: number }) { - return ( - - - - ); - } - - const fireOnLayout = () => { - fireEvent(screen.UNSAFE_queryByType(ScrollView), 'layout', { - nativeEvent: { - layout: { - height: SCROLLVIEW_HEIGHT, - }, - }, - }); - }; - - afterEach(() => { - cleanup(); - }); - - it("sets scrollview's height as initial trigger value", () => { - const { update } = render(); - - act(() => { - fireOnLayout(); - }); - - update(); - - expect(screen.getByText(/^Trigger Scroll:/).children).toEqual([ - `Trigger Scroll:${SCROLLVIEW_HEIGHT}`, - ]); - }); - - it('adjusts trigger value with offset prop', () => { - const OFFSET = -100; - const { update } = render(); - - act(() => { - fireOnLayout(); - }); - - update(); - - expect(screen.getByText(/^Trigger Scroll:/).children).toEqual([ - `Trigger Scroll:${SCROLLVIEW_HEIGHT + OFFSET}`, - ]); - }); - - it('adjusts trigger value on scroll', () => { - const SCROLL_VALUE = 200; - const { update } = render(); - - act(() => { - fireOnLayout(); - - fireEvent.scroll(screen.UNSAFE_queryByType(ScrollView), { - nativeEvent: { - contentOffset: { - y: SCROLL_VALUE, - }, - contentSize: { - height: SCROLLVIEW_HEIGHT, - }, - }, - }); - }); - - update(); - - expect(screen.getByText(/^Trigger Scroll:/).children).toEqual([ - `Trigger Scroll:${SCROLLVIEW_HEIGHT + SCROLL_VALUE}`, - ]); - }); -});