test: updated test, added number button click test

This commit is contained in:
Arman
2022-05-20 17:02:27 +02:00
parent 1685b9a5fd
commit 574f96bd6c
+50 -19
View File
@@ -4,11 +4,11 @@ import { Pagination } from '../../../src/lib/components';
test('shows controls', () => {
const { getByLabelText } = render(Pagination, {
limit: 0,
limit: 100,
offset: 0,
sum: 100
sum: 150
});
expect(getByLabelText('previous page')).toBeInTheDocument();
expect(getByLabelText('prev page')).toBeInTheDocument();
expect(getByLabelText('next page')).toBeInTheDocument();
});
@@ -19,8 +19,8 @@ test('pagination - first page', () => {
sum: 100
});
expect(getByLabelText('previous page')).toBeDisabled();
expect(getByLabelText('next page')).not.toBeDisabled();
expect(getByLabelText('prev page')).toHaveClass('is-disabled');
expect(getByLabelText('next page')).not.toHaveClass('is-disabled');
});
test('pagination - last page', () => {
@@ -30,8 +30,8 @@ test('pagination - last page', () => {
sum: 30
});
expect(getByLabelText('previous page')).not.toBeDisabled();
expect(getByLabelText('next page')).toBeDisabled();
expect(getByLabelText('prev page')).not.toHaveClass('is-disabled');
expect(getByLabelText('next page')).toHaveClass('is-disabled');
});
test('pagination - forward', async () => {
@@ -41,9 +41,9 @@ test('pagination - forward', async () => {
sum: 60
});
const back = getByLabelText('previous page');
const back = getByLabelText('prev page');
const forth = getByLabelText('next page');
expect(back).toBeDisabled();
expect(back).toHaveClass('is-disabled');
await fireEvent.click(forth);
expect(component.offset).toEqual(25);
@@ -52,8 +52,8 @@ test('pagination - forward', async () => {
expect(component.offset).toEqual(50);
await fireEvent.click(forth);
expect(component.offset).toEqual(60);
expect(forth).toBeDisabled();
expect(component.offset).toEqual(50);
expect(forth).toHaveClass('is-disabled');
});
test('pagination - backwards', async () => {
@@ -63,19 +63,50 @@ test('pagination - backwards', async () => {
sum: 60
});
const back = getByLabelText('previous page');
const back = getByLabelText('prev page');
const forth = getByLabelText('next page');
expect(forth).toBeDisabled();
expect(forth).toHaveClass('is-disabled');
await fireEvent.click(back);
expect(component.offset).toEqual(30);
await fireEvent.click(back);
expect(component.offset).toEqual(5);
expect(component.offset).toEqual(25);
await fireEvent.click(back);
expect(component.offset).toEqual(0);
expect(back).toBeDisabled();
await fireEvent.click(back);
expect(component.offset).toEqual(0);
expect(back).toHaveClass('is-disabled');
});
test('pagination - number button click', async () => {
const { getByText, getAllByLabelText, component } = render(Pagination, {
limit: 25,
offset: 0,
sum: 60
});
const buttons = getAllByLabelText('page');
const [button1, button2, button3] = buttons;
const one = getByText('1');
const two = getByText('2');
const three = getByText('3');
expect(button1).toHaveClass('is-disabled');
await fireEvent.click(two);
expect(component.offset).toEqual(25);
expect(button1).not.toHaveClass('is-disabled');
expect(button2).toHaveClass('is-disabled');
await fireEvent.click(three);
expect(component.offset).toEqual(50);
expect(button2).not.toHaveClass('is-disabled');
expect(button3).toHaveClass('is-disabled');
await fireEvent.click(one);
expect(component.offset).toEqual(0);
expect(button1).toHaveClass('is-disabled');
expect(button3).not.toHaveClass('is-disabled');
});
test('shows no controls', () => {
@@ -85,6 +116,6 @@ test('shows no controls', () => {
sum: 10
});
expect(queryByLabelText('previous page')).not.toBeInTheDocument();
expect(queryByLabelText('prev page')).not.toBeInTheDocument();
expect(queryByLabelText('next page')).not.toBeInTheDocument();
});