Commit 50b1b777 authored by Kushal Pandya's avatar Kushal Pandya

Refactor `handleToggleTodo` to be DRY

parent b2aac5ee
......@@ -178,6 +178,14 @@ export default {
saveEndDate(date) {
return this.saveDate('end', date);
},
saveTodoState({ count, deletePath }) {
this.savingTodoAction = false;
this.store.setTodoExists(!this.store.todoExists);
if (deletePath) {
this.store.setTodoDeletePath(deletePath);
}
$(document).trigger('todo:toggle', count);
},
handleLabelClick(label) {
if (label.isAny) {
this.epicContext.labels = [];
......@@ -223,12 +231,11 @@ export default {
if (!this.store.todoExists) {
this.service
.addTodo(this.epicId)
.then(res => res.data)
.then(data => {
this.savingTodoAction = false;
this.store.setTodoDeletePath(data.delete_path);
this.store.setTodoExists(!this.store.todoExists);
$(document).trigger('todo:toggle', data.count);
.then(({ data }) => {
this.saveTodoState({
count: data.count,
deletePath: data.delete_path,
});
})
.catch(() => {
this.savingTodoAction = false;
......@@ -237,11 +244,10 @@ export default {
} else {
this.service
.deleteTodo(this.store.todoDeletePath)
.then(res => res.data)
.then(data => {
this.savingTodoAction = false;
this.store.setTodoExists(!this.store.todoExists);
$(document).trigger('todo:toggle', data.count);
.then(({ data }) => {
this.saveTodoState({
count: data.count,
});
})
.catch(() => {
this.savingTodoAction = false;
......
......@@ -99,7 +99,7 @@ describe('epicSidebar', () => {
});
it('should render collapsed grouped date picker', () => {
expect(vm.$el.querySelector('.sidebar-collapsed-icon span').innerText.trim()).toEqual('From Jan 1 2017');
expect(vm.$el.querySelector('.sidebar-grouped-item .sidebar-collapsed-icon span').innerText.trim()).toEqual('From Jan 1 2017');
});
it('should render collapsed labels picker', () => {
......@@ -225,7 +225,7 @@ describe('epicSidebar', () => {
beforeEach(() => {
mock = new MockAdapter(axios);
document.body.innerHTML += '<div class="flash-container"></div>';
setFixtures('<div class="flash-container"></div>');
});
afterEach(() => {
......
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