| 1 |
"use strict"; |
| 2 |
|
| 3 |
var tz = require("../../moment-timezone-utils").tz; |
| 4 |
|
| 5 |
// A == B |
| 6 |
// C == D == E |
| 7 |
|
| 8 |
var ZONE_A = { |
| 9 |
name : "Zone/A", |
| 10 |
abbrs : ["ABC", "DEF", "GHI"], |
| 11 |
offsets : [10, 20, 30], |
| 12 |
untils : [-1000, 100, 200] |
| 13 |
}; |
| 14 |
|
| 15 |
var ZONE_B = { |
| 16 |
name : "Zone/B", |
| 17 |
abbrs : ["ABC", "DEF", "GHI"], |
| 18 |
offsets : [10, 20, 30], |
| 19 |
untils : [-1000, 100, 200] |
| 20 |
}; |
| 21 |
|
| 22 |
var ZONE_C = { |
| 23 |
name : "Zone/C", |
| 24 |
abbrs : ["ZYX", "WVU"], |
| 25 |
offsets : [20, 30], |
| 26 |
untils : [-3000, 900] |
| 27 |
}; |
| 28 |
|
| 29 |
var ZONE_D = { |
| 30 |
name : "Zone/D", |
| 31 |
abbrs : ["ZYX", "WVU"], |
| 32 |
offsets : [20, 30], |
| 33 |
untils : [-3000, 900] |
| 34 |
}; |
| 35 |
|
| 36 |
var ZONE_E = { |
| 37 |
name : "Zone/E", |
| 38 |
abbrs : ["ZYX", "WVU"], |
| 39 |
offsets : [20, 30], |
| 40 |
untils : [-3000, 900] |
| 41 |
}; |
| 42 |
|
| 43 |
var ZONES_ABC = { |
| 44 |
zones : [ZONE_A, ZONE_B, ZONE_C], |
| 45 |
links : [], |
| 46 |
version : '2014abc' |
| 47 |
}; |
| 48 |
|
| 49 |
var ZONES_ACD = { |
| 50 |
zones : [ZONE_A, ZONE_C, ZONE_D], |
| 51 |
links : [], |
| 52 |
version : '2014acd' |
| 53 |
}; |
| 54 |
|
| 55 |
var ZONES_ADCB = { |
| 56 |
zones : [ZONE_A, ZONE_D, ZONE_C, ZONE_B], |
| 57 |
links : [], |
| 58 |
version : '2014adcb' |
| 59 |
}; |
| 60 |
|
| 61 |
var ZONES_ABCD = { |
| 62 |
zones : [ZONE_A, ZONE_B, ZONE_C, ZONE_D], |
| 63 |
links : [], |
| 64 |
version : '2014abcd' |
| 65 |
}; |
| 66 |
|
| 67 |
var ZONES_ABCDE = { |
| 68 |
zones : [ZONE_A, ZONE_B, ZONE_C, ZONE_D, ZONE_E], |
| 69 |
links : [], |
| 70 |
version : '2014abcde' |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
exports['create-links'] = { |
| 75 |
abc : function (test) { |
| 76 |
var actual = tz.createLinks(ZONES_ABC), |
| 77 |
expected = { |
| 78 |
zones : [ZONE_A, ZONE_C], |
| 79 |
links : ['Zone/A|Zone/B'], |
| 80 |
version : '2014abc' |
| 81 |
}; |
| 82 |
|
| 83 |
test.deepEqual(actual, expected, "Should be able to create a link between two identical zones."); |
| 84 |
test.done(); |
| 85 |
}, |
| 86 |
|
| 87 |
acd : function (test) { |
| 88 |
var actual = tz.createLinks(ZONES_ACD), |
| 89 |
expected = { |
| 90 |
zones : [ZONE_A, ZONE_C], |
| 91 |
links : ['Zone/C|Zone/D'], |
| 92 |
version : '2014acd' |
| 93 |
}; |
| 94 |
|
| 95 |
test.deepEqual(actual, expected, "Should be able to create a link between two identical zones."); |
| 96 |
test.done(); |
| 97 |
}, |
| 98 |
|
| 99 |
adcb : function (test) { |
| 100 |
var actual = tz.createLinks(ZONES_ADCB), |
| 101 |
expected = { |
| 102 |
zones : [ZONE_A, ZONE_D], |
| 103 |
links : ['Zone/A|Zone/B', 'Zone/D|Zone/C'], |
| 104 |
version : '2014adcb' |
| 105 |
}; |
| 106 |
|
| 107 |
test.deepEqual(actual, expected, "Should be able to create a link between two identical zones."); |
| 108 |
test.done(); |
| 109 |
}, |
| 110 |
|
| 111 |
abcd : function (test) { |
| 112 |
var actual = tz.createLinks(ZONES_ABCD), |
| 113 |
expected = { |
| 114 |
zones : [ZONE_A, ZONE_C], |
| 115 |
links : ['Zone/A|Zone/B', 'Zone/C|Zone/D'], |
| 116 |
version : '2014abcd' |
| 117 |
}; |
| 118 |
|
| 119 |
test.deepEqual(actual, expected, "Should be able to create a link between two identical zones."); |
| 120 |
test.done(); |
| 121 |
}, |
| 122 |
|
| 123 |
abcde : function (test) { |
| 124 |
var actual = tz.createLinks(ZONES_ABCDE), |
| 125 |
expected = { |
| 126 |
zones : [ZONE_A, ZONE_C], |
| 127 |
links : ['Zone/A|Zone/B', 'Zone/C|Zone/D', 'Zone/C|Zone/E'], |
| 128 |
version : '2014abcde' |
| 129 |
}; |
| 130 |
|
| 131 |
test.deepEqual(actual, expected, "Should be able to create a link between two identical zones."); |
| 132 |
test.done(); |
| 133 |
}, |
| 134 |
|
| 135 |
'differing offsets' : function (test) { |
| 136 |
var A = { |
| 137 |
name : "Zone/A", |
| 138 |
abbrs : ["ABC", "DEF", "GHI"], |
| 139 |
offsets : [10, 20, 30], |
| 140 |
untils : [-1000, 100, 200] |
| 141 |
}, |
| 142 |
B = { |
| 143 |
name : "Zone/B", |
| 144 |
abbrs : ["ABC", "DEF", "GHI"], |
| 145 |
offsets : [10, 20, 40], |
| 146 |
untils : [-1000, 100, 200] |
| 147 |
}, |
| 148 |
AB = { |
| 149 |
zones : [A, B], |
| 150 |
links : [], |
| 151 |
version : '2014ab' |
| 152 |
}; |
| 153 |
|
| 154 |
var actual = tz.createLinks(AB), |
| 155 |
expected = { |
| 156 |
zones : [A, B], |
| 157 |
links : [], |
| 158 |
version : '2014ab' |
| 159 |
}; |
| 160 |
|
| 161 |
test.deepEqual(actual, expected, "Should not create a link if the offsets are different."); |
| 162 |
test.done(); |
| 163 |
}, |
| 164 |
|
| 165 |
'differing untils' : function (test) { |
| 166 |
var A = { |
| 167 |
name : "Zone/A", |
| 168 |
abbrs : ["ABC", "DEF", "GHI"], |
| 169 |
offsets : [10, 20, 30], |
| 170 |
untils : [-1000, 100, 200] |
| 171 |
}, |
| 172 |
B = { |
| 173 |
name : "Zone/B", |
| 174 |
abbrs : ["ABC", "DEF", "GHI"], |
| 175 |
offsets : [10, 20, 30], |
| 176 |
untils : [-1000, 100, 300] |
| 177 |
}, |
| 178 |
AB = { |
| 179 |
zones : [A, B], |
| 180 |
links : [], |
| 181 |
version : '2014ab' |
| 182 |
}; |
| 183 |
|
| 184 |
var actual = tz.createLinks(AB), |
| 185 |
expected = { |
| 186 |
zones : [A, B], |
| 187 |
links : [], |
| 188 |
version : '2014ab' |
| 189 |
}; |
| 190 |
|
| 191 |
test.deepEqual(actual, expected, "Should not create a link if the untils are different."); |
| 192 |
test.done(); |
| 193 |
}, |
| 194 |
|
| 195 |
'differing abbrs' : function (test) { |
| 196 |
var A = { |
| 197 |
name : "Zone/A", |
| 198 |
abbrs : ["ABC", "DEF", "GHI"], |
| 199 |
offsets : [10, 20, 30], |
| 200 |
untils : [-1000, 100, 200] |
| 201 |
}, |
| 202 |
B = { |
| 203 |
name : "Zone/B", |
| 204 |
abbrs : ["ABC", "DEF", "XYZ"], |
| 205 |
offsets : [10, 20, 30], |
| 206 |
untils : [-1000, 100, 200] |
| 207 |
}, |
| 208 |
AB = { |
| 209 |
zones : [A, B], |
| 210 |
links : [], |
| 211 |
version : '2014ab' |
| 212 |
}; |
| 213 |
|
| 214 |
var actual = tz.createLinks(AB), |
| 215 |
expected = { |
| 216 |
zones : [A, B], |
| 217 |
links : [], |
| 218 |
version : '2014ab' |
| 219 |
}; |
| 220 |
|
| 221 |
test.deepEqual(actual, expected, "Should not create a link if the abbrs are different."); |
| 222 |
test.done(); |
| 223 |
}, |
| 224 |
|
| 225 |
'differing lengths' : function (test) { |
| 226 |
var A = { |
| 227 |
name : "Zone/A", |
| 228 |
abbrs : ["ABC", "DEF", "GHI"], |
| 229 |
offsets : [10, 20, 30], |
| 230 |
untils : [-1000, 100, 200] |
| 231 |
}, |
| 232 |
B = { |
| 233 |
name : "Zone/B", |
| 234 |
abbrs : ["ABC", "DEF", "GHI", "JKL"], |
| 235 |
offsets : [10, 20, 30, 40], |
| 236 |
untils : [-1000, 100, 200, 300] |
| 237 |
}, |
| 238 |
AB = { |
| 239 |
zones : [A, B], |
| 240 |
links : [], |
| 241 |
version : '2014ab' |
| 242 |
}; |
| 243 |
|
| 244 |
var actual = tz.createLinks(AB), |
| 245 |
expected = { |
| 246 |
zones : [A, B], |
| 247 |
links : [], |
| 248 |
version : '2014ab' |
| 249 |
}; |
| 250 |
|
| 251 |
test.deepEqual(actual, expected, "Should not create a link if the lengths of any of the arrays are different."); |
| 252 |
test.done(); |
| 253 |
}, |
| 254 |
|
| 255 |
'retain existing links' : function (test) { |
| 256 |
var actual = tz.createLinks({ |
| 257 |
zones : [ZONE_A, ZONE_B, ZONE_C], |
| 258 |
links : ["Test/A|Test/B", "Test/A|Test/C"], |
| 259 |
version : '2014abcretain' |
| 260 |
}), |
| 261 |
expected = { |
| 262 |
zones : [ZONE_A, ZONE_C], |
| 263 |
links : ["Test/A|Test/B", "Test/A|Test/C", "Zone/A|Zone/B"], |
| 264 |
version : '2014abcretain' |
| 265 |
}; |
| 266 |
|
| 267 |
test.deepEqual(actual, expected, "Should retain existing links passed in."); |
| 268 |
test.done(); |
| 269 |
}, |
| 270 |
|
| 271 |
'make the zone with the smaller population a link' : function (test) { |
| 272 |
var large = { |
| 273 |
name : "Zone/Large", |
| 274 |
abbrs : ["ABC", "DEF", "GHI"], |
| 275 |
offsets : [10, 20, 30], |
| 276 |
untils : [-1000, 100, 200], |
| 277 |
population : 100 |
| 278 |
}, |
| 279 |
small = { |
| 280 |
name : "Zone/Small", |
| 281 |
abbrs : ["ABC", "DEF", "GHI"], |
| 282 |
offsets : [10, 20, 30], |
| 283 |
untils : [-1000, 100, 200], |
| 284 |
population : 20 |
| 285 |
}, |
| 286 |
largeFirst = { |
| 287 |
zones : [large, small], |
| 288 |
links : [], |
| 289 |
version : '2014populations' |
| 290 |
}, |
| 291 |
smallFirst = { |
| 292 |
zones : [small, large], |
| 293 |
links : [], |
| 294 |
version : '2014populations' |
| 295 |
}, |
| 296 |
expected = { |
| 297 |
zones : [large], |
| 298 |
links : ["Zone/Large|Zone/Small"], |
| 299 |
version : '2014populations' |
| 300 |
}; |
| 301 |
|
| 302 |
test.deepEqual(tz.createLinks(largeFirst), expected, "Make smaller population a link."); |
| 303 |
test.deepEqual(tz.createLinks(smallFirst), expected, "Make smaller population a link."); |
| 304 |
|
| 305 |
test.done(); |
| 306 |
} |
| 307 |
}; |