Skip to content

Commit

Permalink
chore(#639): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Decipher committed Jul 3, 2023
1 parent 3f8340b commit e1df7b8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/views/src/stores/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ const DruxtViewsStore = ({ store }) => {
* @mutator {object} addResults=results Removes JSON:API Views results from the Vuex state object.
*
* @example @lang js
* this.$store.commit('druxt/views/flushResults', { viewId, displayId, prefix, hash })
* this.$store.commit('druxt/views/purgeResults', { viewId, displayId, prefix, hash })
*/
flushResults (state, { viewId, displayId, prefix, hash }) {
if (!viewId) Vue.set(state, 'results', {})
else if (viewId && !displayId) Vue.set(state.results, viewId, {})
else if (viewId && displayId && !prefix) Vue.set(state.results[viewId], displayId, {})
else if (viewId && !displayId && !prefix && !hash) Vue.set(state.results, viewId, {})
else if (viewId && displayId && !prefix && !hash) Vue.set(state.results[viewId], displayId, {})
else if (viewId && displayId && prefix && !hash) Vue.set(state.results[viewId][displayId], prefix, {})
else if (viewId && displayId && prefix && hash) Vue.set(state.results[viewId][displayId][prefix], hash, {})
else if (viewId && displayId && (prefix || prefix === undefined) && hash) Vue.set(state.results[viewId][displayId][prefix], hash, {})
},
},

Expand Down
23 changes: 23 additions & 0 deletions packages/views/test/stores/views.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ describe('DruxtViewsStore', () => {
expect(Object.keys(store.state['druxt/views'].results)).toHaveLength(1)
})

test('flushResults', async () => {
// Ensure that the results state is populated.
const results = await store.$druxt.getResource(`views--${viewId}`, displayId)
const prefix = 'en'
store.commit('druxt/views/addResults', { results, viewId, displayId, prefix, hash: '_default' })
expect(store.state['druxt/views'].results[viewId][displayId][prefix]._default).toBe(results)

store.commit('druxt/views/flushResults', { viewId, displayId, prefix, hash: '_default'})
expect(store.state['druxt/views'].results[viewId][displayId][prefix]._default).toStrictEqual({})

store.commit('druxt/views/flushResults', { viewId, displayId, prefix})
expect(store.state['druxt/views'].results[viewId][displayId][prefix]).toStrictEqual({})

store.commit('druxt/views/flushResults', { viewId, displayId })
expect(store.state['druxt/views'].results[viewId][displayId]).toStrictEqual({})

store.commit('druxt/views/flushResults', { viewId })
expect(store.state['druxt/views'].results[viewId]).toStrictEqual({})

store.commit('druxt/views/flushResults', {})
expect(store.state['druxt/views'].results).toStrictEqual({})
})

test('getResults', async () => {
const query = { viewId, displayId, query: {} }
const results = await store.dispatch('druxt/views/getResults', query)
Expand Down

0 comments on commit e1df7b8

Please sign in to comment.