import * as React from 'react';
import { Text, View } from 'react-native';
import renderer from 'react-test-renderer';
import MDButton, { MDButtonType } from '../index';
const ButtonTypeEnum = ['default', 'primary', 'warning', 'disabled', 'link'];
it('renders correctly with different type', () => {
for (const item in ButtonTypeEnum) {
const instance = renderer
.create(
{item} button
)
.toJSON();
expect(instance).toMatchSnapshot();
}
});
it('renders correctly with round', () => {
const round = renderer
.create(Default & Round button)
.toJSON();
expect(round).toMatchSnapshot();
});
it('renders correctly with plain', () => {
for (const key in ButtonTypeEnum) {
const instance = renderer
.create(
Default & Plain button
)
.toJSON();
expect(instance).toMatchSnapshot();
}
});
it('renders correctly with size', () => {
const instance = renderer
.create(Default & Small button)
.toJSON();
expect(instance).toMatchSnapshot();
const customWidth = renderer
.create(Custom size button)
.toJSON();
expect(customWidth).toMatchSnapshot();
const customHeight = renderer
.create(Custom size button)
.toJSON();
expect(customHeight).toMatchSnapshot();
const customFontSize = renderer
.create(Custom size button)
.toJSON();
expect(customFontSize).toMatchSnapshot();
});
it('renders correctly with icon', () => {
const instance = renderer
.create(
Default & icon button
)
.toJSON();
expect(instance).toMatchSnapshot();
const pureIconButton = renderer
.create()
.toJSON();
expect(pureIconButton).toMatchSnapshot();
});
it('renders correctly with inactive', () => {
const instance = renderer
.create(
Default & icon button
)
.toJSON();
expect(instance).toMatchSnapshot();
});
it('renders correctly with custom children', () => {
const instance = renderer
.create(
Custom children
)
.toJSON();
expect(instance).toMatchSnapshot();
expect(renderer.create({''}).toJSON).toMatchSnapshot;
});
it('renders correctly with custom style', () => {
const instance = renderer
.create(
Default & Custom style
)
.toJSON();
expect(instance).toMatchSnapshot();
});
it('renders correctly with onPress', () => {
const instance = renderer
.create(
console.log('press')}>
Default & onPress event
)
.toJSON();
expect(instance).toMatchSnapshot();
});
it('renders correctly with custom props', () => {
const instance = renderer
.create(
console.log('press')}
style={{ backgroundColor: '#fff' }}
size={'small'}
inactive={true}
round={true}
plain={true}
type={'primary'}
>
Custom children
)
.toJSON();
expect(instance).toMatchSnapshot();
const pureIconButton = renderer
.create(
console.log('press')}
size={'small'}
inactive={true}
round={true}
plain={true}
type={'warning'}
icon='setting'
/>
)
.toJSON();
expect(pureIconButton).toMatchSnapshot();
});