2015-09-03 16:55:55 -04:00
|
|
|
import createStore from 'helpers/create-store';
|
2015-08-11 12:27:07 -04:00
|
|
|
import { blank, present } from 'helpers/qunit-helpers';
|
|
|
|
|
2015-09-03 16:55:55 -04:00
|
|
|
module("model:site");
|
2013-06-17 11:38:30 -04:00
|
|
|
|
2013-10-29 13:01:42 -04:00
|
|
|
test('create', function() {
|
|
|
|
ok(Discourse.Site.create(), 'it can create with no parameters');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('instance', function() {
|
2015-09-03 16:55:55 -04:00
|
|
|
const site = Discourse.Site.current();
|
2013-06-17 11:38:30 -04:00
|
|
|
|
|
|
|
present(site, "We have a current site singleton");
|
|
|
|
present(site.get('categories'), "The instance has a list of categories");
|
|
|
|
present(site.get('flagTypes'), "The instance has a list of flag types");
|
2013-07-12 16:18:32 -04:00
|
|
|
present(site.get('trustLevels'), "The instance has a list of trust levels");
|
2013-06-17 11:38:30 -04:00
|
|
|
|
2013-10-23 13:29:20 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('create categories', function() {
|
2015-09-03 16:55:55 -04:00
|
|
|
const store = createStore();
|
|
|
|
const site = store.createRecord('site', {
|
2013-10-23 13:29:20 -04:00
|
|
|
categories: [{ id: 1234, name: 'Test'},
|
|
|
|
{ id: 3456, name: 'Test Subcategory', parent_category_id: 1234},
|
2015-09-03 16:55:55 -04:00
|
|
|
{ id: 3458, name: 'Invalid Subcategory', parent_category_id: 6666}]
|
2013-10-23 13:29:20 -04:00
|
|
|
});
|
|
|
|
|
2015-09-03 16:55:55 -04:00
|
|
|
const categories = site.get('categories');
|
2015-07-09 22:09:43 -04:00
|
|
|
site.get('sortedCategories');
|
2013-10-23 13:29:20 -04:00
|
|
|
|
|
|
|
present(categories, "The categories are present");
|
|
|
|
equal(categories.length, 3, "it loaded all three categories");
|
|
|
|
|
2015-09-03 16:55:55 -04:00
|
|
|
const parent = categories.findBy('id', 1234);
|
2013-10-23 13:29:20 -04:00
|
|
|
present(parent, "it loaded the parent category");
|
|
|
|
blank(parent.get('parentCategory'), 'it has no parent category');
|
|
|
|
|
2015-09-03 16:55:55 -04:00
|
|
|
const subcategory = categories.findBy('id', 3456);
|
2013-10-23 13:29:20 -04:00
|
|
|
present(subcategory, "it loaded the subcategory");
|
|
|
|
equal(subcategory.get('parentCategory'), parent, "it has associated the child with the parent");
|
|
|
|
|
2015-07-09 22:09:43 -04:00
|
|
|
// remove invalid category and child
|
|
|
|
categories.removeObject(categories[2]);
|
|
|
|
categories.removeObject(categories[1]);
|
|
|
|
|
|
|
|
equal(categories.length, site.get('categoriesByCount').length, "categories by count should change on removal");
|
|
|
|
equal(categories.length, site.get('sortedCategories').length, "sorted categories should change on removal");
|
|
|
|
|
2014-07-30 18:56:01 -04:00
|
|
|
});
|