/* globals describe, it, expect */
var Rx = require('../../dist/cjs/Rx');
var Observable = Rx.Observable;

describe('Observable.prototype.windowWhen', function () {
  it('should emit windows that close and reopen', function (done) {
    var expected = [
      [0, 1, 2],
      [3, 4, 5],
      [6, 7, 8]
    ];
    Observable.interval(100)
      .windowWhen(function () { return Observable.timer(320); })
      .take(3)
      .mergeMap(function (x) { return x.toArray(); })
      .subscribe(function (w) {
        expect(w).toEqual(expected.shift());
      }, null, done);
  }, 2000);
});
@@ -67,12 +67,24 @@
 s/Rx
+.KitchenSink
 ');%0A
-
 var 
@@ -230,20 +230,16 @@
 nction (
-done
 ) %7B%0A    
@@ -247,246 +247,889 @@
 ar e
-xpected = %5B%0A      %5B0, 1, 2%5D,%0A      %5B3, 4, 5%5D,%0A      %5B6, 7, 8%5D%0A    %5D;%0A    Observable.interval(100)%0A      .windowWhen(function () %7B return Observable.timer(320); %7D)%0A      .take(3)%0A      .mergeMap(function (x) %7B return x.toArray(); %7D)
+1 = hot('--a--%5E--b--c--d--e--f--g--h--i--%7C');%0A    var e2 = cold(    '-----------(x%7C)');%0A    //                            -----------(x%7C)%0A    // a              '---b--c--d-%7C');%0A    var a =           '---b--c--d-%7C';%0A    // b                         '-e--f--g--h%7C')%0A    var b =           '------------e--f--g--h%7C';%0A    // c                                    '--i--%7C'%0A    var c =           '------------------------i--%7C';%0A    var expected =    'a----------b----------c----%7C';%0A%0A    var values = %7B%0A      a: Rx.TestScheduler.parseMarbles(a),%0A      b: Rx.TestScheduler.parseMarbles(b),%0A      c: Rx.TestScheduler.parseMarbles(c)%0A    %7D;%0A%0A    var source = e1.windowWhen(function () %7B return e2; %7D)%0A      .map(function (x) %7B%0A        var arr = %5B%5D;%0A%0A        x.materialize().map(function (notification) %7B%0A          return %7B frame: rxTestScheduler.frame, notification: notification %7D;
 %0A      
+  %7D)
 .sub
@@ -1149,89 +1149,126 @@
 on (
-w) %7B%0A        expect(w).toEqual(expected.shift());%0A      %7D, null, done);%0A  %7D, 2000
+value) %7B arr.push(value); %7D);%0A%0A        return arr;%0A      %7D);%0A%0A    expectObservable(source).toBe(expected, values);%0A  %7D
 );%0A%7D

move windowWhen test to marble tests