-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
97 lines (81 loc) · 3.17 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
var test = require('tape');
var logicFile = require('./logic.js');
var state = [
{ id: -3, description: 'first todo', done: false },
{ id: -2, description: 'second todo', done: false},
{ id: -1, description: 'third todo', done: false },
]
var sortOrder = function(a,b) {
if (a.description < b.description) {
return -1;
}
if (a.description > b.description) {
return 1;
}
return 0;
}
test('Tape is up and running', function(t) {
t.equal(1, 1, 'one should equal one');
t.end();
});
test('check that to do has been added', function(t){
var actual = logicFile.addTodo(state, {description: 'fourth todo', done: false});
var expected = [
{ id: -3, description: 'first todo', done: false },
{ id: -2, description: 'second todo', done: false},
{ id: -1, description: 'third todo', done: false },
{id: 1, description: 'fourth todo', done: false},
]
t.deepEqual(actual, expected, 'should return the todos array with new todo added ');
t.end();
});
test('check that id is removed from returned array', function(t) {
var actual = logicFile.deleteTodo(state, -3);
var expected = [{ id: -2, description: 'second todo',done:false }, { id: -1, description: 'third todo',done:false }];
t.deepEqual(actual,expected, 'should return ids');
t.end();
});
test('deleteTodo() check that passed array is not equal to the returned one', function(t) {
var actual = logicFile.deleteTodo(state,-3);
var expected = state;
t.notEqual(actual,expected,"The arrays should npt be the same");
t.end();
});
test('Test if the done property is changed', function(t) {
var actual = logicFile.markTodo(state, -3);
var expected = [{ id: -3, description: 'first todo', done: true },
{ id: -2, description: 'second todo', done: false},
{ id: -1, description: 'third todo', done: false }];
t.deepEqual(actual, expected, 'should toggle the property done for the element with id passed as argument');
t.end();
});
test('markTodo() check that passed array is not equal to the returned one', function(t) {
var actual = logicFile.markTodo(state,-2);
var expected = state;
t.notEqual(actual,expected,"The arrays should npt be the same");
t.end();
});
test('check if items are sorted alphabetically by description', function(t) {
var actual = logicFile.sortTodos(state, sortOrder);
var expected = [
{ id: -3, description: 'first todo', done: false },
{ id: -2, description: 'second todo', done: false},
{ id: -1, description: 'third todo', done: false }
];
t.deepEqual(actual, expected, 'should have description in alphabetical order');
t.end();
});
test('check if items are sorted alphabetically by description', function(t) {
var actual = logicFile.sortTodos([
{ id: -2, description: 'second todo', done: false},
{ id: -1, description: 'third todo', done: false },
{ id: -3, description: 'first todo', done: false }
], sortOrder);
var expected = [
{ id: -3, description: 'first todo', done: false },
{ id: -2, description: 'second todo', done: false},
{ id: -1, description: 'third todo', done: false }
];
t.deepEqual(actual, expected, 'should have description in alphabetical order');
t.end();
});