mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Discourse.Site.instance now returns a singleton object; add js test for NavItem
This commit is contained in:
parent
3c7eb3a4e8
commit
014db4c2e9
2 changed files with 25 additions and 1 deletions
|
@ -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) {
|
||||
|
|
22
test/javascripts/models/nav_item_test.js
Normal file
22
test/javascripts/models/nav_item_test.js
Normal 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");
|
||||
});
|
Loading…
Reference in a new issue