Skip to content

Commit 7943d0b

Browse files
committed
fix todomvc according to spec
1 parent 2ca2d77 commit 7943d0b

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

examples/todomvc/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ <h1>todos</h1>
6868
<li><a href="#/completed" v-class="selected:filter=='completed'">Completed</a></li>
6969
</ul>
7070
<button id="clear-completed" v-on="click:removeCompleted" v-show="todos.length > remaining">
71-
Remove Completed ({{todos.length - remaining}})
71+
Clear completed ({{todos.length - remaining}})
7272
</button>
7373
</footer>
7474
</section>

examples/todomvc/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var app = new Vue({
6969
addTodo: function () {
7070
var value = this.newTodo && this.newTodo.trim()
7171
if (value) {
72-
this.todos.unshift({ title: value, completed: false })
72+
this.todos.push({ title: value, completed: false })
7373
this.newTodo = ''
7474
this.remaining++
7575
todoStorage.save()

examples/todomvc/js/store.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
var todoStorage = (function () {
2+
23
var STORAGE_KEY = 'todos-vuejs',
34
todos = null
5+
46
return {
57
fetch: function () {
6-
if (!todos) todos = JSON.parse(localStorage.getItem(this.STORAGE_KEY) || '[]')
8+
if (!todos) {
9+
todos = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]')
10+
}
711
return todos
812
},
913
save: function () {
10-
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(todos))
14+
localStorage.setItem(STORAGE_KEY, JSON.stringify(todos))
1115
}
1216
}
1317
}())

test/functional/specs/todomvc.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ casper.test.begin('todomvc', 69, function (test) {
4747
})
4848
.then(function () {
4949
test.assertElementCount('.todo', 2, 'should have 2 items now')
50-
test.assertSelectorHasText('.todo label', 'test2', 'new item should have correct label text')
50+
test.assertSelectorHasText('.todo:nth-child(2) label', 'test2', 'new item should have correct label text')
5151
test.assertSelectorHasText('#todo-count strong', '2', 'remaining count should be 2')
5252
})
5353

@@ -61,7 +61,7 @@ casper.test.begin('todomvc', 69, function (test) {
6161

6262
test.assertSelectorHasText('#todo-count strong', '1', 'remaining count should be 1')
6363
test.assertVisible('#clear-completed', '#clear-completed should now be visible')
64-
test.assertSelectorHasText('#clear-completed', 'Remove Completed (1)')
64+
test.assertSelectorHasText('#clear-completed', 'Clear completed (1)')
6565
})
6666

6767
// add yet another item -----------------------------------------------
@@ -71,7 +71,7 @@ casper.test.begin('todomvc', 69, function (test) {
7171
})
7272
.then(function () {
7373
test.assertElementCount('.todo', 3, 'should have 3 items now')
74-
test.assertSelectorHasText('.todo label', 'test3', 'new item should have correct label text')
74+
test.assertSelectorHasText('.todo:nth-child(3) label', 'test3', 'new item should have correct label text')
7575
test.assertSelectorHasText('#todo-count strong', '2', 'remaining count should be 2')
7676
})
7777

@@ -88,12 +88,12 @@ casper.test.begin('todomvc', 69, function (test) {
8888

8989
// check more as completed --------------------------------------------
9090
.then(function () {
91-
this.click('.todo:nth-child(1) .toggle')
92-
this.click('.todo:nth-child(2) .toggle')
91+
this.click('.todo:nth-child(4) .toggle')
92+
this.click('.todo:nth-child(5) .toggle')
9393
})
9494
.then(function () {
9595
test.assertElementCount('.todo.completed', 3, 'should have 3 item completed')
96-
test.assertSelectorHasText('#clear-completed', 'Remove Completed (3)')
96+
test.assertSelectorHasText('#clear-completed', 'Clear completed (3)')
9797
test.assertSelectorHasText('#todo-count strong', '2', 'remaining count should be 2')
9898
})
9999

@@ -102,7 +102,7 @@ casper.test.begin('todomvc', 69, function (test) {
102102
.thenClick('.todo:nth-child(1) .destroy', function () {
103103
test.assertElementCount('.todo', 4, 'should have 4 items now')
104104
test.assertElementCount('.todo.completed', 2, 'should have 2 item completed')
105-
test.assertSelectorHasText('#clear-completed', 'Remove Completed (2)')
105+
test.assertSelectorHasText('#clear-completed', 'Clear completed (2)')
106106
test.assertSelectorHasText('#todo-count strong', '2', 'remaining count should be 2')
107107
})
108108

@@ -111,15 +111,15 @@ casper.test.begin('todomvc', 69, function (test) {
111111
.thenClick('.todo:nth-child(2) .destroy', function () {
112112
test.assertElementCount('.todo', 3, 'should have 3 items now')
113113
test.assertElementCount('.todo.completed', 2, 'should have 2 item completed')
114-
test.assertSelectorHasText('#clear-completed', 'Remove Completed (2)')
114+
test.assertSelectorHasText('#clear-completed', 'Clear completed (2)')
115115
test.assertSelectorHasText('#todo-count strong', '1', 'remaining count should be 1')
116116
})
117117

118118
// remove all completed ------------------------------------------------
119119

120120
.thenClick('#clear-completed', function () {
121121
test.assertElementCount('.todo', 1, 'should have 1 item now')
122-
test.assertSelectorHasText('.todo label', 'test', 'the remaining one should be the first one')
122+
test.assertSelectorHasText('.todo label', 'test2', 'the remaining one should be the second one')
123123
test.assertElementCount('.todo.completed', 0, 'should have no completed items now')
124124
test.assertSelectorHasText('#todo-count strong', '1', 'remaining count should be 1')
125125
test.assertNotVisible('#clear-completed', '#clear-completed should be hidden')
@@ -129,14 +129,14 @@ casper.test.begin('todomvc', 69, function (test) {
129129
.then(function () {
130130
createNewItem('test')
131131
createNewItem('test')
132-
this.click('.todo:nth-child(1) .toggle')
133132
this.click('.todo:nth-child(2) .toggle')
133+
this.click('.todo:nth-child(3) .toggle')
134134
})
135135

136136
// active filter ----------------------------------------------------------
137137
.thenClick('#filters li:nth-child(2) a', function () {
138-
test.assertElementCount('.todo', 1, 'filter active should have 2 items')
139-
test.assertElementCount('.todo.completed', 0, 'visible items should be incompleted')
138+
test.assertElementCount('.todo', 1, 'filter active should have 1 item')
139+
test.assertElementCount('.todo.completed', 0, 'visible items should be incomplete')
140140
})
141141

142142
// add item with filter active --------------------------------------------
@@ -158,15 +158,15 @@ casper.test.begin('todomvc', 69, function (test) {
158158
.thenOpen('../../examples/todomvc/index.html#/active', function () {
159159
test.assertElementCount('.todo', 2, 'filter active should have 2 items')
160160
test.assertElementCount('.todo.completed', 0, 'visible items should be incompleted')
161-
test.assertSelectorHasText('#clear-completed', 'Remove Completed (2)')
161+
test.assertSelectorHasText('#clear-completed', 'Clear completed (2)')
162162
test.assertSelectorHasText('#todo-count strong', '2', 'remaining count should be 2')
163163
})
164164

165165
// completed filter on page load ------------------------------------------
166166
.thenOpen('../../examples/todomvc/index.html#/completed', function () {
167167
test.assertElementCount('.todo', 2, 'filter completed should have 2 items')
168168
test.assertElementCount('.todo.completed', 2, 'visible items should be completed')
169-
test.assertSelectorHasText('#clear-completed', 'Remove Completed (2)')
169+
test.assertSelectorHasText('#clear-completed', 'Clear completed (2)')
170170
test.assertSelectorHasText('#todo-count strong', '2', 'remaining count should be 2')
171171
})
172172

0 commit comments

Comments
 (0)