Refactored editTask into TaskService
This commit is contained in:
@@ -174,4 +174,20 @@ describe('Challenges Controller', function() {
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('editTask', function() {
|
||||
it('calls Tasks.editTask', function() {
|
||||
inject(function(Tasks) {
|
||||
sinon.stub(Tasks, 'editTask');
|
||||
var task = {
|
||||
id: 'task-id',
|
||||
type: 'todo'
|
||||
};
|
||||
|
||||
scope.editTask(task);
|
||||
expect(Tasks.editTask).to.be.calledOnce;
|
||||
expect(Tasks.editTask).to.be.calledWith(task);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
describe('Tasks Controller', function() {
|
||||
var $rootScope, scope, user, ctrl;
|
||||
|
||||
beforeEach(function() {
|
||||
user = specHelper.newUser();
|
||||
module(function($provide) {
|
||||
$provide.value('User', {user: user});
|
||||
$provide.value('Guide', {});
|
||||
});
|
||||
|
||||
inject(function($rootScope, $controller){
|
||||
|
||||
scope = $rootScope.$new();
|
||||
|
||||
$controller('RootCtrl', {$scope: scope, User: {user: user}});
|
||||
|
||||
ctrl = $controller('TasksCtrl', {$scope: scope, User: {user: user}});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('editTask', function() {
|
||||
it('calls Tasks.editTask', function() {
|
||||
inject(function(Tasks) {
|
||||
sinon.stub(Tasks, 'editTask');
|
||||
var task = {
|
||||
id: 'task-id',
|
||||
type: 'todo'
|
||||
};
|
||||
|
||||
scope.editTask(task);
|
||||
expect(Tasks.editTask).to.be.calledOnce;
|
||||
expect(Tasks.editTask).to.be.calledWith(task);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
|
||||
describe('Tasks Service', function() {
|
||||
var rootScope, tasks, user;
|
||||
|
||||
beforeEach(function() {
|
||||
|
||||
module(function($provide) {
|
||||
user = specHelper.newUser();
|
||||
$provide.value('User', {user: user});
|
||||
});
|
||||
|
||||
inject(function(_$rootScope_, Tasks, User) {
|
||||
rootScope = _$rootScope_;
|
||||
rootScope.charts = {};
|
||||
tasks = Tasks;
|
||||
});
|
||||
});
|
||||
|
||||
describe('editTask', function() {
|
||||
|
||||
var task;
|
||||
|
||||
beforeEach(function(){
|
||||
task = { id: 'task-id' }; // @TODO: replace with task factory
|
||||
});
|
||||
|
||||
it('opens the edit menu if it is not already open', function() {
|
||||
tasks.editTask(task);
|
||||
|
||||
expect(task._editing).to.eql(true);
|
||||
});
|
||||
|
||||
it('closes the edit menu if it is not already open', function() {
|
||||
task._editing = true;
|
||||
tasks.editTask(task);
|
||||
|
||||
expect(task._editing).to.eql(false);
|
||||
});
|
||||
|
||||
it('shows tags by default', function() {
|
||||
tasks.editTask(task);
|
||||
|
||||
expect(task._tags).to.eql(true);
|
||||
});
|
||||
|
||||
it('does not show tags if tagsCollapsed preference is enabled', function() {
|
||||
user.preferences.tagsCollapsed = true;
|
||||
tasks.editTask(task);
|
||||
|
||||
expect(task._tags).to.eql(false);
|
||||
});
|
||||
|
||||
it('closes the edit menu if it is not already open', function() {
|
||||
task._editing = true;
|
||||
tasks.editTask(task);
|
||||
|
||||
expect(task._editing).to.eql(false);
|
||||
});
|
||||
|
||||
it('does not open open advanced options automatically if user preference is set to collapsed', function(){
|
||||
user.preferences.advancedCollapsed = true;
|
||||
tasks.editTask(task);
|
||||
|
||||
expect(task._advanced).to.eql(false);
|
||||
});
|
||||
|
||||
it('does open open advanced options automatically if user preference is set to not collapsed', function(){
|
||||
user.preferences.advancedCollapsed = false;
|
||||
tasks.editTask(task);
|
||||
|
||||
expect(task._advanced).to.eql(true);
|
||||
});
|
||||
|
||||
it('closes task chart if it exists', function() {
|
||||
rootScope.charts[task.id] = true;
|
||||
|
||||
tasks.editTask(task);
|
||||
expect(rootScope.charts[task.id]).to.eql(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user