Skip to content

Commit 4e7494b

Browse files
rename action to be more precise
1 parent 8c248d8 commit 4e7494b

8 files changed

Lines changed: 29 additions & 29 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"eslint-plugin-prettier": "^3.3.1",
5555
"jest": "^26.6.3",
5656
"next": "^11.0.1",
57-
"next-router-mock": "^0.1.4",
57+
"next-router-mock": "^0.6.1",
5858
"prettier": "^2.2.1",
5959
"react": "^17.0.2",
6060
"react-dom": "^17.0.2",

src/__test__/inMemoryPagination.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test('should change search', () => {
2525
)
2626

2727
act(() => {
28-
result.current.actions.query({ search: 'Max' })
28+
result.current.actions.updateQuery({ search: 'Max' })
2929
})
3030

3131
expect(result.current.queryParameters.search).toBe('Max')
@@ -43,7 +43,7 @@ test('on search change -> page should be reset', () => {
4343
expect(result.current.page).toBe(2)
4444

4545
act(() => {
46-
result.current.actions.query({ search: 'Max' })
46+
result.current.actions.updateQuery({ search: 'Max' })
4747
})
4848

4949
expect(result.current.queryParameters.search).toBe('Max')
@@ -56,7 +56,7 @@ test('clear pagination should reset search and page', () => {
5656
)
5757

5858
act(() => {
59-
result.current.actions.query({ search: 'Max' })
59+
result.current.actions.updateQuery({ search: 'Max' })
6060
})
6161

6262
act(() => {
@@ -91,8 +91,8 @@ test('query multiple different properties, should keep them all', () => {
9191
)
9292

9393
act(() => {
94-
result.current.actions.query({ search: 'Max' })
95-
result.current.actions.query({ department: 'IT' })
94+
result.current.actions.updateQuery({ search: 'Max' })
95+
result.current.actions.updateQuery({ department: 'IT' })
9696
})
9797

9898
expect(result.current.queryParameters.search).toBe('Max')
@@ -107,7 +107,7 @@ test('query a property that is not configured, should do nothing', () => {
107107
)
108108

109109
act(() => {
110-
result.current.actions.query({ department: 'IT' })
110+
result.current.actions.updateQuery({ department: 'IT' })
111111
})
112112

113113
expect(result.current.queryParameters.search).toBe('')

src/__test__/nextRouterPagination.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test('should change search', () => {
3636
)
3737

3838
act(() => {
39-
result.current.actions.query({ search: 'Max' })
39+
result.current.actions.updateQuery({ search: 'Max' })
4040
})
4141

4242
expect(result.current.queryParameters.search).toBe('Max')
@@ -49,7 +49,7 @@ test('clear pagination should reset search and page', () => {
4949
)
5050

5151
act(() => {
52-
result.current.actions.query({ search: 'Max' })
52+
result.current.actions.updateQuery({ search: 'Max' })
5353
})
5454

5555
act(() => {
@@ -91,7 +91,7 @@ test('on search change -> page should be reset', () => {
9191
expect(router.query.page).toBe('2')
9292

9393
act(() => {
94-
result.current.actions.query({ search: 'Max' })
94+
result.current.actions.updateQuery({ search: 'Max' })
9595
})
9696

9797
expect(result.current.queryParameters.search).toBe('Max')
@@ -108,8 +108,8 @@ test('query multiple different properties, should keep them all', () => {
108108
)
109109

110110
act(() => {
111-
result.current.actions.query({ search: 'Max' })
112-
result.current.actions.query({ department: 'IT' })
111+
result.current.actions.updateQuery({ search: 'Max' })
112+
result.current.actions.updateQuery({ department: 'IT' })
113113
})
114114

115115
expect(result.current.queryParameters.search).toBe('Max')
@@ -124,7 +124,7 @@ test('query a property that is not configured, should do nothing', () => {
124124
)
125125

126126
act(() => {
127-
result.current.actions.query({ department: 'IT' })
127+
result.current.actions.updateQuery({ department: 'IT' })
128128
})
129129

130130
expect(result.current.queryParameters.search).toBe('')
@@ -141,7 +141,7 @@ test('properties in the URL, that are not part of the configuration should be le
141141
)
142142

143143
act(() => {
144-
result.current.actions.query({ search: 'Max' })
144+
result.current.actions.updateQuery({ search: 'Max' })
145145
})
146146

147147
expect(result.current.queryParameters.search).toBe('Max')
@@ -159,7 +159,7 @@ test('query property with default value, should remove it from url', () => {
159159
)
160160

161161
act(() => {
162-
result.current.actions.query({ search: '' })
162+
result.current.actions.updateQuery({ search: '' })
163163
})
164164

165165
expect(result.current.queryParameters.search).toBe('')

src/__test__/reactRouterPagination.test.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test('should change search', () => {
3434
)
3535

3636
act(() => {
37-
result.current.actions.query({ search: 'Max' })
37+
result.current.actions.updateQuery({ search: 'Max' })
3838
})
3939

4040
expect(result.current.queryParameters.search).toBe('Max')
@@ -48,7 +48,7 @@ test('clear pagination should reset search and page', () => {
4848
)
4949

5050
act(() => {
51-
result.current.actions.query({ search: 'Max' })
51+
result.current.actions.updateQuery({ search: 'Max' })
5252
})
5353

5454
act(() => {
@@ -88,8 +88,8 @@ test('query multiple different properties, should keep them all', () => {
8888
)
8989

9090
act(() => {
91-
result.current.actions.query({ search: 'Max' })
92-
result.current.actions.query({ department: 'IT' })
91+
result.current.actions.updateQuery({ search: 'Max' })
92+
result.current.actions.updateQuery({ department: 'IT' })
9393
})
9494

9595
expect(result.current.queryParameters.search).toBe('Max')
@@ -106,7 +106,7 @@ test('query a property that is not configured, should do nothing', () => {
106106
)
107107

108108
act(() => {
109-
result.current.actions.query({ department: 'IT' })
109+
result.current.actions.updateQuery({ department: 'IT' })
110110
})
111111

112112
expect(result.current.queryParameters.search).toBe('')
@@ -125,7 +125,7 @@ test('properties in the URL, that are not part of the configuration should be le
125125
)
126126

127127
act(() => {
128-
result.current.actions.query({ search: 'Max' })
128+
result.current.actions.updateQuery({ search: 'Max' })
129129
})
130130

131131
expect(result.current.queryParameters.search).toBe('Max')
@@ -145,7 +145,7 @@ test('query property with default value, should remove it from url', () => {
145145
)
146146

147147
act(() => {
148-
result.current.actions.query({ search: '' })
148+
result.current.actions.updateQuery({ search: '' })
149149
})
150150

151151
expect(result.current.queryParameters.search).toBe('')

src/inMemoryPagination.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const useQueryAndPagination: IUseQueryAndPagination = function (config) {
1515

1616
const [state, setState] = useState(initialState)
1717

18-
const query = useCallback((queryParameters: QueryParameters) => {
18+
const updateQuery = useCallback((queryParameters: QueryParameters) => {
1919
setState((currentState) => {
2020
const updatedQueryParameters = {
2121
...currentState.queryParameters,
@@ -59,7 +59,7 @@ export const useQueryAndPagination: IUseQueryAndPagination = function (config) {
5959
return {
6060
queryParameters: state.queryParameters,
6161
actions: {
62-
query,
62+
updateQuery,
6363
clear,
6464
setPage,
6565
},

src/nextRouterPagination.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const useQueryAndPagination: IUseQueryAndPagination = function (config) {
5151
[router]
5252
)
5353

54-
const query = useCallback(
54+
const updateQuery = useCallback(
5555
(queryParameters: QueryParameters) => {
5656
const params = {
5757
...router.query,
@@ -107,7 +107,7 @@ export const useQueryAndPagination: IUseQueryAndPagination = function (config) {
107107
),
108108
size: convert(getSingleParameterValue(router.query.size) || null, pageSize),
109109
actions: {
110-
query,
110+
updateQuery,
111111
clear,
112112
setPage,
113113
},

src/reactRouterPagination.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const useQueryAndPagination: IUseQueryAndPagination = function (config) {
3131

3232
const params = useMemo(() => new URLSearchParams(routeQuery), [routeQuery])
3333

34-
const query = useCallback(
34+
const updateQuery = useCallback(
3535
(queryParameters: QueryParameters) => {
3636
for (const parameter in queryParameters) {
3737
if (
@@ -92,7 +92,7 @@ export const useQueryAndPagination: IUseQueryAndPagination = function (config) {
9292
),
9393
size: convert(params.get('size'), pageSize),
9494
actions: {
95-
query,
95+
updateQuery,
9696
clear,
9797
setPage,
9898
},

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type Config = {
1212
}
1313

1414
export type Actions = {
15-
query: (query: QueryParameters) => void
15+
updateQuery: (query: QueryParameters) => void
1616
clear: () => void
1717
setPage: (page: number) => void
1818
}

0 commit comments

Comments
 (0)