Example #1
0
QUnit.test('Block-less {{link-to}} with only query-params updates when route changes', function() {
  Router.map(function() {
    this.route('about');
  });

  if (isEnabled('ember-routing-route-configured-query-params')) {
    App.ApplicationRoute = Ember.Route.extend({
      queryParams: {
        foo: {
          defaultValue: '123'
        },
        bar: {
          defaultValue: 'yes'
        }
      }
    });
  } else {
    App.ApplicationController = Ember.Controller.extend({
      queryParams: ['foo', 'bar'],
      foo: '123',
      bar: 'yes'
    });
  }

  Ember.TEMPLATES.application = compile('{{link-to "Index" (query-params foo=\'456\' bar=\'NAW\') id=\'the-link\'}}');
  bootApplication();
  equal(Ember.$('#the-link').attr('href'), '/?bar=NAW&foo=456', 'link has right href');

  Ember.run(function() {
    router.handleURL('/about');
  });
  equal(Ember.$('#the-link').attr('href'), '/about?bar=NAW&foo=456', 'link has right href');
});
Example #2
0
QUnit.test('ApplicationRoute#currentPath reflects loading state path', function() {
  expect(4);

  var momDeferred = Ember.RSVP.defer();

  Router.map(function() {
    this.route('grandma', function() {
      this.route('mom');
    });
  });

  templates.grandma = 'GRANDMA {{outlet}}';
  templates['grandma/loading'] = 'GRANDMALOADING';
  templates['grandma/mom'] = 'MOM';

  App.GrandmaMomRoute = Ember.Route.extend({
    model() {
      return momDeferred.promise;
    }
  });

  bootApplication('/grandma/mom');

  equal(Ember.$('#app', '#qunit-fixture').text(), 'GRANDMA GRANDMALOADING');

  var appController = container.lookup('controller:application');
  equal(appController.get('currentPath'), 'grandma.loading', 'currentPath reflects loading state');

  Ember.run(momDeferred, 'resolve', {});
  equal(Ember.$('#app', '#qunit-fixture').text(), 'GRANDMA MOM');
  equal(appController.get('currentPath'), 'grandma.mom', 'currentPath reflects final state');
});
Example #3
0
  QUnit.test('Prioritized loading substate entry works with preserved-namespace nested routes', function() {
    expect(2);

    templates['foo/bar_loading'] = 'FOOBAR LOADING';
    templates['foo/bar'] = 'YAY';

    Router.map(function() {
      this.route('foo', function() {
        this.route('bar');
      });
    });

    App.ApplicationController = Ember.Controller.extend();

    var deferred = Ember.RSVP.defer();
    App.FooBarRoute = Ember.Route.extend({
      model() {
        return deferred.promise;
      }
    });

    bootApplication('/foo/bar');

    equal(Ember.$('#app', '#qunit-fixture').text(), 'FOOBAR LOADING', 'foo.bar_loading was entered (as opposed to something like foo/foo/bar_loading)');

    Ember.run(deferred, 'resolve');

    equal(Ember.$('#app', '#qunit-fixture').text(), 'YAY');
  });
Example #4
0
QUnit.test('Slow promise from a child route of application enters nested loading state', function() {
  var broModel = {};
  var broDeferred = Ember.RSVP.defer();

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

  App.ApplicationRoute = Ember.Route.extend({
    setupController() {
      step(2, 'ApplicationRoute#setup');
    }
  });

  App.BroRoute = Ember.Route.extend({
    model() {
      step(1, 'BroRoute#model');
      return broDeferred.promise;
    }
  });

  bootApplication('/bro');

  equal(Ember.$('#app', '#qunit-fixture').text(), 'LOADING', 'The Loading template is nested in application template\'s outlet');

  Ember.run(broDeferred, 'resolve', broModel);

  equal(Ember.$('#app', '#qunit-fixture').text(), 'BRO', 'bro template has loaded and replaced loading template');
});
Example #5
0
QUnit.test('The {{link-to}} helper accepts string/numeric arguments', function() {
  Router.map(function() {
    this.route('filter', { path: '/filters/:filter' });
    this.route('post', { path: '/post/:post_id' });
    this.route('repo', { path: '/repo/:owner/:name' });
  });

  App.FilterController = Ember.Controller.extend({
    filter: 'unpopular',
    repo: Ember.Object.create({ owner: 'ember', name: 'ember.js' }),
    post_id: 123
  });
  Ember.TEMPLATES.filter = compile('<p>{{filter}}</p>{{#link-to "filter" "unpopular" id="link"}}Unpopular{{/link-to}}{{#link-to "filter" filter id="path-link"}}Unpopular{{/link-to}}{{#link-to "post" post_id id="post-path-link"}}Post{{/link-to}}{{#link-to "post" 123 id="post-number-link"}}Post{{/link-to}}{{#link-to "repo" repo id="repo-object-link"}}Repo{{/link-to}}');

  Ember.TEMPLATES.index = compile(' ');

  bootApplication();

  Ember.run(function() { router.handleURL('/filters/popular'); });

  equal(normalizeUrl(Ember.$('#link', '#qunit-fixture').attr('href')), '/filters/unpopular');
  equal(normalizeUrl(Ember.$('#path-link', '#qunit-fixture').attr('href')), '/filters/unpopular');
  equal(normalizeUrl(Ember.$('#post-path-link', '#qunit-fixture').attr('href')), '/post/123');
  equal(normalizeUrl(Ember.$('#post-number-link', '#qunit-fixture').attr('href')), '/post/123');
  equal(normalizeUrl(Ember.$('#repo-object-link', '#qunit-fixture').attr('href')), '/repo/ember/ember.js');
});
Example #6
0
  QUnit.test('Rejected promises returned from ApplicationRoute transition into top-level application_error', function() {
    expect(3);

    templates['application_error'] = '<p id="toplevel-error">TOPLEVEL ERROR: {{model.msg}}</p>';

    var reject = true;
    App.ApplicationRoute = Ember.Route.extend({
      model() {
        if (reject) {
          return Ember.RSVP.reject({ msg: 'BAD NEWS BEARS' });
        } else {
          return {};
        }
      }
    });

    throws(function() {
      bootApplication();
    }, function(err) { return err.msg === 'BAD NEWS BEARS'; });

    equal(Ember.$('#toplevel-error', '#qunit-fixture').text(), 'TOPLEVEL ERROR: BAD NEWS BEARS');

    reject = false;
    Ember.run(router, 'transitionTo', 'index');

    equal(Ember.$('#app', '#qunit-fixture').text(), 'INDEX');
  });
Example #7
0
QUnit.test('The {{link-to}} helper refreshes href element when one of params changes', function() {
  Router.map(function() {
    this.route('post', { path: '/posts/:post_id' });
  });

  var post = Ember.Object.create({ id: '1' });
  var secondPost = Ember.Object.create({ id: '2' });

  Ember.TEMPLATES.index = compile('{{#link-to "post" post id="post"}}post{{/link-to}}');

  App.IndexController = Ember.Controller.extend();
  var indexController = container.lookup('controller:index');

  Ember.run(function() { indexController.set('post', post); });

  bootApplication();

  Ember.run(function() { router.handleURL('/'); });

  equal(normalizeUrl(Ember.$('#post', '#qunit-fixture').attr('href')), '/posts/1', 'precond - Link has rendered href attr properly');

  Ember.run(function() { indexController.set('post', secondPost); });

  equal(Ember.$('#post', '#qunit-fixture').attr('href'), '/posts/2', 'href attr was updated after one of the params had been changed');

  Ember.run(function() { indexController.set('post', null); });

  equal(Ember.$('#post', '#qunit-fixture').attr('href'), '#', 'href attr becomes # when one of the arguments in nullified');
});
Example #8
0
  QUnit.test('Prioritized loading substate entry works with auto-generated index routes', function() {
    expect(2);

    templates['foo/index_loading'] = 'FOO LOADING';
    templates['foo/index'] = 'YAY';
    templates['foo'] = '{{outlet}}';

    Router.map(function() {
      this.route('foo', function() {
        this.route('bar');
      });
    });

    App.ApplicationController = Ember.Controller.extend();

    var deferred = Ember.RSVP.defer();
    App.FooIndexRoute = Ember.Route.extend({
      model() {
        return deferred.promise;
      }
    });
    App.FooRoute = Ember.Route.extend({
      model() {
        return true;
      }
    });

    bootApplication('/foo');

    equal(Ember.$('#app', '#qunit-fixture').text(), 'FOO LOADING', 'foo.index_loading was entered');

    Ember.run(deferred, 'resolve');

    equal(Ember.$('#app', '#qunit-fixture').text(), 'YAY');
  });
