Commit 34f66899 authored by Jesse Hall's avatar Jesse Hall Committed by Paul Slaughter

Fixes #30967 - Over one thousand todo messages displaying a count of one in the UI.

parent 1b8e2e49
...@@ -15,11 +15,10 @@ import { parseBoolean } from '~/lib/utils/common_utils'; ...@@ -15,11 +15,10 @@ import { parseBoolean } from '~/lib/utils/common_utils';
*/ */
export default function initTodoToggle() { export default function initTodoToggle() {
$(document).on('todo:toggle', (e, count) => { $(document).on('todo:toggle', (e, count) => {
const parsedCount = parseInt(count, 10);
const $todoPendingCount = $('.todos-count'); const $todoPendingCount = $('.todos-count');
$todoPendingCount.text(highCountTrim(parsedCount)); $todoPendingCount.text(highCountTrim(count));
$todoPendingCount.toggleClass('hidden', parsedCount === 0); $todoPendingCount.toggleClass('hidden', count === 0);
}); });
} }
......
...@@ -4,6 +4,7 @@ import $ from 'jquery'; ...@@ -4,6 +4,7 @@ import $ from 'jquery';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import UsersSelect from '~/users_select'; import UsersSelect from '~/users_select';
import { isMetaClick } from '~/lib/utils/common_utils'; import { isMetaClick } from '~/lib/utils/common_utils';
import { addDelimiter } from '~/lib/utils/text_utility';
import { __ } from '~/locale'; import { __ } from '~/locale';
import flash from '~/flash'; import flash from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -145,8 +146,8 @@ export default class Todos { ...@@ -145,8 +146,8 @@ export default class Todos {
updateBadges(data) { updateBadges(data) {
$(document).trigger('todo:toggle', data.count); $(document).trigger('todo:toggle', data.count);
document.querySelector('.todos-pending .badge').innerHTML = data.count; document.querySelector('.todos-pending .badge').innerHTML = addDelimiter(data.count);
document.querySelector('.todos-done .badge').innerHTML = data.done_count; document.querySelector('.todos-done .badge').innerHTML = addDelimiter(data.done_count);
} }
goToTodoUrl(e) { goToTodoUrl(e) {
......
...@@ -78,8 +78,8 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -78,8 +78,8 @@ class Dashboard::TodosController < Dashboard::ApplicationController
def todos_counts def todos_counts
{ {
count: number_with_delimiter(current_user.todos_pending_count), count: current_user.todos_pending_count,
done_count: number_with_delimiter(current_user.todos_done_count) done_count: current_user.todos_done_count
} }
end end
......
---
title: Fix for count in todo badge when user has over 1,000 todos. Will now correctly
display todo count after user marks some todos as done.
merge_request: 16844
author: Jesse Hall @jessehall3
type: fixed
...@@ -131,7 +131,7 @@ describe Dashboard::TodosController do ...@@ -131,7 +131,7 @@ describe Dashboard::TodosController do
expect(todo.reload).to be_pending expect(todo.reload).to be_pending
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq({ "count" => "1", "done_count" => "0" }) expect(json_response).to eq({ "count" => 1, "done_count" => 0 })
end end
end end
...@@ -145,7 +145,7 @@ describe Dashboard::TodosController do ...@@ -145,7 +145,7 @@ describe Dashboard::TodosController do
expect(todo.reload).to be_pending expect(todo.reload).to be_pending
end end
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response).to eq({ 'count' => '2', 'done_count' => '0' }) expect(json_response).to eq({ 'count' => 2, 'done_count' => 0 })
end end
end end
end end
...@@ -20,26 +20,26 @@ describe('Header', function() { ...@@ -20,26 +20,26 @@ describe('Header', function() {
}); });
it('should update todos-count after receiving the todo:toggle event', () => { it('should update todos-count after receiving the todo:toggle event', () => {
triggerToggle('5'); triggerToggle(5);
expect($(todosPendingCount).text()).toEqual('5'); expect($(todosPendingCount).text()).toEqual('5');
}); });
it('should hide todos-count when it is 0', () => { it('should hide todos-count when it is 0', () => {
triggerToggle('0'); triggerToggle(0);
expect(isTodosCountHidden()).toEqual(true); expect(isTodosCountHidden()).toEqual(true);
}); });
it('should show todos-count when it is more than 0', () => { it('should show todos-count when it is more than 0', () => {
triggerToggle('10'); triggerToggle(10);
expect(isTodosCountHidden()).toEqual(false); expect(isTodosCountHidden()).toEqual(false);
}); });
describe('when todos-count is 1000', () => { describe('when todos-count is 1000', () => {
beforeEach(() => { beforeEach(() => {
triggerToggle('1000'); triggerToggle(1000);
}); });
it('should show todos-count', () => { it('should show todos-count', () => {
......
import $ from 'jquery'; import $ from 'jquery';
import MockAdapter from 'axios-mock-adapter';
import Todos from '~/pages/dashboard/todos/index/todos'; import Todos from '~/pages/dashboard/todos/index/todos';
import '~/lib/utils/common_utils'; import '~/lib/utils/common_utils';
import '~/gl_dropdown';
import axios from '~/lib/utils/axios_utils';
import { addDelimiter } from '~/lib/utils/text_utility';
const TEST_COUNT_BIG = 2000;
const TEST_DONE_COUNT_BIG = 7300;
describe('Todos', () => { describe('Todos', () => {
preloadFixtures('todos/todos.html'); preloadFixtures('todos/todos.html');
let todoItem; let todoItem;
let mock;
beforeEach(() => { beforeEach(() => {
loadFixtures('todos/todos.html'); loadFixtures('todos/todos.html');
todoItem = document.querySelector('.todos-list .todo'); todoItem = document.querySelector('.todos-list .todo');
mock = new MockAdapter(axios);
return new Todos(); return new Todos();
}); });
afterEach(() => {
mock.restore();
});
describe('goToTodoUrl', () => { describe('goToTodoUrl', () => {
it('opens the todo url', done => { it('opens the todo url', done => {
const todoLink = todoItem.dataset.url; const todoLink = todoItem.dataset.url;
...@@ -53,5 +66,43 @@ describe('Todos', () => { ...@@ -53,5 +66,43 @@ describe('Todos', () => {
expect(windowOpenSpy).not.toHaveBeenCalled(); expect(windowOpenSpy).not.toHaveBeenCalled();
}); });
}); });
describe('on done todo click', () => {
let onToggleSpy;
beforeEach(done => {
const el = document.querySelector('.js-done-todo');
const path = el.dataset.href;
// Arrange
mock
.onDelete(path)
.replyOnce(200, { count: TEST_COUNT_BIG, done_count: TEST_DONE_COUNT_BIG });
onToggleSpy = jasmine.createSpy('onToggle');
$(document).on('todo:toggle', onToggleSpy);
// Act
el.click();
// Wait for axios and HTML to udpate
setImmediate(done);
});
it('dispatches todo:toggle', () => {
expect(onToggleSpy).toHaveBeenCalledWith(jasmine.anything(), TEST_COUNT_BIG);
});
it('updates pending text', () => {
expect(document.querySelector('.todos-pending .badge').innerHTML).toEqual(
addDelimiter(TEST_COUNT_BIG),
);
});
it('updates done text', () => {
expect(document.querySelector('.todos-done .badge').innerHTML).toEqual(
addDelimiter(TEST_DONE_COUNT_BIG),
);
});
});
}); });
}); });
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