-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-keurig.js
116 lines (101 loc) · 3 KB
/
test-keurig.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
const expect = require('chai').expect;
const mockery = require('mockery');
const mockLcd = require('./mock-jsupm_i2clcd.js');
describe('Testing keurig', () => {
let keurig;
before(() => {
mockery.enable();
mockery.warnOnUnregistered(false);
mockery.registerMock('jsupm_i2clcd', mockLcd);
});
after(() => {
mockery.deregisterMock('jsupm_i2clcd');
mockery.disable();
});
beforeEach(() => {
const Keurig = require('../src/keurig.js'); // eslint-disable-line global-require
keurig = new Keurig();
});
afterEach(() => {
keurig = undefined;
});
describe('#constructor()', () => {
it('should be in waiting state.', (done) => {
expect(keurig._state).to.equal(0);
expect(mockLcd.locals.message).to.equal(keurig._messages.WAITING);
done();
});
});
describe('#markReady()', () => {
it('should become ready', (done) => {
keurig._state = 1;
keurig.markReady();
expect(mockLcd.locals.message).to.equal(keurig._messages.READY);
expect(keurig._state).to.equal(2);
done();
});
});
describe('#heatUp()', () => {
it('should start heating up', (done) => {
const res = keurig.heatUp();
expect(res).to.be.true;
expect(mockLcd.locals.message).to.equal(keurig._messages.HEATING_UP);
expect(keurig._state).to.equal(1);
done();
});
it('should not heat up if not waiting.', (done) => {
for (let state = 1; state < 4; state += 1) {
keurig._state = state;
const res = keurig.heatUp();
expect(res).to.be.false;
}
done();
});
});
describe('#brew()', () => {
it('should brew', (done) => {
keurig._state = 2; // Prepare keurig state to READY.
keurig.brew('medium', done);
});
it('should throw due to invalid size', (done) => {
keurig._state = 2;
keurig.brew('invalidsize', (err) => {
expect(err).to.be.an.error;
done();
});
});
it('should throw due to wrong state.', (done) => {
keurig.brew('medium', (err) => {
expect(err).to.be.an.error;
done();
});
});
});
describe('#getSchedule()', () => {
it('should return the schedule', (done) => {
const schedule = ['mockDate1', 'mockDate2'];
keurig.schedule = schedule;
expect(keurig.getSchedule()).to.equal(schedule);
done();
});
});
describe('#setSchedule(schedule)', () => {
it('should set the schedule', (done) => {
const schedule = ['mockDate1', 'mockDate2'];
keurig.setSchedule(schedule);
expect(keurig.schedule).to.equal(schedule);
done();
});
});
describe('#validateSize(size)', () => {
it('should validate correct sizes.', (done) => {
const sizes = ['Small', 'Medium', 'Large'];
sizes.forEach((size) => {
expect(keurig.validateSize(size)).to.be.true;
expect(keurig.validateSize(size.toLowerCase())).to.be.true;
expect(keurig.validateSize(size.toUpperCase())).to.be.true;
});
done();
});
});
});