Example #1
0
QUnit.test('Ember.Application#setupForTesting', function() {
  run(function() {
    App = EmberApplication.create();
    App.setupForTesting();
  });

  equal(App.__container__.lookup('router:main').location, 'none');
});
Example #2
0
    ['@test Destroying a namespace before caching lookup removes it from the list of namespaces'](
      assert
    ) {
      let CF = (lookup.CF = Namespace.create());

      run(CF, 'destroy');
      assert.equal(Namespace.byName('CF'), undefined, 'namespace can not be found after destroyed');
    }
Example #3
0
function setupApp() {
  run(function() {
    App = EmberApplication.create();
    App.setupForTesting();

    App.injectTestHelpers();
  });
}
Example #4
0
QUnit.test('Ember.Application.setupForTesting leaves the system in a deferred state.', function() {
  run(function() {
    App = EmberApplication.create();
    App.setupForTesting();
  });

  equal(App._readinessDeferrals, 1, 'App is in deferred state after setupForTesting.');
});
Example #5
0
QUnit.test('Ember.Application.setupForTesting sets the application to `testing`.', function() {
  run(function() {
    App = EmberApplication.create();
    App.setupForTesting();
  });

  equal(App.testing, true, 'Application instance is set to testing.');
});
Example #6
0
QUnit.test('TransitionAborted errors are not re-thrown', function() {
  expect(1);
  let fakeTransitionAbort = { name: 'TransitionAborted' };

  run(RSVP, 'reject', fakeTransitionAbort);

  ok(true, 'did not throw an error when dealing with TransitionAborted');
});
Example #7
0
QUnit.test('initializers are concatenated', function() {
  let firstInitializerRunCount = 0;
  let secondInitializerRunCount = 0;
  let FirstApp = Application.extend();

  FirstApp.initializer({
    name: 'first',
    initialize(registry) {
      firstInitializerRunCount++;
    }
  });

  let SecondApp = FirstApp.extend();
  SecondApp.initializer({
    name: 'second',
    initialize(registry) {
      secondInitializerRunCount++;
    }
  });

  jQuery('#qunit-fixture').html('<div id="first"></div><div id="second"></div>');
  let firstApp = run(() => {
    return FirstApp.create({
      router: false,
      rootElement: '#qunit-fixture #first'
    });
  });
  equal(firstInitializerRunCount, 1, 'first initializer only was run when base class created');
  equal(secondInitializerRunCount, 0, 'first initializer only was run when base class created');
  firstInitializerRunCount = 0;

  let secondApp = run(() => {
    return SecondApp.create({
      router: false,
      rootElement: '#qunit-fixture #second'
    });
  });

  equal(firstInitializerRunCount, 1, 'first initializer was run when subclass created');
  equal(secondInitializerRunCount, 1, 'second initializers was run when subclass created');
  run(() => {
    firstApp.destroy();
    secondApp.destroy();
  });
});
Example #8
0
    return this.visit('/').then(() => {
      let controller = this.getController('bar');

      this.expectedPushURL = '/foo';
      run(document.getElementById('foo-link'), 'click');

      this.expectedPushURL = '/bar';
      run(document.getElementById('bar-no-qp-link'), 'click');

      this.expectedReplaceURL = '/bar?raytiley=woot';
      this.setAndFlush(controller, 'raytiley', 'woot');

      this.expectedPushURL = '/foo';
      run(document.getElementById('foo-link'), 'click');

      this.expectedPushURL = '/bar?raytiley=isthebest';
      run(document.getElementById('bar-link'), 'click');
    });
Example #9
0
 QUnit.throws(function() {
   run(function() {
     let rejection = RSVP.Promise.reject(reason);
     store.find('user', 1).then(() => {
       rejection.catch(function() { });
       ok(true, 'reached end of test');
     });
   });
 }, reason);
Example #10
0
 QUnit.throws(function() {
   run(function() {
     let rejection = RSVP.Promise.reject(reason);
     ajax('/something/').then(() => {
       rejection.catch(function() {});
       ok(true, 'reached end of test');
     });
   });
 }, reason);
