diff --git a/common/locales/en/tasks.json b/common/locales/en/tasks.json index 66cca5774f..f3d677f6a5 100644 --- a/common/locales/en/tasks.json +++ b/common/locales/en/tasks.json @@ -5,6 +5,7 @@ "beeminderDeleteWarning": "Beeminder users: First read Deleting Completed To-Dos Without Confusing Beeminder!", "addmultiple": "Add Multiple", "addsingle": "Add Single", + "habit": "Habit", "habits": "Habits", "newHabit": "New Habit", "newHabitBulk": "New Habits (one per line)", @@ -32,6 +33,7 @@ "mental": "Mental", "otherExamples": "Eg, professional pursuits, hobbies, financial, etc.", "progress": "Progress", + "daily": "Daily", "dailies": "Dailies", "newDaily": "New Daily", "newDailyBulk": "New Dailies (one per line)", @@ -46,6 +48,7 @@ "day": "Day", "days": "Days", "restoreStreak": "Restore Streak", + "todo": "To-Do", "todos": "To-Dos", "newTodo": "New To-Do", "newTodoBulk": "New To-Dos (one per line)", @@ -57,6 +60,7 @@ "notDue": "Not Due", "grey": "Grey", "score": "Score", + "reward": "Reward", "rewards": "Rewards", "ingamerewards": "Equipment & Skills", "gold": "Gold", @@ -86,7 +90,7 @@ "fortifyPop": "Return all tasks to neutral value (yellow color), and restore all lost Health.", "fortify": "Fortify", "fortifyText": "Fortify will return all your tasks to a neutral (yellow) state, as if you'd just added them, and top your Health off to full. This is great if all your red tasks are making the game too hard, or all your blue tasks are making the game too easy. If starting fresh sounds much more motivating, spend the Gems and catch a reprieve!", - "sureDelete": "Are you sure you want to delete this task?", + "sureDelete": "Are you sure you want to delete the <%= taskType %> with the text \"<%= taskText %>\"?", "streakCoins": "Streak Bonus!", "pushTaskToTop": "Push task to top. Hold ctrl or cmd to push to bottom.", "emptyTask": "Enter the task's title first.", diff --git a/test/spec/controllers/tasksCtrlSpec.js b/test/spec/controllers/tasksCtrlSpec.js index 28ffa79f0b..ea6da32897 100644 --- a/test/spec/controllers/tasksCtrlSpec.js +++ b/test/spec/controllers/tasksCtrlSpec.js @@ -1,12 +1,18 @@ 'use strict'; describe('Tasks Controller', function() { - var $rootScope, shared, scope, user, ctrl; + var $rootScope, shared, scope, user, User, ctrl; beforeEach(function() { user = specHelper.newUser(); + User = { + user: user + }; + User.user.ops = { + deleteTask: sandbox.stub(), + }; module(function($provide) { - $provide.value('User', {user: user}); + $provide.value('User', User); $provide.value('Guide', {}); }); @@ -14,9 +20,9 @@ describe('Tasks Controller', function() { scope = $rootScope.$new(); shared = Shared; - $controller('RootCtrl', {$scope: scope, User: {user: user}}); + $controller('RootCtrl', {$scope: scope, User: User}); - ctrl = $controller('TasksCtrl', {$scope: scope, User: {user: user}}); + ctrl = $controller('TasksCtrl', {$scope: scope, User: User}); }); }); @@ -29,6 +35,32 @@ describe('Tasks Controller', function() { }); }); + describe('removeTask', function() { + var task; + + beforeEach(function() { + sandbox.stub(window, 'confirm'); + task = specHelper.newTodo(); + }); + + it('asks user to confirm deletion', function() { + scope.removeTask(task); + expect(window.confirm).to.be.calledOnce; + }); + + it('does not remove task if not confirmed', function() { + window.confirm.returns(false); + scope.removeTask(task); + expect(user.ops.deleteTask).to.not.be.called; + }); + + it('removes task', function() { + window.confirm.returns(true); + scope.removeTask(task); + expect(user.ops.deleteTask).to.be.calledOnce; + }); + }); + describe('watch to updateStore', function() { it('updates itemStore when user gear changes', function() { sinon.stub(shared, 'updateStore').returns({item: true}); diff --git a/website/public/js/controllers/challengesCtrl.js b/website/public/js/controllers/challengesCtrl.js index 1cafe40d44..9152857195 100644 --- a/website/public/js/controllers/challengesCtrl.js +++ b/website/public/js/controllers/challengesCtrl.js @@ -212,7 +212,7 @@ habitrpg.controller("ChallengesCtrl", ['$rootScope','$scope', 'Shared', 'User', }; $scope.removeTask = function(task, list) { - if (!confirm(window.env.t('sureDelete'))) return; + if (!confirm(window.env.t('sureDelete', {taskType: window.env.t(task.type), taskText: task.text}))) return; //TODO persist // User.log({op: "delTask", data: task}); _.remove(list, task); diff --git a/website/public/js/controllers/tasksCtrl.js b/website/public/js/controllers/tasksCtrl.js index 9797e7eb21..49c5414793 100644 --- a/website/public/js/controllers/tasksCtrl.js +++ b/website/public/js/controllers/tasksCtrl.js @@ -92,7 +92,7 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N }; $scope.removeTask = function(task) { - if (!confirm(window.env.t('sureDelete'))) return; + if (!confirm(window.env.t('sureDelete', {taskType: window.env.t(task.type), taskText: task.text}))) return; User.user.ops.deleteTask({params:{id:task.id}}) };