Commit b0a3500c authored by Tim Zallmann's avatar Tim Zallmann

Merge branch 'sh-fix-boards-new-issue-weight' into 'master'

Fix setting of weight of a new issue in board list

See merge request gitlab-org/gitlab!16299
parents cd0d97c0 0075d0f8
...@@ -11,11 +11,6 @@ import boardsStore from '../stores/boards_store'; ...@@ -11,11 +11,6 @@ import boardsStore from '../stores/boards_store';
class ListIssue { class ListIssue {
constructor(obj, defaultAvatar) { constructor(obj, defaultAvatar) {
this.id = obj.id;
this.iid = obj.iid;
this.title = obj.title;
this.confidential = obj.confidential;
this.dueDate = obj.due_date;
this.subscribed = obj.subscribed; this.subscribed = obj.subscribed;
this.labels = []; this.labels = [];
this.assignees = []; this.assignees = [];
...@@ -25,6 +20,16 @@ class ListIssue { ...@@ -25,6 +20,16 @@ class ListIssue {
subscriptions: true, subscriptions: true,
}; };
this.isLoading = {}; this.isLoading = {};
this.refreshData(obj, defaultAvatar);
}
refreshData(obj, defaultAvatar) {
this.id = obj.id;
this.iid = obj.iid;
this.title = obj.title;
this.confidential = obj.confidential;
this.dueDate = obj.due_date;
this.sidebarInfoEndpoint = obj.issue_sidebar_endpoint; this.sidebarInfoEndpoint = obj.issue_sidebar_endpoint;
this.referencePath = obj.reference_path; this.referencePath = obj.reference_path;
this.path = obj.real_path; this.path = obj.real_path;
...@@ -42,12 +47,14 @@ class ListIssue { ...@@ -42,12 +47,14 @@ class ListIssue {
this.milestone_id = obj.milestone.id; this.milestone_id = obj.milestone.id;
} }
obj.labels.forEach(label => { if (obj.labels) {
this.labels.push(new ListLabel(label)); this.labels = obj.labels.map(label => new ListLabel(label));
}); }
if (obj.assignees) {
this.assignees = obj.assignees.map(a => new ListAssignee(a, defaultAvatar)); this.assignees = obj.assignees.map(a => new ListAssignee(a, defaultAvatar));
} }
}
addLabel(label) { addLabel(label) {
if (!this.findLabel(label)) { if (!this.findLabel(label)) {
......
/* eslint-disable no-underscore-dangle, class-methods-use-this, consistent-return, no-shadow, no-param-reassign */ /* eslint-disable no-underscore-dangle, class-methods-use-this, consistent-return, no-shadow */
import { __ } from '~/locale'; import { __ } from '~/locale';
import ListLabel from './label'; import ListLabel from './label';
...@@ -259,12 +259,7 @@ class List { ...@@ -259,12 +259,7 @@ class List {
} }
onNewIssueResponse(issue, data) { onNewIssueResponse(issue, data) {
issue.id = data.id; issue.refreshData(data);
issue.iid = data.iid;
issue.project = data.project;
issue.path = data.real_path;
issue.referencePath = data.reference_path;
issue.assignableLabelsEndpoint = data.assignable_labels_endpoint;
if (this.issuesSize > 1) { if (this.issuesSize > 1) {
const moveBeforeId = this.issues[1].id; const moveBeforeId = this.issues[1].id;
......
---
title: Fix setting of weight of a new issue in board list
merge_request: 16299
author:
type: fixed
# frozen_string_literal: true
require 'spec_helper'
describe 'Issue Boards new issue', :js do
let(:project) { create(:project, :public) }
let(:board) { create(:board, project: project) }
let!(:list) { create(:list, board: board, position: 0) }
let(:user) { create(:user) }
context 'authorized user' do
before do
project.add_maintainer(user)
sign_in(user)
visit project_board_path(project, board)
wait_for_requests
expect(page).to have_selector('.board', count: 3)
end
it 'successfully assigns weight to newly-created issue' do
page.within(first('.board')) do
find('.issue-count-badge-add-button').click
end
page.within(first('.board-new-issue-form')) do
find('.form-control').set('new issue')
click_button 'Submit issue'
end
wait_for_requests
page.within(first('.issue-boards-sidebar')) do
find('.weight .js-weight-edit-link').click
find('.weight .form-control').set("10\n")
end
wait_for_requests
page.within(first('.board-card')) do
expect(find('.board-card-weight .board-card-info-text').text).to eq("10")
end
end
end
end
/* global List */ /* global List */
/* global ListAssignee */
/* global ListIssue */ /* global ListIssue */
/* global ListLabel */
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -174,18 +176,29 @@ describe('List model', () => { ...@@ -174,18 +176,29 @@ describe('List model', () => {
Promise.resolve({ Promise.resolve({
data: { data: {
id: 42, id: 42,
subscribed: false,
assignable_labels_endpoint: '/issue/42/labels',
toggle_subscription_endpoint: '/issue/42/subscriptions',
issue_sidebar_endpoint: '/issue/42/sidebar_info',
}, },
}), }),
); );
}); });
it('adds new issue to top of list', done => { it('adds new issue to top of list', done => {
const user = new ListAssignee({
id: 1,
name: 'testing 123',
username: 'test',
avatar: 'test_image',
});
list.issues.push( list.issues.push(
new ListIssue({ new ListIssue({
title: 'Testing', title: 'Testing',
id: _.random(10000), id: _.random(10000),
confidential: false, confidential: false,
labels: [list.label], labels: [new ListLabel(list.label)],
assignees: [], assignees: [],
}), }),
); );
...@@ -193,8 +206,9 @@ describe('List model', () => { ...@@ -193,8 +206,9 @@ describe('List model', () => {
title: 'new issue', title: 'new issue',
id: _.random(10000), id: _.random(10000),
confidential: false, confidential: false,
labels: [list.label], labels: [new ListLabel(list.label)],
assignees: [], assignees: [user],
subscribed: false,
}); });
list list
...@@ -202,6 +216,12 @@ describe('List model', () => { ...@@ -202,6 +216,12 @@ describe('List model', () => {
.then(() => { .then(() => {
expect(list.issues.length).toBe(2); expect(list.issues.length).toBe(2);
expect(list.issues[0]).toBe(dummyIssue); expect(list.issues[0]).toBe(dummyIssue);
expect(list.issues[0].subscribed).toBe(false);
expect(list.issues[0].assignableLabelsEndpoint).toBe('/issue/42/labels');
expect(list.issues[0].toggleSubscriptionEndpoint).toBe('/issue/42/subscriptions');
expect(list.issues[0].sidebarInfoEndpoint).toBe('/issue/42/sidebar_info');
expect(list.issues[0].labels).toBe(dummyIssue.labels);
expect(list.issues[0].assignees).toBe(dummyIssue.assignees);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
......
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