@beisen/paging
Version:
configurable page component
35 lines (31 loc) • 1.29 kB
JavaScript
import React, {Component, PropTypes} from 'react'
import App from '../src/index';
import { shallow, mount, render } from 'enzyme';
describe('App', ()=> {
const options = {
total_page: 9, //总页数
current_page: 1, // 当前页数
visible_pages: 9, // 显示的页数 min = 5
page_sizes: 20, // 每页条数
ellipsis_text: '···', // 省略文字
next_text: '下一页', // 翻页文字
callback: index => console.log(index) // 回调函数
};
it('render correct', () => {
const warpper = shallow(<App {...options} />);
expect(warpper.find('ul').children().length).toEqual(options.total_page - 2);
});
it('next page click', () => {
const warpper = mount(<App {...options} />);
const pageNext = warpper.find('.next_page');
const beforeClick = warpper.state('current_page');
pageNext.simulate('click');
expect(warpper.state('current_page')).toEqual(beforeClick + 1);
});
it ('showEllipsis', () => {
const warpper = mount(<App {...options} total_page={20}/>);
const pageEllipsis = warpper.find('.page-ellipsis');
expect(pageEllipsis.nodes[0].getAttribute('style')).toEqual('display:inline-block;');
expect(pageEllipsis.nodes[1].getAttribute('style')).toEqual('display:none;');
});
})