react-bootstrap-table2/packages/react-bootstrap-table2-paginator/test/page-button.test.js
Allen 3c88364efe
fix #135
* init react-bootstrap-table2-paginator

* add react-bootstrap-table2-paginator as dependency

* no container

* handle for wrapping pagination component

* add style for paginator addon

* add story for pagination

* implement pagination list

* constants maintain in core package

* implement sizePerPage dropdown

* fix unalign for sizePerPage dropdown and pagination list

* allow to return array from render(react@16 new feature)

* implement pagination hooks

* add story for pagination hooks

* fixed dependencies version and upgrade enzyme

* Shallow renderer no longer calls componentDidMount because DOM refs are not available

* classNames -> className for TextEditor

* add tests for pagination

* fix react-bootstrap-table can't be resolved in other modules

* implement custom page button title

* add test for page button title

* fix bug when sizePerPageList is an object array

* add story for custom pagination

* remove necessary component extends

* move pagination options to react-bootstrap-table2-paginator

* refine pagination stories

* implement hideSizePerPage

* implement hidePageListOnlyOnePage

* fix multiple same key warning

* remove help

* support start from react@^16
2017-11-19 17:42:20 +08:00

118 lines
3.0 KiB
JavaScript

import React from 'react';
import sinon from 'sinon';
import { shallow } from 'enzyme';
import PageButton from '../src/page-button';
describe('PageButton', () => {
let wrapper;
const onPageChangeCallback = sinon.stub();
const props = {
onPageChange: onPageChangeCallback,
page: 2
};
describe('default PageButton', () => {
beforeEach(() => {
wrapper = shallow(
<PageButton { ...props } active disabled={ false } />
);
});
it('should rendering PageButton correctly', () => {
expect(wrapper.find('a.page-link').length).toBe(1);
expect(wrapper.text()).toEqual(`${props.page}`);
});
describe('when clicking', () => {
let preventDefault;
beforeEach(() => {
preventDefault = sinon.stub();
wrapper.find('a.page-link').simulate('click', { preventDefault });
});
afterEach(() => {
onPageChangeCallback.reset();
});
it('should calling e.preventDefault', () => {
expect(preventDefault.calledOnce).toBeTruthy();
});
it('should calling onPageChange prop', () => {
expect(onPageChangeCallback.calledOnce).toBeTruthy();
});
it('should calling onPageChange prop with correct argument', () => {
expect(onPageChangeCallback.calledWith(props.page)).toBeTruthy();
});
});
});
describe('when active prop is true', () => {
beforeEach(() => {
wrapper = shallow(
<PageButton { ...props } active disabled={ false } />
);
});
it('should render PageButton correctly', () => {
expect(wrapper.length).toBe(1);
expect(wrapper.hasClass('active')).toBeTruthy();
});
});
describe('when active prop is false', () => {
beforeEach(() => {
wrapper = shallow(
<PageButton { ...props } active={ false } disabled={ false } />
);
});
it('should render PageButton correctly', () => {
expect(wrapper.length).toBe(1);
expect(wrapper.hasClass('active')).toBeFalsy();
});
});
describe('when disabled prop is true', () => {
beforeEach(() => {
wrapper = shallow(
<PageButton { ...props } active disabled />
);
});
it('should render PageButton correctly', () => {
expect(wrapper.length).toBe(1);
expect(wrapper.hasClass('disabled')).toBeTruthy();
});
});
describe('when disabled prop is false', () => {
beforeEach(() => {
wrapper = shallow(
<PageButton { ...props } active disabled={ false } />
);
});
it('should render PageButton correctly', () => {
expect(wrapper.length).toBe(1);
expect(wrapper.hasClass('disabled')).toBeFalsy();
});
});
describe('when title prop is defined', () => {
const title = 'aTitle';
beforeEach(() => {
wrapper = shallow(
<PageButton { ...props } active disabled={ false } title={ title } />
);
});
it('should render PageButton correctly', () => {
expect(wrapper.length).toBe(1);
expect(wrapper.prop('title')).toEqual(title);
});
});
});