react95-native
Version:
Refreshed Windows 95 style UI components for your React Native app
127 lines • 4.04 kB
JavaScript
import React from 'react';
import { render, fireEvent } from '@testing-library/react-native';
import { testId } from '../Panel/Panel';
import { AppBar, Text } from '../..';
describe('<AppBar />', () => {
it('should render children', () => {
const {
getByTestId
} = render( /*#__PURE__*/React.createElement(AppBar, null, /*#__PURE__*/React.createElement(Text, null, "This is an AppBar")));
expect(getByTestId(testId)).toHaveTextContent('This is an AppBar');
});
it('should render custom styles', () => {
const style = {
marginTop: 42
};
const {
getByTestId
} = render( /*#__PURE__*/React.createElement(AppBar, {
style: style
}, /*#__PURE__*/React.createElement(Text, null, "This is an AppBar")));
expect(getByTestId(testId)).toHaveStyle(style);
});
});
describe('<AppBar.Content />', () => {
it('should render custom styles', () => {
const style = {
marginTop: 42
};
const {
getByTestId
} = render( /*#__PURE__*/React.createElement(AppBar, null, /*#__PURE__*/React.createElement(AppBar.Content, {
title: "Title",
style: style,
testID: "content"
})));
expect(getByTestId('content')).toHaveStyle(style);
});
describe('title', () => {
it('should render title', () => {
const {
getByText
} = render( /*#__PURE__*/React.createElement(AppBar, null, /*#__PURE__*/React.createElement(AppBar.Content, {
title: "Title"
})));
expect(getByText('Title')).toBeTruthy();
});
it('should pass styles to title', () => {
const style = {
color: 'red'
};
const {
getByText
} = render( /*#__PURE__*/React.createElement(AppBar, null, /*#__PURE__*/React.createElement(AppBar.Content, {
title: "Title",
titleStyle: style
})));
expect(getByText('Title')).toHaveStyle(style);
});
});
describe('subtitle', () => {
it('should render subtitle', () => {
const {
getByText
} = render( /*#__PURE__*/React.createElement(AppBar, null, /*#__PURE__*/React.createElement(AppBar.Content, {
title: "Title",
subtitle: "Subtitle"
})));
expect(getByText('Subtitle')).toBeTruthy();
});
it('should pass styles to subtitle', () => {
const style = {
color: 'red'
};
const {
getByText
} = render( /*#__PURE__*/React.createElement(AppBar, null, /*#__PURE__*/React.createElement(AppBar.Content, {
title: "Title",
subtitle: "Subtitle",
subtitleStyle: style
})));
expect(getByText('Subtitle')).toHaveStyle(style);
});
});
describe('prop: onPress', () => {
it('should handle onPress', () => {
const onPress = jest.fn();
const {
getByTestId
} = render( /*#__PURE__*/React.createElement(AppBar, null, /*#__PURE__*/React.createElement(AppBar.Content, {
testID: "content",
onPress: onPress,
title: "Title",
subtitle: "Subtitle"
})));
fireEvent(getByTestId('content'), 'press');
expect(onPress).toHaveBeenCalled();
});
});
});
describe('<AppBar.BackAction />', () => {
it('should render custom styles', () => {
const style = {
marginTop: 42
};
const {
getByTestId
} = render( /*#__PURE__*/React.createElement(AppBar, null, /*#__PURE__*/React.createElement(AppBar.BackAction, {
testID: "backAction",
style: style
})));
expect(getByTestId('backAction')).toHaveStyle(style);
});
describe('prop: onPress', () => {
it('should handle onPress', () => {
const onPress = jest.fn();
const {
getByTestId
} = render( /*#__PURE__*/React.createElement(AppBar, null, /*#__PURE__*/React.createElement(AppBar.BackAction, {
testID: "backAction",
onPress: onPress
})));
fireEvent(getByTestId('backAction'), 'press');
expect(onPress).toHaveBeenCalled();
});
});
});
//# sourceMappingURL=AppBar.spec.js.map