Skip to content
Snippets Groups Projects
Commit a14a9b12 authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Fix setInElement on API errors from ListElementEntities

parent 75052216
No related branches found
No related tags found
1 merge request!1011Fix setInElement on API errors from ListElementEntities
......@@ -34,6 +34,13 @@ export const mutations = {
state.elements = clone(elements)
},
setInElement (state, { id, ...data }) {
// Empty object: remove instead of setting
if (!Object.keys(data).length) {
const newInElement = { ...state.inElement }
delete newInElement[id]
state.inElement = newInElement
return
}
state.inElement = {
...state.inElement,
[id]: data
......@@ -124,7 +131,7 @@ export const actions = {
const data = await api.listElementEntities(id)
commit('setInElement', { id, ...data })
} catch (err) {
commit('setInElement', null)
commit('setInElement', { id })
commit('notifications/notify', { type: 'error', text: errorParser(err) }, { root: true })
}
},
......
......@@ -38,14 +38,23 @@ describe('entity', () => {
assert.deepStrictEqual(state.elements, elementSample)
})
it('setInElement', () => {
const state = initialState()
mutations.setInElement(state, {
id: 'elementid',
...entitiesInElementSample
describe('setInElement', () => {
it('sets the elements of an entity', () => {
const state = initialState()
mutations.setInElement(state, {
id: 'elementid',
...entitiesInElementSample
})
assert.deepStrictEqual(state.inElement, {
elementid: entitiesInElementSample
})
})
assert.deepStrictEqual(state.inElement, {
elementid: entitiesInElementSample
it('deletes the elements of an entity', () => {
const state = initialState()
state.inElement.elementid = entitiesInElementSample
mutations.setInElement(state, { id: 'elementid' })
assert.deepStrictEqual(state.inElement, {})
})
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment