File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515 <li
1616 v-for =" (todo, todoKey) of todos"
1717 :data-testid =" `todo-${todoKey}`"
18+ :data-done =" todo.done"
1819 :key =" todoKey"
19- class =" "
20+ class =" block mb-3"
21+ :class =" todo.done ? 'done' : ''"
2022 >
21- {{ todo }}
23+ <span
24+ :data-testid =" `todo-${todoKey}-toggle`"
25+ @click.prevent =" toggle(todo)"
26+ class =" checkbox"
27+ :class =" todo.done ? 'done' : ''"
28+ > {{ todo.done ? "Done" : "Mark done" }}</span >
29+ {{ todo.description }}
2230 </li >
2331 </ul >
2432 </div >
@@ -44,10 +52,30 @@ export default {
4452
4553 methods: {
4654 addTodo () {
47- this .todos .push (this .newTodo )
55+ this .todos .push ({
56+ description: this .newTodo ,
57+ done: false
58+ })
4859 this .newTodo = ' '
60+ },
61+ toggle (todo ) {
62+ todo .done = ! todo .done
4963 }
5064 }
5165
5266}
5367 </script >
68+ <style lang="css">
69+ li .done {
70+ @apply line-through ;
71+ }
72+ .checkbox {
73+ @apply w- 6 h- 6 overflow-hidden inline-block border- 4 bottom- 0 relative mr- 2 rounded-full cursor-pointer ;
74+ text-indent : -1000px ;
75+ top : 5px ;
76+ }
77+
78+ .checkbox.done {
79+ @apply bg-blue- 500;
80+ }
81+ </style >
Original file line number Diff line number Diff line change @@ -56,5 +56,18 @@ describe('The Todo.vue component', () => {
5656 expect ( elementText ( 'todo-0' ) ) . toMatch ( 'First' )
5757 expect ( elementText ( 'todo-1' ) ) . toMatch ( 'Second' )
5858 } )
59+ it ( 'items can be marked as done by clicking an element before the item.' , async ( ) => {
60+
61+ function itemIsDone ( itemId ) {
62+ return wrapper . find ( `[data-testid="todo-${ itemId } "]` ) . attributes ( 'data-done' ) === 'true'
63+ }
64+
65+ await addTodo ( 'First' )
66+ await addTodo ( 'Second' )
67+
68+ expect ( itemIsDone ( 0 ) ) . toBe ( false )
69+ await wrapper . find ( '[data-testid="todo-0-toggle"]' ) . trigger ( 'click' )
70+ expect ( itemIsDone ( 0 ) ) . toBe ( true )
71+ } )
5972 } )
6073} )
You can’t perform that action at this time.
0 commit comments