Пример #1
0
    it('removes listeners when destroyed', function() {
        const model = new Model();
        const mediaModel = model.get('mediaModel');
        const viewModel = new ViewModel(model);
        const instream = {
            model: new Model()
        };
        const instreamMediaModel = instream.model.get('mediaModel');

        const modelSpy = sinon.spy();
        const mediaModelSpy = sinon.spy();
        const instreamChangeModeSpy = sinon.spy();
        const instreamModelSpy = sinon.spy();
        const instreamMediaModelSpy = sinon.spy();
        const viewModelSpy = sinon.spy();

        viewModel.on('test-model', modelSpy);
        viewModel.on('test-media', mediaModelSpy);
        viewModel.on('test-instream-model', instreamModelSpy);
        viewModel.on('test-instream-media-model', instreamMediaModelSpy);
        viewModel.on('test-view-model', viewModelSpy);
        viewModel.on('instreamMode', instreamChangeModeSpy);

        viewModel.destroy();

        model.trigger('test-model');
        mediaModel.trigger('test-media');
        viewModel.trigger('test-view-model');

        // Activate instream mode
        model.set('instream', instream);

        instream.model.trigger('test-instream-model');
        instreamMediaModel.trigger('test-instream-media-model');
        viewModel.trigger('test-view-model');

        assert(modelSpy.notCalled, 'Model listeners removed');
        assert(mediaModelSpy.notCalled, 'Media-model listeners removed');
        assert(instreamChangeModeSpy.notCalled, '"instreamMode" view-model listener removed');
        assert(instreamModelSpy.notCalled, 'Instream-model listeners removed');
        assert(instreamMediaModelSpy.notCalled, 'Instream media-model listeners removed');
        assert(viewModelSpy.notCalled, 'View-model listeners removed');
    });
Пример #2
0
    it('has a player only sub view-model', function() {
        const model = new Model();
        const mediaModel = model.get('mediaModel');
        const instream = {
            model: new Model()
        };
        const instreamMediaModel = instream.model.get('mediaModel');
        const viewModel = new ViewModel(model);
        const playerViewModel = viewModel.player;

        const modelSpy = sinon.spy();
        const mediaModelSpy = sinon.spy();
        const instreamChangeModeSpy = sinon.spy();
        const instreamModelSpy = sinon.spy();
        const instreamMediaModelSpy = sinon.spy();
        const viewModelSpy = sinon.spy();

        playerViewModel.on('change:a', modelSpy);
        playerViewModel.on('change:b', mediaModelSpy);
        playerViewModel.on('change:c', instreamModelSpy);
        playerViewModel.on('change:d', instreamMediaModelSpy);
        playerViewModel.on('viewModelEvent', viewModelSpy);
        playerViewModel.on('instreamMode', instreamChangeModeSpy);

        // Activate media-model in view-model
        model.attributes.mediaModel = null;
        model.setMediaModel(mediaModel);

        model.set('a', 30);
        mediaModel.set('b', 30);

        // Activate instream mode
        model.set('instream', instream);

        instream.model.set('c', 30);
        instreamMediaModel.set('d', 30);

        viewModel.trigger('viewModelEvent');
        
        assert(modelSpy.calledOnce, 'Player-model listeners called');
        assert(mediaModelSpy.calledOnce, 'Player media-model listeners called');

        assert(viewModelSpy.notCalled, 'View-model listeners not called');
        assert(instreamChangeModeSpy.notCalled, '"instreamMode" view-model listener not called');
        assert(instreamModelSpy.notCalled, 'Instream-model listeners not called');
        assert(instreamMediaModelSpy.notCalled, 'Instream media-model listeners not called');
    });