mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 03:44:47 +08:00
ES6ify some of the remaining files
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
moduleFor('controller:admin-user-badges', 'Admin User Badges Controller', {
|
||||
moduleFor('controller:admin-user-badges', {
|
||||
needs: ['controller:adminUser']
|
||||
});
|
||||
|
||||
|
@ -15,7 +15,7 @@ function setTemplates(lookupTemplateStrings) {
|
||||
});
|
||||
}
|
||||
|
||||
module("Resolver", {
|
||||
module("lib:resolver", {
|
||||
setup: function() {
|
||||
originalTemplates = Ember.TEMPLATES;
|
||||
Ember.TEMPLATES = {};
|
||||
|
@ -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");
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
module("SelectedPostsCount");
|
||||
module("mixin:selected-posts-count");
|
||||
|
||||
import SelectedPostsCount from 'discourse/mixins/selected-posts-count';
|
||||
import Topic from 'discourse/models/topic';
|
||||
|
@ -1,8 +1,10 @@
|
||||
module("Discourse.Singleton");
|
||||
import Singleton from 'discourse/mixins/singleton';
|
||||
|
||||
module("mixin:singleton");
|
||||
|
||||
test("current", function() {
|
||||
var DummyModel = Ember.Object.extend({});
|
||||
DummyModel.reopenClass(Discourse.Singleton);
|
||||
DummyModel.reopenClass(Singleton);
|
||||
|
||||
var current = DummyModel.current();
|
||||
present(current, 'current returns the current instance');
|
||||
@ -12,7 +14,7 @@ test("current", function() {
|
||||
|
||||
test("currentProp reading", function() {
|
||||
var DummyModel = Ember.Object.extend({});
|
||||
DummyModel.reopenClass(Discourse.Singleton);
|
||||
DummyModel.reopenClass(Singleton);
|
||||
var current = DummyModel.current();
|
||||
|
||||
blank(DummyModel.currentProp('evil'), 'by default attributes are blank');
|
||||
@ -22,7 +24,7 @@ test("currentProp reading", function() {
|
||||
|
||||
test("currentProp writing", function() {
|
||||
var DummyModel = Ember.Object.extend({});
|
||||
DummyModel.reopenClass(Discourse.Singleton);
|
||||
DummyModel.reopenClass(Singleton);
|
||||
|
||||
blank(DummyModel.currentProp('adventure'), 'by default attributes are blank');
|
||||
var result = DummyModel.currentProp('adventure', 'time');
|
||||
@ -38,7 +40,7 @@ test("currentProp writing", function() {
|
||||
|
||||
test("createCurrent", function() {
|
||||
var Shoe = Ember.Object.extend({});
|
||||
Shoe.reopenClass(Discourse.Singleton, {
|
||||
Shoe.reopenClass(Singleton, {
|
||||
createCurrent: function() {
|
||||
return Shoe.create({toes: 5});
|
||||
}
|
||||
@ -50,7 +52,7 @@ test("createCurrent", function() {
|
||||
|
||||
test("createCurrent that returns null", function() {
|
||||
var Missing = Ember.Object.extend({});
|
||||
Missing.reopenClass(Discourse.Singleton, {
|
||||
Missing.reopenClass(Singleton, {
|
||||
createCurrent: function() {
|
||||
return null;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import Session from "discourse/models/session";
|
||||
|
||||
module("Discourse.Session");
|
||||
module("model:session");
|
||||
|
||||
test('highestSeenByTopic', function() {
|
||||
var session = Session.current();
|
||||
const session = Session.current();
|
||||
deepEqual(session.get('highestSeenByTopic'), {}, "by default it returns an empty object");
|
||||
});
|
||||
|
@ -79,6 +79,7 @@ var origDebounce = Ember.run.debounce,
|
||||
createPretendServer = require('helpers/create-pretender', null, null, false).default,
|
||||
fixtures = require('fixtures/site_fixtures', null, null, false).default,
|
||||
flushMap = require('discourse/models/store', null, null, false).flushMap,
|
||||
ScrollingDOMMethods = require('discourse/mixins/scrolling', null, null, false).ScrollingDOMMethods,
|
||||
server;
|
||||
|
||||
function dup(obj) {
|
||||
@ -92,6 +93,7 @@ QUnit.testStart(function(ctx) {
|
||||
Discourse.SiteSettings = dup(Discourse.SiteSettingsOriginal);
|
||||
Discourse.BaseUri = "/";
|
||||
Discourse.BaseUrl = "localhost";
|
||||
Discourse.Session.resetCurrent();
|
||||
Discourse.User.resetCurrent();
|
||||
Discourse.Site.resetCurrent(Discourse.Site.create(dup(fixtures['site.json'].site)));
|
||||
|
||||
@ -103,8 +105,8 @@ QUnit.testStart(function(ctx) {
|
||||
PreloadStore.reset();
|
||||
|
||||
window.sandbox = sinon.sandbox.create();
|
||||
window.sandbox.stub(Discourse.ScrollingDOMMethods, "bindOnScroll");
|
||||
window.sandbox.stub(Discourse.ScrollingDOMMethods, "unbindOnScroll");
|
||||
window.sandbox.stub(ScrollingDOMMethods, "bindOnScroll");
|
||||
window.sandbox.stub(ScrollingDOMMethods, "unbindOnScroll");
|
||||
|
||||
// Don't debounce in test unless we're testing debouncing
|
||||
if (ctx.module.indexOf('debounce') === -1) {
|
||||
|
Reference in New Issue
Block a user