Example #9
0
QUnit.test('The {{link-to}} helper supports multiple current-when routes', function() {
  Router.map(function(match) {
    this.route('index', { path: '/' }, function() {
      this.route('about');
    });
    this.route('item');
    this.route('foo');
  });

  Ember.TEMPLATES.index = compile('<h3>Home</h3>{{outlet}}');
  Ember.TEMPLATES['index/about'] = compile('{{#link-to \'item\' id=\'link1\' current-when=\'item index\'}}ITEM{{/link-to}}');
  Ember.TEMPLATES['item'] = compile('{{#link-to \'item\' id=\'link2\' current-when=\'item index\'}}ITEM{{/link-to}}');
  Ember.TEMPLATES['foo'] = compile('{{#link-to \'item\' id=\'link3\' current-when=\'item index\'}}ITEM{{/link-to}}');

  bootApplication();

  Ember.run(function() {
    router.handleURL('/about');
  });

  equal(Ember.$('#link1.active', '#qunit-fixture').length, 1, 'The link is active since current-when contains the parent route');

  Ember.run(function() {
    router.handleURL('/item');
  });

  equal(Ember.$('#link2.active', '#qunit-fixture').length, 1, 'The link is active since you are on the active route');

  Ember.run(function() {
    router.handleURL('/foo');
  });

  equal(Ember.$('#link3.active', '#qunit-fixture').length, 0, 'The link is not active since current-when does not contain the active route');
});
Example #10
0
  QUnit.test('Slow promises returned from ApplicationRoute#model enter application_loading if template present', function() {
    expect(3);

    templates['application_loading'] = 'TOPLEVEL LOADING';

    var appDeferred = Ember.RSVP.defer();
    App.ApplicationRoute = Ember.Route.extend({
      model() {
        return appDeferred.promise;
      }
    });

    var loadingRouteEntered = false;
    App.ApplicationLoadingRoute = Ember.Route.extend({
      setupController() {
        loadingRouteEntered = true;
      }
    });

    App.ApplicationLoadingView = EmberView.extend({
      elementId: 'toplevel-loading'
    });

    bootApplication();

    equal(Ember.$('#qunit-fixture > #toplevel-loading').text(), 'TOPLEVEL LOADING');

    Ember.run(appDeferred, 'resolve', {});

    equal(Ember.$('#toplevel-loading', '#qunit-fixture').length, 0, 'top-level loading View has been entirely removed from DOM');
    equal(Ember.$('#app', '#qunit-fixture').text(), 'INDEX');
  });
  QUnit.test('The {{link-to}} helper disregards query-params in activeness computation when current-when specified', function() {
    App.Router.map(function() {
      this.route('parent');
    });

    Ember.TEMPLATES.application = compile(
      '{{#link-to \'parent\' (query-params page=1) current-when=\'parent\' id=\'app-link\'}}Parent{{/link-to}} {{outlet}}');
    Ember.TEMPLATES.parent = compile(
      '{{#link-to \'parent\' (query-params page=1) current-when=\'parent\' id=\'parent-link\'}}Parent{{/link-to}} {{outlet}}');

    App.ParentController = Ember.Controller.extend({
      queryParams: ['page'],
      page: 1
    });

    bootApplication();
    equal(Ember.$('#app-link').attr('href'), '/parent');
    shouldNotBeActive('#app-link');

    Ember.run(router, 'handleURL', '/parent?page=2');
    equal(Ember.$('#app-link').attr('href'), '/parent');
    shouldBeActive('#app-link');
    equal(Ember.$('#parent-link').attr('href'), '/parent');
    shouldBeActive('#parent-link');

    var parentController = container.lookup('controller:parent');
    equal(parentController.get('page'), 2);
    Ember.run(parentController, 'set', 'page', 3);
    equal(router.get('location.path'), '/parent?page=3');
    shouldBeActive('#app-link');
    shouldBeActive('#parent-link');

    Ember.$('#app-link').click();
    equal(router.get('location.path'), '/parent');
  });
  QUnit.test('supplied QP properties can be bound', function() {
    var indexController = container.lookup('controller:index');
    Ember.TEMPLATES.index = compile('{{#link-to (query-params foo=boundThing) id=\'the-link\'}}Index{{/link-to}}');

    bootApplication();

    equal(Ember.$('#the-link').attr('href'), '/?foo=OMG');
    Ember.run(indexController, 'set', 'boundThing', 'ASL');
    equal(Ember.$('#the-link').attr('href'), '/?foo=ASL');
  });
