Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eugene Shen
todomvc
Commits
c462121c
Commit
c462121c
authored
May 23, 2013
by
Pascal Hartig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AngularJS: Trim todos on save
parent
ae73f1c9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
14 deletions
+62
-14
architecture-examples/angularjs/js/controllers/todoCtrl.js
architecture-examples/angularjs/js/controllers/todoCtrl.js
+6
-3
architecture-examples/angularjs/test/unit/todoCtrlSpec.js
architecture-examples/angularjs/test/unit/todoCtrlSpec.js
+56
-11
No files found.
architecture-examples/angularjs/js/controllers/todoCtrl.js
View file @
c462121c
...
...
@@ -13,7 +13,7 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
$scope
.
editedTodo
=
null
;
$scope
.
$watch
(
'
todos
'
,
function
()
{
$scope
.
remainingCount
=
filterFilter
(
todos
,
{
completed
:
false
}).
length
;
$scope
.
remainingCount
=
filterFilter
(
todos
,
{
completed
:
false
}).
length
;
$scope
.
completedCount
=
todos
.
length
-
$scope
.
remainingCount
;
$scope
.
allChecked
=
!
$scope
.
remainingCount
;
todoStorage
.
put
(
todos
);
...
...
@@ -32,12 +32,13 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
});
$scope
.
addTodo
=
function
()
{
if
(
!
$scope
.
newTodo
.
length
)
{
var
newTodo
=
$scope
.
newTodo
.
trim
();
if
(
!
newTodo
.
length
)
{
return
;
}
todos
.
push
({
title
:
$scope
.
newTodo
,
title
:
newTodo
,
completed
:
false
});
...
...
@@ -50,6 +51,8 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
$scope
.
doneEditing
=
function
(
todo
)
{
$scope
.
editedTodo
=
null
;
todo
.
title
=
todo
.
title
.
trim
();
if
(
!
todo
.
title
)
{
$scope
.
removeTodo
(
todo
);
}
...
...
architecture-examples/angularjs/test/unit/todoCtrlSpec.js
View file @
c462121c
...
...
@@ -4,13 +4,23 @@
describe
(
'
Todo Controller
'
,
function
()
{
var
ctrl
,
scope
;
var
todoList
;
var
todoStorage
=
{
storage
:
{},
get
:
function
()
{
return
this
.
storage
;
},
put
:
function
(
value
)
{
this
.
storage
=
value
;
}
};
// Load the module containing the app, only 'ng' is loaded by default.
beforeEach
(
module
(
'
todomvc
'
));
beforeEach
(
inject
(
function
(
$controller
,
$rootScope
)
{
scope
=
$rootScope
.
$new
();
ctrl
=
$controller
(
'
TodoCtrl
'
,
{
$scope
:
scope
});
ctrl
=
$controller
(
'
TodoCtrl
'
,
{
$scope
:
scope
});
}));
it
(
'
should not have an edited Todo on start
'
,
function
()
{
...
...
@@ -60,17 +70,44 @@
});
});
describe
(
'
having no Todos
'
,
function
()
{
var
ctrl
;
beforeEach
(
inject
(
function
(
$controller
)
{
todoStorage
.
storage
=
[];
ctrl
=
$controller
(
'
TodoCtrl
'
,
{
$scope
:
scope
,
todoStorage
:
todoStorage
});
scope
.
$digest
();
}));
it
(
'
should not add empty Todos
'
,
function
()
{
scope
.
newTodo
=
''
;
scope
.
addTodo
();
scope
.
$digest
();
expect
(
scope
.
todos
.
length
).
toBe
(
0
);
});
it
(
'
should not add items consisting only of whitespaces
'
,
function
()
{
scope
.
newTodo
=
'
'
;
scope
.
addTodo
();
scope
.
$digest
();
expect
(
scope
.
todos
.
length
).
toBe
(
0
);
});
it
(
'
should trim whitespace from new Todos
'
,
function
()
{
scope
.
newTodo
=
'
buy some unicorns
'
;
scope
.
addTodo
();
scope
.
$digest
();
expect
(
scope
.
todos
.
length
).
toBe
(
1
);
expect
(
scope
.
todos
[
0
].
title
).
toBe
(
'
buy some unicorns
'
);
});
});
describe
(
'
having some saved Todos
'
,
function
()
{
var
todoList
,
todoStorage
=
{
storage
:
{},
get
:
function
()
{
return
this
.
storage
;
},
put
:
function
(
value
)
{
this
.
storage
=
value
;
}
};
var
ctrl
;
beforeEach
(
inject
(
function
(
$controller
)
{
todoList
=
[{
...
...
@@ -117,6 +154,14 @@
expect
(
scope
.
todos
.
length
).
toBe
(
4
);
});
it
(
'
should trim Todos on saving
'
,
function
()
{
var
todo
=
todoList
[
0
];
todo
.
title
=
'
buy moar unicorns
'
;
scope
.
doneEditing
(
todo
);
expect
(
scope
.
todos
[
0
].
title
).
toBe
(
'
buy moar unicorns
'
);
});
it
(
'
clearCompletedTodos() should clear completed Todos
'
,
function
()
{
scope
.
clearCompletedTodos
();
expect
(
scope
.
todos
.
length
).
toBe
(
3
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment