Commit 0af419d3 authored by samdbeckham's avatar samdbeckham

Fixes a bug with watched getters in the filters

parent 1d1e95c8
...@@ -5,8 +5,12 @@ export default { ...@@ -5,8 +5,12 @@ export default {
const { filterId, optionId } = payload; const { filterId, optionId } = payload;
const activeFilter = state.filters.find(filter => filter.id === filterId); const activeFilter = state.filters.find(filter => filter.id === filterId);
if (activeFilter) { if (activeFilter) {
activeFilter.options.find(option => option.selected).selected = false; activeFilter.options = [
activeFilter.options.find(option => option.id === optionId).selected = true; ...activeFilter.options.map(option => ({
...option,
selected: option.id === optionId,
})),
];
} }
}, },
}; };
...@@ -7,12 +7,11 @@ describe('filters module mutations', () => { ...@@ -7,12 +7,11 @@ describe('filters module mutations', () => {
let state; let state;
let typeFilter; let typeFilter;
let sastOption; let sastOption;
let allOption;
beforeEach(() => { beforeEach(() => {
state = createState(); state = createState();
[typeFilter] = state.filters; [typeFilter] = state.filters;
[allOption, sastOption] = typeFilter.options; [, sastOption] = typeFilter.options;
mutations[types.SET_FILTER](state, { mutations[types.SET_FILTER](state, {
filterId: typeFilter.id, filterId: typeFilter.id,
...@@ -21,11 +20,11 @@ describe('filters module mutations', () => { ...@@ -21,11 +20,11 @@ describe('filters module mutations', () => {
}); });
it('should make SAST the selected option', () => { it('should make SAST the selected option', () => {
expect(sastOption.selected).toEqual(true); expect(state.filters[0].options[1].selected).toEqual(true);
}); });
it('should remove ALL as the selected option', () => { it('should remove ALL as the selected option', () => {
expect(allOption.selected).toEqual(false); expect(state.filters[0].options[0].selected).toEqual(false);
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment