-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
knob.test.js
45 lines (36 loc) · 1.13 KB
/
knob.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
import test from "ava";
import Knob from "./knob.js";
import almostEqual from "../../../test/_almost-equal.js";
test.beforeEach((t) => {
t.context = new Knob([0, 0], {
value: 2,
});
});
test("constructor", (t) => {
t.true(t.context.isRotatable);
t.context.click(); // Should do nothing
});
test("get and set radius", (t) => {
t.is(t.context.radius, 100);
t.context.radius = 200;
t.is(t.context.radius, 200);
});
test("get and set value", (t) => {
t.context.value = 0.8;
t.true(almostEqual(t.context.value, 0.8));
t.true(almostEqual(t.context.options.rotation, 0.8));
t.context.value = -1.5;
t.true(almostEqual(t.context.value, 0.5));
t.true(almostEqual(t.context.options.rotation, 0.5));
t.context.value = 2.6;
t.true(almostEqual(t.context.value, 0.6));
t.true(almostEqual(t.context.options.rotation, 0.6));
});
test("default options and NOTCH_SIZE", (t) => {
const { defaultOptions } = Knob;
t.is(defaultOptions.min, 0);
t.is(defaultOptions.max, 1);
t.is(defaultOptions.value, 0);
t.is(defaultOptions.radius, 100);
t.is(Knob.NOTCH_SIZE, 0.09);
});