Example #13
0
QUnit.test('Slow promises waterfall on startup', function() {
  expect(7);

  var grandmaDeferred = Ember.RSVP.defer();
  var sallyDeferred = Ember.RSVP.defer();

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

  templates.grandma = 'GRANDMA {{outlet}}';
  templates.mom = 'MOM {{outlet}}';
  templates['mom/loading'] = 'MOMLOADING';
  templates['mom/sally'] = 'SALLY';

  App.GrandmaRoute = Ember.Route.extend({
    model() {
      step(1, 'GrandmaRoute#model');
      return grandmaDeferred.promise;
    }
  });

  App.MomRoute = Ember.Route.extend({
    model() {
      step(2, 'Mom#model');
      return {};
    }
  });

  App.MomSallyRoute = Ember.Route.extend({
    model() {
      step(3, 'SallyRoute#model');
      return sallyDeferred.promise;
    },
    setupController() {
      step(4, 'SallyRoute#setupController');
    }
  });

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

  equal(Ember.$('#app', '#qunit-fixture').text(), 'LOADING', 'The Loading template is nested in application template\'s outlet');

  Ember.run(grandmaDeferred, 'resolve', {});
  equal(Ember.$('#app', '#qunit-fixture').text(), 'GRANDMA MOM MOMLOADING', 'Mom\'s child loading route is displayed due to sally\'s slow promise');

  Ember.run(sallyDeferred, 'resolve', {});
  equal(Ember.$('#app', '#qunit-fixture').text(), 'GRANDMA MOM SALLY', 'Sally template displayed');
});
  QUnit.test('href updates when unsupplied controller QP props change', function() {
    Ember.TEMPLATES.index = compile('{{#link-to (query-params foo=\'lol\') id=\'the-link\'}}Index{{/link-to}}');

    bootApplication();
    var indexController = container.lookup('controller:index');

    equal(Ember.$('#the-link').attr('href'), '/?foo=lol');
    Ember.run(indexController, 'set', 'bar', 'BORF');
    equal(Ember.$('#the-link').attr('href'), '/?bar=BORF&foo=lol');
    Ember.run(indexController, 'set', 'foo', 'YEAH');
    equal(Ember.$('#the-link').attr('href'), '/?bar=BORF&foo=lol');
  });
  QUnit.test('supplied QP properties can be bound (booleans)', function() {
    var indexController = container.lookup('controller:index');
    Ember.TEMPLATES.index = compile('{{#link-to (query-params abool=boundThing) id=\'the-link\'}}Index{{/link-to}}');

    bootApplication();

    equal(Ember.$('#the-link').attr('href'), '/?abool=OMG');
    Ember.run(indexController, 'set', 'boundThing', false);
    equal(Ember.$('#the-link').attr('href'), '/?abool=false');

    Ember.run(Ember.$('#the-link'), 'click');

    deepEqual(indexController.getProperties('foo', 'bar', 'abool'), { foo: '123', bar: 'abc', abool: false });
  });
