Skip to content

Commit

Permalink
fix: missing components mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Jan 6, 2024
1 parent 51894de commit 455ff48
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@
## 📝 Checklist

- [ ] CI successfully passed
- [ ] I added new mocks and corresponding unit-tests if library API was changed
2 changes: 1 addition & 1 deletion .github/workflows/label-sponsors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`components rendering should render \`KeyboardAvoidingView\` 1`] = `
<View
behavior="height"
style={
{
"marginBottom": 20,
}
}
>
<View
style={
{
"backgroundColor": "black",
"height": 20,
"width": 20,
}
}
/>
</View>
`;

exports[`components rendering should render \`KeyboardAwareScrollView\` 1`] = `
<RCTScrollView
bottomOffset={20}
style={
{
"marginBottom": 20,
}
}
>
<View>
<View
style={
{
"backgroundColor": "black",
"height": 20,
"width": 20,
}
}
/>
</View>
</RCTScrollView>
`;

exports[`components rendering should render \`KeyboardControllerView\` 1`] = `
<KeyboardControllerView
statusBarTranslucent={true}
Expand All @@ -21,3 +65,29 @@ exports[`components rendering should render \`KeyboardProvider\` 1`] = `
/>
</KeyboardProvider>
`;

exports[`components rendering should render \`KeyboardStickyView\` 1`] = `
<View
offset={
{
"closed": -20,
"opened": -40,
}
}
style={
{
"marginBottom": 20,
}
}
>
<View
style={
{
"backgroundColor": "black",
"height": 20,
"width": 20,
}
}
/>
</View>
`;
49 changes: 48 additions & 1 deletion FabricExample/__tests__/components-rendering.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,57 @@ 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 <View style={{ width: 20, height: 20, backgroundColor: "black" }} />;
}

function KeyboardControllerViewTest() {
return <KeyboardControllerView statusBarTranslucent />;
}

function KeyboardProviderTest() {
return (
<KeyboardProvider statusBarTranslucent>
<View style={{ width: 20, height: 20, backgroundColor: "black" }} />
<EmptyView />
</KeyboardProvider>
);
}

const style = { marginBottom: 20 };

function KeyboardAvoidingViewTest() {
return (
<KeyboardAvoidingView behavior="height" style={style}>
<EmptyView />
</KeyboardAvoidingView>
);
}

function KeyboardAwareScrollViewTest() {
return (
<KeyboardAwareScrollView bottomOffset={20} style={style}>
<EmptyView />
</KeyboardAwareScrollView>
);
}

const offset = { closed: -20, opened: -40 };

function KeyboardStickyViewTest() {
return (
<KeyboardStickyView offset={offset} style={style}>
<EmptyView />
</KeyboardStickyView>
);
}

describe("components rendering", () => {
it("should render `KeyboardControllerView`", () => {
expect(render(<KeyboardControllerViewTest />)).toMatchSnapshot();
Expand All @@ -26,4 +61,16 @@ describe("components rendering", () => {
it("should render `KeyboardProvider`", () => {
expect(render(<KeyboardProviderTest />)).toMatchSnapshot();
});

it("should render `KeyboardAvoidingView`", () => {
expect(render(<KeyboardAvoidingViewTest />)).toMatchSnapshot();
});

it("should render `KeyboardAwareScrollView`", () => {
expect(render(<KeyboardAwareScrollViewTest />)).toMatchSnapshot();
});

it("should render `KeyboardStickyView`", () => {
expect(render(<KeyboardStickyViewTest />)).toMatchSnapshot();
});
});
70 changes: 70 additions & 0 deletions example/__tests__/__snapshots__/components-rendering.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`components rendering should render \`KeyboardAvoidingView\` 1`] = `
<View
behavior="height"
style={
{
"marginBottom": 20,
}
}
>
<View
style={
{
"backgroundColor": "black",
"height": 20,
"width": 20,
}
}
/>
</View>
`;

exports[`components rendering should render \`KeyboardAwareScrollView\` 1`] = `
<RCTScrollView
bottomOffset={20}
style={
{
"marginBottom": 20,
}
}
>
<View>
<View
style={
{
"backgroundColor": "black",
"height": 20,
"width": 20,
}
}
/>
</View>
</RCTScrollView>
`;

exports[`components rendering should render \`KeyboardControllerView\` 1`] = `
<KeyboardControllerView
statusBarTranslucent={true}
Expand All @@ -21,3 +65,29 @@ exports[`components rendering should render \`KeyboardProvider\` 1`] = `
/>
</KeyboardProvider>
`;

exports[`components rendering should render \`KeyboardStickyView\` 1`] = `
<View
offset={
{
"closed": -20,
"opened": -40,
}
}
style={
{
"marginBottom": 20,
}
}
>
<View
style={
{
"backgroundColor": "black",
"height": 20,
"width": 20,
}
}
/>
</View>
`;
49 changes: 48 additions & 1 deletion example/__tests__/components-rendering.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,57 @@ 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 <View style={{ width: 20, height: 20, backgroundColor: "black" }} />;
}

function KeyboardControllerViewTest() {
return <KeyboardControllerView statusBarTranslucent />;
}

function KeyboardProviderTest() {
return (
<KeyboardProvider statusBarTranslucent>
<View style={{ width: 20, height: 20, backgroundColor: "black" }} />
<EmptyView />
</KeyboardProvider>
);
}

const style = { marginBottom: 20 };

function KeyboardAvoidingViewTest() {
return (
<KeyboardAvoidingView behavior="height" style={style}>
<EmptyView />
</KeyboardAvoidingView>
);
}

function KeyboardAwareScrollViewTest() {
return (
<KeyboardAwareScrollView bottomOffset={20} style={style}>
<EmptyView />
</KeyboardAwareScrollView>
);
}

const offset = { closed: -20, opened: -40 };

function KeyboardStickyViewTest() {
return (
<KeyboardStickyView offset={offset} style={style}>
<EmptyView />
</KeyboardStickyView>
);
}

describe("components rendering", () => {
it("should render `KeyboardControllerView`", () => {
expect(render(<KeyboardControllerViewTest />)).toMatchSnapshot();
Expand All @@ -26,4 +61,16 @@ describe("components rendering", () => {
it("should render `KeyboardProvider`", () => {
expect(render(<KeyboardProviderTest />)).toMatchSnapshot();
});

it("should render `KeyboardAvoidingView`", () => {
expect(render(<KeyboardAvoidingViewTest />)).toMatchSnapshot();
});

it("should render `KeyboardAwareScrollView`", () => {
expect(render(<KeyboardAwareScrollViewTest />)).toMatchSnapshot();
});

it("should render `KeyboardStickyView`", () => {
expect(render(<KeyboardStickyViewTest />)).toMatchSnapshot();
});
});
6 changes: 5 additions & 1 deletion jest/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Animated } from "react-native";
import { Animated, ScrollView, View } from "react-native";

const values = {
animated: {
Expand Down Expand Up @@ -49,6 +49,10 @@ const mock = {
KeyboardGestureArea: "KeyboardGestureArea",
// providers
KeyboardProvider: "KeyboardProvider",
// components
KeyboardStickyView: View,
KeyboardAvoidingView: View,
KeyboardAwareScrollView: ScrollView,
};

module.exports = mock;
2 changes: 1 addition & 1 deletion src/components/KeyboardAvoidingView/hooks.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/components/KeyboardStickyView/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/components/hooks/useKeyboardInterpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit 455ff48

Please sign in to comment.