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