Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added ember-href-to performance tests #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
{ name: 'Render Simple Ember List', path: '/render-simple-ember-list' },
{ name: 'Render List with link-to', path: '/render-list-with-link-to' },

{ name: 'Render link-to', path: '/render-link-to' }
{ name: 'Render link-to', path: '/render-link-to' },

{ name: 'GJ: baseline', path: '/gj-baseline' },
{ name: 'GJ: link-to', path: '/gj-link-to' },
{ name: 'GJ: href-to', path: '/gj-href-to' },
];

var EMBER_VERSIONS = [
Expand Down
45 changes: 45 additions & 0 deletions tests/gj-baseline/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* global TestClient */
(function() {

var ContainerView, ViewClass, view;

var template = "hi";

TestClient.run({
name: 'GJ baseline',

setup: function() {
var App = Ember.Application.create({ rootElement: '#scratch' });

ViewClass = Ember.View.extend({
template: this.compile(template)
});

return new Ember.RSVP.Promise(function(resolve) {
App.IndexView = Ember.ContainerView.extend({
_triggerStart: function() {
ContainerView = this;
resolve();
}.on('didInsertElement')
});
});
},

reset: function() {
if (view) { ContainerView.removeObject(view); }

return new Ember.RSVP.Promise(function(resolve) {
Ember.run.next(resolve);
});
},

test: function() {
return new Ember.RSVP.Promise(function(resolve) {
view = ViewClass.create({ people: TestClient.PEOPLE_JSON });
view.on('didInsertElement', resolve);
ContainerView.addObject(view);
});
}
});

})();
149 changes: 149 additions & 0 deletions tests/gj-href-to/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/* global TestClient */
(function() {

var application;

function getApplication() {
var apps = Ember.Namespace.NAMESPACES.filter(function(namespace) {
return namespace instanceof Ember.Application;
});

return apps[0];
}

function containerLookup(key) {
if(application === undefined || application.testing) {
application = getApplication();
}

return application.__container__.lookup(key);
}

function getRouter() {
return containerLookup('router:main');
}

var appNeedsClickHandler = true;

function setupClickHandler() {
Ember.$(document.body).on('click', 'a', function(e) {
var $target = Em.$(e.currentTarget);
var handleClick = (e.which === 1 && !e.ctrlKey && !e.metaKey);

if(handleClick && !$target.hasClass('ember-view') && Ember.isNone($target.attr('data-ember-action'))) {
var router = getRouter();

var url = $target.attr('href');
var rootUrlLength = router.rootURL.length;
if(rootUrlLength > 1) {
url = url.substr(rootUrlLength);
}

if(router.router.recognizer.recognize(url)) {
router.handleURL(url);
router.router.updateURL(url);
return false;
}
}
return true;
});
}

function hrefTo(params) {
if(appNeedsClickHandler) {
setupClickHandler();
appNeedsClickHandler = false;
}

var lastParam = params[params.length - 1];

var queryParams = {};
if (lastParam && lastParam.isQueryParams) {
queryParams = params.pop();
}

var targetRouteName = params.shift();

var args = [targetRouteName];
args.push.apply(args, params);
args.push({ queryParams: queryParams.values });

var router = getRouter();
return router.generate.apply(router, args);
}

var ContainerView, ViewClass, view;

var template =
"<a href=\"{{href-to 'index'}}\">Home</a>" +
"<a href=\"{{href-to 'about'}}\">About</a>" +
"<a href=\"{{href-to 'contact-us'}}\">Contact Us</a>" +
"<a href=\"{{href-to 'index' (query-params a='aaa' b='bbb' c='ccc')}}\">Home with query params</a>" +
"<a href=\"{{href-to 'parent.child1'}}\">Parent Child 1</a>" +
"<a href=\"{{href-to 'parent.child2'}}\">Parent Child 2</a>" +
"<a href=\"{{href-to 'parent.child3'}}\">Parent Child 3</a>" +
"<a href=\"{{href-to 'contacts.contact.details' view.contact1}}\">Contact 1</a>" +
"<a href=\"{{href-to 'contacts.contact.details' view.contact2}}\">Contact 2</a>" +
"<a href=\"{{href-to 'contacts.contact.details' view.contact3}}\">Contact 3</a>";

TestClient.run({
name: 'GJ href-to',

setup: function() {
var App = Ember.Application.create({ rootElement: '#scratch' });

App.Router.map(function() {
this.route('about', { path: '/about' });
this.route('favorites', { path: '/favs' });
this.route('contact-us', { path: '/contact-us' });
this.route('parent', function() {
this.route('child1');
this.route('child2');
this.route('child3');
});
this.route('contacts', function() {
this.route('contact', { path: ':contact_id' }, function() {
this.route('details');
});
})
});

ViewClass = Ember.View.extend({
template: this.compile(template)
});

Ember.HTMLBars._registerHelper('href-to', hrefTo);


return new Ember.RSVP.Promise(function(resolve) {
App.IndexView = Ember.ContainerView.extend({
_triggerStart: function() {
ContainerView = this;
resolve();
}.on('didInsertElement')
});
});
},

reset: function() {
if (view) { ContainerView.removeObject(view); }

return new Ember.RSVP.Promise(function(resolve) {
Ember.run.next(resolve);
});
},

test: function() {
return new Ember.RSVP.Promise(function(resolve) {
view = ViewClass.create({
contact1: { id: 1 },
contact2: { id: 2 },
contact3: { id: 3 }
});
view.on('didInsertElement', resolve);
ContainerView.addObject(view);
});
}
});

})();
75 changes: 75 additions & 0 deletions tests/gj-link-to/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* global TestClient */
(function() {

var ContainerView, ViewClass, view;

var template =
"{{#link-to 'index'}}Home{{/link-to}}" +
"{{#link-to 'about'}}About{{/link-to}}" +
"{{#link-to 'contact-us'}}Contact Us{{/link-to}}" +
"{{#link-to 'index' (query-params a='aaa' b='bbb' c='ccc')}}Home with query params{{/link-to}}" +
"{{#link-to 'parent.child1'}}Parent Child 1{{/link-to}}" +
"{{#link-to 'parent.child2'}}Parent Child 2{{/link-to}}" +
"{{#link-to 'parent.child3'}}Parent Child 3{{/link-to}}" +
"{{#link-to 'contacts.contact.details' view.contact1}}Contact 1{{/link-to}}" +
"{{#link-to 'contacts.contact.details' view.contact2}}Contact 2{{/link-to}}" +
"{{#link-to 'contacts.contact.details' view.contact3}}Contact 3{{/link-to}}";

TestClient.run({
name: 'GJ link-to',

setup: function() {
var App = Ember.Application.create({ rootElement: '#scratch' });

App.Router.map(function() {
this.route('about', { path: '/about' });
this.route('favorites', { path: '/favs' });
this.route('contact-us', { path: '/contact-us' });
this.route('parent', function() {
this.route('child1');
this.route('child2');
this.route('child3');
});
this.route('contacts', function() {
this.route('contact', { path: ':contact_id' }, function() {
this.route('details');
});
})
});

ViewClass = Ember.View.extend({
template: this.compile(template)
});

return new Ember.RSVP.Promise(function(resolve) {
App.IndexView = Ember.ContainerView.extend({
_triggerStart: function() {
ContainerView = this;
resolve();
}.on('didInsertElement')
});
});
},

reset: function() {
if (view) { ContainerView.removeObject(view); }

return new Ember.RSVP.Promise(function(resolve) {
Ember.run.next(resolve);
});
},

test: function() {
return new Ember.RSVP.Promise(function(resolve) {
view = ViewClass.create({
contact1: { id: 1 },
contact2: { id: 2 },
contact3: { id: 3 }
});
view.on('didInsertElement', resolve);
ContainerView.addObject(view);
});
}
});

})();