Commit d6db5727 authored by Tim Zallmann's avatar Tim Zallmann

Merge branch 'upgrade-bootstrap-vue/dropdown-value-spec' into 'master'

Prepare dropdown-value specs for BootstrapVue upgrade

See merge request gitlab-org/gitlab!20552
parents 01928c68 747acc3f
import Vue from 'vue'; import { mount } from '@vue/test-utils';
import $ from 'jquery'; import { hexToRgb } from '~/lib/utils/color_utils';
import DropdownValueComponent from '~/vue_shared/components/sidebar/labels_select/dropdown_value.vue';
import DropdownValueScopedLabel from '~/vue_shared/components/sidebar/labels_select/dropdown_value_scoped_label.vue';
import dropdownValueComponent from '~/vue_shared/components/sidebar/labels_select/dropdown_value.vue';
import mountComponent from 'helpers/vue_mount_component_helper';
import { import {
mockConfig, mockConfig,
mockLabels, mockLabels,
} from '../../../../../javascripts/vue_shared/components/sidebar/labels_select/mock_data'; } from '../../../../../javascripts/vue_shared/components/sidebar/labels_select/mock_data';
const labelStyles = {
textColor: '#FFFFFF',
color: '#BADA55',
};
const createComponent = ( const createComponent = (
labels = mockLabels, labels = mockLabels,
labelFilterBasePath = mockConfig.labelFilterBasePath, labelFilterBasePath = mockConfig.labelFilterBasePath,
) => { ) => {
const Component = Vue.extend(dropdownValueComponent); labels.forEach(label => Object.assign(label, labelStyles));
return mountComponent(Component, { return mount(DropdownValueComponent, {
labels, propsData: {
labelFilterBasePath, labels,
enableScopedLabels: true, labelFilterBasePath,
enableScopedLabels: true,
},
attachToDocument: true,
sync: false,
}); });
}; };
...@@ -30,7 +37,7 @@ describe('DropdownValueComponent', () => { ...@@ -30,7 +37,7 @@ describe('DropdownValueComponent', () => {
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.destroy();
}); });
describe('computed', () => { describe('computed', () => {
...@@ -38,12 +45,12 @@ describe('DropdownValueComponent', () => { ...@@ -38,12 +45,12 @@ describe('DropdownValueComponent', () => {
it('returns true if `labels` prop is empty', () => { it('returns true if `labels` prop is empty', () => {
const vmEmptyLabels = createComponent([]); const vmEmptyLabels = createComponent([]);
expect(vmEmptyLabels.isEmpty).toBe(true); expect(vmEmptyLabels.classes()).not.toContain('has-labels');
vmEmptyLabels.$destroy(); vmEmptyLabels.destroy();
}); });
it('returns false if `labels` prop is empty', () => { it('returns false if `labels` prop is empty', () => {
expect(vm.isEmpty).toBe(false); expect(vm.classes()).toContain('has-labels');
}); });
}); });
}); });
...@@ -51,88 +58,71 @@ describe('DropdownValueComponent', () => { ...@@ -51,88 +58,71 @@ describe('DropdownValueComponent', () => {
describe('methods', () => { describe('methods', () => {
describe('labelFilterUrl', () => { describe('labelFilterUrl', () => {
it('returns URL string starting with labelFilterBasePath and encoded label.title', () => { it('returns URL string starting with labelFilterBasePath and encoded label.title', () => {
expect( expect(vm.find(DropdownValueScopedLabel).props('labelFilterUrl')).toBe(
vm.labelFilterUrl({ '/gitlab-org/my-project/issues?label_name[]=Foo%3A%3ABar',
title: 'Foo bar', );
}),
).toBe('/gitlab-org/my-project/issues?label_name[]=Foo%20bar');
}); });
}); });
describe('labelStyle', () => { describe('labelStyle', () => {
it('returns object with `color` & `backgroundColor` properties from label.textColor & label.color', () => { it('returns object with `color` & `backgroundColor` properties from label.textColor & label.color', () => {
const label = { expect(vm.find(DropdownValueScopedLabel).props('labelStyle')).toEqual({
textColor: '#FFFFFF', color: labelStyles.textColor,
color: '#BADA55', backgroundColor: labelStyles.color,
}; });
const styleObj = vm.labelStyle(label);
expect(styleObj.color).toBe(label.textColor);
expect(styleObj.backgroundColor).toBe(label.color);
});
});
describe('scopedLabelsDescription', () => {
it('returns html for tooltip', () => {
const html = vm.scopedLabelsDescription(mockLabels[1]);
const $el = $.parseHTML(html);
expect($el[0]).toHaveClass('scoped-label-tooltip-title');
expect($el[2].textContent).toEqual(mockLabels[1].description);
}); });
}); });
describe('showScopedLabels', () => { describe('showScopedLabels', () => {
it('returns true if the label is scoped label', () => { it('returns true if the label is scoped label', () => {
expect(vm.showScopedLabels(mockLabels[1])).toBe(true); expect(vm.findAll(DropdownValueScopedLabel).length).toEqual(1);
});
it('returns false when label is a regular label', () => {
expect(vm.showScopedLabels(mockLabels[0])).toBe(false);
}); });
}); });
}); });
describe('template', () => { describe('template', () => {
it('renders component container element with classes `hide-collapsed value issuable-show-labels`', () => { it('renders component container element with classes `hide-collapsed value issuable-show-labels`', () => {
expect(vm.$el.classList.contains('hide-collapsed', 'value', 'issuable-show-labels')).toBe( expect(vm.classes()).toContain('hide-collapsed', 'value', 'issuable-show-labels');
true,
);
}); });
it('render slot content inside component when `labels` prop is empty', () => { it('render slot content inside component when `labels` prop is empty', () => {
const vmEmptyLabels = createComponent([]); const vmEmptyLabels = createComponent([]);
expect(vmEmptyLabels.$el.querySelector('.text-secondary').innerText.trim()).toBe( expect(
mockConfig.emptyValueText, vmEmptyLabels
); .find('.text-secondary')
vmEmptyLabels.$destroy(); .text()
.trim(),
).toBe(mockConfig.emptyValueText);
vmEmptyLabels.destroy();
}); });
it('renders label element with filter URL', () => { it('renders label element with filter URL', () => {
expect(vm.$el.querySelector('a').getAttribute('href')).toBe( expect(vm.find('a').attributes('href')).toBe(
'/gitlab-org/my-project/issues?label_name[]=Foo%20Label', '/gitlab-org/my-project/issues?label_name[]=Foo%20Label',
); );
}); });
it('renders label element and styles based on label details', () => { it('renders label element and styles based on label details', () => {
const labelEl = vm.$el.querySelector('a span.badge.color-label'); const labelEl = vm.find('a span.badge.color-label');
expect(labelEl).not.toBeNull(); expect(labelEl.exists()).toBe(true);
expect(labelEl.getAttribute('style')).toBe('background-color: rgb(186, 218, 85);'); expect(labelEl.attributes('style')).toContain(
expect(labelEl.innerText.trim()).toBe(mockLabels[0].title); `background-color: rgb(${hexToRgb(labelStyles.color).join(', ')});`,
);
expect(labelEl.text().trim()).toBe(mockLabels[0].title);
}); });
describe('label is of scoped-label type', () => { describe('label is of scoped-label type', () => {
it('renders a scoped-label-wrapper span to incorporate 2 anchors', () => { it('renders a scoped-label-wrapper span to incorporate 2 anchors', () => {
expect(vm.$el.querySelector('span.scoped-label-wrapper')).not.toBeNull(); expect(vm.find('span.scoped-label-wrapper').exists()).toBe(true);
}); });
it('renders anchor tag containing question icon', () => { it('renders anchor tag containing question icon', () => {
const anchor = vm.$el.querySelector('.scoped-label-wrapper a.scoped-label'); const anchor = vm.find('.scoped-label-wrapper a.scoped-label');
expect(anchor).not.toBeNull(); expect(anchor.exists()).toBe(true);
expect(anchor.querySelector('i.fa-question-circle')).not.toBeNull(); expect(anchor.find('i.fa-question-circle').exists()).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