Skip to content

Commit

Permalink
chore: migrate two-pagination.test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed Nov 28, 2023
1 parent c829ebd commit a8ab208
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions tests/two-pagination.test.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
import { mount } from 'enzyme';
import { render, fireEvent } from '@testing-library/react';
import React from 'react';
import Pagination from '../src';
import TwoPagination from './two-pagination';

describe('Two Pagination', () => {
let wrapper;
let mockPagination;

beforeEach(() => {
wrapper = mount(<TwoPagination />);
jest.mock('../src', () => {});
wrapper = render(<TwoPagination />);
});

afterEach(() => {
wrapper.unmount();
});

it('should has initial pageSize 20', () => {
const p1 = wrapper.find(Pagination).at(0);
const p2 = wrapper.find(Pagination).at(1);
// expect(p1.state().pageSize).toBe(20); // Class component
expect(p1.props().pageSize).toBe(20); // Function component
// expect(p2.state().pageSize).toBe(20); // Class component
expect(p2.props().pageSize).toBe(20); // Function component
const findPagination = wrapper.container.querySelectorAll('.rc-pagination');
expect(findPagination).toHaveLength(2);
const [p1, p2] = findPagination;

const p1Items = p1.querySelectorAll('.rc-pagination-item');
expect(p1Items).toHaveLength(6);
expect(p1Items[p1Items.length - 1].textContent).toBe('25');

const p2Items = p2.querySelectorAll('.rc-pagination-item');
expect(p2Items).toHaveLength(6);
expect(p2Items[p2Items.length - 1].textContent).toBe('25');
});

it('should sync pageSize via state', () => {
const p1 = wrapper.find(Pagination).at(0);
const p2 = wrapper.find(Pagination).at(1);
wrapper.find('.hook').simulate('click');
// wrapper.update();
const newP1 = wrapper.find(Pagination).at(0);
const newP2 = wrapper.find(Pagination).at(1);
// expect(p1.state().pageSize).toBe(50); // Class component
expect(newP1.props().pageSize).toBe(50); // Function component
// expect(p2.state().pageSize).toBe(50); // Class component
expect(newP2.props().pageSize).toBe(50); // Function component
const findPagination = wrapper.container.querySelectorAll('.rc-pagination');
const [p1, p2] = findPagination;

const button = wrapper.container.querySelector('.hook');
expect(button).toBeTruthy();
fireEvent.click(button);

const p1Items = p1.querySelectorAll('.rc-pagination-item');
expect(p1Items).toHaveLength(6);
expect(p1Items[p1Items.length - 1].textContent).toBe('10');

const p2Items = p2.querySelectorAll('.rc-pagination-item');
expect(p2Items).toHaveLength(6);
expect(p2Items[p2Items.length - 1].textContent).toBe('10');
});
});

0 comments on commit a8ab208

Please sign in to comment.