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-08-07 15:08:27 -04:00
|
|
|
module("lib:category-link");
|
2015-01-20 11:36:28 -05:00
|
|
|
|
2015-08-10 17:11:27 -04:00
|
|
|
import parseHTML from 'helpers/parse-html';
|
2015-01-20 11:36:28 -05:00
|
|
|
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
|
|
|
|
|
|
|
test("categoryBadge without a category", function() {
|
|
|
|
blank(categoryBadgeHTML(), "it returns no HTML");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Regular categoryBadge", function() {
|
2015-09-03 16:55:55 -04:00
|
|
|
const store = createStore();
|
|
|
|
const category = store.createRecord('category', {
|
|
|
|
name: 'hello',
|
|
|
|
id: 123,
|
|
|
|
description_text: 'cool description',
|
|
|
|
color: 'ff0',
|
|
|
|
text_color: 'f00'
|
|
|
|
});
|
|
|
|
const tag = parseHTML(categoryBadgeHTML(category))[0];
|
2015-01-20 11:36:28 -05:00
|
|
|
|
2015-01-29 01:57:34 -05: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-20 11:36:28 -05:00
|
|
|
|
2015-09-03 16:55:55 -04:00
|
|
|
const label = tag.children[1];
|
2015-01-20 11:36:28 -05:00
|
|
|
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() {
|
2015-09-03 16:55:55 -04:00
|
|
|
const store = createStore();
|
|
|
|
const noColor = store.createRecord('category', { name: 'hello', id: 123 });
|
|
|
|
const tag = parseHTML(categoryBadgeHTML(noColor))[0];
|
2015-01-20 11:36:28 -05:00
|
|
|
|
|
|
|
blank(tag.attributes.style, "it has no color style because there are no colors");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("allowUncategorized", function() {
|
2015-09-03 16:55:55 -04:00
|
|
|
const store = createStore();
|
|
|
|
const uncategorized = store.createRecord('category', {name: 'uncategorized', id: 345});
|
2015-01-20 11:36:28 -05:00
|
|
|
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");
|
|
|
|
});
|