Example #16
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' });
  });

  Ember.TEMPLATES.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 = Ember.Route.extend({
    model() {
      return Ember.A([
        { id: 'yehuda', name: 'Yehuda Katz' },
        { id: 'tom', name: 'Tom Dale' },
        { id: 'erik', name: 'Erik Brynroflsson' }
      ]);
    }
  });

  App.ItemRoute = Ember.Route.extend({
    serialize(object) {
      return { id: object.id };
    }
  });

  bootApplication();

  Ember.run(function() {
    router.handleURL('/about');
  });

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

  Ember.run(function() {
    Ember.$('li a:contains(Yehuda)', '#qunit-fixture').click();
  });

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

  Ember.run(function() { Ember.$('#home-link').click(); });
  Ember.run(function() { Ember.$('#about-link').click(); });

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

  Ember.run(function() {
    Ember.$('li a:contains(Erik)', '#qunit-fixture').click();
  });

  equal(Ember.$('h3:contains(Item)', '#qunit-fixture').length, 1, 'The item template was rendered');
  equal(Ember.$('p', '#qunit-fixture').text(), 'Erik Brynroflsson', 'The name is correct');
});
  QUnit.test('updates controller QP properties on other route after transitioning to that route', function() {
    Router.map(function() {
      this.route('about');
    });

    Ember.TEMPLATES.index = compile('{{#link-to \'about\' (query-params baz=\'lol\') id=\'the-link\'}}About{{/link-to}}');
    bootApplication();

    equal(Ember.$('#the-link').attr('href'), '/about?baz=lol');
    Ember.run(Ember.$('#the-link'), 'click');
    var aboutController = container.lookup('controller:about');
    deepEqual(aboutController.getProperties('baz', 'bat'), { baz: 'lol', bat: 'borf' }, 'about controller QP properties updated');

    equal(container.lookup('controller:application').get('currentPath'), 'about');
  });
Example #18
0
  QUnit.test('Prioritized error substate entry works with auto-generated index routes', function() {
    expect(2);

    templates['foo/index_error'] = 'FOO ERROR: {{model.msg}}';
    templates['foo/index'] = 'YAY';
    templates['foo'] = '{{outlet}}';

    Router.map(function() {
      this.route('foo', function() {
        this.route('bar');
      });
    });

    App.ApplicationController = Ember.Controller.extend();

    App.FooIndexRoute = Ember.Route.extend({
      model() {
        return Ember.RSVP.reject({
          msg: 'did it broke?'
        });
      }
    });
    App.FooRoute = Ember.Route.extend({
      model() {
        return true;
      }
    });

    throws(function() {
      bootApplication('/foo');
    }, function(err) { return err.msg === 'did it broke?'; });

    equal(Ember.$('#app', '#qunit-fixture').text(), 'FOO ERROR: did it broke?', 'foo.index_error was entered');
  });
Example #19
0
  QUnit.test('Prioritized error substate entry works with preserved-namespace nested routes', function() {
    expect(2);

    templates['foo/bar_error'] = 'FOOBAR ERROR: {{model.msg}}';
    templates['foo/bar'] = 'YAY';

    Router.map(function() {
      this.route('foo', function() {
        this.route('bar');
      });
    });

    App.ApplicationController = Ember.Controller.extend();

    App.FooBarRoute = Ember.Route.extend({
      model() {
        return Ember.RSVP.reject({
          msg: 'did it broke?'
        });
      }
    });

    throws(function() {
      bootApplication('/foo/bar');
    }, function(err) { return err.msg === 'did it broke?'; });

    equal(Ember.$('#app', '#qunit-fixture').text(), 'FOOBAR ERROR: did it broke?', 'foo.bar_error was entered (as opposed to something like foo/foo/bar_error)');
  });
