﻿'use strict';

describe('The translate events test suite', function() {
    var $events, callback;

    beforeEach(function() {
        module('mutant-ng-translate');

        inject(function ($translateEvents) {
            $events = $translateEvents;
        });

        callback = jasmine.createSpy('callback');
    });

    describe('>> Common tests', function () {
        it('should be defined', function () {
            expect($events).toBeDefined();
        });

        it('should be an object', function () {
            expect(typeof $events).toBe('object');
        });
    });

    describe('>> Subscribe exceptions tests', function() {
        it('should throw an exception if called without params', function () {
            expect($events.partLoaded.subscribe)
                .toThrowError(/callback must be defined to subscribe for an event/);
        });

        it('should throw an exception if callback is not a function', function () {
            expect(function () { $events.partLoaded.subscribe('callback'); })
                .toThrowError(/callback must be a function to subscribe for an event/);
        });
    });

    describe('>> Subscribe tests', function() {
        it('should call registered callback', function () {
            $events.partLoaded.subscribe(callback);
            $events.partLoaded.publish();

            expect(callback.calls.count()).toBe(1);
        });

        it('should call all registered callbacks', function () {
            $events.partLoaded.subscribe(callback);
            $events.partLoaded.subscribe(callback);
            $events.partLoaded.publish();

            expect(callback.calls.count()).toBe(2);
        });

        it('should not call callback if unsibscribed', function () {
            $events.partLoaded.subscribe(callback);
            $events.partLoaded.subscribe(callback).unsubscribe();
            $events.partLoaded.publish();

            expect(callback.calls.count()).toBe(1);
        });

        it('should call callback one time if disposable', function () {
            $events.partLoaded.subscribe(callback, true);
            $events.partLoaded.publish();
            $events.partLoaded.publish();

            expect(callback.calls.count()).toBe(1);
        });
    });
});
@@ -2253,28 +2253,742 @@
 (1);%0A        %7D);
+%0A%0A        it('should remove correct subscriber from list', function() %7B%0A            var callback2 = jasmine.createSpy('callback2');%0A            var callback3 = jasmine.createSpy('callback3');%0A%0A            var token1 = $events.partLoaded.subscribe(callback);%0A            var token2 = $events.partLoaded.subscribe(callback2);%0A            var token3 = $events.partLoaded.subscribe(callback3);%0A%0A            token2.unsubscribe();%0A            $events.partLoaded.publish();%0A%0A            token1.unsubscribe();%0A            $events.partLoaded.publish();%0A%0A            expect(callback.calls.count()).toBe(1);%0A            expect(callback2.calls.count()).toBe(0);%0A            expect(callback3.calls.count()).toBe(2);%0A        %7D);
 %0A    %7D);%0A%7D);

update translate events test suite