Commit c15be006 authored by Clement Ho's avatar Clement Ho

Merge branch...

Merge branch '9102-hide-dismissed-vulnerabilities-in-the-group-security-dashboard-backport' into 'master'

Add toggle to show/hide dismissed vulnerabilities (ports ee!15333)

See merge request gitlab-org/gitlab-ce!32413
parents 55f05e6e 929eb056
<script>
import { GlToggle } from '@gitlab/ui';
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
export default {
name: 'GlToggleVuex',
components: {
GlToggle,
},
props: {
stateProperty: {
type: String,
required: true,
},
storeModule: {
type: String,
required: false,
default: null,
},
setAction: {
type: String,
required: false,
default() {
return `set${capitalizeFirstCharacter(this.stateProperty)}`;
},
},
},
computed: {
value: {
get() {
const { state } = this.$store;
const { stateProperty, storeModule } = this;
return storeModule ? state[storeModule][stateProperty] : state[stateProperty];
},
set(value) {
const { stateProperty, storeModule, setAction } = this;
const action = storeModule ? `${storeModule}/${setAction}` : setAction;
this.$store.dispatch(action, { key: stateProperty, value });
},
},
},
};
</script>
<template>
<gl-toggle v-model="value">
<slot v-bind="{ value }"></slot>
</gl-toggle>
</template>
import Vuex from 'vuex';
import GlToggleVuex from '~/vue_shared/components/gl_toggle_vuex.vue';
import { GlToggle } from '@gitlab/ui';
import { mount, createLocalVue } from '@vue/test-utils';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('GlToggleVuex component', () => {
let wrapper;
let store;
const findButton = () => wrapper.find('button');
const createWrapper = (props = {}) => {
wrapper = mount(GlToggleVuex, {
localVue,
store,
propsData: {
stateProperty: 'toggleState',
...props,
},
sync: false,
});
};
beforeEach(() => {
store = new Vuex.Store({
state: {
toggleState: false,
},
actions: {
setToggleState: ({ commit }, { key, value }) => commit('setToggleState', { key, value }),
},
mutations: {
setToggleState: (state, { key, value }) => {
state[key] = value;
},
},
});
createWrapper();
});
afterEach(() => {
wrapper.destroy();
});
it('renders gl-toggle', () => {
expect(wrapper.find(GlToggle).exists()).toBe(true);
});
it('properly computes default value for setAction', () => {
expect(wrapper.props('setAction')).toBe('setToggleState');
});
describe('without a store module', () => {
it('calls action with new value when value changes', () => {
jest.spyOn(store, 'dispatch');
findButton().trigger('click');
expect(store.dispatch).toHaveBeenCalledWith('setToggleState', {
key: 'toggleState',
value: true,
});
});
it('updates store property when value changes', () => {
findButton().trigger('click');
expect(store.state.toggleState).toBe(true);
});
});
describe('with a store module', () => {
beforeEach(() => {
store = new Vuex.Store({
modules: {
someModule: {
namespaced: true,
state: {
toggleState: false,
},
actions: {
setToggleState: ({ commit }, { key, value }) =>
commit('setToggleState', { key, value }),
},
mutations: {
setToggleState: (state, { key, value }) => {
state[key] = value;
},
},
},
},
});
createWrapper({
storeModule: 'someModule',
});
});
it('calls action with new value when value changes', () => {
jest.spyOn(store, 'dispatch');
findButton().trigger('click');
expect(store.dispatch).toHaveBeenCalledWith('someModule/setToggleState', {
key: 'toggleState',
value: true,
});
});
it('updates store property when value changes', () => {
findButton().trigger('click');
expect(store.state.someModule.toggleState).toBe(true);
});
});
});
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