Example #11
0
QUnit.test('The {{link-to}} helper supports `target` attribute', function() {
  setTemplate('index', compile("<h3>Home</h3>{{#link-to 'index' id='self-link' target='_blank'}}Self{{/link-to}}"));
  bootApplication();

  run(() => router.handleURL('/'));

  let link = jQuery('#self-link', '#qunit-fixture');
  equal(link.attr('target'), '_blank', 'The self-link contains `target` attribute');
});
Example #12
0
    ['@test Destroying a namespace after looking up removes it from the list of namespaces'](
      assert
    ) {
      let CF = (lookup.CF = Namespace.create());

      assert.equal(Namespace.byName('CF'), CF, 'precondition - namespace can be looked up by name');

      run(CF, 'destroy');
      assert.equal(Namespace.byName('CF'), undefined, 'namespace can not be found after destroyed');
    }
  ['@test tracks built instances'](assert) {
    let instanceA = this.application.buildInstance();
    let instanceB = this.application.buildInstance();
    run(() => {
      this.application.destroy();
    });

    assert.ok(instanceA.isDestroyed, 'instanceA was destroyed');
    assert.ok(instanceB.isDestroyed, 'instanceB was destroyed');
  }
Example #14
0
    ["@test hooks in ENV.EMBER_LOAD_HOOKS['hookName'] get executed"](assert) {
      // Note that the necessary code to perform this test is run before
      // the Ember lib is loaded in tests/index.html

      run(() => {
        runLoadHooks('__before_ember_test_hook__', 1);
      });

      assert.equal(window.ENV.__test_hook_count__, 1, 'the object was passed into the load hook');
    }
Example #15
0
      return this.boot().then(() => {
        this.$input = document.getElementById('filters-checkbox');

        // click the checkbox once to set filters.shared to false
        run(this.$input, 'click');

        return this.visit('/dashboard').then(() => {
          assert.ok(true, 'expecting navigating to dashboard to succeed');
        });
      });
Example #16
0
  ['@test Ember.Application\'s ready event can be deferred by other components'](assert) {
    run(() => {
      application = Application.create({ router: false });
      application.deferReadiness();
    });

    assert.equal(readyWasCalled, 0, 'ready wasn\'t called yet');

    domReady();

    assert.equal(readyWasCalled, 0, 'ready wasn\'t called yet');

    run(() => {
      application.advanceReadiness();
      assert.equal(readyWasCalled, 0);
    });

    assert.equal(readyWasCalled, 1, 'ready was called now all readiness deferrals are advanced');
  }
