Skip to content

Commit

Permalink
[ICIJ/datashare#397] Restore the "Go to first page" link
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Mar 5, 2020
1 parent 6b1fcf4 commit 093998f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/store/modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,12 @@ export const actions = {
},
async updateFromRouteQuery ({ state, commit, getters }, query) {
// Add the query to the state with a mutation to not triggering a search
if (query.q) commit('query', query.q)
if (query.index) commit('index', query.index)
if (query.from) commit('from', query.from)
if (query.size) commit('size', query.size)
if (query.sort) commit('sort', query.sort)
if (query.field) commit('field', query.field)
if (has(query, 'q')) commit('query', query.q)
if (has(query, 'index')) commit('index', query.index)
if (has(query, 'from')) commit('from', query.from)
if (has(query, 'size')) commit('size', query.size)
if (has(query, 'sort')) commit('sort', query.sort)
if (has(query, 'field')) commit('field', query.field)
// Iterate over the list of filter
each(getters.instantiatedFilters, filter => {
// The filter key are formatted in the URL as follow.
Expand Down
14 changes: 12 additions & 2 deletions tests/unit/specs/store/modules/search.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,31 +326,43 @@ describe('SearchStore', () => {

describe('updateFromRouteQuery should restore search state from url', () => {
it('should set the index of the store according to the url', async () => {
store.commit('search/index', 'anything')
await store.dispatch('search/updateFromRouteQuery', { index: process.env.VUE_APP_ES_ANOTHER_INDEX })

expect(store.state.search.index).toBe(process.env.VUE_APP_ES_ANOTHER_INDEX)
})

it('should set the query of the store according to the url', async () => {
store.commit('search/query', 'anything')
await store.dispatch('search/updateFromRouteQuery', { q: 'new_query' })

expect(store.state.search.query).toBe('new_query')
})

it('should set the from of the store according to the url', async () => {
store.commit('search/from', 12)
await store.dispatch('search/updateFromRouteQuery', { from: 42 })

expect(store.state.search.from).toBe(42)
})

it('should RESET the from of the store according to the url', async () => {
store.commit('search/from', 12)
await store.dispatch('search/updateFromRouteQuery', { from: 0 })

expect(store.state.search.from).toBe(0)
})

it('should set the size of the store according to the url', async () => {
store.commit('search/size', 12)
await store.dispatch('search/updateFromRouteQuery', { size: 24 })

expect(store.state.search.size).toBe(24)
store.commit('search/size', 25)
})

it('should set the sort of the store according to the url', async () => {
store.commit('search/sort', 'anything')
await store.dispatch('search/updateFromRouteQuery', { sort: 'new_sort' })

expect(store.state.search.sort).toBe('new_sort')
Expand All @@ -363,15 +375,13 @@ describe('SearchStore', () => {

it('should not change the starredDocuments on updateFromRouteQuery', async () => {
store.commit('search/starredDocuments', ['doc_01', 'doc_02'])

await store.dispatch('search/updateFromRouteQuery', {})

expect(store.state.search.starredDocuments).toEqual(['doc_01', 'doc_02'])
})

it('should not change the field on updateFromRouteQuery', async () => {
store.commit('search/field', 'author')

await store.dispatch('search/updateFromRouteQuery', {})

expect(store.state.search.field).toBe('author')
Expand Down

0 comments on commit 093998f

Please sign in to comment.