Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"access": "public"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^12.0.0",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@types/jest": "^28.1.3",
"@types/react": "^17.0.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/react-router-dom": "^5.3.3",
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/parser": "^5.30.0",
Expand All @@ -59,18 +59,18 @@
"eslint-plugin-prettier": "^4.1.0",
"jest": "^28.1.1",
"jest-environment-jsdom": "^28.1.1",
"next": "^12.2.0",
"next": "^13.1.3",
"next-router-mock": "^0.7.4",
"prettier": "^2.7.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.3.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-router-dom": "^6.7.0",
"ts-jest": "^28.0.5",
"typescript": "^4.7.4"
},
"peerDependencies": {
"next": "^12.0.0",
"react": "^16.0.0 || ^17.0.0",
"next": "^12.0.0 || ^13.0.0",
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
"react-router-dom": "^6.0.0"
},
"peerDependenciesMeta": {
Expand Down
2 changes: 1 addition & 1 deletion src/__test__/inMemoryPagination.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, renderHook } from '@testing-library/react-hooks'
import { act, renderHook } from '@testing-library/react'
import { useQueryAndPagination } from '../inMemoryPagination'
import { IndexType } from '../types'

Expand Down
2 changes: 1 addition & 1 deletion src/__test__/nextRouterPagination.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import React from 'react'
import { act, renderHook } from '@testing-library/react-hooks'
import { act, renderHook } from '@testing-library/react'
import router from 'next/router'

import { useQueryAndPagination } from '../nextRouterPagination'
Expand Down
33 changes: 20 additions & 13 deletions src/__test__/reactRouterPagination.test.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import React from 'react'
import { act, renderHook } from '@testing-library/react-hooks'
import React, { ReactNode } from 'react'
import { act, renderHook } from '@testing-library/react'
import { BrowserRouter as Router } from 'react-router-dom'
import { useQueryAndPagination } from '../reactRouterPagination'
import { IndexType } from '../types'
const wrapper: React.FC = ({ children }) => <Router>{children}</Router>

function Wrapper({ children }: { children?: ReactNode }) {
return <Router>{children}</Router>
}

beforeEach(() => {
window.history.pushState({}, '', '/')
})

test('should initialize pagination', () => {
const { result } = renderHook(() => useQueryAndPagination(), { wrapper })
const { result } = renderHook(() => useQueryAndPagination(), {
wrapper: Wrapper,
})

expect(result.current.page).toBe(0)
expect(result.current.size).toBe(15)
})

test('should change page', () => {
const { result } = renderHook(() => useQueryAndPagination(), { wrapper })
const { result } = renderHook(() => useQueryAndPagination(), {
wrapper: Wrapper,
})

act(() => {
result.current.actions.setPage(2)
Expand All @@ -30,7 +37,7 @@ test('should change page', () => {
test('should change search', () => {
const { result } = renderHook(
() => useQueryAndPagination({ defaultQueryParameters: { search: '' } }),
{ wrapper }
{ wrapper: Wrapper }
)

act(() => {
Expand All @@ -44,7 +51,7 @@ test('should change search', () => {
test('clear pagination should reset search and page', () => {
const { result } = renderHook(
() => useQueryAndPagination({ defaultQueryParameters: { search: '' } }),
{ wrapper }
{ wrapper: Wrapper }
)

act(() => {
Expand All @@ -71,7 +78,7 @@ test('change default parameters', () => {
const { result } = renderHook(
() =>
useQueryAndPagination({ indexType: IndexType.ONE_BASED, pageSize: 10 }),
{ wrapper }
{ wrapper: Wrapper }
)

expect(result.current.page).toBe(1)
Expand All @@ -84,7 +91,7 @@ test('query multiple different properties, should keep them all', () => {
useQueryAndPagination({
defaultQueryParameters: { search: '', department: '' },
}),
{ wrapper }
{ wrapper: Wrapper }
)

act(() => {
Expand All @@ -102,7 +109,7 @@ test('query a property that is not configured, should do nothing', () => {
useQueryAndPagination({
defaultQueryParameters: { search: '' },
}),
{ wrapper }
{ wrapper: Wrapper }
)

act(() => {
Expand All @@ -121,7 +128,7 @@ test('properties in the URL, that are not part of the configuration should be le
useQueryAndPagination({
defaultQueryParameters: { search: '' },
}),
{ wrapper }
{ wrapper: Wrapper }
)

act(() => {
Expand All @@ -141,7 +148,7 @@ test('query property with default value, should remove it from url', () => {
useQueryAndPagination({
defaultQueryParameters: { search: '' },
}),
{ wrapper }
{ wrapper: Wrapper }
)

act(() => {
Expand All @@ -158,7 +165,7 @@ test('query property with empty value and different default value', () => {
useQueryAndPagination({
defaultQueryParameters: { search: 'Default search' },
}),
{ wrapper }
{ wrapper: Wrapper }
)

act(() => {
Expand Down