2015-08-08 03:08:27 +08:00
|
|
|
module("lib:category-link");
|
2015-01-21 00:36:28 +08:00
|
|
|
|
2015-08-11 05:11:27 +08:00
|
|
|
import parseHTML from 'helpers/parse-html';
|
2015-01-21 00:36:28 +08:00
|
|
|
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
|
|
|
|
|
|
|
test("categoryBadge without a category", function() {
|
|
|
|
blank(categoryBadgeHTML(), "it returns no HTML");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Regular categoryBadge", function() {
|
|
|
|
var category = Discourse.Category.create({
|
|
|
|
name: 'hello',
|
|
|
|
id: 123,
|
|
|
|
description_text: 'cool description',
|
|
|
|
color: 'ff0',
|
|
|
|
text_color: 'f00'
|
|
|
|
}),
|
|
|
|
tag = parseHTML(categoryBadgeHTML(category))[0];
|
|
|
|
|
2015-01-29 14:57:34 +08:00
|
|
|
equal(tag.name, 'a', 'it creates a `a` wrapper tag');
|
|
|
|
equal(tag.attributes['class'].trim(), 'badge-wrapper', 'it has the correct class');
|
2015-01-21 00:36:28 +08:00
|
|
|
|
|
|
|
var label = tag.children[1];
|
|
|
|
equal(label.attributes.title, 'cool description', 'it has the correct title');
|
|
|
|
|
|
|
|
equal(label.children[0].data, 'hello', 'it has the category name');
|
|
|
|
});
|
|
|
|
|
|
|
|
test("undefined color", function() {
|
|
|
|
var noColor = Discourse.Category.create({ name: 'hello', id: 123 }),
|
|
|
|
tag = parseHTML(categoryBadgeHTML(noColor))[0];
|
|
|
|
|
|
|
|
blank(tag.attributes.style, "it has no color style because there are no colors");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("allowUncategorized", function() {
|
|
|
|
var uncategorized = Discourse.Category.create({name: 'uncategorized', id: 345});
|
|
|
|
sandbox.stub(Discourse.Site, 'currentProp').withArgs('uncategorized_category_id').returns(345);
|
|
|
|
|
|
|
|
blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default");
|
|
|
|
present(categoryBadgeHTML(uncategorized, {allowUncategorized: true}), "it returns HTML");
|
|
|
|
});
|