/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


var App = require('app');
require('views/common/modal_popups/invalid_KDC_popup');

describe('App.showInvalidKDCPopup', function () {
  var view,
    ajaxOpt = {
        kdcCancelHandler: sinon.spy()
      };
  
  describe('#onClose', function () {
    
    beforeEach(function () {
      view = App.showInvalidKDCPopup(ajaxOpt);
      sinon.stub(view, 'hide');
    });
    
    afterEach(function() {
      view.hide.restore();
    });
  
    it('kdcCancelHandler should be called', function () {
      view.onClose();
      expect(ajaxOpt.kdcCancelHandler.calledOnce).to.be.true;
    });
    
    it('hide should be called', function () {
      view.onClose();
      expect(view.hide.calledOnce).to.be.true;
    });
  });
  
  describe('#onSecondary', function () {
    
    beforeEach(function () {
      view = App.showInvalidKDCPopup(ajaxOpt);
      sinon.stub(view, 'onClose');
    });
    
    afterEach(function() {
      view.onClose.restore();
    });
    
    it('onClose should be called', function () {
      view.onSecondary();
      expect(view.onClose.calledOnce).to.be.true;
    });
  });
  
  describe('#onSecondary', function () {
    
    beforeEach(function () {
      view = App.showInvalidKDCPopup(ajaxOpt);
      sinon.stub(view, 'onClose');
    });
    
    afterEach(function() {
      view.onClose.restore();
    });
    
    it('onClose should be called', function () {
      view.onSecondary();
      expect(view.onClose.calledOnce).to.be.true;
    });
  });
  
  describe('#onPrimary', function () {
    var mock = {
      createKerberosAdminSession: sinon.spy()
    };
    
    beforeEach(function () {
      view = App.showInvalidKDCPopup(ajaxOpt);
      sinon.stub(App, 'get').returns(mock);
    });
    
    afterEach(function() {
      App.get.restore();
    });
    
    it('createKerberosAdminSession should be called', function () {
      view.onPrimary();
      expect(mock.createKerberosAdminSession.calledOnce).to.be.true;
    });
  });
});