Example #20
0
QUnit.test('The {{link-to}} helper supports bubbles=false', function() {
  Ember.TEMPLATES.about = compile('<div {{action \'hide\'}}>{{#link-to \'about.contact\' id=\'about-contact\' bubbles=false}}About{{/link-to}}</div>{{outlet}}');
  Ember.TEMPLATES['about/contact'] = compile('<h1 id=\'contact\'>Contact</h1>');

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

  var hidden = 0;

  App.AboutRoute = Ember.Route.extend({
    actions: {
      hide() {
        hidden++;
      }
    }
  });

  bootApplication();

  Ember.run(function() {
    router.handleURL('/about');
  });

  Ember.run(function() {
    Ember.$('#about-contact', '#qunit-fixture').click();
  });

  equal(Ember.$('#contact', '#qunit-fixture').text(), 'Contact', 'precond - the link worked');

  equal(hidden, 0, 'The link didn\'t bubble');
});
Example #21
0
QUnit.test('Enter loading route if only LoadingRoute defined', function() {
  delete templates.loading;

  expect(4);

  var indexDeferred = Ember.RSVP.defer();

  App.IndexRoute = Ember.Route.extend({
    model() {
      step(1, 'IndexRoute#model');
      return indexDeferred.promise;
    }
  });

  App.LoadingRoute = Ember.Route.extend({
    setupController() {
      step(2, 'LoadingRoute#setupController');
    }
  });

  bootApplication();

  var appController = container.lookup('controller:application');
  equal(appController.get('currentPath'), 'loading', 'loading state entered');

  Ember.run(indexDeferred, 'resolve', {});
  equal(Ember.$('#app', '#qunit-fixture').text(), 'INDEX');
});
Example #22
0
  QUnit.test('Slow promises returned from ApplicationRoute#model enter ApplicationLoadingRoute if present', function() {
    expect(2);

    var appDeferred = Ember.RSVP.defer();

    App.ApplicationRoute = Ember.Route.extend({
      model() {
        return appDeferred.promise;
      }
    });

    var loadingRouteEntered = false;
    App.ApplicationLoadingRoute = Ember.Route.extend({
      setupController() {
        loadingRouteEntered = true;
      }
    });

    bootApplication();

    ok(loadingRouteEntered, 'ApplicationLoadingRoute was entered');

    Ember.run(appDeferred, 'resolve', {});
    equal(Ember.$('#app', '#qunit-fixture').text(), 'INDEX');
  });
  QUnit.test('updates controller QP properties on current route when invoked (inferred route)', function() {
    Ember.TEMPLATES.index = compile('{{#link-to (query-params foo=\'456\') id=\'the-link\'}}Index{{/link-to}}');
    bootApplication();

    Ember.run(Ember.$('#the-link'), 'click');
    var indexController = container.lookup('controller:index');
    deepEqual(indexController.getProperties('foo', 'bar'), { foo: '456', bar: 'abc' }, 'controller QP properties updated');
  });
Example #24
0
QUnit.test('The {{link-to}} helper supports a custom activeClass', function() {
  Ember.TEMPLATES.index = compile('<h3>Home</h3>{{#link-to \'about\' id=\'about-link\'}}About{{/link-to}}{{#link-to \'index\' id=\'self-link\' activeClass=\'zomg-active\'}}Self{{/link-to}}');

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

  bootApplication();

  Ember.run(function() {
    router.handleURL('/');
  });

  equal(Ember.$('h3:contains(Home)', '#qunit-fixture').length, 1, 'The home template was rendered');
  equal(Ember.$('#self-link.zomg-active', '#qunit-fixture').length, 1, 'The self-link was rendered with active class');
  equal(Ember.$('#about-link:not(.active)', '#qunit-fixture').length, 1, 'The other link was rendered without active class');
});
  QUnit.test('doesn\'t update controller QP properties on current route when invoked (empty query-params obj)', function() {
    Ember.TEMPLATES.index = compile('{{#link-to \'index\' (query-params) id=\'the-link\'}}Index{{/link-to}}');
    bootApplication();

    Ember.run(Ember.$('#the-link'), 'click');
    var indexController = container.lookup('controller:index');
    deepEqual(indexController.getProperties('foo', 'bar'), { foo: '123', bar: 'abc' }, 'controller QP properties not');
  });
Example #26
0
  function linksEqual($links, expected) {
    equal($links.length, expected.length, 'Has correct number of links');

    var idx;
    for (idx = 0; idx < $links.length; idx++) {
      var href = Ember.$($links[idx]).attr('href');
      // Old IE includes the whole hostname as well
      equal(href.slice(-expected[idx].length), expected[idx], 'Expected link to be \'' + expected[idx] + '\', but was \'' + href + '\'');
    }
  }
