Skip to content

Commit

Permalink
fix:修复测试用例动画问题
Browse files Browse the repository at this point in the history
  • Loading branch information
SunLxy committed Jul 11, 2023
1 parent 43ec91f commit ec58148
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 21 deletions.
Empty file.
1 change: 1 addition & 0 deletions packages/core/src/NoticeBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Icon from '../Icon';
import Marquee, { MarqueeProps } from './Marquee';
import { Theme } from '../theme';
import { useTheme } from '@shopify/restyle';
export { Marquee };

export type NoticeBarProps = {
children?: any;
Expand Down
3 changes: 2 additions & 1 deletion test-ci/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const conf = require('@uimjs/metro-config');
module.exports = conf.default();
module.exports = mergeConfig(getDefaultConfig(__dirname), conf.default());
34 changes: 23 additions & 11 deletions test-ci/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,41 @@
},
"dependencies": {
"react": "18.0.0",
"react-native": "0.70.6"
"react-native": "0.72.1"
},
"devDependencies": {
"@react-native/metro-config": "~0.72.9",
"@react-native-camera-roll/camera-roll": "5.3.1",
"@react-native-community/masked-view": "~0.1.11",
"@react-navigation/native": "~6.0.11",
"@react-navigation/stack": "~6.2.2",
"@uiw/react-native": "4.0.11",
"@uiw/react-native-image-picker": "4.0.11",
"react": "18.0.0",
"react-native": "0.69.7",
"react-native-gesture-handler": "~2.5.0",
"react-native-image-picker": "^5.3.1",
"react-native-image-viewing": "~0.2.2",
"react-native-safe-area-context": "~4.3.1",
"react-native-screens": "~3.15.0",
"react-native-svg": "13.9.0",
"@babel/core": "^7.20.7",
"@babel/runtime": "^7.20.7",
"@react-native-community/eslint-config": "^2.0.0",
"@testing-library/react-native": "^11.5.0",
"@testing-library/react-native": "^12.1.2",
"@tsconfig/react-native": "^2.0.2",
"@types/jest": "^29.2.5",
"@types/jest": "^29.5.3",
"@types/react": "^18.0.21",
"@types/react-native": "^0.70.6",
"@types/react-test-renderer": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"@uiw/react-native": "4.0.10",
"@uimjs/metro-config": "^1.0.2",
"@uimjs/metro-config": "^2.0.1",
"@shopify/restyle": "~2.4.2",
"eslint": "^7.32.0",
"jest": "^29.3.1",
"jest": "^29.6.1",
"metro-react-native-babel-preset": "0.72.3",
"react-test-renderer": "18.1.0",
"react-test-renderer": "18.2.0",
"typescript": "^4.8.3",
"@types/color": "~3.0.3",
"@types/lodash": "~4.14.191",
Expand All @@ -41,12 +55,10 @@
"color": "4.2.3",
"lodash": "4.17.21",
"prop-types": "15.7.2",
"react-native-gesture-handler": "2.8.0",
"react-native-root-siblings": "4.1.1",
"react-native-svg": "13.9.0"
"react-native-root-siblings": "4.1.1"
},
"jest": {
"setupFiles": [
"setupFilesAfterEnv": [
"./mock.js"
],
"preset": "react-native",
Expand Down
19 changes: 18 additions & 1 deletion test-ci/src/__tests__/radio.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,62 @@
import 'react-native';
import React from 'react';
import Radio from '../lib/Radio';
import { render, fireEvent } from '@testing-library/react-native';
import { render, fireEvent, act } from '@testing-library/react-native';

describe('Radio', () => {
it('disabled', () => {
jest.useFakeTimers();
const { getByTestId } = render(<Radio disabled />);
act(() => jest.runAllTimers());

const component = getByTestId('RNE__Radio__view');
expect(component.props.accessibilityState.disabled).toBe(true);
});

it('borderColor', () => {
jest.useFakeTimers();
const { getByTestId } = render(<Radio borderColor="#bdc1cc" />);
act(() => jest.runAllTimers());

const component = getByTestId('RNE__Radio__border');

expect(component.props.style.borderColor).toBe('#bdc1cc');
});

it('checkedColor', () => {
jest.useFakeTimers();

const { getByTestId } = render(<Radio checkedColor="#008EF0" />);
act(() => jest.runAllTimers());

const component = getByTestId('RNE__Radio__box');
expect(component.props.style.backgroundColor).toBe('#008EF0');
});

it('circleSize', () => {
jest.useFakeTimers();
const { getByTestId } = render(<Radio circleSize={21} />);
act(() => jest.runAllTimers());
const component = getByTestId('RNE__Radio__border');
expect(component.props.style.width).toBe(21);
expect(component.props.style.height).toBe(21);
});

it('onPress events', () => {
jest.useFakeTimers();
const fn = jest.fn();
const { getByTestId } = render(<Radio onPress={fn} />);
act(() => jest.runAllTimers());
const component = getByTestId('RNE__Radio__view');
fireEvent(component, 'press');
expect(fn).toHaveBeenCalled();
});

it('disabled onPress events', () => {
jest.useFakeTimers();
const fn = jest.fn();
const { getByTestId } = render(<Radio disabled onPress={fn} />);
act(() => jest.runAllTimers());
const component = getByTestId('RNE__Radio__view');
fireEvent(component, 'press');
expect(fn).not.toHaveBeenCalled();
Expand Down
33 changes: 28 additions & 5 deletions test-ci/src/__tests__/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { View, Text } from 'react-native';
import React from 'react';
import Tooltip from '../lib/Tooltip';
import { render, fireEvent } from '@testing-library/react-native';
import { render, fireEvent, act } from '@testing-library/react-native';
import { toObject } from '../utils';

describe('Tooltip', () => {
it('title', () => {
jest.useFakeTimers();
const { getByTestId, getByText } = render(
<Tooltip title="标题">
<View>
Expand All @@ -14,59 +15,81 @@ describe('Tooltip', () => {
</Tooltip>,
);
const pressable = getByTestId('RNE__Tooltip__pressable');
act(() => {
jest.runAllTimers();
});
fireEvent(pressable, 'press');
expect(getByText('标题')).toBeTruthy();
});
it('height', () => {
jest.useFakeTimers();
const { getByTestId } = render(
<Tooltip title="标题" height={80}>
<View>
<Text>我是一个文本</Text>
</View>
</Tooltip>,
);
act(() => {
jest.runAllTimers();
});
const pressable = getByTestId('RNE__Tooltip__pressable');
// const component = getByTestId('RNE__Tooltip__wrap');
fireEvent(pressable, 'press');
const component = getByTestId('RNE__Tooltip__wrap');
// expect(component.props.height).toBe(80);
// expect(component.props.height).toBe(80)
});
it('width', () => {
jest.useFakeTimers();

const { getByTestId } = render(
<Tooltip title="标题" width={100}>
<View>
<Text>我是一个文本</Text>
</View>
</Tooltip>,
);
act(() => {
jest.runAllTimers();
});
const pressable = getByTestId('RNE__Tooltip__pressable');
// const component = getByTestId('RNE__Tooltip__wrap');
fireEvent(pressable, 'press');
const component = getByTestId('RNE__Tooltip__wrap');
// expect(component.props.width).toBe(100);
// expect(component.props.width).toBe(100)
});
it('backgroundColor', () => {
jest.useFakeTimers();
const { getByTestId } = render(
<Tooltip backgroundColor="red" title="标题">
<View>
<Text>我是一个文本</Text>
</View>
</Tooltip>,
);
act(() => {
jest.runAllTimers();
});
const pressable = getByTestId('RNE__Tooltip__pressable');
fireEvent(pressable, 'press');

const component = getByTestId('RNE__Tooltip__cloud__view');
const styles = toObject(component.props.style);
expect(styles.backgroundColor).toBe('red');
});
it('borderRadius', () => {
jest.useFakeTimers();
const { getByTestId } = render(
<Tooltip borderRadius={10} title="标题">
<View>
<Text>我是一个文本</Text>
</View>
</Tooltip>,
);
act(() => {
jest.runAllTimers();
});
const pressable = getByTestId('RNE__Tooltip__pressable');
fireEvent(pressable, 'press');

const component = getByTestId('RNE__Tooltip__cloud__view');
const styles = toObject(component.props.style);
expect(styles.borderRadius).toBe(10);
Expand Down
6 changes: 3 additions & 3 deletions test-ci/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// prettier-ignore
{
"extends": "@tsconfig/react-native/tsconfig.json", /* Recommended React Native TSConfig base */
"extends": "@tsconfig/react-native/tsconfig.json", /* Recommended React Native TSConfig base */
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

"jsx": "react-native" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
/* Completeness */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}

0 comments on commit ec58148

Please sign in to comment.