2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-02-28 07:33:46 -05:00
|
|
|
import LabelsSelect from '~/labels_select';
|
|
|
|
|
|
|
|
const mockUrl = '/foo/bar/url';
|
|
|
|
|
|
|
|
const mockLabels = [
|
|
|
|
{
|
|
|
|
id: 26,
|
|
|
|
title: 'Foo Label',
|
|
|
|
description: 'Foobar',
|
|
|
|
color: '#BADA55',
|
|
|
|
text_color: '#FFFFFF',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2019-04-02 06:46:21 -04:00
|
|
|
const mockScopedLabels = [
|
|
|
|
{
|
|
|
|
id: 27,
|
|
|
|
title: 'Foo::Bar',
|
|
|
|
description: 'Foobar',
|
|
|
|
color: '#333ABC',
|
|
|
|
text_color: '#FFFFFF',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2020-03-16 05:09:29 -04:00
|
|
|
const mockScopedLabels2 = [
|
|
|
|
{
|
|
|
|
id: 28,
|
|
|
|
title: 'Foo::Bar2',
|
|
|
|
description: 'Foobar2',
|
|
|
|
color: '#FFFFFF',
|
|
|
|
text_color: '#000000',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2018-02-28 07:33:46 -05:00
|
|
|
describe('LabelsSelect', () => {
|
|
|
|
describe('getLabelTemplate', () => {
|
2019-04-02 06:46:21 -04:00
|
|
|
describe('when normal label is present', () => {
|
|
|
|
const label = mockLabels[0];
|
|
|
|
let $labelEl;
|
2018-02-28 07:33:46 -05:00
|
|
|
|
2019-04-02 06:46:21 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
$labelEl = $(
|
|
|
|
LabelsSelect.getLabelTemplate({
|
|
|
|
labels: mockLabels,
|
|
|
|
issueUpdateURL: mockUrl,
|
|
|
|
enableScopedLabels: true,
|
|
|
|
scopedLabelsDocumentationLink: 'docs-link',
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
2018-02-28 07:33:46 -05:00
|
|
|
|
2019-04-02 06:46:21 -04:00
|
|
|
it('generated label item template has correct label URL', () => {
|
2020-02-28 04:09:01 -05:00
|
|
|
expect($labelEl.find('a').attr('href')).toBe('/foo/bar?label_name[]=Foo%20Label');
|
2019-04-02 06:46:21 -04:00
|
|
|
});
|
2018-02-28 07:33:46 -05:00
|
|
|
|
2019-04-02 06:46:21 -04:00
|
|
|
it('generated label item template has correct label title', () => {
|
2020-02-28 04:09:01 -05:00
|
|
|
expect($labelEl.find('span.gl-label-text').text()).toBe(label.title);
|
2019-04-02 06:46:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('generated label item template has label description as title attribute', () => {
|
2020-02-28 04:09:01 -05:00
|
|
|
expect($labelEl.find('a').attr('title')).toBe(label.description);
|
2019-04-02 06:46:21 -04:00
|
|
|
});
|
2018-02-28 07:33:46 -05:00
|
|
|
|
2019-04-02 06:46:21 -04:00
|
|
|
it('generated label item template has correct label styles', () => {
|
2020-02-28 04:09:01 -05:00
|
|
|
expect($labelEl.find('span.gl-label-text').attr('style')).toBe(
|
2019-04-02 06:46:21 -04:00
|
|
|
`background-color: ${label.color}; color: ${label.text_color};`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-02-28 04:09:01 -05:00
|
|
|
it('generated label item has a gl-label-text class', () => {
|
|
|
|
expect($labelEl.find('span').hasClass('gl-label-text')).toEqual(true);
|
2019-04-02 06:46:21 -04:00
|
|
|
});
|
|
|
|
|
2020-02-28 04:09:01 -05:00
|
|
|
it('generated label item template does not have gl-label-icon class', () => {
|
|
|
|
expect($labelEl.find('.gl-label-icon')).toHaveLength(0);
|
2019-04-02 06:46:21 -04:00
|
|
|
});
|
2018-02-28 07:33:46 -05:00
|
|
|
});
|
2018-06-04 17:39:44 -04:00
|
|
|
|
2019-04-02 06:46:21 -04:00
|
|
|
describe('when scoped label is present', () => {
|
|
|
|
const label = mockScopedLabels[0];
|
|
|
|
let $labelEl;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
$labelEl = $(
|
|
|
|
LabelsSelect.getLabelTemplate({
|
|
|
|
labels: mockScopedLabels,
|
|
|
|
issueUpdateURL: mockUrl,
|
|
|
|
enableScopedLabels: true,
|
|
|
|
scopedLabelsDocumentationLink: 'docs-link',
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('generated label item template has correct label URL', () => {
|
|
|
|
expect($labelEl.find('a').attr('href')).toBe('/foo/bar?label_name[]=Foo%3A%3ABar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('generated label item template has correct label title', () => {
|
2020-02-28 04:09:01 -05:00
|
|
|
const scopedTitle = label.title.split('::');
|
|
|
|
expect($labelEl.find('span.gl-label-text').text()).toContain(scopedTitle[0]);
|
|
|
|
expect($labelEl.find('span.gl-label-text').text()).toContain(scopedTitle[1]);
|
2019-04-02 06:46:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('generated label item template has html flag as true', () => {
|
2020-02-28 04:09:01 -05:00
|
|
|
expect($labelEl.find('a').attr('data-html')).toBe('true');
|
2019-04-02 06:46:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('generated label item template has question icon', () => {
|
|
|
|
expect($labelEl.find('i.fa-question-circle')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
2020-02-28 04:09:01 -05:00
|
|
|
it('generated label item template has gl-label-icon class', () => {
|
|
|
|
expect($labelEl.find('.gl-label-icon')).toHaveLength(1);
|
2019-04-02 06:46:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('generated label item template has correct label styles', () => {
|
2020-02-28 04:09:01 -05:00
|
|
|
expect($labelEl.find('span.gl-label-text').attr('style')).toBe(
|
2019-04-02 06:46:21 -04:00
|
|
|
`background-color: ${label.color}; color: ${label.text_color};`,
|
|
|
|
);
|
2020-03-16 05:09:29 -04:00
|
|
|
expect(
|
|
|
|
$labelEl
|
|
|
|
.find('span.gl-label-text')
|
|
|
|
.last()
|
|
|
|
.attr('style'),
|
|
|
|
).toBe(`color: ${label.color};`);
|
2019-04-02 06:46:21 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('generated label item has a badge class', () => {
|
2020-02-28 04:09:01 -05:00
|
|
|
expect($labelEl.find('span').hasClass('gl-label-text')).toEqual(true);
|
2019-04-02 06:46:21 -04:00
|
|
|
});
|
2018-06-04 17:39:44 -04:00
|
|
|
});
|
2020-03-16 05:09:29 -04:00
|
|
|
|
|
|
|
describe('when scoped label is present, with text color not white', () => {
|
|
|
|
const label = mockScopedLabels2[0];
|
|
|
|
let $labelEl;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
$labelEl = $(
|
|
|
|
LabelsSelect.getLabelTemplate({
|
|
|
|
labels: mockScopedLabels2,
|
|
|
|
issueUpdateURL: mockUrl,
|
|
|
|
enableScopedLabels: true,
|
|
|
|
scopedLabelsDocumentationLink: 'docs-link',
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('generated label item template has correct label styles', () => {
|
|
|
|
expect($labelEl.find('span.gl-label-text').attr('style')).toBe(
|
|
|
|
`background-color: ${label.color}; color: ${label.text_color};`,
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
$labelEl
|
|
|
|
.find('span.gl-label-text')
|
|
|
|
.last()
|
|
|
|
.attr('style'),
|
|
|
|
).toBe(`color: ${label.text_color};`);
|
|
|
|
});
|
|
|
|
});
|
2018-02-28 07:33:46 -05:00
|
|
|
});
|
|
|
|
});
|