|
1 |
| -/* globals describe, it, expect, expectObservable, expectSubscriptions, hot, cold */ |
| 1 | +/* globals describe, it, expect, rxTestScheduler, expectObservable, expectSubscriptions, hot, cold */ |
2 | 2 | var Rx = require('../../dist/cjs/Rx');
|
3 | 3 | var Observable = Rx.Observable;
|
4 | 4 |
|
@@ -225,4 +225,150 @@ describe('Observable.prototype.mergeScan()', function () {
|
225 | 225 | expectObservable(source, sub).toBe(expected, values);
|
226 | 226 | expectSubscriptions(e1.subscriptions).toBe(sub);
|
227 | 227 | });
|
| 228 | + |
| 229 | + it('should mergescan projects cold Observable with single concurrency', function () { |
| 230 | + var e1 = hot('--a--b--c--|'); |
| 231 | + var e1subs = '^ !'; |
| 232 | + |
| 233 | + var inner = [ |
| 234 | + cold( '--d--e--f--| '), |
| 235 | + cold( '--g--h--i--| '), |
| 236 | + cold( '--j--k--l--|') |
| 237 | + ]; |
| 238 | + |
| 239 | + var xsubs = ' ^ !'; |
| 240 | + var ysubs = ' ^ !'; |
| 241 | + var zsubs = ' ^ !'; |
| 242 | + |
| 243 | + var expected = '--x-d--e--f--f-g--h--i--i-j--k--l--|'; |
| 244 | + |
| 245 | + var index = 0; |
| 246 | + var source = e1.mergeScan(function (acc, x) { |
| 247 | + var value = inner[index++]; |
| 248 | + return value.startWith(acc); |
| 249 | + }, 'x', 1); |
| 250 | + |
| 251 | + expectObservable(source).toBe(expected); |
| 252 | + |
| 253 | + expectSubscriptions(e1.subscriptions).toBe(e1subs); |
| 254 | + expectSubscriptions(inner[0].subscriptions).toBe(xsubs); |
| 255 | + expectSubscriptions(inner[1].subscriptions).toBe(ysubs); |
| 256 | + expectSubscriptions(inner[2].subscriptions).toBe(zsubs); |
| 257 | + }); |
| 258 | + |
| 259 | + it('should emit accumulator if inner completes without value', function () { |
| 260 | + var e1 = hot('--a--^--b--c--d--e--f--g--|'); |
| 261 | + var e1subs = '^ !'; |
| 262 | + var expected = '---------------------(x|)'; |
| 263 | + |
| 264 | + var source = e1.mergeScan(function (acc, x) { |
| 265 | + return Observable.empty(); |
| 266 | + }, ['1']); |
| 267 | + |
| 268 | + expectObservable(source).toBe(expected, {x: ['1']}); |
| 269 | + expectSubscriptions(e1.subscriptions).toBe(e1subs); |
| 270 | + }); |
| 271 | + |
| 272 | + it('should emit accumulator if inner completes without value after source completes', function () { |
| 273 | + var e1 = hot('--a--^--b--c--d--e--f--g--|'); |
| 274 | + var e1subs = '^ !'; |
| 275 | + var expected = '-----------------------(x|)'; |
| 276 | + |
| 277 | + var source = e1.mergeScan(function (acc, x) { |
| 278 | + return Observable.empty().delay(50, rxTestScheduler); |
| 279 | + }, ['1']); |
| 280 | + |
| 281 | + expectObservable(source).toBe(expected, {x: ['1']}); |
| 282 | + expectSubscriptions(e1.subscriptions).toBe(e1subs); |
| 283 | + }); |
| 284 | + |
| 285 | + it('should mergescan projects hot Observable with single concurrency', function () { |
| 286 | + var e1 = hot('---a---b---c---|'); |
| 287 | + var e1subs = '^ !'; |
| 288 | + |
| 289 | + var inner = [ |
| 290 | + hot( '--d--e--f--|'), |
| 291 | + hot( '----g----h----i----|'), |
| 292 | + hot( '------j------k-------l------|') |
| 293 | + ]; |
| 294 | + |
| 295 | + var xsubs = ' ^ !'; |
| 296 | + var ysubs = ' ^ !'; |
| 297 | + var zsubs = ' ^ !'; |
| 298 | + |
| 299 | + var expected = '---x-e--f--f--i----i-l------|'; |
| 300 | + |
| 301 | + var index = 0; |
| 302 | + var source = e1.mergeScan(function (acc, x) { |
| 303 | + var value = inner[index++]; |
| 304 | + return value.startWith(acc); |
| 305 | + }, 'x', 1); |
| 306 | + |
| 307 | + expectObservable(source).toBe(expected); |
| 308 | + |
| 309 | + expectSubscriptions(e1.subscriptions).toBe(e1subs); |
| 310 | + expectSubscriptions(inner[0].subscriptions).toBe(xsubs); |
| 311 | + expectSubscriptions(inner[1].subscriptions).toBe(ysubs); |
| 312 | + expectSubscriptions(inner[2].subscriptions).toBe(zsubs); |
| 313 | + }); |
| 314 | + |
| 315 | + it('should mergescan projects cold Observable with dual concurrency', function () { |
| 316 | + var e1 = hot('----a----b----c----|'); |
| 317 | + var e1subs = '^ !'; |
| 318 | + |
| 319 | + var inner = [ |
| 320 | + cold( '---d---e---f---| '), |
| 321 | + cold( '---g---h---i---| '), |
| 322 | + cold( '---j---k---l---|') |
| 323 | + ]; |
| 324 | + |
| 325 | + var xsubs = ' ^ !'; |
| 326 | + var ysubs = ' ^ !'; |
| 327 | + var zsubs = ' ^ !'; |
| 328 | + |
| 329 | + var expected = '----x--d-d-eg--fh--hi-j---k---l---|'; |
| 330 | + |
| 331 | + var index = 0; |
| 332 | + var source = e1.mergeScan(function (acc, x) { |
| 333 | + var value = inner[index++]; |
| 334 | + return value.startWith(acc); |
| 335 | + }, 'x', 2); |
| 336 | + |
| 337 | + expectObservable(source).toBe(expected); |
| 338 | + |
| 339 | + expectSubscriptions(e1.subscriptions).toBe(e1subs); |
| 340 | + expectSubscriptions(inner[0].subscriptions).toBe(xsubs); |
| 341 | + expectSubscriptions(inner[1].subscriptions).toBe(ysubs); |
| 342 | + expectSubscriptions(inner[2].subscriptions).toBe(zsubs); |
| 343 | + }); |
| 344 | + |
| 345 | + it('should mergescan projects hot Observable with dual concurrency', function () { |
| 346 | + var e1 = hot('---a---b---c---|'); |
| 347 | + var e1subs = '^ !'; |
| 348 | + |
| 349 | + var inner = [ |
| 350 | + hot( '--d--e--f--|'), |
| 351 | + hot( '----g----h----i----|'), |
| 352 | + hot( '------j------k-------l------|') |
| 353 | + ]; |
| 354 | + |
| 355 | + var xsubs = ' ^ !'; |
| 356 | + var ysubs = ' ^ !'; |
| 357 | + var zsubs = ' ^ !'; |
| 358 | + |
| 359 | + var expected = '---x-e-efh-h-ki------l------|'; |
| 360 | + |
| 361 | + var index = 0; |
| 362 | + var source = e1.mergeScan(function (acc, x) { |
| 363 | + var value = inner[index++]; |
| 364 | + return value.startWith(acc); |
| 365 | + }, 'x', 2); |
| 366 | + |
| 367 | + expectObservable(source).toBe(expected); |
| 368 | + |
| 369 | + expectSubscriptions(e1.subscriptions).toBe(e1subs); |
| 370 | + expectSubscriptions(inner[0].subscriptions).toBe(xsubs); |
| 371 | + expectSubscriptions(inner[1].subscriptions).toBe(ysubs); |
| 372 | + expectSubscriptions(inner[2].subscriptions).toBe(zsubs); |
| 373 | + }); |
228 | 374 | });
|
0 commit comments