Skip to content

Commit

Permalink
add NoticeBar test, ref #1274
Browse files Browse the repository at this point in the history
  • Loading branch information
warmhug committed Jun 13, 2017
1 parent ec8edc9 commit 5f02d7f
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 0 deletions.
75 changes: 75 additions & 0 deletions components/notice-bar/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`NoticeBar renders correctly 1`] = `
<View
accessibilityComponentType={undefined}
accessibilityLabel={undefined}
accessibilityTraits={undefined}
accessible={true}
hitSlop={undefined}
onLayout={undefined}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
"alignItems": "center",
"backgroundColor": "#fffada",
"flexDirection": "row",
"height": 36,
"overflow": "hidden",
},
undefined,
]
}
testID={undefined}
>
<View
style={
Array [
Object {
"marginLeft": 15,
},
]
}
>
<Image
source={
Object {
"uri": "https://zos.alipayobjects.com/rmsportal/UgviADRsIpznkjSEXWEaPTlKtPCMSlth.png",
}
}
style={
Object {
"height": 12,
"width": 14,
}
}
/>
</View>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail"
style={
Array [
Object {
"color": "#f4333c",
"flex": 1,
"fontSize": 15,
"marginRight": 15,
},
Object {
"marginLeft": 5,
},
]
}
>
Notice: The arrival time of incomes and transfers of Yu 'E Bao will be delayed during National Day.
</Text>
</View>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`NoticeBar renders correctly 1`] = `
<div
class="am-notice-bar"
role="alert"
>
<div
aria-hidden="true"
class="am-notice-bar-icon"
>
<svg
class="am-icon am-icon-[object Object] am-icon-xxs"
>
<use
xlink:href="#[object Object]"
/>
</svg>
</div>
<div
class="am-notice-bar-content"
>
<div
class="am-notice-bar-marquee-wrap "
role="marquee"
style="overflow:hidden;"
>
<div
class="am-notice-bar-marquee"
style="position:relative;right:0;white-space:nowrap;display:inline-block;"
>
foo
</div>
</div>
</div>
</div>
`;
35 changes: 35 additions & 0 deletions components/notice-bar/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { shallow } from 'enzyme';

import NoticeBar from '../index';

describe('NoticeBar', () => {
it('renders correctly', () => {
const wrapper = renderer.create(<NoticeBar>foo</NoticeBar>);
expect(wrapper.toJSON()).toMatchSnapshot();
});

describe('onClick', () => {
let handleClick;
let wrapper;

beforeEach(() => {
handleClick = jest.fn();
wrapper = shallow(
<NoticeBar mode="closable" onClick={handleClick}>
Notice: The arrival time of incomes and
</NoticeBar>,
);
wrapper.find('TouchableWithoutFeedback').simulate('press');
});

it('fires onClick event', () => {
expect(handleClick).toBeCalledWith();
});

it('change state', () => {
expect(wrapper.state('show')).toBe(false);
});
});
});
34 changes: 34 additions & 0 deletions components/notice-bar/__tests__/index.test.web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { render, shallow } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
import NoticeBar from '../index.web';

describe('NoticeBar', () => {
it('renders correctly', () => {
const wrapper = render(<NoticeBar>foo</NoticeBar>);
expect(renderToJson(wrapper)).toMatchSnapshot();
});

describe('onClick', () => {
let handleClick;
let wrapper;

beforeEach(() => {
handleClick = jest.fn();
wrapper = shallow(
<NoticeBar mode="closable" onClick={handleClick}>
Notice: The arrival time of incomes and
</NoticeBar>,
);
wrapper.find('.am-notice-bar-operation').simulate('click');
});

it('fires onClick event', () => {
expect(handleClick).toBeCalledWith();
});

it('change state', () => {
expect(wrapper.state('show')).toBe(false);
});
});
});

0 comments on commit 5f02d7f

Please sign in to comment.