Example #27
0
QUnit.test('The non-block form {{link-to}} helper moves into the named route', function() {
  expect(3);
  Router.map(function(match) {
    this.route('contact');
  });

  Ember.TEMPLATES.index = compile('<h3>Home</h3>{{link-to \'Contact us\' \'contact\' id=\'contact-link\'}}{{#link-to \'index\' id=\'self-link\'}}Self{{/link-to}}');
  Ember.TEMPLATES.contact = compile('<h3>Contact</h3>{{link-to \'Home\' \'index\' id=\'home-link\'}}{{link-to \'Self\' \'contact\' id=\'self-link\'}}');

  bootApplication();

  Ember.run(function() {
    Ember.$('#contact-link', '#qunit-fixture').click();
  });

  equal(Ember.$('h3:contains(Contact)', '#qunit-fixture').length, 1, 'The contact template was rendered');
  equal(Ember.$('#self-link.active', '#qunit-fixture').length, 1, 'The self-link was rendered with active class');
  equal(Ember.$('#home-link:not(.active)', '#qunit-fixture').length, 1, 'The other link was rendered without active class');
});
Example #28
0
QUnit.test('The {{link-to}} helper supports `target` attribute', function() {
  Ember.TEMPLATES.index = compile('<h3>Home</h3>{{#link-to \'index\' id=\'self-link\' target=\'_blank\'}}Self{{/link-to}}');
  bootApplication();

  Ember.run(function() {
    router.handleURL('/');
  });

  var link = Ember.$('#self-link', '#qunit-fixture');
  equal(link.attr('target'), '_blank', 'The self-link contains `target` attribute');
});
Example #29
0
QUnit.test('The {{link-to}} helper works in an #each\'d array of string route names', function() {
  Router.map(function() {
    this.route('foo');
    this.route('bar');
    this.route('rar');
  });

  App.IndexController = Ember.Controller.extend({
    routeNames: Ember.A(['foo', 'bar', 'rar']),
    route1: 'bar',
    route2: 'foo'
  });

  Ember.TEMPLATES = {
    index: compile('{{#each routeNames as |routeName|}}{{#link-to routeName}}{{routeName}}{{/link-to}}{{/each}}{{#each routeNames as |r|}}{{#link-to r}}{{r}}{{/link-to}}{{/each}}{{#link-to route1}}a{{/link-to}}{{#link-to route2}}b{{/link-to}}')
  };

  bootApplication();

  function linksEqual($links, expected) {
    equal($links.length, expected.length, 'Has correct number of links');

    var idx;
    for (idx = 0; idx < $links.length; idx++) {
      var href = Ember.$($links[idx]).attr('href');
      // Old IE includes the whole hostname as well
      equal(href.slice(-expected[idx].length), expected[idx], 'Expected link to be \'' + expected[idx] + '\', but was \'' + href + '\'');
    }
  }

  linksEqual(Ember.$('a', '#qunit-fixture'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/bar', '/foo']);

  var indexController = container.lookup('controller:index');
  Ember.run(indexController, 'set', 'route1', 'rar');

  linksEqual(Ember.$('a', '#qunit-fixture'), ['/foo', '/bar', '/rar', '/foo', '/bar', '/rar', '/rar', '/foo']);

  Ember.run(indexController.routeNames, 'shiftObject');

  linksEqual(Ember.$('a', '#qunit-fixture'), ['/bar', '/rar', '/bar', '/rar', '/rar', '/foo']);
});
Example #30
0
QUnit.test('The non-block form {{link-to}} protects against XSS', function() {
  Ember.TEMPLATES.application = compile('{{link-to display \'index\' id=\'link\'}}');

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

  bootApplication();

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

  var controller = container.lookup('controller:application');

  equal(Ember.$('#link', '#qunit-fixture').text(), 'blahzorz');
  Ember.run(function() {
    controller.set('display', '<b>BLAMMO</b>');
  });

  equal(Ember.$('#link', '#qunit-fixture').text(), '<b>BLAMMO</b>');
  equal(Ember.$('b', '#qunit-fixture').length, 0);
});