ES6ify some of the remaining files
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import avatarTemplate from 'discourse/lib/avatar-template';
|
||||
|
||||
module('avatarTemplate');
|
||||
module('lib:avatar-template');
|
||||
|
||||
test("avatarTemplate", function(){
|
||||
var oldCDN = Discourse.CDN;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module("categoryBadgeHTML");
|
||||
module("lib:category-link");
|
||||
|
||||
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ var windowOpen,
|
||||
win,
|
||||
redirectTo;
|
||||
|
||||
module("ClickTrack", {
|
||||
module("lib:click-track", {
|
||||
setup: function() {
|
||||
|
||||
// Prevent any of these tests from navigating away
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
module("Discourse.Computed", {
|
||||
import { setting, propertyEqual, propertyNotEqual, fmt, i18n, url } from 'discourse/lib/computed';
|
||||
|
||||
module("lib:computed", {
|
||||
setup: function() {
|
||||
sandbox.stub(I18n, "t", function(scope) {
|
||||
return "%@ translated: " + scope;
|
||||
@@ -12,8 +14,8 @@ module("Discourse.Computed", {
|
||||
|
||||
test("setting", function() {
|
||||
var t = Em.Object.extend({
|
||||
vehicle: Discourse.computed.setting('vehicle'),
|
||||
missingProp: Discourse.computed.setting('madeUpThing')
|
||||
vehicle: setting('vehicle'),
|
||||
missingProp: setting('madeUpThing')
|
||||
}).create();
|
||||
|
||||
Discourse.SiteSettings.vehicle = "airplane";
|
||||
@@ -23,7 +25,7 @@ test("setting", function() {
|
||||
|
||||
test("propertyEqual", function() {
|
||||
var t = Em.Object.extend({
|
||||
same: Discourse.computed.propertyEqual('cookies', 'biscuits')
|
||||
same: propertyEqual('cookies', 'biscuits')
|
||||
}).create({
|
||||
cookies: 10,
|
||||
biscuits: 10
|
||||
@@ -36,7 +38,7 @@ test("propertyEqual", function() {
|
||||
|
||||
test("propertyNotEqual", function() {
|
||||
var t = Em.Object.extend({
|
||||
diff: Discourse.computed.propertyNotEqual('cookies', 'biscuits')
|
||||
diff: propertyNotEqual('cookies', 'biscuits')
|
||||
}).create({
|
||||
cookies: 10,
|
||||
biscuits: 10
|
||||
@@ -50,8 +52,8 @@ test("propertyNotEqual", function() {
|
||||
|
||||
test("fmt", function() {
|
||||
var t = Em.Object.extend({
|
||||
exclaimyUsername: Discourse.computed.fmt('username', "!!! %@ !!!"),
|
||||
multiple: Discourse.computed.fmt('username', 'mood', "%@ is %@")
|
||||
exclaimyUsername: fmt('username', "!!! %@ !!!"),
|
||||
multiple: fmt('username', 'mood', "%@ is %@")
|
||||
}).create({
|
||||
username: 'eviltrout',
|
||||
mood: "happy"
|
||||
@@ -69,8 +71,8 @@ test("fmt", function() {
|
||||
|
||||
test("i18n", function() {
|
||||
var t = Em.Object.extend({
|
||||
exclaimyUsername: Discourse.computed.i18n('username', "!!! %@ !!!"),
|
||||
multiple: Discourse.computed.i18n('username', 'mood', "%@ is %@")
|
||||
exclaimyUsername: i18n('username', "!!! %@ !!!"),
|
||||
multiple: i18n('username', 'mood', "%@ is %@")
|
||||
}).create({
|
||||
username: 'eviltrout',
|
||||
mood: "happy"
|
||||
@@ -90,7 +92,7 @@ test("url", function() {
|
||||
var t, testClass;
|
||||
|
||||
testClass = Em.Object.extend({
|
||||
userUrl: Discourse.computed.url('username', "/users/%@")
|
||||
userUrl: url('username', "/users/%@")
|
||||
});
|
||||
|
||||
t = testClass.create({ username: 'eviltrout' });
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
var clock;
|
||||
|
||||
module("Discourse.Formatter", {
|
||||
import { relativeAge, autoUpdatingRelativeAge, updateRelativeAge, breakUp, number } from 'discourse/lib/formatter';
|
||||
|
||||
module("lib:formatter", {
|
||||
setup: function() {
|
||||
clock = sinon.useFakeTimers(new Date(2012,11,31,12,0).getTime());
|
||||
},
|
||||
@@ -17,7 +19,7 @@ var mins_ago = function(mins){
|
||||
};
|
||||
|
||||
var formatMins = function(mins) {
|
||||
return Discourse.Formatter.relativeAge(mins_ago(mins), {format: format, leaveAgo: leaveAgo});
|
||||
return relativeAge(mins_ago(mins), {format: format, leaveAgo: leaveAgo});
|
||||
};
|
||||
|
||||
var formatHours = function(hours) {
|
||||
@@ -141,26 +143,24 @@ test("formating tiny dates", function() {
|
||||
Discourse.SiteSettings.relative_date_duration = originalValue;
|
||||
});
|
||||
|
||||
module("Discourse.Formatter");
|
||||
|
||||
test("autoUpdatingRelativeAge", function() {
|
||||
var d = moment().subtract(1, 'day').toDate();
|
||||
|
||||
var $elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d));
|
||||
var $elem = $(autoUpdatingRelativeAge(d));
|
||||
equal($elem.data('format'), "tiny");
|
||||
equal($elem.data('time'), d.getTime());
|
||||
equal($elem.attr('title'), undefined);
|
||||
|
||||
$elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d, {title: true}));
|
||||
$elem = $(autoUpdatingRelativeAge(d, {title: true}));
|
||||
equal($elem.attr('title'), moment(d).longDate());
|
||||
|
||||
$elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d,{format: 'medium', title: true, leaveAgo: true}));
|
||||
$elem = $(autoUpdatingRelativeAge(d,{format: 'medium', title: true, leaveAgo: true}));
|
||||
equal($elem.data('format'), "medium-with-ago");
|
||||
equal($elem.data('time'), d.getTime());
|
||||
equal($elem.attr('title'), moment(d).longDate());
|
||||
equal($elem.html(), '1 day ago');
|
||||
|
||||
$elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d,{format: 'medium'}));
|
||||
$elem = $(autoUpdatingRelativeAge(d,{format: 'medium'}));
|
||||
equal($elem.data('format'), "medium");
|
||||
equal($elem.data('time'), d.getTime());
|
||||
equal($elem.attr('title'), undefined);
|
||||
@@ -170,25 +170,25 @@ test("autoUpdatingRelativeAge", function() {
|
||||
test("updateRelativeAge", function(){
|
||||
|
||||
var d = new Date();
|
||||
var $elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d));
|
||||
var $elem = $(autoUpdatingRelativeAge(d));
|
||||
$elem.data('time', d.getTime() - 2 * 60 * 1000);
|
||||
|
||||
Discourse.Formatter.updateRelativeAge($elem);
|
||||
updateRelativeAge($elem);
|
||||
|
||||
equal($elem.html(), "2m");
|
||||
|
||||
d = new Date();
|
||||
$elem = $(Discourse.Formatter.autoUpdatingRelativeAge(d, {format: 'medium', leaveAgo: true}));
|
||||
$elem = $(autoUpdatingRelativeAge(d, {format: 'medium', leaveAgo: true}));
|
||||
$elem.data('time', d.getTime() - 2 * 60 * 1000);
|
||||
|
||||
Discourse.Formatter.updateRelativeAge($elem);
|
||||
updateRelativeAge($elem);
|
||||
|
||||
equal($elem.html(), "2 mins ago");
|
||||
});
|
||||
|
||||
test("breakUp", function(){
|
||||
|
||||
var b = function(s,hint){ return Discourse.Formatter.breakUp(s,hint); };
|
||||
var b = function(s,hint){ return breakUp(s,hint); };
|
||||
|
||||
equal(b("hello"), "hello");
|
||||
equal(b("helloworld"), "helloworld");
|
||||
@@ -201,9 +201,9 @@ test("breakUp", function(){
|
||||
});
|
||||
|
||||
test("number", function() {
|
||||
equal(Discourse.Formatter.number(123), "123", "it returns a string version of the number");
|
||||
equal(Discourse.Formatter.number("123"), "123", "it works with a string command");
|
||||
equal(Discourse.Formatter.number(NaN), "0", "it returns 0 for NaN");
|
||||
equal(Discourse.Formatter.number(3333), "3.3k", "it abbreviates thousands");
|
||||
equal(Discourse.Formatter.number(2499999), "2.5M", "it abbreviates millions");
|
||||
equal(number(123), "123", "it returns a string version of the number");
|
||||
equal(number("123"), "123", "it works with a string command");
|
||||
equal(number(NaN), "0", "it returns 0 for NaN");
|
||||
equal(number(3333), "3.3k", "it abbreviates thousands");
|
||||
equal(number(2499999), "2.5M", "it abbreviates millions");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user