QUnit.test('supplied QP properties can be bound', function() {
  let indexController = container.lookup('controller:index');
  setTemplate('index', compile(`{{#link-to (query-params foo=boundThing) id='the-link'}}Index{{/link-to}}`));

  bootApplication();

  equal(jQuery('#the-link').attr('href'), '/?foo=OMG');
  run(indexController, 'set', 'boundThing', 'ASL');
  equal(jQuery('#the-link').attr('href'), '/?foo=ASL');
});
Example #18
0
QUnit.test('The {{link-to}} helper supports URL replacement', function() {
  setTemplate('index', compile(`<h3>Home</h3>{{#link-to 'about' id='about-link' replace=true}}About{{/link-to}}`));

  Router.map(function() {
    this.route('about');
  });

  bootApplication();

  run(() => router.handleURL('/'));

  equal(updateCount, 0, 'precond: setURL has not been called');
  equal(replaceCount, 0, 'precond: replaceURL has not been called');

  run(() => jQuery('#about-link', '#qunit-fixture').click());

  equal(updateCount, 0, 'setURL should not be called');
  equal(replaceCount, 1, 'replaceURL should be called once');
});
Example #19
0
QUnit.test('The non-block form {{link-to}} protects against XSS', function() {
  setTemplate('application', compile("{{link-to display 'index' id='link'}}"));

  App.ApplicationController = Controller.extend({
    display: 'blahzorz'
  });

  bootApplication();

  run(router, 'handleURL', '/');

  let controller = appInstance.lookup('controller:application');

  equal(jQuery('#link', '#qunit-fixture').text(), 'blahzorz');
  run(() => controller.set('display', '<b>BLAMMO</b>'));

  equal(jQuery('#link', '#qunit-fixture').text(), '<b>BLAMMO</b>');
  equal(jQuery('b', '#qunit-fixture').length, 0);
});
Example #20
0
QUnit.test('The {{link-to}} helper moves into the named route', function() {
  Router.map(function(match) {
    this.route('about');
  });

  bootApplication();

  run(() => router.handleURL('/'));

  equal(jQuery('h3:contains(Home)', '#qunit-fixture').length, 1, 'The home template was rendered');
  equal(jQuery('#self-link.active', '#qunit-fixture').length, 1, 'The self-link was rendered with active class');
  equal(jQuery('#about-link:not(.active)', '#qunit-fixture').length, 1, 'The other link was rendered without active class');

  run(() => jQuery('#about-link', '#qunit-fixture').click());

  equal(jQuery('h3:contains(About)', '#qunit-fixture').length, 1, 'The about template was rendered');
  equal(jQuery('#self-link.active', '#qunit-fixture').length, 1, 'The self-link was rendered with active class');
  equal(jQuery('#home-link:not(.active)', '#qunit-fixture').length, 1, 'The other link was rendered without active class');
});
QUnit.test('The ArrayProxy doesn\'t explode when assigned a destroyed object', function() {
  let proxy1 = ArrayProxy.create();
  let proxy2 = ArrayProxy.create();

  run(() => proxy1.destroy());

  set(proxy2, 'content', proxy1);

  ok(true, 'No exception was raised');
});
Example #22
0
QUnit.test('initializers can have multiple dependencies', function () {
  let order = [];
  let a = {
    name: 'a',
    before: 'b',
    initialize(registry) {
      order.push('a');
    }
  };
  let b = {
    name: 'b',
    initialize(registry) {
      order.push('b');
    }
  };
  let c = {
    name: 'c',
    after: 'b',
    initialize(registry) {
      order.push('c');
    }
  };
  let afterB = {
    name: 'after b',
    after: 'b',
    initialize(registry) {
      order.push('after b');
    }
  };
  let afterC = {
    name: 'after c',
    after: 'c',
    initialize(registry) {
      order.push('after c');
    }
  };

  Application.initializer(b);
  Application.initializer(a);
  Application.initializer(afterC);
  Application.initializer(afterB);
  Application.initializer(c);

  run(() => {
    app = Application.create({
      router: false,
      rootElement: '#qunit-fixture'
    });
  });

  ok(order.indexOf(a.name) < order.indexOf(b.name), 'a < b');
  ok(order.indexOf(b.name) < order.indexOf(c.name), 'b < c');
  ok(order.indexOf(b.name) < order.indexOf(afterB.name), 'b < afterB');
  ok(order.indexOf(c.name) < order.indexOf(afterC.name), 'c < afterC');
});
Example #23
0
QUnit.test('Enter child loading state of pivot route', function() {
  expect(4);

  let deferred = RSVP.defer();

  Router.map(function() {
    this.route('grandma', function() {
      this.route('mom', { resetNamespace: true }, function() {
        this.route('sally');
      });
      this.route('smells');
    });
  });

  templates['grandma/loading'] = 'GMONEYLOADING';

  App.ApplicationController = Controller.extend();

  App.MomSallyRoute = Route.extend({
    setupController() {
      step(1, 'SallyRoute#setupController');
    }
  });

  App.GrandmaSmellsRoute = Route.extend({
    model() {
      return deferred.promise;
    }
  });

  bootApplication('/grandma/mom/sally');

  let appController = container.lookup('controller:application');
  equal(appController.get('currentPath'), 'grandma.mom.sally', 'Initial route fully loaded');

  run(router, 'transitionTo', 'grandma.smells');
  equal(appController.get('currentPath'), 'grandma.loading', 'in pivot route\'s child loading state');

  run(deferred, 'resolve', {});

  equal(appController.get('currentPath'), 'grandma.smells', 'Finished transition');
});
Example #24
0
QUnit.test('The {{link-to}} helper moves into the named route with context', function() {
  Router.map(function(match) {
    this.route('about');
    this.route('item', { path: '/item/:id' });
  });

  setTemplate('about', compile("<h3>List</h3><ul>{{#each model as |person|}}<li>{{#link-to 'item' person}}{{person.name}}{{/link-to}}</li>{{/each}}</ul>{{#link-to 'index' id='home-link'}}Home{{/link-to}}"));

  App.AboutRoute = Route.extend({
    model() {
      return emberA([
        { id: 'yehuda', name: 'Yehuda Katz' },
        { id: 'tom', name: 'Tom Dale' },
        { id: 'erik', name: 'Erik Brynroflsson' }
      ]);
    }
  });

  bootApplication();

  run(() => router.handleURL('/about'));

  equal(jQuery('h3:contains(List)', '#qunit-fixture').length, 1, 'The home template was rendered');
  equal(normalizeUrl(jQuery('#home-link').attr('href')), '/', 'The home link points back at /');

  run(() => jQuery('li a:contains(Yehuda)', '#qunit-fixture').click());

  equal(jQuery('h3:contains(Item)', '#qunit-fixture').length, 1, 'The item template was rendered');
  equal(jQuery('p', '#qunit-fixture').text(), 'Yehuda Katz', 'The name is correct');

  run(() => jQuery('#home-link').click());
  run(() => jQuery('#about-link').click());

  equal(normalizeUrl(jQuery('li a:contains(Yehuda)').attr('href')), '/item/yehuda');
  equal(normalizeUrl(jQuery('li a:contains(Tom)').attr('href')), '/item/tom');
  equal(normalizeUrl(jQuery('li a:contains(Erik)').attr('href')), '/item/erik');

  run(() => jQuery('li a:contains(Erik)', '#qunit-fixture').click());

  equal(jQuery('h3:contains(Item)', '#qunit-fixture').length, 1, 'The item template was rendered');
  equal(jQuery('p', '#qunit-fixture').text(), 'Erik Brynroflsson', 'The name is correct');
});
Example #25
0
  QUnit.test('should raise an exception when modifying watched properties on a destroyed object', function(assert) {
    let obj = EmberObject.extend({
      fooDidChange: observer('foo', function() { })
    }).create({
      foo: 'bar'
    });

    run(() => obj.destroy());

    assert.throws(() => set(obj, 'foo', 'baz'), Error, 'raises an exception');
  });
