Commit 63eb5a66 authored by Clement Ho's avatar Clement Ho

Merge branch...

Merge branch '31393-when-adding-labels-in-a-merge-request-adds-them-out-of-order-until-refresh-page' into 'master'

alphabetically sorts selected sidebar labels

Closes #31393

See merge request gitlab-org/gitlab!17309
parents b4ccf32f fa75b37a
...@@ -120,7 +120,7 @@ export default class LabelsSelect { ...@@ -120,7 +120,7 @@ export default class LabelsSelect {
labelCount = 0; labelCount = 0;
if (data.labels.length && issueUpdateURL) { if (data.labels.length && issueUpdateURL) {
template = LabelsSelect.getLabelTemplate({ template = LabelsSelect.getLabelTemplate({
labels: data.labels, labels: _.sortBy(data.labels, 'title'),
issueUpdateURL, issueUpdateURL,
enableScopedLabels: scopedLabels, enableScopedLabels: scopedLabels,
scopedLabelsDocumentationLink, scopedLabelsDocumentationLink,
......
---
title: Alphabetically sorts selected sidebar labels.
merge_request: 17309
author:
type: fixed
...@@ -5,6 +5,7 @@ import MockAdapter from 'axios-mock-adapter'; ...@@ -5,6 +5,7 @@ import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import IssuableContext from '~/issuable_context'; import IssuableContext from '~/issuable_context';
import LabelsSelect from '~/labels_select'; import LabelsSelect from '~/labels_select';
import _ from 'underscore';
import '~/gl_dropdown'; import '~/gl_dropdown';
import 'select2'; import 'select2';
...@@ -15,6 +16,35 @@ import '~/users_select'; ...@@ -15,6 +16,35 @@ import '~/users_select';
let saveLabelCount = 0; let saveLabelCount = 0;
let mock; let mock;
function testLabelClicks(labelOrder, done) {
$('.edit-link')
.get(0)
.click();
setTimeout(() => {
const labelsInDropdown = $('.dropdown-content a');
expect(labelsInDropdown.length).toBe(10);
const arrayOfLabels = labelsInDropdown.get();
const randomArrayOfLabels = _.shuffle(arrayOfLabels);
randomArrayOfLabels.forEach((label, i) => {
if (i < saveLabelCount) {
$(label).click();
}
});
$('.edit-link')
.get(0)
.click();
setTimeout(() => {
expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe(labelOrder);
done();
}, 0);
}, 0);
}
describe('Issue dropdown sidebar', () => { describe('Issue dropdown sidebar', () => {
preloadFixtures('static/issue_sidebar_label.html'); preloadFixtures('static/issue_sidebar_label.html');
...@@ -29,7 +59,7 @@ describe('Issue dropdown sidebar', () => { ...@@ -29,7 +59,7 @@ describe('Issue dropdown sidebar', () => {
mock.onGet('/root/test/labels.json').reply(() => { mock.onGet('/root/test/labels.json').reply(() => {
const labels = Array(10) const labels = Array(10)
.fill() .fill()
.map((_, i) => ({ .map((_val, i) => ({
id: i, id: i,
title: `test ${i}`, title: `test ${i}`,
color: '#5CB85C', color: '#5CB85C',
...@@ -41,7 +71,7 @@ describe('Issue dropdown sidebar', () => { ...@@ -41,7 +71,7 @@ describe('Issue dropdown sidebar', () => {
mock.onPut('/root/test/issues/2.json').reply(() => { mock.onPut('/root/test/issues/2.json').reply(() => {
const labels = Array(saveLabelCount) const labels = Array(saveLabelCount)
.fill() .fill()
.map((_, i) => ({ .map((_val, i) => ({
id: i, id: i,
title: `test ${i}`, title: `test ${i}`,
color: '#5CB85C', color: '#5CB85C',
...@@ -57,61 +87,11 @@ describe('Issue dropdown sidebar', () => { ...@@ -57,61 +87,11 @@ describe('Issue dropdown sidebar', () => {
it('changes collapsed tooltip when changing labels when less than 5', done => { it('changes collapsed tooltip when changing labels when less than 5', done => {
saveLabelCount = 5; saveLabelCount = 5;
$('.edit-link') testLabelClicks('test 0, test 1, test 2, test 3, test 4', done);
.get(0)
.click();
setTimeout(() => {
expect($('.dropdown-content a').length).toBe(10);
$('.dropdown-content a').each(function(i) {
if (i < saveLabelCount) {
$(this)
.get(0)
.click();
}
});
$('.edit-link')
.get(0)
.click();
setTimeout(() => {
expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe(
'test 0, test 1, test 2, test 3, test 4',
);
done();
}, 0);
}, 0);
}); });
it('changes collapsed tooltip when changing labels when more than 5', done => { it('changes collapsed tooltip when changing labels when more than 5', done => {
saveLabelCount = 6; saveLabelCount = 6;
$('.edit-link') testLabelClicks('test 0, test 1, test 2, test 3, test 4, and 1 more', done);
.get(0)
.click();
setTimeout(() => {
expect($('.dropdown-content a').length).toBe(10);
$('.dropdown-content a').each(function(i) {
if (i < saveLabelCount) {
$(this)
.get(0)
.click();
}
});
$('.edit-link')
.get(0)
.click();
setTimeout(() => {
expect($('.sidebar-collapsed-icon').attr('data-original-title')).toBe(
'test 0, test 1, test 2, test 3, test 4, and 1 more',
);
done();
}, 0);
}, 0);
}); });
}); });
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