-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathtests.js
More file actions
128 lines (89 loc) · 3.95 KB
/
Copy pathtests.js
File metadata and controls
128 lines (89 loc) · 3.95 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// 'use strict'
var chai = require('chai');
var assert = chai.assert;
var NotesApplication = require('./lib/notesapplication.js');
var Note = require('./lib/notes.js');
describe("Note creation works properly", function() {
it("creates a note with parameters author and note_content", function() {
var note = new Note("This is my first note");
assert(note.hasOwnProperty("author"))
assert(note.hasOwnProperty("note_content"))
})
it("assigns author based on the parameter supplied in the constructor", function() {
var note = new Note("Chidiebere", "Hello world");
assert(note.author === "Chidiebere")
})
it("assigns note content based on the parameter supplied in the constructor", function() {
var note = new Note("Awa", "Welcom Awa");
assert(note.note_content === "Welcom Awa");
})
})
describe("Notes application works properly", function() {
it("creates an empty list of notes when notes application is created", function() {
var noteapp = new NotesApplication();
assert(noteapp.notesList)
})
it("implements the create, getNote, searchNote, listNotes, editNote and deleteNote functions", function() {
var noteapp = new NotesApplication();
assert(noteapp.hasOwnProperty("create"))
assert(noteapp.hasOwnProperty("getNote"))
assert(noteapp.hasOwnProperty("searchNote"))
assert(noteapp.hasOwnProperty("listNotes"))
assert(noteapp.hasOwnProperty("editNote"))
assert(noteapp.hasOwnProperty("deleteNote"))
})
it("adds notes successfully", function() {
var note = new Note("Chidiebere", "Hello world");
var noteapp = new NotesApplication();
var len = noteapp.notesList.length
noteapp.create(note)
var new_len = noteapp.notesList.length
assert(new_len === (len + 1));
assert(note === noteapp.notesList[0]);
})
it("retrieves notes successfully", function() {
var note = new Note("Chidiebere", "Hello world");
var noteapp = new NotesApplication();
noteapp.create(note)
assert(noteapp.getNote(0) === note)
assert(noteapp.getNote(5) === "No note with ID " + "'" + 5 + "'")
})
it("searches for notes successfully", function() {
var note1 = new Note("Chidiebere", "Hello world");
var noteapp = new NotesApplication();
assert(noteapp.searchNote("world") == "O Results Found")
noteapp.create(note1);
assert(noteapp.searchNote("world") == "1 Results Found");
var note2 = new Note("Awa", "working with Functions");
noteapp.create(note2);
assert(noteapp.searchNote("wor") === "2 Results Found");
assert(noteapp.searchNote("Awa") === "0 Results Found")
})
it("returns a list of notes or an empty list if no list is present", function() {
var noteapp = new NotesApplication();
assert(noteapp.listNotes().length === 0)
var note1 = new Note("Awa", "Hello world");
var note2 = new Note("Awa", "Working with Functions");
noteapp.create(note1);
noteapp.create(note2);
assert(noteapp.listNotes() === noteapp.notesList)
assert(noteapp.notesList.length === 2)
})
it("deletes note correctly", function() {
var note = new Note("Chidiebere", "Hello world");
var noteapp = new NotesApplication();
assert(noteapp.notesList.length === 0)
noteapp.create(note);
assert(noteapp.notesList.length === 1)
noteapp.deleteNote(0)
assert(noteapp.notesList.length === 0)
})
it("edits notes correctly", function() {
var note = new Note("Awa", "Hello world");
var noteapp = new NotesApplication();
noteapp.create(note);
assert(noteapp.notesList[0] === note)
noteapp.editNote(0, "Going Deeper in Javascript")
assert(noteapp.notesList[0].note_content === "Going Deeper in Javascript")
})
})