Beispiel #1
0
        var continueTest = _.after(2, () => { originalSetTimeout(() => {
            this.mockHistogram.off('complete', continueTest);
            expect(onResolveOne.called).toBe(true);
            expect(onResolveTwo.called).toBe(true);
            expectSparklinesOn(['_a', '_b']);

            // For the next set timeout, change the mock data and verify that next request
            // contains the correct data
            this.mockHistogram.update({
                '/first': [{
                    path: '/a',
                    series: [{ name: 'pageview', data: [{count: 500}]}],
                    totalHits: 500
                }],
                '/second': [{
                    path: '/b',
                    series: [{ name: 'pageview', data: [{count: 12345}]}],
                    totalHits: 12345
                }]
            });
            var afterInterval = _.after(2, () => { originalSetTimeout(() => {
                this.mockHistogram.off('complete', afterInterval);
                expect(sparklinesTitle('_a')).toBe('500');
                expect(sparklinesTitle('_b')).toBe('12,345');

                finishTest();
            }, 10); });
            this.mockHistogram.on('complete', afterInterval);

            tick(3000);
            tick(100);
        }, 10); });
Beispiel #2
0
    it('refreshes when the collection changes', function (done) {
        vars.CONST.sparksRefreshMs = 2000;
        jasmine.clock().install();

        var front = mockFrontWidget('first', {
                one: [{ article: '/a' }]
            }),
            container = inject(front),
            finishTest = function () {
                sparklines.unsubscribe(front);
                container.remove();
                jasmine.clock().uninstall();
                done();
            };
        sparklines.subscribe(front);
        front._resolveCollection('one');

        whenComplete(this.mockHistogram, () => {
            expectSparklinesOn(['_a']);
            expect(sparklinesTitle('_a')).toBe('100');

            // Change the data, however note that articles already displayed shouldn't refresh
            this.mockHistogram.update({
                '/first': [{
                    path: '/a',
                    series: [{ name: 'pageview', data: [{count: 77}]}],
                    totalHits: 77
                }, {
                    path: '/b',
                    series: [{ name: 'pageview', data: [{count: 200}]}],
                    totalHits: 200
                }]
            });

            // Inject a new article in the front (either dragging or collection update)
            front._addArticle('one', { article: '/b' });
            // Adding an article makes a new request for the added articles
            tick(100)
            .then(() => {
                expectSparklinesOn(['_a', '_b']);
                // Note that the old article doesn't change
                expect(sparklinesTitle('_a')).toBe('100');
                expect(sparklinesTitle('_b')).toBe('200');

                // wait a set interval and check that A is refreshed correctly
                return tick(2000).then(() => tick(100));
            })
            .then(() => {
                expectSparklinesOn(['_a', '_b']);
                expect(sparklinesTitle('_a')).toBe('77');
                expect(sparklinesTitle('_b')).toBe('200');

                finishTest();
            });
        });

        // Advance time to get the mocked response
        tick(100).then(() => tick(100)).then(() => tick(100));
    });
Beispiel #3
0
            .then(() => {
                expectSparklinesOn(['_a', '_b']);
                // Note that the old article doesn't change
                expect(sparklinesTitle('_a')).toBe('100');
                expect(sparklinesTitle('_b')).toBe('200');

                // wait a set interval and check that A is refreshed correctly
                return tick(2000).then(() => tick(100));
            })
Beispiel #4
0
        whenComplete(this.mockHistogram, () => {
            expectSparklinesOn(['_a']);
            expect(sparklinesTitle('_a')).toBe('100');

            // Change the data, however note that articles already displayed shouldn't refresh
            this.mockHistogram.update({
                '/first': [{
                    path: '/a',
                    series: [{ name: 'pageview', data: [{count: 77}]}],
                    totalHits: 77
                }, {
                    path: '/b',
                    series: [{ name: 'pageview', data: [{count: 200}]}],
                    totalHits: 200
                }]
            });

            // Inject a new article in the front (either dragging or collection update)
            front._addArticle('one', { article: '/b' });
            // Adding an article makes a new request for the added articles
            tick(100)
            .then(() => {
                expectSparklinesOn(['_a', '_b']);
                // Note that the old article doesn't change
                expect(sparklinesTitle('_a')).toBe('100');
                expect(sparklinesTitle('_b')).toBe('200');

                // wait a set interval and check that A is refreshed correctly
                return tick(2000).then(() => tick(100));
            })
            .then(() => {
                expectSparklinesOn(['_a', '_b']);
                expect(sparklinesTitle('_a')).toBe('77');
                expect(sparklinesTitle('_b')).toBe('200');

                finishTest();
            });
        });
Beispiel #5
0
tick(100).then(() => tick(100)).then(() => tick(100));
Beispiel #6
0
 return tick(2000).then(() => tick(100));
Beispiel #7
0
    it('loads sparklines on multiple fronts and polls', function (done) {
        vars.CONST.sparksRefreshMs = 2000;
        jasmine.clock().install();

        var frontOne = mockFrontWidget('first', {
                one: [{ article: '/a' }]
            }),
            frontTwo = mockFrontWidget('second', {
                two: [{ article: '/b' }]
            }),
            onResolveOne = sinon.spy(),
            onResolveTwo = sinon.spy(),
            containerOne = inject(frontOne),
            containerTwo = inject(frontTwo),
            finishTest = function () {
                sparklines.unsubscribe(frontOne);
                sparklines.unsubscribe(frontTwo);
                containerOne.remove();
                containerTwo.remove();
                jasmine.clock().uninstall();
                done();
            };
        sparklines.subscribe(frontOne);
        sparklines.subscribe(frontTwo);
        frontOne.sparklines.promise.then(onResolveOne);
        frontOne._resolveCollection('one');
        frontTwo.sparklines.promise.then(onResolveTwo);
        frontTwo._resolveCollection('two');

        var continueTest = _.after(2, () => { originalSetTimeout(() => {
            this.mockHistogram.off('complete', continueTest);
            expect(onResolveOne.called).toBe(true);
            expect(onResolveTwo.called).toBe(true);
            expectSparklinesOn(['_a', '_b']);

            // For the next set timeout, change the mock data and verify that next request
            // contains the correct data
            this.mockHistogram.update({
                '/first': [{
                    path: '/a',
                    series: [{ name: 'pageview', data: [{count: 500}]}],
                    totalHits: 500
                }],
                '/second': [{
                    path: '/b',
                    series: [{ name: 'pageview', data: [{count: 12345}]}],
                    totalHits: 12345
                }]
            });
            var afterInterval = _.after(2, () => { originalSetTimeout(() => {
                this.mockHistogram.off('complete', afterInterval);
                expect(sparklinesTitle('_a')).toBe('500');
                expect(sparklinesTitle('_b')).toBe('12,345');

                finishTest();
            }, 10); });
            this.mockHistogram.on('complete', afterInterval);

            tick(3000);
            tick(100);
        }, 10); });
        this.mockHistogram.on('complete', continueTest);

        // Advance time to get the mocked response
        tick(100).then(() => tick(100)).then(() => tick(100));
    });