-
Notifications
You must be signed in to change notification settings - Fork 481
/
ButtonTest.js
59 lines (53 loc) · 1.59 KB
/
ButtonTest.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
/** @file Tests for our johnny-five Button wrapper */
import _ from 'lodash';
import {expect} from '../../../../util/configuredChai';
import five from '@code-dot-org/johnny-five';
import makeStubBoard from './makeStubBoard';
import Button from '@cdo/apps/lib/kits/maker/Button';
import {EXTERNAL_PINS} from '@cdo/apps/lib/kits/maker/PlaygroundConstants';
describe('Button', function() {
it('is a johnny-five Button component', function() {
const button = new Button({
board: makeStubBoard(),
pin: 0
});
expect(button).to.be.an.instanceOf(five.Button);
});
describe('isPressed', () => {
let button;
beforeEach(() => {
button = new Button({
board: makeStubBoard(),
pin: 0
});
});
it('is a readonly property', () => {
const descriptor = Object.getOwnPropertyDescriptor(button, 'isPressed');
expect(descriptor.get).to.be.a('function');
expect(descriptor.set).to.be.undefined;
expect(() => {
button.isPressed = true;
}).to.throw();
});
});
it('becomes a pullup when assigned to an external pin', () => {
EXTERNAL_PINS.forEach(pin => {
const button = new Button({
board: makeStubBoard(),
pin
});
expect(button.pullup).to.be.true;
});
});
it('does not become a pullup when assigned to a non-external pin', () => {
_.range(21)
.filter(pin => !EXTERNAL_PINS.includes(pin))
.forEach(pin => {
const button = new Button({
board: makeStubBoard(),
pin
});
expect(button.pullup).to.be.false;
});
});
});