2015-09-04 04:55:55 +08:00
|
|
|
import createStore from 'helpers/create-store';
|
2015-08-12 00:27:07 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.module("lib:category-link");
|
2015-01-21 00:36:28 +08:00
|
|
|
|
2017-12-15 12:58:20 +08:00
|
|
|
import parseHTML from 'discourse/helpers/parse-html';
|
2015-01-21 00:36:28 +08:00
|
|
|
import { categoryBadgeHTML } from "discourse/helpers/category-link";
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("categoryBadge without a category", assert => {
|
|
|
|
assert.blank(categoryBadgeHTML(), "it returns no HTML");
|
2015-01-21 00:36:28 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("Regular categoryBadge", assert => {
|
2015-09-04 04:55:55 +08: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-21 00:36:28 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(tag.name, 'a', 'it creates a `a` wrapper tag');
|
|
|
|
assert.equal(tag.attributes['class'].trim(), 'badge-wrapper', 'it has the correct class');
|
2015-01-21 00:36:28 +08:00
|
|
|
|
2015-09-04 04:55:55 +08:00
|
|
|
const label = tag.children[1];
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(label.attributes.title, 'cool description', 'it has the correct title');
|
2015-01-21 00:36:28 +08:00
|
|
|
|
2018-01-11 20:43:05 +08:00
|
|
|
assert.equal(label.children[0].children[0].data, 'hello', 'it has the category name');
|
2015-01-21 00:36:28 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("undefined color", assert => {
|
2015-09-04 04:55:55 +08:00
|
|
|
const store = createStore();
|
|
|
|
const noColor = store.createRecord('category', { name: 'hello', id: 123 });
|
|
|
|
const tag = parseHTML(categoryBadgeHTML(noColor))[0];
|
2015-01-21 00:36:28 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.blank(tag.attributes.style, "it has no color style because there are no colors");
|
2015-01-21 00:36:28 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("allowUncategorized", assert => {
|
2015-09-04 04:55:55 +08:00
|
|
|
const store = createStore();
|
|
|
|
const uncategorized = store.createRecord('category', {name: 'uncategorized', id: 345});
|
2015-01-21 00:36:28 +08:00
|
|
|
sandbox.stub(Discourse.Site, 'currentProp').withArgs('uncategorized_category_id').returns(345);
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.blank(categoryBadgeHTML(uncategorized), "it doesn't return HTML for uncategorized by default");
|
|
|
|
assert.present(categoryBadgeHTML(uncategorized, {allowUncategorized: true}), "it returns HTML");
|
2017-12-15 12:58:20 +08:00
|
|
|
});
|
2018-01-30 09:42:19 +08:00
|
|
|
|
|
|
|
QUnit.test("category names are wrapped in dir-spans", assert => {
|
|
|
|
Discourse.SiteSettings.support_mixed_text_direction = true;
|
|
|
|
const store = createStore();
|
|
|
|
const rtlCategory = store.createRecord('category', {
|
|
|
|
name: 'תכנות עם Ruby',
|
|
|
|
id: 123,
|
|
|
|
description_text: 'cool description',
|
|
|
|
color: 'ff0',
|
|
|
|
text_color: 'f00'
|
|
|
|
});
|
|
|
|
|
|
|
|
const ltrCategory = store.createRecord('category', {
|
|
|
|
name: 'Programming in Ruby',
|
|
|
|
id: 234
|
|
|
|
});
|
|
|
|
|
|
|
|
let tag = parseHTML(categoryBadgeHTML(rtlCategory))[0];
|
|
|
|
let dirSpan = tag.children[1].children[0];
|
|
|
|
assert.equal(dirSpan.attributes.dir, 'rtl');
|
|
|
|
|
|
|
|
tag = parseHTML(categoryBadgeHTML(ltrCategory))[0];
|
|
|
|
dirSpan = tag.children[1].children[0];
|
|
|
|
assert.equal(dirSpan.attributes.dir, 'ltr');
|
|
|
|
});
|