<commit_before>/*global jasmine, describe, it, expect, spyOn, mostRecentAjaxRequest */
define(['real/Controller', 'jquery', 'nbd/Class', 'nbd/View', 'nbd/trait/jquery.tmpl'], function(Controller, $, Class, View, jqtmpl) {
  'use strict';

  describe('Controller', function() {

    it('is a class constructor', function() {
      expect( Controller ).toEqual(jasmine.any(Function));
      expect( Controller.inherits(Class) ).toBe(true);
    });

    xdescribe('Controller.addTemplate', function() {
      var tmpl = Controller.addTemplate( 'test-template', "Hello world" );

      it('adds the test-template', function() {
        expect( tmpl.html() ).toEqual('Hello world');
      });

      it('adds template with the given id', function() {
        expect( $('#test-template')[0] ).toBe( tmpl[0] );
      });

    });

    xdescribe('Controller.loadTemplate', function() {
      var tmpl = 'load-test-template',
      spies = { template:function(){} },
      now = Date.now(),
      templateResponse = {
        status : 200,
        responseText : JSON.stringify({ html : now })
      },
      promise;
      View = View.extend({},{ TEMPLATE_ID : tmpl }).mixin(jqtmpl);

      it('can load templates', function() {
        expect(function() {
          Controller.loadTemplate( View );
        }).toThrow("No template found");

        jasmine.Ajax.useMock();
        spyOn( spies, 'template' );
        View.TEMPLATE_URL = "xxx";

        promise = Controller.loadTemplate( View, spies.template )
        .done(function() {
          expect( spies.template ).toHaveBeenCalledWith(tmpl);
          expect( View.prototype.templateScript(false) ).not.toBe(false);
          expect( +View.prototype.templateScript(false).html() ).toEqual(now);
        });

        expect( promise.promise ).toBeDefined();

        mostRecentAjaxRequest().response( templateResponse );
      });
    });

  });

  return Controller;
});
<commit_msg>Controller: additional tests<commit_after>/*global jasmine, describe, it, expect, spyOn, mostRecentAjaxRequest */
define(['real/Controller', 'jquery', 'nbd/Class', 'nbd/View', 'nbd/trait/jquery.tmpl'], function(Controller, $, Class, View, jqtmpl) {
  'use strict';

  describe('Controller', function() {
    var inst;

    beforeEach(function() {
      inst = new Controller();
    });

    it('is a class constructor', function() {
      expect( Controller ).toEqual(jasmine.any(Function));
      expect( Controller.inherits(Class) ).toBe(true);
      expect( inst ).toEqual(jasmine.any(Controller));
    });

    describe('.destroy()', function() {

      it('is a function', function() {
        expect( inst.destroy ).toEqual(jasmine.any(Function));
        expect(function() {
          inst.destroy();
        }).not.toThrow();
      });

    });

    describe('._initView()', function() {
      var Klass = function() {};

      beforeEach(function() {
        inst._initView(Klass);
      });

      it('creates ._view', function() {
        expect(inst._view).toEqual(jasmine.any(Klass));
      });

      it('attaches the controller to the ._view', function() {
        expect(inst._view._controller).toBe(inst);
      });
    });

    describe('.switchView()', function() {
      var Klass = function() {};

      it('creates ._view if nonexistant', function() {
        inst.switchView(Klass);
        expect(inst._view).toEqual(jasmine.any(Klass));
      });

      it('replaces ._view if existing', function() {
        Klass.prototype.$view = 'Klass $view';
        Klass.prototype.destroy = jasmine.createSpy('view destroy');
        inst.switchView(Klass);

        var View = function() {};
        View.prototype.render = jasmine.createSpy('view render');
        inst.switchView(View);

        expect(inst._view).toEqual(jasmine.any(View));
        expect(inst._view.render).toHaveBeenCalled();
        expect(inst._view.$view).toBe(Klass.prototype.$view);
        expect(Klass.prototype.destroy).toHaveBeenCalled();
      });
    });

  });

  return Controller;
});

{'fraction_non_alphanumeric': 0.1694831013916501, 'fraction_numerical': 0.001242544731610338, 'mean_word_length': 2.8479923518164436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '889645', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1165, 'n_words': 227}