UNPKG

3.03 kBJavaScriptView Raw
1import context from '../src/context';
2import Time from '../src/time';
3
4const CONFIGURATION_1 = {
5 context: {
6 blind: {
7 type: 'enum'
8 },
9 time: {
10 type: 'time_of_day',
11 is_generated: true
12 },
13 day: {
14 type: 'day_of_week'
15 },
16 date: {
17 type: 'day_of_month'
18 },
19 month: {
20 type: 'month_of_year'
21 },
22 tz: {
23 type: 'timezone'
24 },
25 happiness: {
26 type: 'continuous'
27 }
28 },
29 output: [
30 'happiness'
31 ],
32 time_quantum: 600
33};
34
35describe('context(...)', function() {
36 it('is able to create a context skeleton', function() {
37 expect(
38 context(
39 CONFIGURATION_1
40 )
41 ).to.be.deep.equal({
42 blind: undefined,
43 day: undefined,
44 date: undefined,
45 month: undefined,
46 time: undefined,
47 tz: undefined
48 });
49 });
50
51 it('is able to fill the relevant keys using the given time', function() {
52 expect(
53 context(
54 CONFIGURATION_1,
55 {
56 blind: 'closed'
57 },
58 new Time('2016-06-09T18:28:49.000Z', '-05:00')
59 )
60 ).to.be.deep.equal({
61 blind: 'closed',
62 day: 3,
63 time: 13.480277777777777,
64 date: 9,
65 month: 6,
66 tz: '-05:00'
67 });
68 });
69
70 it('is able to overrides the relevant keys using the given time', function() {
71 expect(
72 context(
73 CONFIGURATION_1,
74 {
75 blind: 'opened',
76 day: 4,
77 time: 12.5,
78 date: 1,
79 month: 10,
80 tz: '+03:00'
81 },
82 new Time('2016-06-09T18:28:49.000Z', '-05:00')
83 )
84 ).to.be.deep.equal({
85 blind: 'opened',
86 day: 3,
87 time: 13.480277777777777,
88 date: 9,
89 month: 6,
90 tz: '-05:00'
91 });
92 });
93
94 it('is able to overrides the given time using the relevant keys', function() {
95 expect(
96 context(
97 CONFIGURATION_1,
98 new Time('2016-06-09T18:28:49.000Z', '-05:00'),
99 {
100 blind: 'opened',
101 day: 4,
102 time: 12.5,
103 date: 10,
104 month: 1,
105 tz: '+03:00'
106 }
107 )
108 ).to.be.deep.equal({
109 blind: 'opened',
110 day: 4,
111 time: 12.5,
112 date: 10,
113 month: 1,
114 tz: '+03:00'
115 });
116 });
117
118 it('is able to select the actually needed keys', function() {
119 expect(
120 context(
121 CONFIGURATION_1,
122 {
123 blind: 'opened',
124 day: 4,
125 time: 12.5,
126 date: 9,
127 month: 6,
128 tz: '+03:00',
129 foo: 34
130 }
131 )
132 ).to.be.deep.equal({
133 blind: 'opened',
134 day: 4,
135 time: 12.5,
136 date: 9,
137 month: 6,
138 tz: '+03:00'
139 });
140 });
141
142 it('is able to generate the relevant keys using the given time', function() {
143 expect(
144 context(
145 CONFIGURATION_1,
146 new Time('2016-06-09T18:28:49.000Z', '-05:00')
147 )
148 ).to.be.deep.equal({
149 blind: undefined,
150 day: 3,
151 time: 13.480277777777777,
152 date: 9,
153 month: 6,
154 tz: '-05:00'
155 });
156 });
157});