Skip to content

Commit

Permalink
test(List): finish List test
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJustAMan committed May 24, 2021
1 parent 7b57a29 commit 1884672
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/List/__tests__/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`List List render correctly 1`] = `
<div
className="h-list"
>
<div
className="h-list-wrap"
>
<ListItem
arrow="horizontal"
extra="extra content"
subtitle="subtitle"
thumb="logo.png"
>
title
</ListItem>
</div>
</div>
`;
86 changes: 86 additions & 0 deletions src/List/__tests__/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';
import { shallow } from 'enzyme';
import List from '@/List';
import toJson from 'enzyme-to-json';

const { Item } = List;

describe('List', () => {
it('List render correctly', () => {
const wrapper = shallow(
<List>
<Item
subtitle="subtitle"
thumb={require('../../../public/images/logo.png')}
extra="extra content"
arrow="horizontal"
>
title
</Item>
</List>,
);

expect(toJson(wrapper)).toMatchSnapshot();
});
describe('renderHeader', () => {
it('renderHeader is string', () => {
const wrapper = shallow(<List renderHeader="renderHeader" />);

expect(wrapper.find('.h-list-header').text()).toBe('renderHeader');
});

it('renderHeader is function', () => {
const wrapper = shallow(<List renderHeader={() => 'renderHeader'} />);

expect(wrapper.find('.h-list-header').text()).toBe('renderHeader');
});
});
describe('renderFooter', () => {
it('renderFooter is string', () => {
const wrapper = shallow(<List renderFooter="renderFooter" />);

expect(wrapper.find('.h-list-footer').text()).toBe('renderFooter');
});

it('renderFooter is function', () => {
const wrapper = shallow(<List renderFooter={() => 'renderFooter'} />);

expect(wrapper.find('.h-list-footer').text()).toBe('renderFooter');
});
});
describe('ListItem', () => {
it('subtitle', () => {
const wrapper = shallow(<Item subtitle="subtitle" />);

expect(wrapper.find('.h-list-item-subtitle').text()).toBe('subtitle');
});

it('extra', () => {
const wrapper = shallow(<Item extra="extra" />);

expect(wrapper.find('.h-list-item-extra').text()).toBe('extra');
});

it('arrow', () => {
const wrapper = shallow(<Item arrow="horizontal" />);

expect(wrapper.find('.icon-arrow-right')).toBeTruthy();
});

it('thumb', () => {
const wrapper = shallow(
<Item thumb={require('../../../public/images/logo.png')} />,
);

expect(wrapper.find('.h-list-item-thumb').find('img')).toBeTruthy();
});

it('onPress', () => {
const onPress = jest.fn();
const wrapper = shallow(<Item onPress={onPress} />);
wrapper.simulate('press');

expect(onPress).toBeCalled();
});
});
});

0 comments on commit 1884672

Please sign in to comment.