Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pagination paginationMini component test #2604

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/pagination/__tests__/paginationMini.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';
import { render, vi } from '@test/utils';
import PaginationMini from '../PaginationMini';

describe('PaginationMini test', () => {
test('mount and unmount', () => {
const wrapper = render(<PaginationMini />);

expect(() => wrapper.unmount()).not.toThrow();
});

test('PaginationMini: test Disabled', () => {
const disabledPrev = {
prev: true,
current: false,
next: false,
};
const disabledCurrent = {
prev: false,
current: true,
next: false,
};
const disabledNext = {
prev: false,
current: false,
next: true,
};
const onChange = vi.fn();
const { container } = render(<PaginationMini disabled={disabledPrev} onChange={onChange} />);
const { container: container2 } = render(<PaginationMini disabled={disabledCurrent} onChange={onChange} />);
const { container: container3 } = render(<PaginationMini disabled={disabledNext} onChange={onChange} />);
const prev = container.querySelector('.t-pagination-mini__prev');
const current = container2.querySelector('.t-pagination-mini__current');
const next = container3.querySelector('.t-pagination-mini__next');
expect(prev).toHaveClass('t-is-disabled');
expect(current).toHaveClass('t-is-disabled');
expect(next).toHaveClass('t-is-disabled');
});

test('PaginationMini: test onChange', () => {
const onChange = vi.fn();
const { container } = render(<PaginationMini onChange={onChange} />);
const prev = container.querySelector('.t-pagination-mini__prev');
const current = container.querySelector('.t-pagination-mini__current');
const next = container.querySelector('.t-pagination-mini__next');
prev?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
expect(onChange.mock.calls[0][0].trigger).toBe('prev');
current?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
expect(onChange.mock.calls[1][0].trigger).toBe('current');
next?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
expect(onChange.mock.calls[2][0].trigger).toBe('next');
expect(onChange).toBeCalledTimes(3);
});

test('PaginationMini: test title', () => {
const { container } = render(<PaginationMini tips />);
const prev = container.querySelector('.t-pagination-mini__prev');
const current = container.querySelector('.t-pagination-mini__current');
const next = container.querySelector('.t-pagination-mini__next');

expect(prev.getAttribute('title')).toBe('上一页');
expect(current.getAttribute('title')).toBe('当前');
expect(next.getAttribute('title')).toBe('下一页');
});

test('PaginationMini: size variant', () => {
const { container } = render(<PaginationMini size="small" />);
container.querySelectorAll('.t-button').forEach((item) => {
expect(item).toHaveClass('t-size-s');
});

expect(container.querySelectorAll('.t-button').length).toBe(3);
});
});