Upgrade ember qunit, create new interface for testing components

This commit is contained in:
Robin Ward 2015-07-14 13:56:59 -04:00
parent 1397507d05
commit 7a58d64f37
7 changed files with 162 additions and 146 deletions

View File

@ -103,7 +103,7 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, {
const replyCount = post.get('reply_count');
buffer.push("<button class='show-replies highlight-action' data-action='replies'>");
buffer.push(I18n.t("post.has_replies", { count: replyCount }));
buffer.push(I18n.t("post.has_replies", { count: replyCount || 0 }));
const icon = (this.get('post.replies.length') > 0) ? 'chevron-up' : 'chevron-down';
return buffer.push(iconHTML(icon) + "</button>");

View File

@ -70,7 +70,7 @@ const Topic = RestModel.extend({
}.property('url'),
url: function() {
let slug = this.get('slug');
let slug = this.get('slug') || '';
if (slug.trim().length === 0) {
slug = "topic";
}

View File

@ -1,19 +1,17 @@
import componentTest from 'helpers/component-test';
moduleForComponent('ace-editor', {integration: true});
test('css editor', function(assert) {
andThen(() => {
this.render('{{ace-editor mode="css"}}');
});
andThen(() => {
componentTest('css editor', {
template: '{{ace-editor mode="css"}}',
test(assert) {
assert.ok(this.$('.ace_editor').length, 'it renders the ace editor');
});
}
});
test('html editor', function(assert) {
andThen(() => {
this.render('{{ace-editor mode="html"}}');
});
andThen(() => {
componentTest('html editor', {
template: '{{ace-editor mode="html"}}',
test(assert) {
assert.ok(this.$('.ace_editor').length, 'it renders the ace editor');
});
}
});

View File

@ -0,0 +1,14 @@
import componentTest from 'helpers/component-test';
moduleForComponent('post-menu', {integration: true});
componentTest('render buttons', {
template: "{{post-menu post=post}}",
setup(store) {
const topic = store.createRecord('topic', {id: 123});
this.set('post', store.createRecord('post', {id: 1, post_number: 1, topic}));
},
test(assert) {
assert.ok(this.$('.post-menu-area').length, 'it renders a post menu');
}
});

View File

@ -1,10 +1,9 @@
import componentTest from 'helpers/component-test';
moduleForComponent('value-list', {integration: true});
test('functionality', function(assert) {
andThen(() => {
this.render('{{value-list value=values}}');
});
componentTest('functionality', {
template: '{{value-list value=values}}',
test: function(assert) {
andThen(() => {
assert.ok(this.$('.values .value').length === 0, 'it has no values');
assert.ok(this.$('input').length, 'it renders the input');
@ -27,5 +26,5 @@ test('functionality', function(assert) {
andThen(() => {
assert.ok(this.$('.values .value').length === 0, 'it removes the value');
});
}
});

View File

@ -0,0 +1,22 @@
import createStore from 'helpers/create-store';
export default function(name, opts) {
opts = opts || {};
test(name, function(assert) {
if (opts.setup) {
const store = createStore();
opts.setup.call(this, store);
}
this.container.register('site-settings:main', Discourse.SiteSettings, { instantiate: false });
this.container.injection('component', 'siteSettings', 'site-settings:main');
andThen(() => {
this.render(opts.template);
});
andThen(() => {
opts.test.call(this, assert);
});
});
}

View File

@ -229,15 +229,10 @@ define('ember-qunit/test', ['exports', 'ember', 'ember-test-helpers', 'qunit'],
'use strict';
function resetViews() {
Ember['default'].View.views = {};
}
function test(testName, callback) {
function wrapper(assert) {
var context = ember_test_helpers.getContext();
resetViews();
var result = callback.call(context, assert);
function failTestOnPromiseRejection(reason) {
@ -261,13 +256,12 @@ define('ember-qunit/test', ['exports', 'ember', 'ember-test-helpers', 'qunit'],
exports['default'] = test;
});
define('ember-test-helpers', ['exports', 'ember', 'ember-test-helpers/isolated-container', 'ember-test-helpers/test-module', 'ember-test-helpers/test-module-for-component', 'ember-test-helpers/test-module-for-model', 'ember-test-helpers/test-context', 'ember-test-helpers/test-resolver'], function (exports, Ember, isolated_container, TestModule, TestModuleForComponent, TestModuleForModel, test_context, test_resolver) {
define('ember-test-helpers', ['exports', 'ember', 'ember-test-helpers/test-module', 'ember-test-helpers/test-module-for-component', 'ember-test-helpers/test-module-for-model', 'ember-test-helpers/test-context', 'ember-test-helpers/test-resolver'], function (exports, Ember, TestModule, TestModuleForComponent, TestModuleForModel, test_context, test_resolver) {
'use strict';
Ember['default'].testing = true;
exports.isolatedContainer = isolated_container.isolatedContainer;
exports.TestModule = TestModule['default'];
exports.TestModuleForComponent = TestModuleForComponent['default'];
exports.TestModuleForModel = TestModuleForModel['default'];
@ -276,13 +270,10 @@ define('ember-test-helpers', ['exports', 'ember', 'ember-test-helpers/isolated-c
exports.setResolver = test_resolver.setResolver;
});
define('ember-test-helpers/isolated-container', ['exports', 'ember-test-helpers/test-resolver', 'ember'], function (exports, test_resolver, Ember) {
define('ember-test-helpers/build-registry', ['exports'], function (exports) {
'use strict';
exports.isolatedRegistry = isolatedRegistry;
exports.isolatedContainer = isolatedContainer;
function exposeRegistryMethodsWithoutDeprecations(container) {
var methods = [
'register',
@ -309,86 +300,63 @@ define('ember-test-helpers/isolated-container', ['exports', 'ember-test-helpers/
}
}
function isolatedRegistry(fullNames) {
var resolver = test_resolver.getResolver();
var container;
var registry;
exports['default'] = function(resolver) {
var registry, container;
var namespace = Ember.Object.create({
Resolver: { create: function() { return resolver; } }
});
var normalize = function(fullName) {
return resolver.normalize(fullName);
};
function register(name, factory) {
var thingToRegisterWith = registry || container;
if (Ember['default'].Registry) {
registry = new Ember['default'].Registry();
registry.normalizeFullName = normalize;
if (!container.lookupFactory(name)) {
thingToRegisterWith.register(name, factory);
}
}
if (Ember.Application.buildRegistry) {
registry = Ember.Application.buildRegistry(namespace);
registry.register('component-lookup:main', Ember.ComponentLookup);
registry = registry;
container = registry.container();
exposeRegistryMethodsWithoutDeprecations(container);
} else {
container = new Ember['default'].Container();
//normalizeFullName only exists since Ember 1.9
if (Ember['default'].typeOf(container.normalizeFullName) === 'function') {
container.normalizeFullName = normalize;
} else {
container.normalize = normalize;
}
container = Ember.Application.buildContainer(namespace);
container.register('component-lookup:main', Ember.ComponentLookup);
}
container.optionsForType('component', { singleton: false });
container.optionsForType('view', { singleton: false });
container.optionsForType('template', { instantiate: false });
container.optionsForType('helper', { instantiate: false });
container.register('component-lookup:main', Ember['default'].ComponentLookup);
container.register('controller:basic', Ember['default'].Controller, { instantiate: false });
container.register('controller:object', Ember['default'].ObjectController, { instantiate: false });
container.register('controller:array', Ember['default'].ArrayController, { instantiate: false });
container.register('view:default', Ember['default']._MetamorphView);
container.register('view:toplevel', Ember['default'].View.extend());
container.register('view:select', Ember['default'].Select);
container.register('route:basic', Ember['default'].Route, { instantiate: false });
// added in Glimmer
container.register('component:-link-to', Ember['default'].LinkView);
container.register('component:-text-field', Ember['default'].TextField);
container.register('component:-text-area', Ember['default'].TextArea);
container.register('component:-checkbox', Ember['default'].Checkbox);
if (Ember['default']._LegacyEachView) {
container.register('view:-legacy-each', Ember['default']._LegacyEachView);
}
// Ember 1.10.0 did not properly add `view:toplevel` or `view:default`
// to the registry in Ember.Application.buildRegistry :(
register('view:toplevel', Ember.View.extend());
register('view:default', Ember._MetamorphView);
var globalContext = typeof global === 'object' && global || self;
if (globalContext.DS) {
var DS = globalContext.DS;
if (DS._setupContainer) {
DS._setupContainer(container);
DS._setupContainer(registry || container);
} else {
container.register('transform:boolean', DS.BooleanTransform);
container.register('transform:date', DS.DateTransform);
container.register('transform:number', DS.NumberTransform);
container.register('transform:string', DS.StringTransform);
container.register('serializer:-default', DS.JSONSerializer);
container.register('serializer:-rest', DS.RESTSerializer);
container.register('adapter:-rest', DS.RESTAdapter);
register('transform:boolean', DS.BooleanTransform);
register('transform:date', DS.DateTransform);
register('transform:number', DS.NumberTransform);
register('transform:string', DS.StringTransform);
register('serializer:-default', DS.JSONSerializer);
register('serializer:-rest', DS.RESTSerializer);
register('adapter:-rest', DS.RESTAdapter);
}
}
for (var i = fullNames.length; i > 0; i--) {
var fullName = fullNames[i - 1];
var normalizedFullName = resolver.normalize(fullName);
container.register(fullName, resolver.resolve(normalizedFullName));
}
return {
container: container,
registry: registry
registry: registry,
container: container
};
}
function isolatedContainer(fullNames) {
return isolatedRegistry(fullNames).container;
}
});
define('ember-test-helpers/isolated-container', function () {
'use strict';
});
define('ember-test-helpers/test-context', ['exports'], function (exports) {
@ -417,8 +385,10 @@ define('ember-test-helpers/test-module-for-component', ['exports', 'ember-test-h
init: function(componentName, description, callbacks) {
// Allow `description` to be omitted
if (!callbacks && typeof description === 'object') {
callbacks = description || {};
callbacks = description;
description = null;
} else if (!callbacks) {
callbacks = {};
}
this.componentName = componentName;
@ -500,7 +470,7 @@ define('ember-test-helpers/test-module-for-component', ['exports', 'ember-test-h
},
setupComponentIntegrationTest: function() {
var self = this;
var module = this;
var context = this.context;
context.dispatcher = Ember['default'].EventDispatcher.create();
context.dispatcher.setup({}, '#ember-testing');
@ -516,19 +486,20 @@ define('ember-test-helpers/test-module-for-component', ['exports', 'ember-test-h
if (typeof template === 'string') {
template = Ember['default'].Handlebars.compile(template);
}
self.component = Ember['default'].View.create({
context: context,
controller: self,
template: template,
container: self.container
module.component = Ember['default'].Component.create({
layout: template,
container: module.container
});
module.component.set('context' ,context);
module.component.set('controller', module);
Ember['default'].run(function() {
self.component.appendTo('#ember-testing');
module.component.appendTo('#ember-testing');
});
};
context.$ = function() {
return self.component.$.apply(self.component, arguments);
return module.component.$.apply(module.component, arguments);
};
context.set = function(key, value) {
@ -542,7 +513,7 @@ define('ember-test-helpers/test-module-for-component', ['exports', 'ember-test-h
};
context.on = function(actionName, handler) {
self.actionHooks[actionName] = handler;
module.actionHooks[actionName] = handler;
};
},
@ -602,8 +573,8 @@ define('ember-test-helpers/test-module-for-model', ['exports', 'ember-test-helpe
callbacks.store = function(){
var container = this.container;
return container.lookup('store:main');
var store = container.lookup('service:store') || container.lookup('store:main');
return store;
};
if (callbacks.subject === defaultSubject) {
@ -611,7 +582,8 @@ define('ember-test-helpers/test-module-for-model', ['exports', 'ember-test-helpe
var container = this.container;
return Ember['default'].run(function() {
return container.lookup('store:main').createRecord(modelName, options);
var store = container.lookup('service:store') || container.lookup('store:main');
return store.createRecord(modelName, options);
});
};
}
@ -619,7 +591,7 @@ define('ember-test-helpers/test-module-for-model', ['exports', 'ember-test-helpe
});
});
define('ember-test-helpers/test-module', ['exports', 'ember', 'ember-test-helpers/isolated-container', 'ember-test-helpers/test-context', 'klassy', 'ember-test-helpers/test-resolver'], function (exports, Ember, isolated_container, test_context, klassy, test_resolver) {
define('ember-test-helpers/test-module', ['exports', 'ember', 'ember-test-helpers/test-context', 'klassy', 'ember-test-helpers/test-resolver', 'ember-test-helpers/build-registry'], function (exports, Ember, test_context, klassy, test_resolver, buildRegistry) {
'use strict';
@ -655,7 +627,7 @@ define('ember-test-helpers/test-module', ['exports', 'ember', 'ember-test-helper
initNeeds: function() {
this.needs = [this.subjectName];
if (this.callbacks.needs) {
this.needs = this.needs.concat(this.callbacks.needs)
this.needs = this.needs.concat(this.callbacks.needs);
delete this.callbacks.needs;
}
},
@ -726,7 +698,10 @@ define('ember-test-helpers/test-module', ['exports', 'ember', 'ember-test-helper
function nextStep() {
var step = steps.shift();
if (step) {
return Ember['default'].RSVP.resolve(step.call(context)).then(nextStep);
// guard against exceptions, for example missing components referenced from needs.
return new Ember['default'].RSVP.Promise(function(ok) {
ok(step.call(context));
}).then(nextStep);
} else {
return Ember['default'].RSVP.resolve();
}
@ -811,7 +786,7 @@ define('ember-test-helpers/test-module', ['exports', 'ember', 'ember-test-helper
this.cache = this.cache || {};
this.cachedCalls = this.cachedCalls || {};
var keys = Ember['default'].keys(callbacks);
var keys = (Object.keys || Ember['default'].keys)(callbacks);
for (var i = 0, l = keys.length; i < l; i++) {
(function(key) {
@ -831,29 +806,36 @@ define('ember-test-helpers/test-module', ['exports', 'ember', 'ember-test-helper
}
},
_setupContainer: function() {
var resolver = test_resolver.getResolver();
var items = buildRegistry['default'](resolver);
this.container = items.container;
this.registry = items.registry;
var thingToRegisterWith = this.registry || this.container;
var router = resolver.resolve('router:main');
router = router || Ember['default'].Router.extend();
thingToRegisterWith.register('router:main', router);
},
_setupIsolatedContainer: function() {
var isolated = isolated_container.isolatedRegistry(this.needs);
this.container = isolated.container;
this.registry = isolated.registry;
var resolver = test_resolver.getResolver();
this._setupContainer();
var thingToRegisterWith = this.registry || this.container;
for (var i = this.needs.length; i > 0; i--) {
var fullName = this.needs[i - 1];
var normalizedFullName = resolver.normalize(fullName);
thingToRegisterWith.register(fullName, resolver.resolve(normalizedFullName));
}
thingToRegisterWith.resolver = function() { };
},
_setupIntegratedContainer: function() {
var resolver = test_resolver.getResolver();
var namespace = Ember['default'].Object.create({
Resolver: { create: function() { return resolver; } }
});
if (Ember['default'].Application.buildRegistry) {
var registry;
registry = Ember['default'].Application.buildRegistry(namespace);
registry.register('component-lookup:main', Ember['default'].ComponentLookup);
this.registry = registry;
this.container = registry.container();
} else {
this.container = Ember['default'].Application.buildContainer(namespace);
this.container.register('component-lookup:main', Ember['default'].ComponentLookup);
}
this._setupContainer();
}
});
@ -1061,3 +1043,4 @@ window.test = emberQunit.test;
window.setResolver = emberQunit.setResolver;
})();
//# sourceMappingURL=ember-qunit.map