2013-10-09 12:24:33 -04:00
|
|
|
module("Discourse.Computed", {
|
|
|
|
setup: function() {
|
|
|
|
sinon.stub(I18n, "t", function(scope) {
|
|
|
|
return "%@ translated: " + scope;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
teardown: function() {
|
|
|
|
I18n.t.restore();
|
|
|
|
}
|
|
|
|
});
|
2013-07-11 19:35:52 -04:00
|
|
|
|
|
|
|
var testClass = Em.Object.extend({
|
|
|
|
same: Discourse.computed.propertyEqual('cookies', 'biscuits'),
|
2013-07-12 16:18:32 -04:00
|
|
|
diff: Discourse.computed.propertyNotEqual('cookies', 'biscuits'),
|
2013-07-11 19:35:52 -04:00
|
|
|
exclaimyUsername: Discourse.computed.fmt('username', "!!! %@ !!!"),
|
|
|
|
multiple: Discourse.computed.fmt('username', 'mood', "%@ is %@"),
|
2013-10-09 12:24:33 -04:00
|
|
|
translatedExclaimyUsername: Discourse.computed.i18n('username', "!!! %@ !!!"),
|
|
|
|
translatedMultiple: Discourse.computed.i18n('username', 'mood', "%@ is %@"),
|
2013-07-11 19:35:52 -04:00
|
|
|
userUrl: Discourse.computed.url('username', "/users/%@")
|
|
|
|
});
|
|
|
|
|
|
|
|
test("propertyEqual", function() {
|
|
|
|
var t = testClass.create({
|
|
|
|
cookies: 10,
|
|
|
|
biscuits: 10
|
|
|
|
});
|
|
|
|
|
|
|
|
ok(t.get('same'), "it is true when the properties are the same");
|
|
|
|
t.set('biscuits', 9);
|
|
|
|
ok(!t.get('same'), "it isn't true when one property is different");
|
|
|
|
});
|
|
|
|
|
2013-07-12 16:18:32 -04:00
|
|
|
test("propertyNotEqual", function() {
|
|
|
|
var t = testClass.create({
|
|
|
|
cookies: 10,
|
|
|
|
biscuits: 10
|
|
|
|
});
|
|
|
|
|
|
|
|
ok(!t.get('diff'), "it isn't true when the properties are the same");
|
|
|
|
t.set('biscuits', 9);
|
|
|
|
ok(t.get('diff'), "it is true when one property is different");
|
|
|
|
});
|
|
|
|
|
2013-07-11 19:35:52 -04:00
|
|
|
|
|
|
|
test("fmt", function() {
|
|
|
|
var t = testClass.create({
|
|
|
|
username: 'eviltrout',
|
|
|
|
mood: "happy"
|
|
|
|
});
|
|
|
|
|
|
|
|
equal(t.get('exclaimyUsername'), '!!! eviltrout !!!', "it inserts the string");
|
2013-10-09 12:24:33 -04:00
|
|
|
equal(t.get('multiple'), "eviltrout is happy", "it inserts multiple strings");
|
2013-07-11 19:35:52 -04:00
|
|
|
|
|
|
|
t.set('username', 'codinghorror');
|
2013-10-09 12:24:33 -04:00
|
|
|
equal(t.get('multiple'), "codinghorror is happy", "it supports changing properties");
|
2013-07-11 19:35:52 -04:00
|
|
|
t.set('mood', 'ecstatic');
|
2013-10-09 12:24:33 -04:00
|
|
|
equal(t.get('multiple'), "codinghorror is ecstatic", "it supports changing another property");
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test("i18n", function() {
|
|
|
|
var t = testClass.create({
|
|
|
|
username: 'eviltrout',
|
|
|
|
mood: "happy"
|
|
|
|
});
|
|
|
|
|
|
|
|
equal(t.get('translatedExclaimyUsername'), '%@ translated: !!! eviltrout !!!', "it inserts the string and then translates");
|
|
|
|
equal(t.get('translatedMultiple'), "%@ translated: eviltrout is happy", "it inserts multiple strings and then translates");
|
|
|
|
|
|
|
|
t.set('username', 'codinghorror');
|
|
|
|
equal(t.get('translatedMultiple'), "%@ translated: codinghorror is happy", "it supports changing properties");
|
|
|
|
t.set('mood', 'ecstatic');
|
|
|
|
equal(t.get('translatedMultiple'), "%@ translated: codinghorror is ecstatic", "it supports changing another property");
|
2013-07-11 19:35:52 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test("url without a prefix", function() {
|
|
|
|
var t = testClass.create({ username: 'eviltrout' });
|
|
|
|
equal(t.get('userUrl'), "/users/eviltrout");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("url with a prefix", function() {
|
|
|
|
Discourse.BaseUri = "/prefixed/";
|
|
|
|
var t = testClass.create({ username: 'eviltrout' });
|
|
|
|
equal(t.get('userUrl'), "/prefixed/users/eviltrout");
|
2013-10-09 12:24:33 -04:00
|
|
|
});
|