2018-03-05 12:40:13 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
|
2019-12-09 12:07:58 +00:00
|
|
|
import mountComponent from 'helpers/vue_mount_component_helper';
|
2018-03-05 12:40:13 +00:00
|
|
|
import dropdownValueCollapsedComponent from '~/vue_shared/components/sidebar/labels_select/dropdown_value_collapsed.vue';
|
|
|
|
|
2020-05-11 09:09:45 +00:00
|
|
|
import { mockLabels } from './mock_data';
|
2018-03-05 12:40:13 +00:00
|
|
|
|
|
|
|
const createComponent = (labels = mockLabels) => {
|
|
|
|
const Component = Vue.extend(dropdownValueCollapsedComponent);
|
|
|
|
|
|
|
|
return mountComponent(Component, {
|
|
|
|
labels,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('DropdownValueCollapsedComponent', () => {
|
|
|
|
let vm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
vm = createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
vm.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('computed', () => {
|
|
|
|
describe('labelsList', () => {
|
2019-04-15 09:22:27 +00:00
|
|
|
it('returns default text when `labels` prop is empty array', () => {
|
2018-03-05 12:40:13 +00:00
|
|
|
const vmEmptyLabels = createComponent([]);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2019-04-15 09:22:27 +00:00
|
|
|
expect(vmEmptyLabels.labelsList).toBe('Labels');
|
2018-03-05 12:40:13 +00:00
|
|
|
vmEmptyLabels.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns labels names separated by coma when `labels` prop has more than one item', () => {
|
2019-04-02 10:46:21 +00:00
|
|
|
const labels = mockLabels.concat(mockLabels);
|
|
|
|
const vmMoreLabels = createComponent(labels);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
const expectedText = labels.map((label) => label.title).join(', ');
|
2019-04-02 10:46:21 +00:00
|
|
|
|
|
|
|
expect(vmMoreLabels.labelsList).toBe(expectedText);
|
2018-03-05 12:40:13 +00:00
|
|
|
vmMoreLabels.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns labels names separated by coma with remaining labels count and `and more` phrase when `labels` prop has more than five items', () => {
|
|
|
|
const mockMoreLabels = Object.assign([], mockLabels);
|
|
|
|
for (let i = 0; i < 6; i += 1) {
|
|
|
|
mockMoreLabels.unshift(mockLabels[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
const vmMoreLabels = createComponent(mockMoreLabels);
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2019-04-02 10:46:21 +00:00
|
|
|
const expectedText = `${mockMoreLabels
|
|
|
|
.slice(0, 5)
|
2020-12-23 21:10:24 +00:00
|
|
|
.map((label) => label.title)
|
2019-04-02 10:46:21 +00:00
|
|
|
.join(', ')}, and ${mockMoreLabels.length - 5} more`;
|
|
|
|
|
|
|
|
expect(vmMoreLabels.labelsList).toBe(expectedText);
|
2018-03-05 12:40:13 +00:00
|
|
|
vmMoreLabels.$destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns first label name when `labels` prop has only one item present', () => {
|
2020-12-23 21:10:24 +00:00
|
|
|
const text = mockLabels.map((label) => label.title).join(', ');
|
2019-04-02 10:46:21 +00:00
|
|
|
|
|
|
|
expect(vm.labelsList).toBe(text);
|
2018-03-05 12:40:13 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-09 11:43:06 +00:00
|
|
|
describe('methods', () => {
|
|
|
|
describe('handleClick', () => {
|
|
|
|
it('emits onValueClick event on component', () => {
|
2019-04-26 12:54:20 +00:00
|
|
|
jest.spyOn(vm, '$emit').mockImplementation(() => {});
|
2018-04-09 11:43:06 +00:00
|
|
|
vm.handleClick();
|
2018-10-09 18:03:09 +00:00
|
|
|
|
2018-04-09 11:43:06 +00:00
|
|
|
expect(vm.$emit).toHaveBeenCalledWith('onValueClick');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-05 12:40:13 +00:00
|
|
|
describe('template', () => {
|
|
|
|
it('renders component container element with tooltip`', () => {
|
2020-10-27 12:08:33 +00:00
|
|
|
expect(vm.$el.title).toBe(vm.labelsList);
|
2018-03-05 12:40:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders tags icon element', () => {
|
2020-08-21 09:10:08 +00:00
|
|
|
expect(vm.$el.querySelector('[data-testid="labels-icon"]')).not.toBeNull();
|
2018-03-05 12:40:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders labels count', () => {
|
|
|
|
expect(vm.$el.querySelector('span').innerText.trim()).toBe(`${vm.labels.length}`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|