Example #26
0
QUnit.test('should have content when isFulfilled is set', function() {
  let deferred = EmberRSVP.defer();

  let proxy = ObjectPromiseProxy.create({
    promise: deferred.promise
  });

  proxy.addObserver('isFulfilled', () => equal(get(proxy, 'content'), true));

  run(deferred, 'resolve', true);
});
Example #27
0
QUnit.test('do NOT log class generation if logging disabled', function() {
  App.reopen({
    LOG_ACTIVE_GENERATION: false
  });

  run(App, 'advanceReadiness');

  visit('/posts').then(() => {
    equal(Object.keys(logs).length, 0, 'expected no logs');
  });
});
Example #28
0
QUnit.test('do not log which views are used with templates when flag is not true', function() {
  App.reopen({
    LOG_VIEW_LOOKUPS: false
  });

  run(App, 'advanceReadiness');

  visit('/posts').then(() => {
    equal(Object.keys(logs).length, 0, 'expected no logs');
  });
});
  teardown() {
    run(() => {
      if (myEngineInstance) {
        myEngineInstance.destroy();
      }

      if (myEngine) {
        myEngine.destroy();
      }
    });
  }
Example #30
0
  teardown() {
    if (App) {
      run(App, App.destroy);
      App.removeTestHelpers();
      App = null;
    }

    Test.adapter = originalAdapter;
    window.QUnit = originalQUnit;
    window.onerror = originalWindowOnerror;
  }