mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
Moved JSHint into Qunit suite. It's much harder to forget about now!
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
/*global md5:true */
|
||||
|
||||
module("Discourse.BBCode");
|
||||
|
||||
var format = function(input, expected, text) {
|
||||
// testing 1 2 3
|
||||
equal(Discourse.BBCode.format(input, {lookupAvatar: false}), expected, text);
|
||||
}
|
||||
};
|
||||
|
||||
test('basic bbcode', function() {
|
||||
format("[b]strong[/b]", "<span class='bbcode-b'>strong</span>", "bolds text");
|
||||
@ -50,7 +50,7 @@ test("quotes", function() {
|
||||
|
||||
var formatQuote = function(val, expected, text) {
|
||||
equal(Discourse.BBCode.buildQuoteBBCode(post, val), expected, text);
|
||||
}
|
||||
};
|
||||
|
||||
formatQuote(undefined, "", "empty string for undefined content");
|
||||
formatQuote(null, "", "empty string for null content");
|
||||
|
@ -37,9 +37,10 @@ module("Discourse.ClickTrack", {
|
||||
|
||||
var track = Discourse.ClickTrack.trackClick;
|
||||
|
||||
// test
|
||||
var generateClickEventOn = function(selector) {
|
||||
return $.Event("click", { currentTarget: $(selector)[0] });
|
||||
}
|
||||
};
|
||||
|
||||
test("does not track clicks on lightboxes", function() {
|
||||
var clickEvent = generateClickEventOn('.lightbox');
|
||||
@ -57,11 +58,11 @@ test("it calls preventDefault when clicking on an a", function() {
|
||||
});
|
||||
|
||||
test("does not track clicks on back buttons", function() {
|
||||
ok(track(generateClickEventOn('.back')))
|
||||
ok(track(generateClickEventOn('.back')));
|
||||
});
|
||||
|
||||
test("does not track clicks on quote buttons", function() {
|
||||
ok(track(generateClickEventOn('.quote-other-topic')))
|
||||
ok(track(generateClickEventOn('.quote-other-topic')));
|
||||
});
|
||||
|
||||
test("removes the href and put it as a data attribute", function() {
|
||||
@ -99,7 +100,7 @@ test("updates badge counts correctly", function() {
|
||||
});
|
||||
|
||||
var trackRightClick = function() {
|
||||
var clickEvent = generateClickEventOn('a')
|
||||
var clickEvent = generateClickEventOn('a');
|
||||
clickEvent.which = 3;
|
||||
return track(clickEvent);
|
||||
};
|
||||
|
@ -27,15 +27,15 @@ test("formating medium length dates", function() {
|
||||
format = "medium";
|
||||
var strip = function(html){
|
||||
return $(html).text();
|
||||
}
|
||||
};
|
||||
|
||||
var shortDate = function(days){
|
||||
return moment().subtract('days', days).format('D MMM');
|
||||
}
|
||||
};
|
||||
|
||||
var shortDateYear = function(days){
|
||||
return moment().subtract('days', days).format('D MMM, YYYY');
|
||||
}
|
||||
};
|
||||
|
||||
leaveAgo = true;
|
||||
equal(strip(formatMins(1.4)), "1 min ago");
|
||||
|
@ -12,11 +12,10 @@ var cooked = function(input, expected, text) {
|
||||
|
||||
var cookedOptions = function(input, opts, expected, text) {
|
||||
equal(Discourse.Markdown.cook(input, opts), expected, text);
|
||||
}
|
||||
};
|
||||
|
||||
test("basic cooking", function() {
|
||||
cooked("hello", "<p>hello</p>", "surrounds text with paragraphs");
|
||||
|
||||
});
|
||||
|
||||
test("Line Breaks", function() {
|
||||
@ -29,10 +28,10 @@ test("Line Breaks", function() {
|
||||
cookedOptions(input,
|
||||
{traditional_markdown_linebreaks: true},
|
||||
traditionalOutput,
|
||||
"It supports traditional markdown via an option")
|
||||
"It supports traditional markdown via an option");
|
||||
|
||||
Discourse.SiteSettings.traditional_markdown_linebreaks = true;
|
||||
cooked(input, traditionalOutput, "It supports traditional markdown via a Site Setting")
|
||||
cooked(input, traditionalOutput, "It supports traditional markdown via a Site Setting");
|
||||
|
||||
});
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
182
test/javascripts/jshint_all.js.erb
Normal file
182
test/javascripts/jshint_all.js.erb
Normal file
@ -0,0 +1,182 @@
|
||||
module("JSHint");
|
||||
|
||||
var qHint = function(name, sourceFile, options, globals) {
|
||||
if (sourceFile === undefined || typeof(sourceFile) == "object") {
|
||||
// jsHintTest('file.js', [options])
|
||||
globals = options;
|
||||
options = sourceFile;
|
||||
sourceFile = name;
|
||||
}
|
||||
|
||||
return asyncTest(name, function() {
|
||||
qHint.sendRequest(sourceFile, function(req) {
|
||||
start();
|
||||
|
||||
if (req.status == 200) {
|
||||
|
||||
var text = req.responseText;
|
||||
|
||||
// Remove our generate IIFEs so we get the same line numbers as original
|
||||
// files
|
||||
text = text.replace(/^[^]*\/\/ IIFE Wrapped Content Begins:\n\n/m, "");
|
||||
text = text.replace(/\n\n\/\/ IIFE Wrapped Content Ends[^]*$/m, "");
|
||||
qHint.validateFile(text, options, globals);
|
||||
} else {
|
||||
ok(false, "HTTP error " + req.status +
|
||||
" while fetching " + sourceFile);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
qHint.validateFile = function (source, options, globals) {
|
||||
var i, len, err;
|
||||
|
||||
if (JSHINT(source, options, globals)) {
|
||||
ok(true);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0, len = JSHINT.errors.length; i < len; i++) {
|
||||
err = JSHINT.errors[i];
|
||||
if (!err) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ok(false, err.reason +
|
||||
" on line " + err.line +
|
||||
", character " + err.character);
|
||||
}
|
||||
};
|
||||
|
||||
var XMLHttpFactories = [
|
||||
function () { return new XMLHttpRequest(); },
|
||||
function () { return new ActiveXObject("Msxml2.XMLHTTP"); },
|
||||
function () { return new ActiveXObject("Msxml3.XMLHTTP"); },
|
||||
function () { return new ActiveXObject("Microsoft.XMLHTTP"); }
|
||||
];
|
||||
|
||||
function createXMLHTTPObject() {
|
||||
for (var i = 0; i < XMLHttpFactories.length; i++) {
|
||||
try {
|
||||
return XMLHttpFactories[i]();
|
||||
} catch (e) {}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// modified version of XHR script by PPK
|
||||
// http://www.quirksmode.org/js/xmlhttp.html
|
||||
// attached to qHint to allow substitution / mocking
|
||||
qHint.sendRequest = function (url, callback) {
|
||||
var req = createXMLHTTPObject();
|
||||
if (!req) {
|
||||
return;
|
||||
}
|
||||
|
||||
var method = "GET";
|
||||
req.open(method,url + "?" + (new Date().getTime()),true);
|
||||
req.onreadystatechange = function () {
|
||||
if (req.readyState != 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback(req);
|
||||
};
|
||||
|
||||
if (req.readyState == 4) {
|
||||
return;
|
||||
}
|
||||
req.send();
|
||||
};
|
||||
|
||||
var jsHintOpts = {
|
||||
"predef":["Ember",
|
||||
"jQuery",
|
||||
"$",
|
||||
"RSVP",
|
||||
"Discourse",
|
||||
"$LAB",
|
||||
"Em",
|
||||
"PreloadStore",
|
||||
"Handlebars",
|
||||
"I18n",
|
||||
"bootbox",
|
||||
"module",
|
||||
"integration",
|
||||
"test",
|
||||
"ok",
|
||||
"expect",
|
||||
"equal",
|
||||
"blank",
|
||||
"present",
|
||||
"visit",
|
||||
"count",
|
||||
"exists",
|
||||
"asyncTest",
|
||||
"find",
|
||||
"resolvingPromise",
|
||||
"sinon",
|
||||
"moment",
|
||||
"start",
|
||||
"_",
|
||||
"console",
|
||||
"alert"],
|
||||
"node" : false,
|
||||
"browser" : true,
|
||||
"boss" : true,
|
||||
"curly": false,
|
||||
"debug": false,
|
||||
"devel": false,
|
||||
"eqeqeq": true,
|
||||
"evil": true,
|
||||
"forin": false,
|
||||
"immed": false,
|
||||
"laxbreak": false,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"noempty": false,
|
||||
"nonew": false,
|
||||
"nomen": false,
|
||||
"onevar": false,
|
||||
"plusplus": false,
|
||||
"regexp": false,
|
||||
"undef": true,
|
||||
"sub": true,
|
||||
"strict": false,
|
||||
"white": false,
|
||||
"eqnull": true,
|
||||
"lastsemic": true
|
||||
};
|
||||
|
||||
<%
|
||||
def jshint(dir, remove, to_ignore)
|
||||
result = ""
|
||||
|
||||
Dir.glob(dir).each do |f|
|
||||
filename = f.sub("#{Rails.root}#{remove}", "")
|
||||
|
||||
ok = true
|
||||
to_ignore.each do |ig|
|
||||
ok = false if (filename =~ ig)
|
||||
end
|
||||
|
||||
result << "qHint('#{filename}', '/assets/#{filename}', jsHintOpts);\n" if ok
|
||||
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
%>
|
||||
|
||||
<%= jshint("#{Rails.root}/test/**/*.js",
|
||||
"/test/javascripts/",
|
||||
[/helpers\//]) %>
|
||||
|
||||
<%= jshint("#{Rails.root}/app/assets/javascripts/**/*.js",
|
||||
"/app/assets/javascripts/",
|
||||
[/external\//,
|
||||
/external_development\//,
|
||||
/external_production\//,
|
||||
/defer\//,
|
||||
/locales\//]) %>
|
@ -4,7 +4,7 @@ test('slugFor', function(){
|
||||
|
||||
var slugFor = function(args, val, text) {
|
||||
equal(Discourse.Category.slugFor(args), val, text);
|
||||
}
|
||||
};
|
||||
|
||||
slugFor({slug: 'hello'}, "hello", "It calculates the proper slug for hello");
|
||||
slugFor({id: 123, slug: ''}, "123-category", "It returns id-category for empty strings");
|
||||
|
@ -21,7 +21,7 @@ test('missingReplyCharacters', function() {
|
||||
var missingReplyCharacters = function(val, isPM, expected, message) {
|
||||
var composer = Discourse.Composer.create({ reply: val, creatingPrivateMessage: isPM });
|
||||
equal(composer.get('missingReplyCharacters'), expected, message);
|
||||
}
|
||||
};
|
||||
|
||||
missingReplyCharacters('hi', false, Discourse.SiteSettings.min_post_length - 2, 'too short public post');
|
||||
missingReplyCharacters('hi', true, Discourse.SiteSettings.min_private_message_post_length - 2, 'too short private message');
|
||||
@ -31,7 +31,7 @@ test('missingTitleCharacters', function() {
|
||||
var missingTitleCharacters = function(val, isPM, expected, message) {
|
||||
var composer = Discourse.Composer.create({ title: val, creatingPrivateMessage: isPM });
|
||||
equal(composer.get('missingTitleCharacters'), expected, message);
|
||||
}
|
||||
};
|
||||
|
||||
missingTitleCharacters('hi', false, Discourse.SiteSettings.min_topic_title_length - 2, 'too short post title');
|
||||
missingTitleCharacters('z', true, Discourse.SiteSettings.min_private_message_title_length - 1, 'too short pm title');
|
||||
|
@ -32,8 +32,9 @@
|
||||
//= require_tree ../../app/assets/javascripts/defer
|
||||
|
||||
|
||||
//= require sinon-1.7.1.js
|
||||
//= require sinon-qunit-1.0.0.js
|
||||
//= require sinon-1.7.1
|
||||
//= require sinon-qunit-1.0.0
|
||||
//= require jshint
|
||||
|
||||
//= require helpers/qunit_helpers
|
||||
//= require helpers/assertions
|
||||
@ -41,6 +42,7 @@
|
||||
//= require_tree ./fixtures
|
||||
//= require_tree .
|
||||
//= require_self
|
||||
//= require jshint_all
|
||||
|
||||
// sinon settings
|
||||
sinon.config = {
|
||||
|
Reference in New Issue
Block a user