Skip to content

Commit

Permalink
refactor: convert remaining tests to TypeScript (callstack#3655)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitarNestorov committed Feb 27, 2023
1 parent 7dd70d7 commit e56a05c
Show file tree
Hide file tree
Showing 54 changed files with 132 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';

import renderer from 'react-test-renderer';

import ActivityIndicator from '../ActivityIndicator.tsx';
import ActivityIndicator from '../ActivityIndicator';

it('renders indicator', () => {
const tree = renderer.create(<ActivityIndicator animating />).toJSON();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fireEvent, render } from '@testing-library/react-native';
import renderer from 'react-test-renderer';

import { red500 } from '../../styles/themes/v2/colors';
import * as Avatar from '../Avatar/Avatar.tsx';
import * as Avatar from '../Avatar/Avatar';

const styles = StyleSheet.create({
bgColor: {
Expand Down Expand Up @@ -57,7 +57,7 @@ it('renders avatar with icon and custom background color', () => {

it('renders avatar with image', () => {
const tree = renderer
.create(<Avatar.Image source={{ src: 'avatar.png' }} />)
.create(<Avatar.Image source={{ uri: 'avatar.png' }} />)
.toJSON();

expect(tree).toMatchSnapshot();
Expand All @@ -70,6 +70,7 @@ describe('AvatarImage listener', () => {
const { getByTestId } = render(
<Avatar.Image
testID={'avatar-image'}
source={{ uri: 'avatar.png' }}
onError={onListenerMock}
onLayout={onListenerMock}
onLoad={onListenerMock}
Expand All @@ -86,6 +87,7 @@ describe('AvatarImage listener', () => {
const { getByTestId } = render(
<Avatar.Image
testID={'avatar-image'}
source={{ uri: 'avatar.png' }}
onError={onListenerMock}
onLayout={onListenerMock}
onLoad={onListenerMock}
Expand All @@ -102,6 +104,7 @@ describe('AvatarImage listener', () => {
const { getByTestId } = render(
<Avatar.Image
testID={'avatar-image'}
source={{ uri: 'avatar.png' }}
onError={onListenerMock}
onLayout={onListenerMock}
onLoad={onListenerMock}
Expand All @@ -118,6 +121,7 @@ describe('AvatarImage listener', () => {
const { getByTestId } = render(
<Avatar.Image
testID={'avatar-image'}
source={{ uri: 'avatar.png' }}
onError={onListenerMock}
onLayout={onListenerMock}
onLoad={onListenerMock}
Expand All @@ -134,6 +138,7 @@ describe('AvatarImage listener', () => {
const { getByTestId } = render(
<Avatar.Image
testID={'avatar-image'}
source={{ uri: 'avatar.png' }}
onError={onListenerMock}
onLayout={onListenerMock}
onLoad={onListenerMock}
Expand All @@ -150,6 +155,7 @@ describe('AvatarImage listener', () => {
const { getByTestId } = render(
<Avatar.Image
testID={'avatar-image'}
source={{ uri: 'avatar.png' }}
onError={onListenerMock}
onLayout={onListenerMock}
onLoad={onListenerMock}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import renderer from 'react-test-renderer';

import { red500 } from '../../styles/themes/v2/colors';
import Badge from '../Badge.tsx';
import Badge from '../Badge';

jest.mock('react-native', () => {
const RN = jest.requireActual('react-native');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ it('should have `accessibilityState={ checked: false }` when `status="indetermin

it('disables the row when the prop disabled is true', () => {
const { getByLabelText } = render(
<Checkbox.Item accessibilityLabel="some checkbox" disabled />
<Checkbox.Item
status="unchecked"
label=""
accessibilityLabel="some checkbox"
disabled
/>
);

const touchable = getByLabelText('some checkbox');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('getAndroidSelectionControlColor - ripple color', () => {
getAndroidSelectionControlColor({
theme: getTheme(),
disabled: true,
checked: false,
})
).toMatchObject({
rippleColor: color(getTheme().colors.onSurface)
Expand All @@ -26,6 +27,7 @@ describe('getAndroidSelectionControlColor - ripple color', () => {
getAndroidSelectionControlColor({
theme: getTheme(false, false),
disabled: true,
checked: false,
})
).toMatchObject({
rippleColor: color(getTheme(false, false).colors.text)
Expand All @@ -40,6 +42,7 @@ describe('getAndroidSelectionControlColor - ripple color', () => {
getAndroidSelectionControlColor({
theme: getTheme(),
customColor: 'purple',
checked: false,
})
).toMatchObject({
rippleColor: color('purple').fade(0.32).rgb().string(),
Expand All @@ -50,6 +53,7 @@ describe('getAndroidSelectionControlColor - ripple color', () => {
expect(
getAndroidSelectionControlColor({
theme: getTheme(),
checked: false,
})
).toMatchObject({
rippleColor: color(getTheme().colors.primary).fade(0.32).rgb().string(),
Expand All @@ -60,6 +64,7 @@ describe('getAndroidSelectionControlColor - ripple color', () => {
expect(
getAndroidSelectionControlColor({
theme: getTheme(false, false),
checked: false,
})
).toMatchObject({
rippleColor: color(getTheme(false, false).colors.accent)
Expand All @@ -76,6 +81,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => {
getAndroidSelectionControlColor({
theme: getTheme(),
disabled: true,
checked: false,
})
).toMatchObject({
selectionControlColor: getTheme().colors.onSurfaceDisabled,
Expand All @@ -87,6 +93,7 @@ describe('getAndroidSelectionControlColor - checkbox color', () => {
getAndroidSelectionControlColor({
theme: getTheme(false, false),
disabled: true,
checked: false,
})
).toMatchObject({
selectionControlColor: getTheme(false, false).colors.text,
Expand Down Expand Up @@ -270,7 +277,6 @@ describe('getSelectionControlIOSColor - checked color', () => {
expect(
getSelectionControlIOSColor({
theme: getTheme(),
checked: true,
customColor: 'purple',
})
).toMatchObject({
Expand All @@ -282,7 +288,6 @@ describe('getSelectionControlIOSColor - checked color', () => {
expect(
getSelectionControlIOSColor({
theme: getTheme(),
checked: true,
})
).toMatchObject({
checkedColor: getTheme().colors.primary,
Expand All @@ -293,7 +298,6 @@ describe('getSelectionControlIOSColor - checked color', () => {
expect(
getSelectionControlIOSColor({
theme: getTheme(false, false),
checked: true,
})
).toMatchObject({
checkedColor: getTheme(false, false).colors.accent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { render } from '@testing-library/react-native';
import renderer from 'react-test-renderer';

import DataTable from '../DataTable/DataTable.tsx';
import DataTable from '../DataTable/DataTable';

it('renders data table header', () => {
const tree = renderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { View } from 'react-native';

import renderer from 'react-test-renderer';

import DrawerSection from '../../Drawer/DrawerSection.tsx';
import DrawerSection from '../../Drawer/DrawerSection';

describe('DrawerSection', () => {
it('renders properly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';

import renderer from 'react-test-renderer';

import DrawerItem from '../Drawer/DrawerItem.tsx';
import DrawerItem from '../Drawer/DrawerItem';

it('renders basic DrawerItem', () => {
const tree = renderer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import renderer from 'react-test-renderer';

import { getTheme } from '../../core/theming';
import { red500 } from '../../styles/themes/v2/colors';
import ListAccordion from '../List/ListAccordion.tsx';
import ListIcon from '../List/ListIcon.tsx';
import ListItem from '../List/ListItem.tsx';
import ListAccordion from '../List/ListAccordion';
import ListIcon from '../List/ListIcon';
import ListItem from '../List/ListItem';
import { getAccordionColors } from '../List/utils';

const styles = StyleSheet.create({
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import renderer from 'react-test-renderer';

import { red500 } from '../../styles/themes/v2/colors';
import Chip from '../Chip/Chip';
import ListIcon from '../List/ListIcon.tsx';
import ListItem from '../List/ListItem.tsx';
import ListIcon from '../List/ListIcon';
import ListItem from '../List/ListItem';

const styles = StyleSheet.create({
title: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { StyleSheet } from 'react-native';
import renderer from 'react-test-renderer';

import { red500 } from '../../styles/themes/v2/colors';
import ListIcon from '../List/ListIcon.tsx';
import ListItem from '../List/ListItem.tsx';
import ListSection from '../List/ListSection.tsx';
import ListSubheader from '../List/ListSubheader.tsx';
import ListIcon from '../List/ListIcon';
import ListItem from '../List/ListItem';
import ListSection from '../List/ListSection';
import ListSubheader from '../List/ListSubheader';

const styles = StyleSheet.create({
itemColor: {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import renderer from 'react-test-renderer';

import { getTheme } from '../../core/theming';
import { black, white } from '../../styles/themes/v2/colors';
import Menu from '../Menu/Menu.tsx';
import Menu from '../Menu/Menu';
import { getMenuItemColor } from '../Menu/utils';

describe('getMenuItemColor - title color', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Text } from 'react-native';

import { render, waitFor } from '@testing-library/react-native';

import Portal from '../Portal/Portal.tsx';
import Portal from '../Portal/Portal';

jest.useRealTimers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Animated } from 'react-native';

import { render, waitFor } from '@testing-library/react-native';

import ProgressBar from '../ProgressBar.tsx';
import ProgressBar, { Props } from '../ProgressBar';

const layoutEvent = {
nativeEvent: {
Expand All @@ -15,11 +15,7 @@ const layoutEvent = {

const a11yRole = 'progressbar';

class ClassProgressBar extends React.Component {
constructor(props) {
super(props);
}

class ClassProgressBar extends React.Component<Props> {
render() {
return <ProgressBar {...this.props} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('RadioButton', () => {
const RN = jest.requireActual('react-native');

RN.Platform = () => ({
select: (objs) => objs.default,
select: (objs: { default: object }) => objs.default,
});

return RN;
Expand All @@ -32,7 +32,7 @@ describe('RadioButton', () => {
const RN = jest.requireActual('react-native');

RN.Platform = () => ({
select: (objs) => objs.ios,
select: (objs: { ios: object }) => objs.ios,
});

return RN;
Expand All @@ -50,7 +50,9 @@ describe('RadioButton', () => {
it('renders properly', () => {
const tree = renderer
.create(
<RadioButtonContext.Provider value="first" onValueChange={() => {}}>
<RadioButtonContext.Provider
value={{ value: 'first', onValueChange: () => {} }}
>
<RadioButton value="first" />
</RadioButtonContext.Provider>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ exports[`RadioButton when RadioButton is wrapped by RadioButtonContext.Provider
accessibilityRole="radio"
accessibilityState={
Object {
"checked": false,
"checked": true,
"disabled": false,
}
}
Expand Down Expand Up @@ -285,7 +285,7 @@ exports[`RadioButton when RadioButton is wrapped by RadioButtonContext.Provider
<View
style={
Object {
"opacity": 0,
"opacity": 1,
}
}
>
Expand Down
Loading

0 comments on commit e56a05c

Please sign in to comment.