mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
REFACTOR: Remove Discourse.Category constants
This commit is contained in:
@@ -7,7 +7,7 @@ QUnit.test("slugFor", assert => {
|
||||
const store = createStore();
|
||||
|
||||
const slugFor = function(cat, val, text) {
|
||||
assert.equal(Discourse.Category.slugFor(cat), val, text);
|
||||
assert.equal(Category.slugFor(cat), val, text);
|
||||
};
|
||||
|
||||
slugFor(
|
||||
@@ -86,35 +86,35 @@ QUnit.test("findBySlug", assert => {
|
||||
}),
|
||||
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
||||
|
||||
sandbox.stub(Discourse.Category, "list").returns(categoryList);
|
||||
sandbox.stub(Category, "list").returns(categoryList);
|
||||
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findBySlug("darth"),
|
||||
Category.findBySlug("darth"),
|
||||
darth,
|
||||
"we can find a category"
|
||||
);
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findBySlug("luke", "darth"),
|
||||
Category.findBySlug("luke", "darth"),
|
||||
luke,
|
||||
"we can find the other category with parent category"
|
||||
);
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findBySlug("熱帶風暴畫眉"),
|
||||
Category.findBySlug("熱帶風暴畫眉"),
|
||||
hurricane,
|
||||
"we can find a category with CJK slug"
|
||||
);
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findBySlug("뉴스피드", "熱帶風暴畫眉"),
|
||||
Category.findBySlug("뉴스피드", "熱帶風暴畫眉"),
|
||||
newsFeed,
|
||||
"we can find a category with CJK slug whose parent slug is also CJK"
|
||||
);
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findBySlug("时间", "darth"),
|
||||
Category.findBySlug("时间", "darth"),
|
||||
time,
|
||||
"we can find a category with CJK slug whose parent slug is english"
|
||||
);
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findBySlug("bah", "熱帶風暴畫眉"),
|
||||
Category.findBySlug("bah", "熱帶風暴畫眉"),
|
||||
bah,
|
||||
"we can find a category with english slug whose parent slug is CJK"
|
||||
);
|
||||
@@ -150,35 +150,35 @@ QUnit.test("findSingleBySlug", assert => {
|
||||
}),
|
||||
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
|
||||
|
||||
sandbox.stub(Discourse.Category, "list").returns(categoryList);
|
||||
sandbox.stub(Category, "list").returns(categoryList);
|
||||
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findSingleBySlug("darth"),
|
||||
Category.findSingleBySlug("darth"),
|
||||
darth,
|
||||
"we can find a category"
|
||||
);
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findSingleBySlug("darth/luke"),
|
||||
Category.findSingleBySlug("darth/luke"),
|
||||
luke,
|
||||
"we can find the other category with parent category"
|
||||
);
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findSingleBySlug("熱帶風暴畫眉"),
|
||||
Category.findSingleBySlug("熱帶風暴畫眉"),
|
||||
hurricane,
|
||||
"we can find a category with CJK slug"
|
||||
);
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findSingleBySlug("熱帶風暴畫眉/뉴스피드"),
|
||||
Category.findSingleBySlug("熱帶風暴畫眉/뉴스피드"),
|
||||
newsFeed,
|
||||
"we can find a category with CJK slug whose parent slug is also CJK"
|
||||
);
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findSingleBySlug("darth/时间"),
|
||||
Category.findSingleBySlug("darth/时间"),
|
||||
time,
|
||||
"we can find a category with CJK slug whose parent slug is english"
|
||||
);
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findSingleBySlug("熱帶風暴畫眉/bah"),
|
||||
Category.findSingleBySlug("熱帶風暴畫眉/bah"),
|
||||
bah,
|
||||
"we can find a category with english slug whose parent slug is CJK"
|
||||
);
|
||||
@@ -191,13 +191,10 @@ QUnit.test("findByIds", assert => {
|
||||
2: store.createRecord("category", { id: 2 })
|
||||
};
|
||||
|
||||
sandbox.stub(Discourse.Category, "idMap").returns(categories);
|
||||
assert.deepEqual(
|
||||
Discourse.Category.findByIds([1, 2, 3]),
|
||||
_.values(categories)
|
||||
);
|
||||
sandbox.stub(Category, "idMap").returns(categories);
|
||||
assert.deepEqual(Category.findByIds([1, 2, 3]), _.values(categories));
|
||||
|
||||
assert.deepEqual(Discourse.Category.findByIds(), []);
|
||||
assert.deepEqual(Category.findByIds(), []);
|
||||
});
|
||||
|
||||
QUnit.test("search with category name", assert => {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { run } from "@ember/runloop";
|
||||
import createStore from "helpers/create-store";
|
||||
import NavItem from "discourse/models/nav-item";
|
||||
import Category from "discourse/models/category";
|
||||
|
||||
QUnit.module("NavItem", {
|
||||
beforeEach() {
|
||||
run(function() {
|
||||
const asianCategory = Discourse.Category.create({
|
||||
const asianCategory = Category.create({
|
||||
name: "确实是这样",
|
||||
id: 343434
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import EmberObject from "@ember/object";
|
||||
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
|
||||
import Category from "discourse/models/category";
|
||||
import Topic from "discourse/models/topic";
|
||||
|
||||
QUnit.module("model:topic");
|
||||
|
||||
import Topic from "discourse/models/topic";
|
||||
|
||||
QUnit.test("defaults", assert => {
|
||||
const topic = Topic.create({ id: 1234 });
|
||||
|
||||
@@ -84,7 +84,7 @@ QUnit.test("has suggestedTopics", assert => {
|
||||
|
||||
QUnit.test("category relationship", assert => {
|
||||
// It finds the category by id
|
||||
const category = Discourse.Category.list()[0];
|
||||
const category = Category.list()[0];
|
||||
const topic = Topic.create({ id: 1111, category_id: category.get("id") });
|
||||
|
||||
assert.equal(topic.get("category"), category);
|
||||
@@ -92,7 +92,7 @@ QUnit.test("category relationship", assert => {
|
||||
|
||||
QUnit.test("updateFromJson", assert => {
|
||||
const topic = Topic.create({ id: 1234 });
|
||||
const category = Discourse.Category.list()[0];
|
||||
const category = Category.list()[0];
|
||||
|
||||
topic.updateFromJson({
|
||||
post_stream: [1, 2, 3],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import TopicTrackingState from "discourse/models/topic-tracking-state";
|
||||
import createStore from "helpers/create-store";
|
||||
import Category from "discourse/models/category";
|
||||
|
||||
QUnit.module("model:topic-tracking-state");
|
||||
|
||||
@@ -37,7 +38,7 @@ QUnit.test("subscribe to category", function(assert) {
|
||||
}),
|
||||
categoryList = [darth, luke];
|
||||
|
||||
sandbox.stub(Discourse.Category, "list").returns(categoryList);
|
||||
sandbox.stub(Category, "list").returns(categoryList);
|
||||
|
||||
const state = TopicTrackingState.create();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user