From 455ff485e59e596889c7aafd628327b48a31ec5d Mon Sep 17 00:00:00 2001 From: kirillzyusko Date: Sat, 6 Jan 2024 15:47:19 +0100 Subject: [PATCH] fix: missing components mocks --- .github/PULL_REQUEST_TEMPLATE.md | 1 + .github/workflows/label-sponsors.yml | 2 +- .../components-rendering.spec.tsx.snap | 70 +++++++++++++++++++ .../__tests__/components-rendering.spec.tsx | 49 ++++++++++++- .../components-rendering.spec.tsx.snap | 70 +++++++++++++++++++ .../__tests__/components-rendering.spec.tsx | 49 ++++++++++++- jest/index.js | 6 +- src/components/KeyboardAvoidingView/hooks.ts | 2 +- src/components/KeyboardStickyView/index.tsx | 3 +- .../hooks/useKeyboardInterpolation.ts | 2 +- 10 files changed, 247 insertions(+), 7 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 69dcffd3be..c10f47f2b2 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -42,3 +42,4 @@ ## 📝 Checklist - [ ] CI successfully passed +- [ ] I added new mocks and corresponding unit-tests if library API was changed diff --git a/.github/workflows/label-sponsors.yml b/.github/workflows/label-sponsors.yml index bcd2878a19..2e40e1c39d 100644 --- a/.github/workflows/label-sponsors.yml +++ b/.github/workflows/label-sponsors.yml @@ -7,7 +7,7 @@ jobs: name: is-sponsor-label runs-on: ubuntu-latest steps: - - uses: JasonEtco/is-sponsor-label-action@v1.2.0 + - uses: JasonEtco/is-sponsor-label-action@v2.0.0 with: label: Sponsor 💖 env: diff --git a/FabricExample/__tests__/__snapshots__/components-rendering.spec.tsx.snap b/FabricExample/__tests__/__snapshots__/components-rendering.spec.tsx.snap index 3dc245be80..454b5afd6e 100644 --- a/FabricExample/__tests__/__snapshots__/components-rendering.spec.tsx.snap +++ b/FabricExample/__tests__/__snapshots__/components-rendering.spec.tsx.snap @@ -1,5 +1,49 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`components rendering should render \`KeyboardAvoidingView\` 1`] = ` + + + +`; + +exports[`components rendering should render \`KeyboardAwareScrollView\` 1`] = ` + + + + + +`; + exports[`components rendering should render \`KeyboardControllerView\` 1`] = ` `; + +exports[`components rendering should render \`KeyboardStickyView\` 1`] = ` + + + +`; diff --git a/FabricExample/__tests__/components-rendering.spec.tsx b/FabricExample/__tests__/components-rendering.spec.tsx index bfc5889696..1e06d2d07c 100644 --- a/FabricExample/__tests__/components-rendering.spec.tsx +++ b/FabricExample/__tests__/components-rendering.spec.tsx @@ -2,10 +2,17 @@ import { render } from "@testing-library/react-native"; import React from "react"; import { View } from "react-native"; import { + KeyboardAvoidingView, + KeyboardAwareScrollView, KeyboardControllerView, KeyboardProvider, + KeyboardStickyView, } from "react-native-keyboard-controller"; +function EmptyView() { + return ; +} + function KeyboardControllerViewTest() { return ; } @@ -13,11 +20,39 @@ function KeyboardControllerViewTest() { function KeyboardProviderTest() { return ( - + ); } +const style = { marginBottom: 20 }; + +function KeyboardAvoidingViewTest() { + return ( + + + + ); +} + +function KeyboardAwareScrollViewTest() { + return ( + + + + ); +} + +const offset = { closed: -20, opened: -40 }; + +function KeyboardStickyViewTest() { + return ( + + + + ); +} + describe("components rendering", () => { it("should render `KeyboardControllerView`", () => { expect(render()).toMatchSnapshot(); @@ -26,4 +61,16 @@ describe("components rendering", () => { it("should render `KeyboardProvider`", () => { expect(render()).toMatchSnapshot(); }); + + it("should render `KeyboardAvoidingView`", () => { + expect(render()).toMatchSnapshot(); + }); + + it("should render `KeyboardAwareScrollView`", () => { + expect(render()).toMatchSnapshot(); + }); + + it("should render `KeyboardStickyView`", () => { + expect(render()).toMatchSnapshot(); + }); }); diff --git a/example/__tests__/__snapshots__/components-rendering.spec.tsx.snap b/example/__tests__/__snapshots__/components-rendering.spec.tsx.snap index 3dc245be80..454b5afd6e 100644 --- a/example/__tests__/__snapshots__/components-rendering.spec.tsx.snap +++ b/example/__tests__/__snapshots__/components-rendering.spec.tsx.snap @@ -1,5 +1,49 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`components rendering should render \`KeyboardAvoidingView\` 1`] = ` + + + +`; + +exports[`components rendering should render \`KeyboardAwareScrollView\` 1`] = ` + + + + + +`; + exports[`components rendering should render \`KeyboardControllerView\` 1`] = ` `; + +exports[`components rendering should render \`KeyboardStickyView\` 1`] = ` + + + +`; diff --git a/example/__tests__/components-rendering.spec.tsx b/example/__tests__/components-rendering.spec.tsx index bfc5889696..1e06d2d07c 100644 --- a/example/__tests__/components-rendering.spec.tsx +++ b/example/__tests__/components-rendering.spec.tsx @@ -2,10 +2,17 @@ import { render } from "@testing-library/react-native"; import React from "react"; import { View } from "react-native"; import { + KeyboardAvoidingView, + KeyboardAwareScrollView, KeyboardControllerView, KeyboardProvider, + KeyboardStickyView, } from "react-native-keyboard-controller"; +function EmptyView() { + return ; +} + function KeyboardControllerViewTest() { return ; } @@ -13,11 +20,39 @@ function KeyboardControllerViewTest() { function KeyboardProviderTest() { return ( - + ); } +const style = { marginBottom: 20 }; + +function KeyboardAvoidingViewTest() { + return ( + + + + ); +} + +function KeyboardAwareScrollViewTest() { + return ( + + + + ); +} + +const offset = { closed: -20, opened: -40 }; + +function KeyboardStickyViewTest() { + return ( + + + + ); +} + describe("components rendering", () => { it("should render `KeyboardControllerView`", () => { expect(render()).toMatchSnapshot(); @@ -26,4 +61,16 @@ describe("components rendering", () => { it("should render `KeyboardProvider`", () => { expect(render()).toMatchSnapshot(); }); + + it("should render `KeyboardAvoidingView`", () => { + expect(render()).toMatchSnapshot(); + }); + + it("should render `KeyboardAwareScrollView`", () => { + expect(render()).toMatchSnapshot(); + }); + + it("should render `KeyboardStickyView`", () => { + expect(render()).toMatchSnapshot(); + }); }); diff --git a/jest/index.js b/jest/index.js index be9e080b2d..521732760e 100644 --- a/jest/index.js +++ b/jest/index.js @@ -1,4 +1,4 @@ -import { Animated } from "react-native"; +import { Animated, ScrollView, View } from "react-native"; const values = { animated: { @@ -49,6 +49,10 @@ const mock = { KeyboardGestureArea: "KeyboardGestureArea", // providers KeyboardProvider: "KeyboardProvider", + // components + KeyboardStickyView: View, + KeyboardAvoidingView: View, + KeyboardAwareScrollView: ScrollView, }; module.exports = mock; diff --git a/src/components/KeyboardAvoidingView/hooks.ts b/src/components/KeyboardAvoidingView/hooks.ts index 01494dd2f8..a7fa06a95a 100644 --- a/src/components/KeyboardAvoidingView/hooks.ts +++ b/src/components/KeyboardAvoidingView/hooks.ts @@ -1,6 +1,6 @@ import { useSharedValue } from "react-native-reanimated"; -import { useKeyboardHandler } from "../../hooks"; +import { useKeyboardHandler } from "react-native-keyboard-controller"; export const useKeyboardAnimation = () => { const heightWhenOpened = useSharedValue(0); diff --git a/src/components/KeyboardStickyView/index.tsx b/src/components/KeyboardStickyView/index.tsx index 5d67b34482..307487f848 100644 --- a/src/components/KeyboardStickyView/index.tsx +++ b/src/components/KeyboardStickyView/index.tsx @@ -1,7 +1,8 @@ import React, { forwardRef, useMemo } from "react"; import Reanimated, { useAnimatedStyle } from "react-native-reanimated"; -import { useReanimatedKeyboardAnimation } from "../../hooks"; +import { useReanimatedKeyboardAnimation } from "react-native-keyboard-controller"; + import useKeyboardInterpolation from "../hooks/useKeyboardInterpolation"; import type { View, ViewProps } from "react-native"; diff --git a/src/components/hooks/useKeyboardInterpolation.ts b/src/components/hooks/useKeyboardInterpolation.ts index 59753d7b53..08535abd31 100644 --- a/src/components/hooks/useKeyboardInterpolation.ts +++ b/src/components/hooks/useKeyboardInterpolation.ts @@ -3,7 +3,7 @@ import { useSharedValue, } from "react-native-reanimated"; -import { useKeyboardHandler } from "../../hooks"; +import { useKeyboardHandler } from "react-native-keyboard-controller"; type KeyboardInterpolationOutput = [number, number];