mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
Cleaned up QUnit test structure
This commit is contained in:
17
.jshintrc
17
.jshintrc
@ -31,7 +31,22 @@
|
|||||||
"PreloadStore",
|
"PreloadStore",
|
||||||
"Handlebars",
|
"Handlebars",
|
||||||
"I18n",
|
"I18n",
|
||||||
"bootbox"],
|
"bootbox",
|
||||||
|
"module",
|
||||||
|
"integration",
|
||||||
|
"test",
|
||||||
|
"ok",
|
||||||
|
"expect",
|
||||||
|
"equal",
|
||||||
|
"blank",
|
||||||
|
"present",
|
||||||
|
"visit",
|
||||||
|
"count",
|
||||||
|
"exists",
|
||||||
|
"asyncTest",
|
||||||
|
"find",
|
||||||
|
"resolvingPromise",
|
||||||
|
"sinon"],
|
||||||
"browser":true,
|
"browser":true,
|
||||||
"rhino":false,
|
"rhino":false,
|
||||||
"devel":true,
|
"devel":true,
|
||||||
|
@ -77,6 +77,21 @@ predef:
|
|||||||
- bootbox
|
- bootbox
|
||||||
- moment
|
- moment
|
||||||
- _
|
- _
|
||||||
|
- module
|
||||||
|
- integration
|
||||||
|
- test
|
||||||
|
- ok
|
||||||
|
- expect
|
||||||
|
- equal
|
||||||
|
- blank
|
||||||
|
- present
|
||||||
|
- visit
|
||||||
|
- count
|
||||||
|
- exists
|
||||||
|
- asyncTest
|
||||||
|
- find
|
||||||
|
- resolvingPromise
|
||||||
|
- sinon
|
||||||
|
|
||||||
browser: true # true if the standard browser globals should be predefined
|
browser: true # true if the standard browser globals should be predefined
|
||||||
rhino: false # true if the Rhino environment globals should be predefined
|
rhino: false # true if the Rhino environment globals should be predefined
|
||||||
|
@ -8,8 +8,9 @@ class DiscourseIIFE < Sprockets::Processor
|
|||||||
# Only discourse or admin paths
|
# Only discourse or admin paths
|
||||||
return data unless (path =~ /\/javascripts\/discourse/ || path =~ /\/javascripts\/admin/ || path =~ /\/test\/javascripts/)
|
return data unless (path =~ /\/javascripts\/discourse/ || path =~ /\/javascripts\/admin/ || path =~ /\/test\/javascripts/)
|
||||||
|
|
||||||
# Ignore the js helper
|
# Ignore the js helpers
|
||||||
return data if (path =~ /test\_helper\.js/)
|
return data if (path =~ /test\_helper\.js/)
|
||||||
|
return data if (path =~ /javascripts\/helpers\//)
|
||||||
|
|
||||||
# Ignore translations
|
# Ignore translations
|
||||||
return data if (path =~ /\/translations/)
|
return data if (path =~ /\/translations/)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true present:true md5:true */
|
/*global md5:true */
|
||||||
|
|
||||||
module("Discourse.BBCode");
|
module("Discourse.BBCode");
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true equal:true exists:true count:true equal:true present:true sinon:true blank:true */
|
|
||||||
|
|
||||||
module("Discourse.ClickTrack", {
|
module("Discourse.ClickTrack", {
|
||||||
setup: function() {
|
setup: function() {
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true equal:true exists:true count:true equal:true present:true md5:true */
|
|
||||||
|
|
||||||
module("Discourse.Formatter");
|
module("Discourse.Formatter");
|
||||||
|
|
||||||
var format = "tiny";
|
var format = "tiny";
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true equal:true exists:true count:true equal:true present:true md5:true */
|
|
||||||
|
|
||||||
var store = Discourse.KeyValueStore;
|
var store = Discourse.KeyValueStore;
|
||||||
|
|
||||||
module("Discourse.KeyValueStore", {
|
module("Discourse.KeyValueStore", {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*global module:true test:true ok:true visit:true equal:true exists:true count:true equal:true present:true md5:true sanitizeHtml:true */
|
/*global sanitizeHtml:true */
|
||||||
|
|
||||||
module("Discourse.Markdown");
|
module("Discourse.Markdown");
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true equal:true exists:true count:true equal:true present:true md5:true resolvingPromise:true */
|
|
||||||
|
|
||||||
module("Discourse.Onebox", {
|
module("Discourse.Onebox", {
|
||||||
setup: function() {
|
setup: function() {
|
||||||
this.anchor = $("<a href='http://bla.com'></a>")[0];
|
this.anchor = $("<a href='http://bla.com'></a>")[0];
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true equal:true count:true present:true asyncTest:true blank:true */
|
|
||||||
|
|
||||||
module("Discourse.PreloadStore", {
|
module("Discourse.PreloadStore", {
|
||||||
setup: function() {
|
setup: function() {
|
||||||
PreloadStore.store('bane', 'evil');
|
PreloadStore.store('bane', 'evil');
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */
|
|
||||||
|
|
||||||
module("Discourse.Utilities");
|
module("Discourse.Utilities");
|
||||||
|
|
||||||
var utils = Discourse.Utilities;
|
var utils = Discourse.Utilities;
|
||||||
|
32
test/javascripts/helpers/assertions.js
Normal file
32
test/javascripts/helpers/assertions.js
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Test helpers
|
||||||
|
var resolvingPromise = Ember.Deferred.promise(function (p) {
|
||||||
|
p.resolve();
|
||||||
|
})
|
||||||
|
|
||||||
|
function exists(selector) {
|
||||||
|
return !!count(selector);
|
||||||
|
}
|
||||||
|
|
||||||
|
function count(selector) {
|
||||||
|
return find(selector).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function objBlank(obj) {
|
||||||
|
if (obj === undefined) return true;
|
||||||
|
|
||||||
|
switch (typeof obj) {
|
||||||
|
case "string":
|
||||||
|
return obj.trim().length === 0;
|
||||||
|
case "object":
|
||||||
|
return $.isEmptyObject(obj);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function present(obj, text) {
|
||||||
|
equal(objBlank(obj), false, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
function blank(obj, text) {
|
||||||
|
equal(objBlank(obj), true, text);
|
||||||
|
}
|
11
test/javascripts/helpers/qunit_helpers.js
Normal file
11
test/javascripts/helpers/qunit_helpers.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
function integration(name) {
|
||||||
|
module(name, {
|
||||||
|
setup: function() {
|
||||||
|
Ember.run(Discourse, Discourse.advanceReadiness);
|
||||||
|
},
|
||||||
|
|
||||||
|
teardown: function() {
|
||||||
|
Discourse.reset();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -1,14 +1,4 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true */
|
integration("Header");
|
||||||
|
|
||||||
module("Header", {
|
|
||||||
setup: function() {
|
|
||||||
Ember.run(Discourse, Discourse.advanceReadiness);
|
|
||||||
},
|
|
||||||
|
|
||||||
teardown: function() {
|
|
||||||
Discourse.reset();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("/", function() {
|
test("/", function() {
|
||||||
|
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true */
|
integration("List Topics");
|
||||||
|
|
||||||
module("List Topics", {
|
|
||||||
setup: function() {
|
|
||||||
Ember.run(Discourse, Discourse.advanceReadiness);
|
|
||||||
},
|
|
||||||
|
|
||||||
teardown: function() {
|
|
||||||
Discourse.reset();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("/", function() {
|
test("/", function() {
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true */
|
|
||||||
|
|
||||||
module("Discourse.Presence");
|
module("Discourse.Presence");
|
||||||
|
|
||||||
var testObj = Em.Object.createWithMixins(Discourse.Presence, {
|
var testObj = Em.Object.createWithMixins(Discourse.Presence, {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */
|
|
||||||
module("Discourse.SelectedPostsCount");
|
module("Discourse.SelectedPostsCount");
|
||||||
|
|
||||||
var buildTestObj = function(params, topicParams) {
|
var buildTestObj = function(params, topicParams) {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */
|
|
||||||
|
|
||||||
module("Discourse.Category");
|
module("Discourse.Category");
|
||||||
|
|
||||||
test('slugFor', function(){
|
test('slugFor', function(){
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */
|
|
||||||
|
|
||||||
module("Discourse.Composer");
|
module("Discourse.Composer");
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */
|
|
||||||
|
|
||||||
module("Discourse.NavItem", {
|
module("Discourse.NavItem", {
|
||||||
setup: function() {
|
setup: function() {
|
||||||
this.site = Discourse.Site.instance();
|
this.site = Discourse.Site.instance();
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true blank:true */
|
|
||||||
|
|
||||||
module("Discourse.Report");
|
module("Discourse.Report");
|
||||||
|
|
||||||
function reportWithData(data) {
|
function reportWithData(data) {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true present:true equal:true */
|
|
||||||
|
|
||||||
module("Discourse.Site");
|
module("Discourse.Site");
|
||||||
|
|
||||||
test('instance', function(){
|
test('instance', function(){
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
/*global module:true test:true ok:true visit:true expect:true exists:true count:true present:true equal:true */
|
|
||||||
|
|
||||||
module("Discourse.UserAction");
|
module("Discourse.UserAction");
|
||||||
|
|
||||||
test("collapsing likes", function () {
|
test("collapsing likes", function () {
|
||||||
|
@ -36,11 +36,12 @@
|
|||||||
//= require sinon-1.7.1.js
|
//= require sinon-1.7.1.js
|
||||||
//= require sinon-qunit-1.0.0.js
|
//= require sinon-qunit-1.0.0.js
|
||||||
|
|
||||||
|
//= require helpers/qunit_helpers
|
||||||
|
//= require helpers/assertions
|
||||||
|
//= require_tree ./fixtures
|
||||||
//= require_tree .
|
//= require_tree .
|
||||||
//= require_self
|
//= require_self
|
||||||
|
|
||||||
//= require_tree ./fixtures
|
|
||||||
|
|
||||||
// sinon settings
|
// sinon settings
|
||||||
sinon.config = {
|
sinon.config = {
|
||||||
injectIntoThis: true,
|
injectIntoThis: true,
|
||||||
@ -65,35 +66,3 @@ Discourse.Router.map(function() {
|
|||||||
return Discourse.routeBuilder.call(this);
|
return Discourse.routeBuilder.call(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test helpers
|
|
||||||
var resolvingPromise = Ember.Deferred.promise(function (p) {
|
|
||||||
p.resolve();
|
|
||||||
})
|
|
||||||
|
|
||||||
function exists(selector) {
|
|
||||||
return !!count(selector);
|
|
||||||
}
|
|
||||||
|
|
||||||
function count(selector) {
|
|
||||||
return find(selector).length;
|
|
||||||
}
|
|
||||||
|
|
||||||
function objBlank(obj) {
|
|
||||||
if (obj === undefined) return true;
|
|
||||||
|
|
||||||
switch (typeof obj) {
|
|
||||||
case "string":
|
|
||||||
return obj.trim().length === 0;
|
|
||||||
case "object":
|
|
||||||
return $.isEmptyObject(obj);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function present(obj, text) {
|
|
||||||
equal(objBlank(obj), false, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
function blank(obj, text) {
|
|
||||||
equal(objBlank(obj), true, text);
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user