mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:11:08 +08:00
FEATURE: add slug geneartion options
This commit is contained in:

committed by
fantasticfears

parent
2344aa2fdd
commit
b772ff6e13
@ -9,6 +9,7 @@ test('slugFor', function(){
|
||||
slugFor(Discourse.Category.create({slug: 'hello'}), "hello", "It calculates the proper slug for hello");
|
||||
slugFor(Discourse.Category.create({id: 123, slug: ''}), "123-category", "It returns id-category for empty strings");
|
||||
slugFor(Discourse.Category.create({id: 456}), "456-category", "It returns id-category for undefined slugs");
|
||||
slugFor(Discourse.Category.create({slug: '熱帶風暴畫眉'}), "熱帶風暴畫眉", "It can be non english characters");
|
||||
|
||||
var parentCategory = Discourse.Category.create({id: 345, slug: 'darth'});
|
||||
slugFor(Discourse.Category.create({slug: 'luke', parentCategory: parentCategory}),
|
||||
@ -27,16 +28,45 @@ test('slugFor', function(){
|
||||
|
||||
|
||||
test('findBySlug', function() {
|
||||
expect(6);
|
||||
|
||||
var darth = Discourse.Category.create({id: 1, slug: 'darth'}),
|
||||
luke = Discourse.Category.create({id: 2, slug: 'luke', parentCategory: darth}),
|
||||
categoryList = [darth, luke];
|
||||
luke = Discourse.Category.create({id: 2, slug: 'luke', parentCategory: darth}),
|
||||
hurricane = Discourse.Category.create({id: 3, slug: '熱帶風暴畫眉'}),
|
||||
newsFeed = Discourse.Category.create({id: 4, slug: '뉴스피드', parentCategory: hurricane}),
|
||||
time = Discourse.Category.create({id: 5, slug: '时间', parentCategory: darth}),
|
||||
bah = Discourse.Category.create({id: 6, slug: 'bah', parentCategory: hurricane}),
|
||||
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
||||
|
||||
sandbox.stub(Discourse.Category, 'list').returns(categoryList);
|
||||
|
||||
equal(Discourse.Category.findBySlug('darth'), darth, 'we can find a parent category');
|
||||
equal(Discourse.Category.findBySlug('luke', 'darth'), luke, 'we can find a child with parent');
|
||||
blank(Discourse.Category.findBySlug('luke'), 'luke is blank without the parent');
|
||||
blank(Discourse.Category.findBySlug('luke', 'leia'), 'luke is blank with an incorrect parent');
|
||||
deepEqual(Discourse.Category.findBySlug('darth'), darth, 'we can find a category');
|
||||
deepEqual(Discourse.Category.findBySlug('luke', 'darth'), luke, 'we can find the other category with parent category');
|
||||
deepEqual(Discourse.Category.findBySlug('熱帶風暴畫眉'), hurricane, 'we can find a category with CJK slug');
|
||||
deepEqual(Discourse.Category.findBySlug('뉴스피드', '熱帶風暴畫眉'), newsFeed, 'we can find a category with CJK slug whose parent slug is also CJK');
|
||||
deepEqual(Discourse.Category.findBySlug('时间', 'darth'), time, 'we can find a category with CJK slug whose parent slug is english');
|
||||
deepEqual(Discourse.Category.findBySlug('bah', '熱帶風暴畫眉'), bah, 'we can find a category with english slug whose parent slug is CJK');
|
||||
});
|
||||
|
||||
test('findSingleBySlug', function() {
|
||||
expect(6);
|
||||
|
||||
var darth = Discourse.Category.create({id: 1, slug: 'darth'}),
|
||||
luke = Discourse.Category.create({id: 2, slug: 'luke', parentCategory: darth}),
|
||||
hurricane = Discourse.Category.create({id: 3, slug: '熱帶風暴畫眉'}),
|
||||
newsFeed = Discourse.Category.create({id: 4, slug: '뉴스피드', parentCategory: hurricane}),
|
||||
time = Discourse.Category.create({id: 5, slug: '时间', parentCategory: darth}),
|
||||
bah = Discourse.Category.create({id: 6, slug: 'bah', parentCategory: hurricane}),
|
||||
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
||||
|
||||
sandbox.stub(Discourse.Category, 'list').returns(categoryList);
|
||||
|
||||
deepEqual(Discourse.Category.findSingleBySlug('darth'), darth, 'we can find a category');
|
||||
deepEqual(Discourse.Category.findSingleBySlug('darth/luke'), luke, 'we can find the other category with parent category');
|
||||
deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉'), hurricane, 'we can find a category with CJK slug');
|
||||
deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉/뉴스피드'), newsFeed, 'we can find a category with CJK slug whose parent slug is also CJK');
|
||||
deepEqual(Discourse.Category.findSingleBySlug('darth/时间'), time, 'we can find a category with CJK slug whose parent slug is english');
|
||||
deepEqual(Discourse.Category.findSingleBySlug('熱帶風暴畫眉/bah'), bah, 'we can find a category with english slug whose parent slug is CJK');
|
||||
});
|
||||
|
||||
test('findByIds', function() {
|
||||
|
Reference in New Issue
Block a user