forked from kth-csc-iprog/dinnerplanner-html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdinnerModel.test.js
119 lines (97 loc) · 3.75 KB
/
dinnerModel.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const assert = chai.assert;
const expect = chai.expect;
describe("DinnerModel", () => {
let model = new DinnerModel();
beforeEach(() => {
model = new DinnerModel();
});
describe("number of guests", () => {
it("can set and get number of guests", () => {
model.setNumberOfGuests(0);
expect(model.getNumberOfGuests()).to.equal(0);
model.setNumberOfGuests(1);
expect(model.getNumberOfGuests()).to.equal(1);
});
it("won't allow negative number of guests", () => {
model.setNumberOfGuests(1);
expect(model.getNumberOfGuests()).to.equal(1);
// this should not change the value
model.setNumberOfGuests(-1);
expect(model.getNumberOfGuests()).to.equal(1);
});
});
describe("getting individual dishes", () => {
it("gets the correct dish", () => {
const dish1 = model.getDish(1);
expect(dish1.id).to.equal(1);
expect(dish1.name).to.equal("French toast");
const dish100 = model.getDish(100);
expect(dish100.id).to.equal(100);
expect(dish100.name).to.equal("Meat balls");
});
it("returns undefined if dish is not found", () => {
const result1 = model.getDish(-1);
expect(result1).to.equal(undefined);
const result2 = model.getDish();
expect(result2).to.equal(undefined);
});
});
describe("filtering for dishes", () => {
it("returns all dishes if no args are specified", () => {
const allDishes = model.getAllDishes();
expect(allDishes.length).to.equal(10);
});
it("returns the correct dish type", () => {
let dishes = model.getAllDishes("starter");
const onlyHasStarters = dishes.every(dish => dish.type === "starter");
expect(onlyHasStarters).to.equal(true);
dishes = model.getAllDishes("main dish");
const onlyHasMain = dishes.every(dish => dish.type === "main dish");
expect(onlyHasMain).to.equal(true);
});
it("filters with keywords", () => {
let dishes = model.getAllDishes("", "French");
let allDishesMatch = dishes.every(dish => dish.name.includes("French"));
expect(dishes.length).to.be.above(0);
expect(allDishesMatch).to.equal(true);
dishes = model.getAllDishes("", "Meat");
allDishesMatch = dishes.every(dish => dish.name.includes("Meat"));
expect(dishes.length).to.be.above(0);
expect(allDishesMatch).to.equal(true);
});
it("returns correct dishes with filter and type", () => {
const dishes = model.getAllDishes("starter", "Sour");
const allDishesMatch = dishes.every(
dish => dish.name.includes("Sour") && dish.type === "starter"
);
expect(dishes.length).to.be.above(0);
expect(allDishesMatch).to.equal(true);
});
});
describe("menu", () => {
it("can add dishes", () => {
model.addDishToMenu(1);
expect(model.getFullMenu()).to.include(model.getDish(1));
model.addDishToMenu(100);
expect(model.getFullMenu()).to.include(model.getDish(1));
expect(model.getFullMenu()).to.include(model.getDish(100));
});
it("overwrites dishes of the same type when adding", () => {
model.addDishToMenu(1);
expect(model.getFullMenu()).to.include(model.getDish(1));
model.addDishToMenu(2);
// the old starter dish should no longer exist
expect(model.getFullMenu()).to.not.include(model.getDish(1));
// the new dish should exist
expect(model.getFullMenu()).to.include(model.getDish(2));
});
it("can remove dishes", () => {
model.addDishToMenu(1);
// dish 1 should be in the menu
expect(model.getFullMenu()).to.include(model.getDish(1));
model.removeDishFromMenu(1);
// should now be removed
expect(model.getFullMenu()).to.not.include(model.getDish(1));
});
});
});