Discourse.Site.instance now returns a singleton object; add js test for NavItem

This commit is contained in:
Neil Lalonde 2013-06-17 13:04:54 -04:00
parent 3c7eb3a4e8
commit 014db4c2e9
2 changed files with 25 additions and 1 deletions

View file

@ -35,7 +35,9 @@ Discourse.Site = Discourse.Model.extend({
Discourse.Site.reopenClass({
instance: function() {
return Discourse.Site.create(PreloadStore.get('site'));
if ( this._site ) return this._site;
this._site = Discourse.Site.create(PreloadStore.get('site'));
return this._site;
},
create: function(obj) {

View file

@ -0,0 +1,22 @@
/*global module:true test:true ok:true visit:true expect:true exists:true count:true equal:true */
module("Discourse.NavItem", {
setup: function() {
this.site = Discourse.Site.instance();
this.originalCategories = Discourse.Site.instance().get('categories') || [];
this.site.set('categories', this.originalCategories.concat( [Discourse.Category.create({name: '确实是这样', id: 343434})] ));
},
teardown: function() {
this.site.set('categories', this.originalCategories);
}
});
test('href', function(){
expect(4);
equal(Discourse.NavItem.fromText('latest', {}).get('href'), '/latest', "latest");
equal(Discourse.NavItem.fromText('categories', {}).get('href'), '/categories', "categories");
equal(Discourse.NavItem.fromText('category/bug', {}).get('href'), '/category/bug', "English category name");
equal(Discourse.NavItem.fromText('category/确实是这样', {}).get('href'), '/category/343434-category', "Chinese category name");
});