Commit e49d15e7 authored by Justin Ho's avatar Justin Ho

Refactor specs to include new prop

parent f2062bc0
...@@ -11,32 +11,31 @@ import { mockConfig, mockRegularLabel, mockScopedLabel } from './mock_data'; ...@@ -11,32 +11,31 @@ import { mockConfig, mockRegularLabel, mockScopedLabel } from './mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
const createComponent = (initialState = mockConfig, slots = {}) => {
const store = new Vuex.Store(labelsSelectModule());
store.dispatch('setInitialState', initialState);
return shallowMount(DropdownValue, {
localVue,
store,
slots,
});
};
describe('DropdownValue', () => { describe('DropdownValue', () => {
let wrapper; let wrapper;
beforeEach(() => { const createComponent = (initialState = {}, slots = {}) => {
wrapper = createComponent(); const store = new Vuex.Store(labelsSelectModule());
});
store.dispatch('setInitialState', { ...mockConfig, ...initialState });
wrapper = shallowMount(DropdownValue, {
localVue,
store,
slots,
});
};
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
describe('methods', () => { describe('methods', () => {
describe('labelFilterUrl', () => { describe('labelFilterUrl', () => {
it('returns a label filter URL based on provided label param', () => { it('returns a label filter URL based on provided label param', () => {
createComponent();
expect(wrapper.vm.labelFilterUrl(mockRegularLabel)).toBe( expect(wrapper.vm.labelFilterUrl(mockRegularLabel)).toBe(
'/gitlab-org/my-project/issues?label_name[]=Foo%20Label', '/gitlab-org/my-project/issues?label_name[]=Foo%20Label',
); );
...@@ -44,6 +43,10 @@ describe('DropdownValue', () => { ...@@ -44,6 +43,10 @@ describe('DropdownValue', () => {
}); });
describe('scopedLabel', () => { describe('scopedLabel', () => {
beforeEach(() => {
createComponent();
});
it('returns `true` when provided label param is a scoped label', () => { it('returns `true` when provided label param is a scoped label', () => {
expect(wrapper.vm.scopedLabel(mockScopedLabel)).toBe(true); expect(wrapper.vm.scopedLabel(mockScopedLabel)).toBe(true);
}); });
...@@ -56,28 +59,29 @@ describe('DropdownValue', () => { ...@@ -56,28 +59,29 @@ describe('DropdownValue', () => {
describe('template', () => { describe('template', () => {
it('renders class `has-labels` on component container element when `selectedLabels` is not empty', () => { it('renders class `has-labels` on component container element when `selectedLabels` is not empty', () => {
createComponent();
expect(wrapper.attributes('class')).toContain('has-labels'); expect(wrapper.attributes('class')).toContain('has-labels');
}); });
it('renders element containing `None` when `selectedLabels` is empty', () => { it('renders element containing `None` when `selectedLabels` is empty', () => {
const wrapperNoLabels = createComponent( createComponent(
{ {
...mockConfig,
selectedLabels: [], selectedLabels: [],
}, },
{ {
default: 'None', default: 'None',
}, },
); );
const noneEl = wrapperNoLabels.find('span.text-secondary'); const noneEl = wrapper.find('span.text-secondary');
expect(noneEl.exists()).toBe(true); expect(noneEl.exists()).toBe(true);
expect(noneEl.text()).toBe('None'); expect(noneEl.text()).toBe('None');
wrapperNoLabels.destroy();
}); });
it('renders labels when `selectedLabels` is not empty', () => { it('renders labels when `selectedLabels` is not empty', () => {
createComponent();
expect(wrapper.findAll(GlLabel).length).toBe(2); expect(wrapper.findAll(GlLabel).length).toBe(2);
}); });
}); });
......
...@@ -47,6 +47,7 @@ export const mockConfig = { ...@@ -47,6 +47,7 @@ export const mockConfig = {
labelsFetchPath: '/gitlab-org/my-project/-/labels.json', labelsFetchPath: '/gitlab-org/my-project/-/labels.json',
labelsManagePath: '/gitlab-org/my-project/-/labels', labelsManagePath: '/gitlab-org/my-project/-/labels',
labelsFilterBasePath: '/gitlab-org/my-project/issues', labelsFilterBasePath: '/gitlab-org/my-project/issues',
labelsFilterParam: 'label_name',
}; };
export const mockSuggestedColors = { export const mockSuggestedColors = {
......
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