mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 09:57:25 +08:00
DEV: introduces prettier for es6 files
This commit is contained in:
@ -1,4 +1,11 @@
|
||||
import { setting, propertyEqual, propertyNotEqual, fmt, i18n, url } from 'discourse/lib/computed';
|
||||
import {
|
||||
setting,
|
||||
propertyEqual,
|
||||
propertyNotEqual,
|
||||
fmt,
|
||||
i18n,
|
||||
url
|
||||
} from "discourse/lib/computed";
|
||||
|
||||
QUnit.module("lib:computed", {
|
||||
beforeEach() {
|
||||
@ -14,91 +21,135 @@ QUnit.module("lib:computed", {
|
||||
|
||||
QUnit.test("setting", assert => {
|
||||
var t = Em.Object.extend({
|
||||
vehicle: setting('vehicle'),
|
||||
missingProp: setting('madeUpThing')
|
||||
vehicle: setting("vehicle"),
|
||||
missingProp: setting("madeUpThing")
|
||||
}).create();
|
||||
|
||||
Discourse.SiteSettings.vehicle = "airplane";
|
||||
assert.equal(t.get('vehicle'), "airplane", "it has the value of the site setting");
|
||||
assert.ok(!t.get('missingProp'), "it is falsy when the site setting is not defined");
|
||||
assert.equal(
|
||||
t.get("vehicle"),
|
||||
"airplane",
|
||||
"it has the value of the site setting"
|
||||
);
|
||||
assert.ok(
|
||||
!t.get("missingProp"),
|
||||
"it is falsy when the site setting is not defined"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("propertyEqual", assert => {
|
||||
var t = Em.Object.extend({
|
||||
same: propertyEqual('cookies', 'biscuits')
|
||||
same: propertyEqual("cookies", "biscuits")
|
||||
}).create({
|
||||
cookies: 10,
|
||||
biscuits: 10
|
||||
});
|
||||
|
||||
assert.ok(t.get('same'), "it is true when the properties are the same");
|
||||
t.set('biscuits', 9);
|
||||
assert.ok(!t.get('same'), "it isn't true when one property is different");
|
||||
assert.ok(t.get("same"), "it is true when the properties are the same");
|
||||
t.set("biscuits", 9);
|
||||
assert.ok(!t.get("same"), "it isn't true when one property is different");
|
||||
});
|
||||
|
||||
QUnit.test("propertyNotEqual", assert => {
|
||||
var t = Em.Object.extend({
|
||||
diff: propertyNotEqual('cookies', 'biscuits')
|
||||
diff: propertyNotEqual("cookies", "biscuits")
|
||||
}).create({
|
||||
cookies: 10,
|
||||
biscuits: 10
|
||||
});
|
||||
|
||||
assert.ok(!t.get('diff'), "it isn't true when the properties are the same");
|
||||
t.set('biscuits', 9);
|
||||
assert.ok(t.get('diff'), "it is true when one property is different");
|
||||
assert.ok(!t.get("diff"), "it isn't true when the properties are the same");
|
||||
t.set("biscuits", 9);
|
||||
assert.ok(t.get("diff"), "it is true when one property is different");
|
||||
});
|
||||
|
||||
|
||||
QUnit.test("fmt", assert => {
|
||||
var t = Em.Object.extend({
|
||||
exclaimyUsername: fmt('username', "!!! %@ !!!"),
|
||||
multiple: fmt('username', 'mood', "%@ is %@")
|
||||
exclaimyUsername: fmt("username", "!!! %@ !!!"),
|
||||
multiple: fmt("username", "mood", "%@ is %@")
|
||||
}).create({
|
||||
username: 'eviltrout',
|
||||
username: "eviltrout",
|
||||
mood: "happy"
|
||||
});
|
||||
|
||||
assert.equal(t.get('exclaimyUsername'), '!!! eviltrout !!!', "it inserts the string");
|
||||
assert.equal(t.get('multiple'), "eviltrout is happy", "it inserts multiple strings");
|
||||
assert.equal(
|
||||
t.get("exclaimyUsername"),
|
||||
"!!! eviltrout !!!",
|
||||
"it inserts the string"
|
||||
);
|
||||
assert.equal(
|
||||
t.get("multiple"),
|
||||
"eviltrout is happy",
|
||||
"it inserts multiple strings"
|
||||
);
|
||||
|
||||
t.set('username', 'codinghorror');
|
||||
assert.equal(t.get('multiple'), "codinghorror is happy", "it supports changing properties");
|
||||
t.set('mood', 'ecstatic');
|
||||
assert.equal(t.get('multiple'), "codinghorror is ecstatic", "it supports changing another property");
|
||||
t.set("username", "codinghorror");
|
||||
assert.equal(
|
||||
t.get("multiple"),
|
||||
"codinghorror is happy",
|
||||
"it supports changing properties"
|
||||
);
|
||||
t.set("mood", "ecstatic");
|
||||
assert.equal(
|
||||
t.get("multiple"),
|
||||
"codinghorror is ecstatic",
|
||||
"it supports changing another property"
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
QUnit.test("i18n", assert => {
|
||||
var t = Em.Object.extend({
|
||||
exclaimyUsername: i18n('username', "!!! %@ !!!"),
|
||||
multiple: i18n('username', 'mood', "%@ is %@")
|
||||
exclaimyUsername: i18n("username", "!!! %@ !!!"),
|
||||
multiple: i18n("username", "mood", "%@ is %@")
|
||||
}).create({
|
||||
username: 'eviltrout',
|
||||
username: "eviltrout",
|
||||
mood: "happy"
|
||||
});
|
||||
|
||||
assert.equal(t.get('exclaimyUsername'), '%@ translated: !!! eviltrout !!!', "it inserts the string and then translates");
|
||||
assert.equal(t.get('multiple'), "%@ translated: eviltrout is happy", "it inserts multiple strings and then translates");
|
||||
assert.equal(
|
||||
t.get("exclaimyUsername"),
|
||||
"%@ translated: !!! eviltrout !!!",
|
||||
"it inserts the string and then translates"
|
||||
);
|
||||
assert.equal(
|
||||
t.get("multiple"),
|
||||
"%@ translated: eviltrout is happy",
|
||||
"it inserts multiple strings and then translates"
|
||||
);
|
||||
|
||||
t.set('username', 'codinghorror');
|
||||
assert.equal(t.get('multiple'), "%@ translated: codinghorror is happy", "it supports changing properties");
|
||||
t.set('mood', 'ecstatic');
|
||||
assert.equal(t.get('multiple'), "%@ translated: codinghorror is ecstatic", "it supports changing another property");
|
||||
t.set("username", "codinghorror");
|
||||
assert.equal(
|
||||
t.get("multiple"),
|
||||
"%@ translated: codinghorror is happy",
|
||||
"it supports changing properties"
|
||||
);
|
||||
t.set("mood", "ecstatic");
|
||||
assert.equal(
|
||||
t.get("multiple"),
|
||||
"%@ translated: codinghorror is ecstatic",
|
||||
"it supports changing another property"
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
QUnit.test("url", assert => {
|
||||
var t, testClass;
|
||||
|
||||
testClass = Em.Object.extend({
|
||||
userUrl: url('username', "/u/%@")
|
||||
userUrl: url("username", "/u/%@")
|
||||
});
|
||||
|
||||
t = testClass.create({ username: 'eviltrout' });
|
||||
assert.equal(t.get('userUrl'), "/u/eviltrout", "it supports urls without a prefix");
|
||||
t = testClass.create({ username: "eviltrout" });
|
||||
assert.equal(
|
||||
t.get("userUrl"),
|
||||
"/u/eviltrout",
|
||||
"it supports urls without a prefix"
|
||||
);
|
||||
|
||||
Discourse.BaseUri = "/prefixed";
|
||||
t = testClass.create({ username: 'eviltrout' });
|
||||
assert.equal(t.get('userUrl'), "/prefixed/u/eviltrout", "it supports urls with a prefix");
|
||||
t = testClass.create({ username: "eviltrout" });
|
||||
assert.equal(
|
||||
t.get("userUrl"),
|
||||
"/prefixed/u/eviltrout",
|
||||
"it supports urls with a prefix"
|
||||
);
|
||||
});
|
||||
|
Reference in New Issue
Block a user