DEV: apply new coding standards (#10592)

This commit is contained in:
Joffrey JAFFEUX
2020-09-04 13:42:47 +02:00
committed by GitHub
parent 80dfaeb0d2
commit 52672b9eab
1473 changed files with 9386 additions and 9958 deletions
+13 -11
View File
@@ -2,17 +2,19 @@ import Badge from "discourse/models/badge";
QUnit.module("model:badge");
QUnit.test("newBadge", assert => {
QUnit.test("newBadge", (assert) => {
const badge1 = Badge.create({ name: "New Badge" }),
badge2 = Badge.create({ id: 1, name: "Old Badge" });
assert.ok(badge1.get("newBadge"), "badges without ids are new");
assert.ok(!badge2.get("newBadge"), "badges with ids are not new");
});
QUnit.test("createFromJson array", assert => {
QUnit.test("createFromJson array", (assert) => {
const badgesJson = {
badge_types: [{ id: 6, name: "Silver 1" }],
badges: [{ id: 1126, name: "Badge 1", description: null, badge_type_id: 6 }]
badges: [
{ id: 1126, name: "Badge 1", description: null, badge_type_id: 6 },
],
};
const badges = Badge.createFromJson(badgesJson);
@@ -26,10 +28,10 @@ QUnit.test("createFromJson array", assert => {
);
});
QUnit.test("createFromJson single", assert => {
QUnit.test("createFromJson single", (assert) => {
const badgeJson = {
badge_types: [{ id: 6, name: "Silver 1" }],
badge: { id: 1126, name: "Badge 1", description: null, badge_type_id: 6 }
badge: { id: 1126, name: "Badge 1", description: null, badge_type_id: 6 },
};
const badge = Badge.createFromJson(badgeJson);
@@ -37,10 +39,10 @@ QUnit.test("createFromJson single", assert => {
assert.ok(!Array.isArray(badge), "does not returns an array");
});
QUnit.test("updateFromJson", assert => {
QUnit.test("updateFromJson", (assert) => {
const badgeJson = {
badge_types: [{ id: 6, name: "Silver 1" }],
badge: { id: 1126, name: "Badge 1", description: null, badge_type_id: 6 }
badge: { id: 1126, name: "Badge 1", description: null, badge_type_id: 6 },
};
const badge = Badge.create({ name: "Badge 1" });
badge.updateFromJson(badgeJson);
@@ -52,22 +54,22 @@ QUnit.test("updateFromJson", assert => {
);
});
QUnit.test("save", assert => {
QUnit.test("save", (assert) => {
assert.expect(0);
const badge = Badge.create({
name: "New Badge",
description: "This is a new badge.",
badge_type_id: 1
badge_type_id: 1,
});
return badge.save(["name", "description", "badge_type_id"]);
});
QUnit.test("destroy", assert => {
QUnit.test("destroy", (assert) => {
assert.expect(0);
const badge = Badge.create({
name: "New Badge",
description: "This is a new badge.",
badge_type_id: 1
badge_type_id: 1,
});
badge.destroy();
badge.set("id", 3);
+25 -25
View File
@@ -3,10 +3,10 @@ import Category from "discourse/models/category";
QUnit.module("model:category");
QUnit.test("slugFor", assert => {
QUnit.test("slugFor", (assert) => {
const store = createStore();
const slugFor = function(cat, val, text) {
const slugFor = function (cat, val, text) {
assert.equal(Category.slugFor(cat), val, text);
};
@@ -33,12 +33,12 @@ QUnit.test("slugFor", assert => {
const parentCategory = store.createRecord("category", {
id: 345,
slug: "darth"
slug: "darth",
});
slugFor(
store.createRecord("category", {
slug: "luke",
parentCategory: parentCategory
parentCategory: parentCategory,
}),
"darth/luke",
"it uses the parent slug before the child"
@@ -58,7 +58,7 @@ QUnit.test("slugFor", assert => {
);
});
QUnit.test("findBySlug", assert => {
QUnit.test("findBySlug", (assert) => {
assert.expect(6);
const store = createStore();
@@ -66,23 +66,23 @@ QUnit.test("findBySlug", assert => {
luke = store.createRecord("category", {
id: 2,
slug: "luke",
parentCategory: darth
parentCategory: darth,
}),
hurricane = store.createRecord("category", { id: 3, slug: "熱帶風暴畫眉" }),
newsFeed = store.createRecord("category", {
id: 4,
slug: "뉴스피드",
parentCategory: hurricane
parentCategory: hurricane,
}),
time = store.createRecord("category", {
id: 5,
slug: "时间",
parentCategory: darth
parentCategory: darth,
}),
bah = store.createRecord("category", {
id: 6,
slug: "bah",
parentCategory: hurricane
parentCategory: hurricane,
}),
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
@@ -122,7 +122,7 @@ QUnit.test("findBySlug", assert => {
sandbox.restore();
});
QUnit.test("findSingleBySlug", assert => {
QUnit.test("findSingleBySlug", (assert) => {
assert.expect(6);
const store = createStore();
@@ -130,23 +130,23 @@ QUnit.test("findSingleBySlug", assert => {
luke = store.createRecord("category", {
id: 2,
slug: "luke",
parentCategory: darth
parentCategory: darth,
}),
hurricane = store.createRecord("category", { id: 3, slug: "熱帶風暴畫眉" }),
newsFeed = store.createRecord("category", {
id: 4,
slug: "뉴스피드",
parentCategory: hurricane
parentCategory: hurricane,
}),
time = store.createRecord("category", {
id: 5,
slug: "时间",
parentCategory: darth
parentCategory: darth,
}),
bah = store.createRecord("category", {
id: 6,
slug: "bah",
parentCategory: hurricane
parentCategory: hurricane,
}),
categoryList = [darth, luke, hurricane, newsFeed, time, bah];
@@ -184,19 +184,19 @@ QUnit.test("findSingleBySlug", assert => {
);
});
QUnit.test("findBySlugPathWithID", assert => {
QUnit.test("findBySlugPathWithID", (assert) => {
const store = createStore();
const foo = store.createRecord("category", { id: 1, slug: "foo" });
const bar = store.createRecord("category", {
id: 2,
slug: "bar",
parentCategory: foo
parentCategory: foo,
});
const baz = store.createRecord("category", {
id: 3,
slug: "baz",
parentCategory: foo
parentCategory: foo,
});
const categoryList = [foo, bar, baz];
@@ -208,17 +208,17 @@ QUnit.test("findBySlugPathWithID", assert => {
assert.deepEqual(Category.findBySlugPathWithID("foo/baz/3"), baz);
});
QUnit.test("search with category name", assert => {
QUnit.test("search with category name", (assert) => {
const store = createStore(),
category1 = store.createRecord("category", {
id: 1,
name: "middle term",
slug: "different-slug"
slug: "different-slug",
}),
category2 = store.createRecord("category", {
id: 2,
name: "middle term",
slug: "another-different-slug"
slug: "another-different-slug",
});
sandbox.stub(Category, "listByActivity").returns([category1, category2]);
@@ -258,12 +258,12 @@ QUnit.test("search with category name", assert => {
const child_category1 = store.createRecord("category", {
id: 3,
name: "term start",
parent_category_id: category1.get("id")
parent_category_id: category1.get("id"),
}),
read_restricted_category = store.createRecord("category", {
id: 4,
name: "some term",
read_restricted: true
read_restricted: true,
});
sandbox
@@ -297,17 +297,17 @@ QUnit.test("search with category name", assert => {
sandbox.restore();
});
QUnit.test("search with category slug", assert => {
QUnit.test("search with category slug", (assert) => {
const store = createStore(),
category1 = store.createRecord("category", {
id: 1,
name: "middle term",
slug: "different-slug"
slug: "different-slug",
}),
category2 = store.createRecord("category", {
id: 2,
name: "middle term",
slug: "another-different-slug"
slug: "another-different-slug",
});
sandbox.stub(Category, "listByActivity").returns([category1, category2]);
+43 -38
View File
@@ -5,7 +5,7 @@ import {
EDIT,
REPLY,
CREATE_TOPIC,
PRIVATE_MESSAGE
PRIVATE_MESSAGE,
} from "discourse/models/composer";
import Post from "discourse/models/post";
import createStore from "helpers/create-store";
@@ -25,8 +25,8 @@ function openComposer(opts) {
return composer;
}
QUnit.test("replyLength", assert => {
const replyLength = function(val, expectedLength) {
QUnit.test("replyLength", (assert) => {
const replyLength = function (val, expectedLength) {
const composer = createComposer({ reply: val });
assert.equal(composer.get("replyLength"), expectedLength);
};
@@ -46,9 +46,9 @@ QUnit.test("replyLength", assert => {
);
});
QUnit.test("missingReplyCharacters", function(assert) {
QUnit.test("missingReplyCharacters", function (assert) {
this.siteSettings.min_first_post_length = 40;
const missingReplyCharacters = function(
const missingReplyCharacters = function (
val,
isPM,
isFirstPost,
@@ -96,7 +96,7 @@ QUnit.test("missingReplyCharacters", function(assert) {
categoryId: 12345,
featuredLink: link,
action: CREATE_TOPIC,
reply: link
reply: link,
});
assert.equal(
@@ -106,11 +106,11 @@ QUnit.test("missingReplyCharacters", function(assert) {
);
});
QUnit.test("missingTitleCharacters", function(assert) {
const missingTitleCharacters = function(val, isPM, expected, message) {
QUnit.test("missingTitleCharacters", function (assert) {
const missingTitleCharacters = function (val, isPM, expected, message) {
const composer = createComposer({
title: val,
action: isPM ? PRIVATE_MESSAGE : REPLY
action: isPM ? PRIVATE_MESSAGE : REPLY,
});
assert.equal(composer.get("missingTitleCharacters"), expected, message);
};
@@ -129,13 +129,13 @@ QUnit.test("missingTitleCharacters", function(assert) {
);
});
QUnit.test("replyDirty", assert => {
QUnit.test("replyDirty", (assert) => {
const composer = createComposer();
assert.ok(!composer.get("replyDirty"), "by default it's false");
composer.setProperties({
originalText: "hello",
reply: "hello"
reply: "hello",
});
assert.ok(
@@ -146,7 +146,7 @@ QUnit.test("replyDirty", assert => {
assert.ok(composer.get("replyDirty"), "it's true when the reply changes");
});
QUnit.test("appendText", assert => {
QUnit.test("appendText", (assert) => {
const composer = createComposer();
assert.blank(composer.get("reply"), "the reply is blank by default");
@@ -179,7 +179,7 @@ QUnit.test("appendText", assert => {
assert.equal(composer.get("reply"), "c\n\nab");
});
QUnit.test("prependText", assert => {
QUnit.test("prependText", (assert) => {
const composer = createComposer();
assert.blank(composer.get("reply"), "the reply is blank by default");
@@ -202,7 +202,7 @@ QUnit.test("prependText", assert => {
);
});
QUnit.test("Title length for regular topics", function(assert) {
QUnit.test("Title length for regular topics", function (assert) {
this.siteSettings.min_topic_title_length = 5;
this.siteSettings.max_topic_title_length = 10;
const composer = createComposer();
@@ -217,7 +217,7 @@ QUnit.test("Title length for regular topics", function(assert) {
assert.ok(composer.get("titleLengthValid"), "in the range is okay");
});
QUnit.test("Title length for private messages", function(assert) {
QUnit.test("Title length for private messages", function (assert) {
this.siteSettings.min_personal_message_title_length = 5;
this.siteSettings.max_topic_title_length = 10;
const composer = createComposer({ action: PRIVATE_MESSAGE });
@@ -232,15 +232,18 @@ QUnit.test("Title length for private messages", function(assert) {
assert.ok(composer.get("titleLengthValid"), "in the range is okay");
});
QUnit.test("Post length for private messages with non human users", assert => {
const composer = createComposer({
topic: EmberObject.create({ pm_with_non_human_user: true })
});
QUnit.test(
"Post length for private messages with non human users",
(assert) => {
const composer = createComposer({
topic: EmberObject.create({ pm_with_non_human_user: true }),
});
assert.equal(composer.get("minimumPostLength"), 1);
});
assert.equal(composer.get("minimumPostLength"), 1);
}
);
QUnit.test("editingFirstPost", assert => {
QUnit.test("editingFirstPost", (assert) => {
const composer = createComposer();
assert.ok(!composer.get("editingFirstPost"), "it's false by default");
@@ -258,12 +261,12 @@ QUnit.test("editingFirstPost", assert => {
);
});
QUnit.test("clearState", assert => {
QUnit.test("clearState", (assert) => {
const composer = createComposer({
originalText: "asdf",
reply: "asdf2",
post: Post.create({ id: 1 }),
title: "wat"
title: "wat",
});
composer.clearState();
@@ -274,24 +277,24 @@ QUnit.test("clearState", assert => {
assert.blank(composer.get("title"));
});
QUnit.test("initial category when uncategorized is allowed", function(assert) {
QUnit.test("initial category when uncategorized is allowed", function (assert) {
this.siteSettings.allow_uncategorized_topics = true;
const composer = openComposer({
action: CREATE_TOPIC,
draftKey: "asfd",
draftSequence: 1
draftSequence: 1,
});
assert.ok(!composer.get("categoryId"), "Uncategorized by default");
});
QUnit.test("initial category when uncategorized is not allowed", function(
QUnit.test("initial category when uncategorized is not allowed", function (
assert
) {
this.siteSettings.allow_uncategorized_topics = false;
const composer = openComposer({
action: CREATE_TOPIC,
draftKey: "asfd",
draftSequence: 1
draftSequence: 1,
});
assert.ok(
!composer.get("categoryId"),
@@ -299,15 +302,15 @@ QUnit.test("initial category when uncategorized is not allowed", function(
);
});
QUnit.test("open with a quote", assert => {
QUnit.test("open with a quote", (assert) => {
const quote =
'[quote="neil, post:5, topic:413"]\nSimmer down you two.\n[/quote]';
const newComposer = function() {
const newComposer = function () {
return openComposer({
action: REPLY,
draftKey: "asfd",
draftSequence: 1,
quote: quote
quote: quote,
});
};
@@ -323,7 +326,7 @@ QUnit.test("open with a quote", assert => {
);
});
QUnit.test("Title length for static page topics as admin", function(assert) {
QUnit.test("Title length for static page topics as admin", function (assert) {
this.siteSettings.min_topic_title_length = 5;
this.siteSettings.max_topic_title_length = 10;
const composer = createComposer();
@@ -331,7 +334,7 @@ QUnit.test("Title length for static page topics as admin", function(assert) {
const post = Post.create({
id: 123,
post_number: 2,
static_doc: true
static_doc: true,
});
composer.setProperties({ post: post, action: EDIT });
@@ -351,7 +354,7 @@ QUnit.test("Title length for static page topics as admin", function(assert) {
);
});
QUnit.test("title placeholder depends on what you're doing", function(assert) {
QUnit.test("title placeholder depends on what you're doing", function (assert) {
let composer = createComposer({ action: CREATE_TOPIC });
assert.equal(
composer.get("titlePlaceholder"),
@@ -383,7 +386,9 @@ QUnit.test("title placeholder depends on what you're doing", function(assert) {
);
});
QUnit.test("allows featured link before choosing a category", function(assert) {
QUnit.test("allows featured link before choosing a category", function (
assert
) {
this.siteSettings.topic_featured_link_enabled = true;
this.siteSettings.allow_uncategorized_topics = false;
let composer = createComposer({ action: CREATE_TOPIC });
@@ -395,14 +400,14 @@ QUnit.test("allows featured link before choosing a category", function(assert) {
assert.ok(composer.get("canEditTopicFeaturedLink"), "can paste link");
});
QUnit.test("targetRecipientsArray contains types", assert => {
QUnit.test("targetRecipientsArray contains types", (assert) => {
let composer = createComposer({
targetRecipients: "test,codinghorror,staff,foo@bar.com"
targetRecipients: "test,codinghorror,staff,foo@bar.com",
});
assert.ok(composer.targetRecipientsArray, [
{ type: "group", name: "test" },
{ type: "user", name: "codinghorror" },
{ type: "group", name: "staff" },
{ type: "email", name: "foo@bar.com" }
{ type: "email", name: "foo@bar.com" },
]);
});
+4 -4
View File
@@ -3,11 +3,11 @@ import { setPrefix } from "discourse-common/lib/get-url";
QUnit.module("model:email-log");
QUnit.test("create", assert => {
QUnit.test("create", (assert) => {
assert.ok(EmailLog.create(), "it can be created without arguments");
});
QUnit.test("subfolder support", assert => {
QUnit.test("subfolder support", (assert) => {
setPrefix("/forum");
const attrs = {
id: 60,
@@ -22,8 +22,8 @@ QUnit.test("subfolder support", assert => {
id: 9,
username: "wikiman",
avatar_template:
"/forum/letter_avatar_proxy/v2/letter/w/dfb087/{size}.png"
}
"/forum/letter_avatar_proxy/v2/letter/w/dfb087/{size}.png",
},
};
const emailLog = EmailLog.create(attrs);
assert.equal(
+1 -1
View File
@@ -2,7 +2,7 @@ import Group from "discourse/models/group";
QUnit.module("model:group");
QUnit.test("displayName", assert => {
QUnit.test("displayName", (assert) => {
const group = Group.create({ name: "test", display_name: "donkey" });
assert.equal(
+1 -1
View File
@@ -2,6 +2,6 @@ import Invite from "discourse/models/invite";
QUnit.module("model:invite");
QUnit.test("create", assert => {
QUnit.test("create", (assert) => {
assert.ok(Invite.create(), "it can be created without arguments");
});
+5 -5
View File
@@ -6,17 +6,17 @@ import Site from "discourse/models/site";
QUnit.module("NavItem", {
beforeEach() {
run(function() {
run(function () {
const asianCategory = Category.create({
name: "确实是这样",
id: 343434
id: 343434,
});
Site.currentProp("categories").addObject(asianCategory);
});
}
},
});
QUnit.test("href", assert => {
QUnit.test("href", (assert) => {
assert.expect(2);
function href(text, expected, label) {
@@ -27,7 +27,7 @@ QUnit.test("href", assert => {
href("categories", "/categories", "categories");
});
QUnit.test("count", assert => {
QUnit.test("count", (assert) => {
const navItem = createStore().createRecord("nav-item", { name: "new" });
assert.equal(navItem.get("count"), 0, "it has no count by default");
+61 -61
View File
@@ -7,7 +7,7 @@ import pretender from "helpers/create-pretender";
QUnit.module("model:post-stream");
const buildStream = function(id, stream) {
const buildStream = function (id, stream) {
const store = createStore();
const topic = store.createRecord("topic", { id, chunk_size: 5 });
const ps = topic.get("postStream");
@@ -19,7 +19,7 @@ const buildStream = function(id, stream) {
const participant = { username: "eviltrout" };
QUnit.test("create", assert => {
QUnit.test("create", (assert) => {
const store = createStore();
assert.ok(
store.createRecord("postStream"),
@@ -27,7 +27,7 @@ QUnit.test("create", assert => {
);
});
QUnit.test("defaults", assert => {
QUnit.test("defaults", (assert) => {
const postStream = buildStream(1234);
assert.blank(
postStream.get("posts"),
@@ -37,7 +37,7 @@ QUnit.test("defaults", assert => {
assert.present(postStream.get("topic"));
});
QUnit.test("appending posts", assert => {
QUnit.test("appending posts", (assert) => {
const postStream = buildStream(4567, [1, 3, 4]);
const store = postStream.store;
@@ -108,7 +108,7 @@ QUnit.test("appending posts", assert => {
);
});
QUnit.test("closestPostNumberFor", assert => {
QUnit.test("closestPostNumberFor", (assert) => {
const postStream = buildStream(1231);
const store = postStream.store;
@@ -142,12 +142,12 @@ QUnit.test("closestPostNumberFor", assert => {
);
});
QUnit.test("closestDaysAgoFor", assert => {
QUnit.test("closestDaysAgoFor", (assert) => {
const postStream = buildStream(1231);
postStream.set("timelineLookup", [
[1, 10],
[3, 8],
[5, 1]
[5, 1],
]);
assert.equal(postStream.closestDaysAgoFor(1), 10);
@@ -165,20 +165,20 @@ QUnit.test("closestDaysAgoFor", assert => {
assert.equal(postStream.closestDaysAgoFor(1), undefined);
});
QUnit.test("closestDaysAgoFor - empty", assert => {
QUnit.test("closestDaysAgoFor - empty", (assert) => {
const postStream = buildStream(1231);
postStream.set("timelineLookup", []);
assert.equal(postStream.closestDaysAgoFor(1), null);
});
QUnit.test("updateFromJson", assert => {
QUnit.test("updateFromJson", (assert) => {
const postStream = buildStream(1231);
postStream.updateFromJson({
posts: [{ id: 1 }],
stream: [1],
extra_property: 12
extra_property: 12,
});
assert.equal(postStream.get("posts.length"), 1, "it loaded the posts");
@@ -187,7 +187,7 @@ QUnit.test("updateFromJson", assert => {
assert.equal(postStream.get("extra_property"), 12);
});
QUnit.test("removePosts", assert => {
QUnit.test("removePosts", (assert) => {
const postStream = buildStream(10000001, [1, 2, 3]);
const store = postStream.store;
@@ -208,7 +208,7 @@ QUnit.test("removePosts", assert => {
assert.deepEqual(postStream.get("stream"), [2]);
});
QUnit.test("cancelFilter", assert => {
QUnit.test("cancelFilter", (assert) => {
const postStream = buildStream(1235);
sandbox.stub(postStream, "refresh").returns(Promise.resolve());
@@ -225,7 +225,7 @@ QUnit.test("cancelFilter", assert => {
);
});
QUnit.test("findPostIdForPostNumber", assert => {
QUnit.test("findPostIdForPostNumber", (assert) => {
const postStream = buildStream(1234, [10, 20, 30, 40, 50, 60, 70]);
postStream.set("gaps", { before: { 60: [55, 58] } });
@@ -247,12 +247,12 @@ QUnit.test("findPostIdForPostNumber", assert => {
assert.equal(postStream.findPostIdForPostNumber(8), 60, "it respects gaps");
});
QUnit.test("fillGapBefore", assert => {
QUnit.test("fillGapBefore", (assert) => {
const postStream = buildStream(1234, [60]);
sandbox.stub(postStream, "findPostsByIds").returns(Promise.resolve([]));
let post = postStream.store.createRecord("post", { id: 60, post_number: 60 });
postStream.set("gaps", {
before: { 60: [51, 52, 53, 54, 55, 56, 57, 58, 59] }
before: { 60: [51, 52, 53, 54, 55, 56, 57, 58, 59] },
});
postStream.fillGapBefore(post, [51, 52, 53, 54, 55, 56, 57, 58, 59]);
@@ -264,7 +264,7 @@ QUnit.test("fillGapBefore", assert => {
);
});
QUnit.test("toggleParticipant", assert => {
QUnit.test("toggleParticipant", (assert) => {
const postStream = buildStream(1236);
sandbox.stub(postStream, "refresh").returns(Promise.resolve());
@@ -287,7 +287,7 @@ QUnit.test("toggleParticipant", assert => {
);
});
QUnit.test("streamFilters", assert => {
QUnit.test("streamFilters", (assert) => {
const postStream = buildStream(1237);
sandbox.stub(postStream, "refresh").returns(Promise.resolve());
@@ -310,13 +310,13 @@ QUnit.test("streamFilters", assert => {
assert.deepEqual(
postStream.get("streamFilters"),
{
username_filters: "eviltrout"
username_filters: "eviltrout",
},
"streamFilters contains the username we filtered"
);
});
QUnit.test("loading", assert => {
QUnit.test("loading", (assert) => {
let postStream = buildStream(1234);
assert.ok(!postStream.get("loading"), "we're not loading by default");
@@ -332,7 +332,7 @@ QUnit.test("loading", assert => {
assert.ok(postStream.get("loading"), "we're loading if loading a filter");
});
QUnit.test("nextWindow", assert => {
QUnit.test("nextWindow", (assert) => {
const postStream = buildStream(1234, [
1,
2,
@@ -345,7 +345,7 @@ QUnit.test("nextWindow", assert => {
13,
14,
15,
16
16,
]);
assert.blank(
@@ -374,7 +374,7 @@ QUnit.test("nextWindow", assert => {
);
});
QUnit.test("previousWindow", assert => {
QUnit.test("previousWindow", (assert) => {
const postStream = buildStream(1234, [
1,
2,
@@ -387,7 +387,7 @@ QUnit.test("previousWindow", assert => {
13,
14,
15,
16
16,
]);
assert.blank(
@@ -416,13 +416,13 @@ QUnit.test("previousWindow", assert => {
);
});
QUnit.test("storePost", assert => {
QUnit.test("storePost", (assert) => {
const postStream = buildStream(1234),
store = postStream.store,
post = store.createRecord("post", {
id: 1,
post_number: 100,
raw: "initial value"
raw: "initial value",
});
assert.blank(
@@ -445,7 +445,7 @@ QUnit.test("storePost", assert => {
const dupePost = store.createRecord("post", {
id: 1,
post_number: 100,
raw: "updated value"
raw: "updated value",
});
const storedDupe = postStream.storePost(dupePost);
assert.equal(
@@ -464,7 +464,7 @@ QUnit.test("storePost", assert => {
assert.equal(stored, postWithoutId, "it returns the same post back");
});
QUnit.test("identity map", async assert => {
QUnit.test("identity map", async (assert) => {
const postStream = buildStream(1234);
const store = postStream.store;
@@ -490,12 +490,12 @@ QUnit.test("identity map", async assert => {
assert.equal(result.objectAt(2), p3);
});
QUnit.test("loadIntoIdentityMap with no data", async assert => {
QUnit.test("loadIntoIdentityMap with no data", async (assert) => {
const result = await buildStream(1234).loadIntoIdentityMap([]);
assert.equal(result.length, 0, "requesting no posts produces no posts");
});
QUnit.test("loadIntoIdentityMap with post ids", async assert => {
QUnit.test("loadIntoIdentityMap with post ids", async (assert) => {
const postStream = buildStream(1234);
await postStream.loadIntoIdentityMap([10]);
@@ -505,14 +505,14 @@ QUnit.test("loadIntoIdentityMap with post ids", async assert => {
);
});
QUnit.test("appendMore for megatopic", async assert => {
QUnit.test("appendMore for megatopic", async (assert) => {
const postStream = buildStream(1234);
const store = createStore();
const post = store.createRecord("post", { id: 1, post_number: 1 });
postStream.setProperties({
isMegaTopic: true,
posts: [post]
posts: [post],
});
await postStream.appendMore();
@@ -528,14 +528,14 @@ QUnit.test("appendMore for megatopic", async assert => {
);
});
QUnit.test("prependMore for megatopic", async assert => {
QUnit.test("prependMore for megatopic", async (assert) => {
const postStream = buildStream(1234);
const store = createStore();
const post = store.createRecord("post", { id: 6, post_number: 6 });
postStream.setProperties({
isMegaTopic: true,
posts: [post]
posts: [post],
});
await postStream.prependMore();
@@ -551,14 +551,14 @@ QUnit.test("prependMore for megatopic", async assert => {
);
});
QUnit.test("staging and undoing a new post", assert => {
QUnit.test("staging and undoing a new post", (assert) => {
const postStream = buildStream(10101, [1]);
const store = postStream.store;
const original = store.createRecord("post", {
id: 1,
post_number: 1,
topic_id: 10101
topic_id: 10101,
});
postStream.appendPost(original);
assert.ok(
@@ -570,17 +570,17 @@ QUnit.test("staging and undoing a new post", assert => {
const user = User.create({
username: "eviltrout",
name: "eviltrout",
id: 321
id: 321,
});
const stagedPost = store.createRecord("post", {
raw: "hello world this is my new post",
topic_id: 10101
topic_id: 10101,
});
const topic = postStream.get("topic");
topic.setProperties({
posts_count: 1,
highest_post_number: 1
highest_post_number: 1,
});
// Stage the new post in the stream
@@ -652,14 +652,14 @@ QUnit.test("staging and undoing a new post", assert => {
);
});
QUnit.test("staging and committing a post", assert => {
QUnit.test("staging and committing a post", (assert) => {
const postStream = buildStream(10101, [1]);
const store = postStream.store;
const original = store.createRecord("post", {
id: 1,
post_number: 1,
topic_id: 10101
topic_id: 10101,
});
postStream.appendPost(original);
assert.ok(
@@ -671,11 +671,11 @@ QUnit.test("staging and committing a post", assert => {
const user = User.create({
username: "eviltrout",
name: "eviltrout",
id: 321
id: 321,
});
const stagedPost = store.createRecord("post", {
raw: "hello world this is my new post",
topic_id: 10101
topic_id: 10101,
});
const topic = postStream.get("topic");
@@ -731,13 +731,13 @@ QUnit.test("staging and committing a post", assert => {
);
});
QUnit.test("loadedAllPosts when the id changes", assert => {
QUnit.test("loadedAllPosts when the id changes", (assert) => {
// This can happen in a race condition between staging a post and it coming through on the
// message bus. If the id of a post changes we should reconsider the loadedAllPosts property.
const postStream = buildStream(10101, [1, 2]);
const store = postStream.store;
const postWithoutId = store.createRecord("post", {
raw: "hello world this is my new post"
raw: "hello world this is my new post",
});
postStream.appendPost(store.createRecord("post", { id: 1, post_number: 1 }));
@@ -751,17 +751,17 @@ QUnit.test("loadedAllPosts when the id changes", assert => {
);
});
QUnit.test("triggerRecoveredPost", async assert => {
QUnit.test("triggerRecoveredPost", async (assert) => {
const postStream = buildStream(4567);
const store = postStream.store;
[1, 2, 3, 5].forEach(id => {
[1, 2, 3, 5].forEach((id) => {
postStream.appendPost(
store.createRecord("post", { id: id, post_number: id })
);
});
const response = object => {
const response = (object) => {
return [200, { "Content-Type": "application/json" }, object];
};
@@ -784,7 +784,7 @@ QUnit.test("triggerRecoveredPost", async assert => {
);
});
QUnit.test("comitting and triggerNewPostInStream race condition", assert => {
QUnit.test("comitting and triggerNewPostInStream race condition", (assert) => {
const postStream = buildStream(4964);
const store = postStream.store;
@@ -792,10 +792,10 @@ QUnit.test("comitting and triggerNewPostInStream race condition", assert => {
const user = User.create({
username: "eviltrout",
name: "eviltrout",
id: 321
id: 321,
});
const stagedPost = store.createRecord("post", {
raw: "hello world this is my new post"
raw: "hello world this is my new post",
});
postStream.stagePost(stagedPost, user);
@@ -818,7 +818,7 @@ QUnit.test("comitting and triggerNewPostInStream race condition", assert => {
);
});
QUnit.test("triggerNewPostInStream for ignored posts", async assert => {
QUnit.test("triggerNewPostInStream for ignored posts", async (assert) => {
const postStream = buildStream(280, [1]);
const store = postStream.store;
User.resetCurrent(
@@ -826,7 +826,7 @@ QUnit.test("triggerNewPostInStream for ignored posts", async assert => {
username: "eviltrout",
name: "eviltrout",
id: 321,
ignored_users: ["ignoreduser"]
ignored_users: ["ignoreduser"],
})
);
@@ -835,13 +835,13 @@ QUnit.test("triggerNewPostInStream for ignored posts", async assert => {
const post2 = store.createRecord("post", {
id: 101,
post_number: 2,
username: "regularuser"
username: "regularuser",
});
const post3 = store.createRecord("post", {
id: 102,
post_number: 3,
username: "ignoreduser"
username: "ignoreduser",
});
var stub = sandbox
@@ -876,7 +876,7 @@ QUnit.test("triggerNewPostInStream for ignored posts", async assert => {
);
});
QUnit.test("postsWithPlaceholders", async assert => {
QUnit.test("postsWithPlaceholders", async (assert) => {
const postStream = buildStream(4964, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
const postsWithPlaceholders = postStream.get("postsWithPlaceholders");
const store = postStream.store;
@@ -925,7 +925,7 @@ QUnit.test("postsWithPlaceholders", async assert => {
assert.equal(testProxy.objectAt(3), p4);
});
QUnit.test("filteredPostsCount", assert => {
QUnit.test("filteredPostsCount", (assert) => {
const postStream = buildStream(4567, [1, 3, 4]);
assert.equal(postStream.get("filteredPostsCount"), 3);
@@ -937,33 +937,33 @@ QUnit.test("filteredPostsCount", assert => {
assert.equal(postStream.get("filteredPostsCount"), 4);
});
QUnit.test("firstPostId", assert => {
QUnit.test("firstPostId", (assert) => {
const postStream = buildStream(4567, [1, 3, 4]);
assert.equal(postStream.get("firstPostId"), 1);
postStream.setProperties({
isMegaTopic: true,
firstId: 2
firstId: 2,
});
assert.equal(postStream.get("firstPostId"), 2);
});
QUnit.test("lastPostId", assert => {
QUnit.test("lastPostId", (assert) => {
const postStream = buildStream(4567, [1, 3, 4]);
assert.equal(postStream.get("lastPostId"), 4);
postStream.setProperties({
isMegaTopic: true,
lastId: 2
lastId: 2,
});
assert.equal(postStream.get("lastPostId"), 2);
});
QUnit.test("progressIndexOfPostId", assert => {
QUnit.test("progressIndexOfPostId", (assert) => {
const postStream = buildStream(4567, [1, 3, 4]);
const store = createStore();
const post = store.createRecord("post", { id: 1, post_number: 5 });
+11 -11
View File
@@ -4,26 +4,26 @@ import { deepMerge } from "discourse-common/lib/object";
QUnit.module("model: Post");
var buildPost = function(args) {
var buildPost = function (args) {
return Post.create(
deepMerge(
{
id: 1,
can_delete: true,
version: 1
version: 1,
},
args || {}
)
);
};
QUnit.test("defaults", assert => {
QUnit.test("defaults", (assert) => {
var post = Post.create({ id: 1 });
assert.blank(post.get("deleted_at"), "it has no deleted_at by default");
assert.blank(post.get("deleted_by"), "there is no deleted_by by default");
});
QUnit.test("new_user", assert => {
QUnit.test("new_user", (assert) => {
var post = Post.create({ trust_level: 0 });
assert.ok(post.get("new_user"), "post is from a new user");
@@ -31,7 +31,7 @@ QUnit.test("new_user", assert => {
assert.ok(!post.get("new_user"), "post is no longer from a new user");
});
QUnit.test("firstPost", assert => {
QUnit.test("firstPost", (assert) => {
var post = Post.create({ post_number: 1 });
assert.ok(post.get("firstPost"), "it's the first post");
@@ -39,25 +39,25 @@ QUnit.test("firstPost", assert => {
assert.ok(!post.get("firstPost"), "post is no longer the first post");
});
QUnit.test("updateFromPost", assert => {
QUnit.test("updateFromPost", (assert) => {
var post = Post.create({
post_number: 1,
raw: "hello world"
raw: "hello world",
});
post.updateFromPost(
Post.create({
raw: "different raw",
wat: function() {
wat: function () {
return 123;
}
},
})
);
assert.equal(post.get("raw"), "different raw", "raw field updated");
});
QUnit.test("destroy by staff", async assert => {
QUnit.test("destroy by staff", async (assert) => {
let user = User.create({ username: "staff", moderator: true });
let post = buildPost({ user: user });
@@ -82,7 +82,7 @@ QUnit.test("destroy by staff", async assert => {
);
});
QUnit.test("destroy by non-staff", async assert => {
QUnit.test("destroy by non-staff", async (assert) => {
const originalCooked = "this is the original cooked value";
const user = User.create({ username: "evil trout" });
const post = buildPost({ user: user, cooked: originalCooked });
+33 -35
View File
@@ -8,16 +8,14 @@ function reportWithData(data) {
type: "topics",
data: data.map((val, index) => {
return {
x: moment()
.subtract(index, "days")
.format("YYYY-MM-DD"),
y: val
x: moment().subtract(index, "days").format("YYYY-MM-DD"),
y: val,
};
})
}),
});
}
QUnit.test("counts", assert => {
QUnit.test("counts", (assert) => {
const report = reportWithData([5, 4, 3, 2, 1, 100, 99, 98, 1000]);
assert.equal(report.get("todayCount"), 5);
@@ -41,7 +39,7 @@ QUnit.test("counts", assert => {
);
});
QUnit.test("percentChangeString", assert => {
QUnit.test("percentChangeString", (assert) => {
const report = reportWithData([]);
assert.equal(report.percentChangeString(5, 8), "+60%", "value increased");
@@ -58,19 +56,19 @@ QUnit.test("percentChangeString", assert => {
);
});
QUnit.test("yesterdayCountTitle with valid values", assert => {
QUnit.test("yesterdayCountTitle with valid values", (assert) => {
const title = reportWithData([6, 8, 5, 2, 1]).get("yesterdayCountTitle");
assert.ok(title.indexOf("+60%") !== -1);
assert.ok(title.match(/Was 5/));
});
QUnit.test("yesterdayCountTitle when two days ago was 0", assert => {
QUnit.test("yesterdayCountTitle when two days ago was 0", (assert) => {
const title = reportWithData([6, 8, 0, 2, 1]).get("yesterdayCountTitle");
assert.equal(title.indexOf("%"), -1);
assert.ok(title.match(/Was 0/));
});
QUnit.test("sevenDaysCountTitle", assert => {
QUnit.test("sevenDaysCountTitle", (assert) => {
const title = reportWithData([
100,
1,
@@ -88,13 +86,13 @@ QUnit.test("sevenDaysCountTitle", assert => {
2,
2,
100,
100
100,
]).get("sevenDaysCountTitle");
assert.ok(title.match(/-50%/));
assert.ok(title.match(/Was 14/));
});
QUnit.test("thirtyDaysCountTitle", assert => {
QUnit.test("thirtyDaysCountTitle", (assert) => {
const report = reportWithData([5, 5, 5, 5]);
report.set("prev30Days", 10);
const title = report.get("thirtyDaysCountTitle");
@@ -103,7 +101,7 @@ QUnit.test("thirtyDaysCountTitle", assert => {
assert.ok(title.match(/Was 10/));
});
QUnit.test("sevenDaysTrend", assert => {
QUnit.test("sevenDaysTrend", (assert) => {
let report;
let trend;
@@ -128,7 +126,7 @@ QUnit.test("sevenDaysTrend", assert => {
assert.ok(trend === "trending-down");
});
QUnit.test("yesterdayTrend", assert => {
QUnit.test("yesterdayTrend", (assert) => {
let report;
let trend;
@@ -153,7 +151,7 @@ QUnit.test("yesterdayTrend", assert => {
assert.ok(trend === "trending-down");
});
QUnit.test("thirtyDaysTrend", assert => {
QUnit.test("thirtyDaysTrend", (assert) => {
let report;
let trend;
@@ -188,7 +186,7 @@ QUnit.test("thirtyDaysTrend", assert => {
1,
1,
1,
1
1,
]);
report.set("prev30Days", 30);
trend = report.get("thirtyDaysTrend");
@@ -225,7 +223,7 @@ QUnit.test("thirtyDaysTrend", assert => {
1,
1,
1,
1
1,
]);
report.set("prev30Days", 0);
trend = report.get("thirtyDaysTrend");
@@ -262,7 +260,7 @@ QUnit.test("thirtyDaysTrend", assert => {
1,
1,
1,
1
1,
]);
report.set("prev30Days", 25);
trend = report.get("thirtyDaysTrend");
@@ -299,7 +297,7 @@ QUnit.test("thirtyDaysTrend", assert => {
0,
0,
0,
0
0,
]);
report.set("prev30Days", 60);
trend = report.get("thirtyDaysTrend");
@@ -336,14 +334,14 @@ QUnit.test("thirtyDaysTrend", assert => {
1,
1,
1,
0
0,
]);
report.set("prev30Days", 35);
trend = report.get("thirtyDaysTrend");
assert.ok(trend === "trending-down");
});
QUnit.test("higher is better false", assert => {
QUnit.test("higher is better false", (assert) => {
let report;
let trend;
@@ -368,7 +366,7 @@ QUnit.test("higher is better false", assert => {
assert.ok(trend === "trending-up");
});
QUnit.test("small variation (-2/+2% change) is no-change", assert => {
QUnit.test("small variation (-2/+2% change) is no-change", (assert) => {
let report;
let trend;
@@ -381,7 +379,7 @@ QUnit.test("small variation (-2/+2% change) is no-change", assert => {
assert.ok(trend === "no-change");
});
QUnit.test("average", assert => {
QUnit.test("average", (assert) => {
let report;
report = reportWithData([5, 5, 5, 5, 5, 5, 5, 5]);
@@ -393,7 +391,7 @@ QUnit.test("average", assert => {
assert.ok(report.get("lastSevenDaysCount") === 35);
});
QUnit.test("computed labels", assert => {
QUnit.test("computed labels", (assert) => {
const data = [
{
username: "joffrey",
@@ -406,8 +404,8 @@ QUnit.test("computed labels", assert => {
topic_title: "Test topic <html>",
post_number: 3,
post_raw: "This is the beginning of <html>",
filesize: 582641
}
filesize: 582641,
},
];
const labels = [
@@ -416,9 +414,9 @@ QUnit.test("computed labels", assert => {
properties: {
username: "username",
id: "user_id",
avatar: "user_avatar"
avatar: "user_avatar",
},
title: "Moderator"
title: "Moderator",
},
{ type: "number", property: "flag_count", title: "Flag count" },
{ type: "seconds", property: "time_read", title: "Time read" },
@@ -427,26 +425,26 @@ QUnit.test("computed labels", assert => {
type: "topic",
properties: {
title: "topic_title",
id: "topic_id"
id: "topic_id",
},
title: "Topic"
title: "Topic",
},
{
type: "post",
properties: {
topic_id: "topic_id",
number: "post_number",
truncated_raw: "post_raw"
truncated_raw: "post_raw",
},
title: "Post"
title: "Post",
},
{ type: "bytes", property: "filesize", title: "Filesize" }
{ type: "bytes", property: "filesize", title: "Filesize" },
];
const report = Report.create({
type: "topics",
labels,
data
data,
});
const row = report.get("data.0");
@@ -473,7 +471,7 @@ QUnit.test("computed labels", assert => {
assert.equal(computedFlagCountLabel.formatedValue, "1.9k");
assert.strictEqual(computedFlagCountLabel.value, 1876);
computedFlagCountLabel = flagCountLabel.compute(row, {
formatNumbers: false
formatNumbers: false,
});
assert.equal(computedFlagCountLabel.formatedValue, 1876);
+15 -15
View File
@@ -4,21 +4,21 @@ import createStore from "helpers/create-store";
import RestModel from "discourse/models/rest";
import RestAdapter from "discourse/adapters/rest";
QUnit.test("munging", assert => {
QUnit.test("munging", (assert) => {
const store = createStore();
const Grape = RestModel.extend();
Grape.reopenClass({
munge: function(json) {
munge: function (json) {
json.inverse = 1 - json.percent;
return json;
}
},
});
var g = Grape.create({ store, percent: 0.4 });
assert.equal(g.get("inverse"), 0.6, "it runs `munge` on `create`");
});
QUnit.test("update", async assert => {
QUnit.test("update", async (assert) => {
const store = createStore();
const widget = await store.find("widget", 123);
assert.equal(widget.get("name"), "Trout Lure");
@@ -39,7 +39,7 @@ QUnit.test("update", async assert => {
assert.equal(result.target.name, widget.get("name"));
});
QUnit.test("updating simultaneously", async assert => {
QUnit.test("updating simultaneously", async (assert) => {
assert.expect(2);
const store = createStore();
@@ -48,16 +48,16 @@ QUnit.test("updating simultaneously", async assert => {
const firstPromise = widget.update({ name: "new name" });
const secondPromise = widget.update({ name: "new name" });
firstPromise.then(function() {
firstPromise.then(function () {
assert.ok(true, "the first promise succeeeds");
});
secondPromise.catch(function() {
secondPromise.catch(function () {
assert.ok(true, "the second promise fails");
});
});
QUnit.test("save new", async assert => {
QUnit.test("save new", async (assert) => {
const store = createStore();
const widget = store.createRecord("widget");
@@ -83,7 +83,7 @@ QUnit.test("save new", async assert => {
assert.equal(result.target.name, widget.get("name"));
});
QUnit.test("creating simultaneously", assert => {
QUnit.test("creating simultaneously", (assert) => {
assert.expect(2);
const store = createStore();
@@ -91,31 +91,31 @@ QUnit.test("creating simultaneously", assert => {
const firstPromise = widget.save({ name: "Evil Widget" });
const secondPromise = widget.save({ name: "Evil Widget" });
firstPromise.then(function() {
firstPromise.then(function () {
assert.ok(true, "the first promise succeeeds");
});
secondPromise.catch(function() {
secondPromise.catch(function () {
assert.ok(true, "the second promise fails");
});
});
QUnit.test("destroyRecord", async assert => {
QUnit.test("destroyRecord", async (assert) => {
const store = createStore();
const widget = await store.find("widget", 123);
assert.ok(await widget.destroyRecord());
});
QUnit.test("custom api name", async assert => {
const store = createStore(type => {
QUnit.test("custom api name", async (assert) => {
const store = createStore((type) => {
if (type === "adapter:my-widget") {
return RestAdapter.extend({
// An adapter like this is used when the server-side key/url
// do not match the name of the es6 class
apiNameFor() {
return "widget";
}
},
}).create();
}
});
+3 -3
View File
@@ -3,7 +3,7 @@ QUnit.module("result-set");
import ResultSet from "discourse/models/result-set";
import createStore from "helpers/create-store";
QUnit.test("defaults", assert => {
QUnit.test("defaults", (assert) => {
const resultSet = ResultSet.create({ content: [] });
assert.equal(resultSet.get("length"), 0);
assert.equal(resultSet.get("totalRows"), 0);
@@ -13,7 +13,7 @@ QUnit.test("defaults", assert => {
assert.ok(!resultSet.get("refreshing"));
});
QUnit.test("pagination support", async assert => {
QUnit.test("pagination support", async (assert) => {
const store = createStore();
const resultSet = await store.findAll("widget");
assert.equal(resultSet.get("length"), 2);
@@ -32,7 +32,7 @@ QUnit.test("pagination support", async assert => {
assert.ok(!resultSet.get("canLoadMore"));
});
QUnit.test("refresh support", async assert => {
QUnit.test("refresh support", async (assert) => {
const store = createStore();
const resultSet = await store.findAll("widget");
assert.equal(
+1 -1
View File
@@ -2,7 +2,7 @@ import Session from "discourse/models/session";
QUnit.module("model:session");
QUnit.test("highestSeenByTopic", assert => {
QUnit.test("highestSeenByTopic", (assert) => {
const session = Session.current();
assert.deepEqual(
session.get("highestSeenByTopic"),
+5 -5
View File
@@ -3,11 +3,11 @@ import Site from "discourse/models/site";
QUnit.module("model:site");
QUnit.test("create", assert => {
QUnit.test("create", (assert) => {
assert.ok(Site.create(), "it can create with no parameters");
});
QUnit.test("instance", assert => {
QUnit.test("instance", (assert) => {
const site = Site.current();
assert.present(site, "We have a current site singleton");
@@ -25,14 +25,14 @@ QUnit.test("instance", assert => {
);
});
QUnit.test("create categories", assert => {
QUnit.test("create categories", (assert) => {
const store = createStore();
const site = store.createRecord("site", {
categories: [
{ id: 1234, name: "Test" },
{ id: 3456, name: "Test Subcategory", parent_category_id: 1234 },
{ id: 3458, name: "Invalid Subcategory", parent_category_id: 6666 }
]
{ id: 3458, name: "Invalid Subcategory", parent_category_id: 6666 },
],
});
const categories = site.get("categories");
@@ -2,6 +2,6 @@ import StaffActionLog from "admin/models/staff-action-log";
QUnit.module("StaffActionLog");
QUnit.test("create", assert => {
QUnit.test("create", (assert) => {
assert.ok(StaffActionLog.create(), "it can be created without arguments");
});
+19 -19
View File
@@ -2,7 +2,7 @@ QUnit.module("service:store");
import createStore from "helpers/create-store";
QUnit.test("createRecord", assert => {
QUnit.test("createRecord", (assert) => {
const store = createStore();
const widget = store.createRecord("widget", { id: 111, name: "hello" });
@@ -11,7 +11,7 @@ QUnit.test("createRecord", assert => {
assert.equal(widget.get("id"), 111);
});
QUnit.test("createRecord without an `id`", assert => {
QUnit.test("createRecord without an `id`", (assert) => {
const store = createStore();
const widget = store.createRecord("widget", { name: "hello" });
@@ -19,7 +19,7 @@ QUnit.test("createRecord without an `id`", assert => {
assert.ok(!widget.get("id"), "there is no id");
});
QUnit.test("createRecord doesn't modify the input `id` field", assert => {
QUnit.test("createRecord doesn't modify the input `id` field", (assert) => {
const store = createStore();
const widget = store.createRecord("widget", { id: 1, name: "hello" });
@@ -31,7 +31,7 @@ QUnit.test("createRecord doesn't modify the input `id` field", assert => {
assert.equal(obj.id, 1, "it does not remove the id from the input");
});
QUnit.test("createRecord without attributes", assert => {
QUnit.test("createRecord without attributes", (assert) => {
const store = createStore();
const widget = store.createRecord("widget");
@@ -41,7 +41,7 @@ QUnit.test("createRecord without attributes", assert => {
QUnit.test(
"createRecord with a record as attributes returns that record from the map",
assert => {
(assert) => {
const store = createStore();
const widget = store.createRecord("widget", { id: 33 });
const secondWidget = store.createRecord("widget", { id: 33 });
@@ -50,7 +50,7 @@ QUnit.test(
}
);
QUnit.test("find", async assert => {
QUnit.test("find", async (assert) => {
const store = createStore();
const widget = await store.find("widget", 123);
@@ -65,19 +65,19 @@ QUnit.test("find", async assert => {
assert.equal(widget.get("extras.hello"), "world", "extra attributes are set");
});
QUnit.test("find with object id", async assert => {
QUnit.test("find with object id", async (assert) => {
const store = createStore();
const widget = await store.find("widget", { id: 123 });
assert.equal(widget.get("firstObject.name"), "Trout Lure");
});
QUnit.test("find with query param", async assert => {
QUnit.test("find with query param", async (assert) => {
const store = createStore();
const widget = await store.find("widget", { name: "Trout Lure" });
assert.equal(widget.get("firstObject.id"), 123);
});
QUnit.test("findStale with no stale results", async assert => {
QUnit.test("findStale with no stale results", async (assert) => {
const store = createStore();
const stale = store.findStale("widget", { name: "Trout Lure" });
@@ -91,20 +91,20 @@ QUnit.test("findStale with no stale results", async assert => {
);
});
QUnit.test("update", async assert => {
QUnit.test("update", async (assert) => {
const store = createStore();
const result = await store.update("widget", 123, { name: "hello" });
assert.ok(result);
});
QUnit.test("update with a multi world name", async assert => {
QUnit.test("update with a multi world name", async (assert) => {
const store = createStore();
const result = await store.update("cool-thing", 123, { name: "hello" });
assert.ok(result);
assert.equal(result.payload.name, "hello");
});
QUnit.test("findAll", async assert => {
QUnit.test("findAll", async (assert) => {
const store = createStore();
const result = await store.findAll("widget");
assert.equal(result.get("length"), 2);
@@ -114,21 +114,21 @@ QUnit.test("findAll", async assert => {
assert.equal(widget.get("name"), "Evil Repellant");
});
QUnit.test("destroyRecord", async assert => {
QUnit.test("destroyRecord", async (assert) => {
const store = createStore();
const widget = await store.find("widget", 123);
assert.ok(await store.destroyRecord("widget", widget));
});
QUnit.test("destroyRecord when new", async assert => {
QUnit.test("destroyRecord when new", async (assert) => {
const store = createStore();
const widget = store.createRecord("widget", { name: "hello" });
assert.ok(await store.destroyRecord("widget", widget));
});
QUnit.test("find embedded", async assert => {
QUnit.test("find embedded", async (assert) => {
const store = createStore();
const fruit = await store.find("fruit", 1);
assert.ok(fruit.get("farmer"), "it has the embedded object");
@@ -141,7 +141,7 @@ QUnit.test("find embedded", async assert => {
assert.ok(fruit.get("category"), "categories are found automatically");
});
QUnit.test("embedded records can be cleared", async assert => {
QUnit.test("embedded records can be cleared", async (assert) => {
const store = createStore();
let fruit = await store.find("fruit", 4);
fruit.set("farmer", { dummy: "object" });
@@ -150,7 +150,7 @@ QUnit.test("embedded records can be cleared", async assert => {
assert.ok(!fruit.get("farmer"));
});
QUnit.test("meta types", async assert => {
QUnit.test("meta types", async (assert) => {
const store = createStore();
const barn = await store.find("barn", 1);
assert.equal(
@@ -160,7 +160,7 @@ QUnit.test("meta types", async assert => {
);
});
QUnit.test("findAll embedded", async assert => {
QUnit.test("findAll embedded", async (assert) => {
const store = createStore();
const fruits = await store.findAll("fruit");
assert.equal(fruits.objectAt(0).get("farmer.name"), "Old MacDonald");
@@ -183,7 +183,7 @@ QUnit.test("findAll embedded", async assert => {
assert.equal(fruits.objectAt(2).get("farmer.name"), "Luke Skywalker");
});
QUnit.test("custom primaryKey", async assert => {
QUnit.test("custom primaryKey", async (assert) => {
const store = createStore();
const cats = await store.findAll("cat");
assert.equal(cats.objectAt(0).name, "souna");
@@ -4,22 +4,22 @@ QUnit.module("model:topic-details");
import Topic from "discourse/models/topic";
var buildDetails = function(id) {
var buildDetails = function (id) {
var topic = Topic.create({ id: id });
return topic.get("details");
};
QUnit.test("defaults", assert => {
QUnit.test("defaults", (assert) => {
var details = buildDetails(1234);
assert.present(details, "the details are present by default");
assert.ok(!details.get("loaded"), "details are not loaded by default");
});
QUnit.test("updateFromJson", assert => {
QUnit.test("updateFromJson", (assert) => {
var details = buildDetails(1234);
details.updateFromJson({
allowed_users: [{ username: "eviltrout" }]
allowed_users: [{ username: "eviltrout" }],
});
assert.equal(
+19 -19
View File
@@ -7,17 +7,17 @@ import { discourseModule } from "helpers/qunit-helpers";
discourseModule("model:topic");
QUnit.test("defaults", assert => {
QUnit.test("defaults", (assert) => {
const topic = Topic.create({ id: 1234 });
assert.blank(topic.get("deleted_at"), "deleted_at defaults to blank");
assert.blank(topic.get("deleted_by"), "deleted_by defaults to blank");
});
QUnit.test("visited", assert => {
QUnit.test("visited", (assert) => {
const topic = Topic.create({
highest_post_number: 2,
last_read_post_number: 1
last_read_post_number: 1,
});
assert.not(
@@ -35,16 +35,16 @@ QUnit.test("visited", assert => {
);
});
QUnit.test("lastUnreadUrl", assert => {
QUnit.test("lastUnreadUrl", (assert) => {
const category = EmberObject.create({
navigate_to_first_post_after_read: true
navigate_to_first_post_after_read: true,
});
const topic = Topic.create({
id: 101,
highest_post_number: 10,
last_read_post_number: 10,
slug: "hello"
slug: "hello",
});
topic.set("category", category);
@@ -52,7 +52,7 @@ QUnit.test("lastUnreadUrl", assert => {
assert.equal(topic.get("lastUnreadUrl"), "/t/hello/101/1");
});
QUnit.test("has details", assert => {
QUnit.test("has details", (assert) => {
const topic = Topic.create({ id: 1234 });
const topicDetails = topic.get("details");
@@ -64,7 +64,7 @@ QUnit.test("has details", assert => {
);
});
QUnit.test("has a postStream", assert => {
QUnit.test("has a postStream", (assert) => {
const topic = Topic.create({ id: 1234 });
const postStream = topic.get("postStream");
@@ -76,7 +76,7 @@ QUnit.test("has a postStream", assert => {
);
});
QUnit.test("has suggestedTopics", assert => {
QUnit.test("has suggestedTopics", (assert) => {
const topic = Topic.create({ suggested_topics: [{ id: 1 }, { id: 2 }] });
const suggestedTopics = topic.get("suggestedTopics");
@@ -84,7 +84,7 @@ QUnit.test("has suggestedTopics", assert => {
assert.containsInstance(suggestedTopics, Topic);
});
QUnit.test("category relationship", assert => {
QUnit.test("category relationship", (assert) => {
// It finds the category by id
const category = Category.list()[0];
const topic = Topic.create({ id: 1111, category_id: category.get("id") });
@@ -92,7 +92,7 @@ QUnit.test("category relationship", assert => {
assert.equal(topic.get("category"), category);
});
QUnit.test("updateFromJson", assert => {
QUnit.test("updateFromJson", (assert) => {
const topic = Topic.create({ id: 1234 });
const category = Category.list()[0];
@@ -100,7 +100,7 @@ QUnit.test("updateFromJson", assert => {
post_stream: [1, 2, 3],
details: { hello: "world" },
cool: "property",
category_id: category.get("id")
category_id: category.get("id"),
});
assert.blank(topic.get("post_stream"), "it does not update post_stream");
@@ -109,12 +109,12 @@ QUnit.test("updateFromJson", assert => {
assert.equal(topic.get("category"), category);
});
QUnit.test("recover", assert => {
QUnit.test("recover", (assert) => {
const user = User.create({ username: "eviltrout" });
const topic = Topic.create({
id: 1234,
deleted_at: new Date(),
deleted_by: user
deleted_by: user,
});
topic.recover();
@@ -122,9 +122,9 @@ QUnit.test("recover", assert => {
assert.blank(topic.get("deleted_by"), "it clears deleted_by");
});
QUnit.test("fancyTitle", assert => {
QUnit.test("fancyTitle", (assert) => {
const topic = Topic.create({
fancy_title: ":smile: with all :) the emojis :pear::peach:"
fancy_title: ":smile: with all :) the emojis :pear::peach:",
});
assert.equal(
@@ -134,7 +134,7 @@ QUnit.test("fancyTitle", assert => {
);
});
QUnit.test("fancyTitle direction", function(assert) {
QUnit.test("fancyTitle direction", function (assert) {
const rtlTopic = Topic.create({ fancy_title: "هذا اختبار" });
const ltrTopic = Topic.create({ fancy_title: "This is a test" });
@@ -151,10 +151,10 @@ QUnit.test("fancyTitle direction", function(assert) {
);
});
QUnit.test("excerpt", assert => {
QUnit.test("excerpt", (assert) => {
const topic = Topic.create({
excerpt: "This is a test topic :smile:",
pinned: true
pinned: true,
});
assert.equal(
@@ -11,49 +11,49 @@ QUnit.module("model:topic-tracking-state", {
afterEach() {
this.clock.restore();
}
},
});
QUnit.test("tag counts", function(assert) {
QUnit.test("tag counts", function (assert) {
const state = TopicTrackingState.create();
state.loadStates([
{
topic_id: 1,
last_read_post_number: null,
tags: ["foo", "new"]
tags: ["foo", "new"],
},
{
topic_id: 2,
last_read_post_number: null,
tags: ["new"]
tags: ["new"],
},
{
topic_id: 3,
last_read_post_number: null,
tags: ["random"]
tags: ["random"],
},
{
topic_id: 4,
last_read_post_number: 1,
highest_post_number: 7,
tags: ["unread"],
notification_level: NotificationLevels.TRACKING
notification_level: NotificationLevels.TRACKING,
},
{
topic_id: 5,
last_read_post_number: 1,
highest_post_number: 7,
tags: ["bar", "unread"],
notification_level: NotificationLevels.TRACKING
notification_level: NotificationLevels.TRACKING,
},
{
topic_id: 6,
last_read_post_number: 1,
highest_post_number: 7,
tags: null,
notification_level: NotificationLevels.TRACKING
}
notification_level: NotificationLevels.TRACKING,
},
]);
const states = state.countTags(["new", "unread"]);
@@ -64,24 +64,24 @@ QUnit.test("tag counts", function(assert) {
assert.equal(states["unread"].newCount, 0, "unread counts");
});
QUnit.test("forEachTracked", function(assert) {
QUnit.test("forEachTracked", function (assert) {
const state = TopicTrackingState.create();
state.loadStates([
{
topic_id: 1,
last_read_post_number: null,
tags: ["foo", "new"]
tags: ["foo", "new"],
},
{
topic_id: 2,
last_read_post_number: null,
tags: ["new"]
tags: ["new"],
},
{
topic_id: 3,
last_read_post_number: null,
tags: ["random"]
tags: ["random"],
},
{
topic_id: 4,
@@ -89,7 +89,7 @@ QUnit.test("forEachTracked", function(assert) {
highest_post_number: 7,
category_id: 7,
tags: ["unread"],
notification_level: NotificationLevels.TRACKING
notification_level: NotificationLevels.TRACKING,
},
{
topic_id: 5,
@@ -97,15 +97,15 @@ QUnit.test("forEachTracked", function(assert) {
highest_post_number: 7,
tags: ["bar", "unread"],
category_id: 7,
notification_level: NotificationLevels.TRACKING
notification_level: NotificationLevels.TRACKING,
},
{
topic_id: 6,
last_read_post_number: 1,
highest_post_number: 7,
tags: null,
notification_level: NotificationLevels.TRACKING
}
notification_level: NotificationLevels.TRACKING,
},
]);
let randomUnread = 0,
@@ -139,7 +139,7 @@ QUnit.test("forEachTracked", function(assert) {
assert.equal(sevenUnread, 2, "seven unread");
});
QUnit.test("sync", function(assert) {
QUnit.test("sync", function (assert) {
const state = TopicTrackingState.create();
state.states["t111"] = { last_read_post_number: null };
@@ -150,9 +150,9 @@ QUnit.test("sync", function(assert) {
highest_post_number: null,
id: 111,
unread: 10,
new_posts: 10
}
]
new_posts: 10,
},
],
};
state.sync(list, "new");
@@ -163,13 +163,13 @@ QUnit.test("sync", function(assert) {
);
});
QUnit.test("subscribe to category", function(assert) {
QUnit.test("subscribe to category", function (assert) {
const store = createStore();
const darth = store.createRecord("category", { id: 1, slug: "darth" }),
luke = store.createRecord("category", {
id: 2,
slug: "luke",
parentCategory: darth
parentCategory: darth,
}),
categoryList = [darth, luke];
@@ -182,17 +182,17 @@ QUnit.test("subscribe to category", function(assert) {
state.notify({
message_type: "new_topic",
topic_id: 1,
payload: { category_id: 2, topic_id: 1 }
payload: { category_id: 2, topic_id: 1 },
});
state.notify({
message_type: "new_topic",
topic_id: 2,
payload: { category_id: 3, topic_id: 2 }
payload: { category_id: 3, topic_id: 2 },
});
state.notify({
message_type: "new_topic",
topic_id: 3,
payload: { category_id: 1, topic_id: 3 }
payload: { category_id: 1, topic_id: 3 },
});
assert.equal(
@@ -207,17 +207,17 @@ QUnit.test("subscribe to category", function(assert) {
state.notify({
message_type: "new_topic",
topic_id: 1,
payload: { category_id: 2, topic_id: 1 }
payload: { category_id: 2, topic_id: 1 },
});
state.notify({
message_type: "new_topic",
topic_id: 2,
payload: { category_id: 3, topic_id: 2 }
payload: { category_id: 3, topic_id: 2 },
});
state.notify({
message_type: "new_topic",
topic_id: 3,
payload: { category_id: 1, topic_id: 3 }
payload: { category_id: 1, topic_id: 3 },
});
assert.equal(
@@ -227,18 +227,18 @@ QUnit.test("subscribe to category", function(assert) {
);
});
QUnit.test("getSubCategoryIds", assert => {
QUnit.test("getSubCategoryIds", (assert) => {
const store = createStore();
const foo = store.createRecord("category", { id: 1, slug: "foo" });
const bar = store.createRecord("category", {
id: 2,
slug: "bar",
parent_category_id: foo.id
parent_category_id: foo.id,
});
const baz = store.createRecord("category", {
id: 3,
slug: "baz",
parent_category_id: bar.id
parent_category_id: bar.id,
});
sandbox.stub(Category, "list").returns([foo, bar, baz]);
@@ -248,31 +248,31 @@ QUnit.test("getSubCategoryIds", assert => {
assert.deepEqual(Array.from(state.getSubCategoryIds(3)), [3]);
});
QUnit.test("countNew", assert => {
QUnit.test("countNew", (assert) => {
const store = createStore();
const foo = store.createRecord("category", {
id: 1,
slug: "foo"
slug: "foo",
});
const bar = store.createRecord("category", {
id: 2,
slug: "bar",
parent_category_id: foo.id
parent_category_id: foo.id,
});
const baz = store.createRecord("category", {
id: 3,
slug: "baz",
parent_category_id: bar.id
parent_category_id: bar.id,
});
const qux = store.createRecord("category", {
id: 4,
slug: "qux"
slug: "qux",
});
sandbox.stub(Category, "list").returns([foo, bar, baz, qux]);
let currentUser = User.create({
username: "chuck",
muted_category_ids: [4]
muted_category_ids: [4],
});
const state = TopicTrackingState.create({ currentUser });
@@ -285,7 +285,7 @@ QUnit.test("countNew", assert => {
last_read_post_number: null,
id: 112,
notification_level: NotificationLevels.TRACKING,
category_id: 2
category_id: 2,
};
assert.equal(state.countNew(1), 1);
@@ -298,7 +298,7 @@ QUnit.test("countNew", assert => {
id: 113,
notification_level: NotificationLevels.TRACKING,
category_id: 3,
tags: ["amazing"]
tags: ["amazing"],
};
assert.equal(state.countNew(1), 2);
@@ -311,7 +311,7 @@ QUnit.test("countNew", assert => {
last_read_post_number: null,
id: 111,
notification_level: NotificationLevels.TRACKING,
category_id: 1
category_id: 1,
};
assert.equal(state.countNew(1), 3);
@@ -321,15 +321,15 @@ QUnit.test("countNew", assert => {
state.states["t115"] = {
last_read_post_number: null,
id: 115,
category_id: 4
category_id: 4,
};
assert.equal(state.countNew(4), 0);
});
QUnit.test("mute topic", function(assert) {
QUnit.test("mute topic", function (assert) {
let currentUser = User.create({
username: "chuck",
muted_category_ids: []
muted_category_ids: [],
});
const state = TopicTrackingState.create({ currentUser });
+5 -5
View File
@@ -2,26 +2,26 @@ import UserAction from "discourse/models/user-action";
QUnit.module("model: user-action");
QUnit.test("collapsing likes", assert => {
QUnit.test("collapsing likes", (assert) => {
var actions = UserAction.collapseStream([
UserAction.create({
action_type: UserAction.TYPES.likes_given,
topic_id: 1,
user_id: 1,
post_number: 1
post_number: 1,
}),
UserAction.create({
action_type: UserAction.TYPES.edits,
topic_id: 2,
user_id: 1,
post_number: 1
post_number: 1,
}),
UserAction.create({
action_type: UserAction.TYPES.likes_given,
topic_id: 1,
user_id: 2,
post_number: 1
})
post_number: 1,
}),
]);
assert.equal(actions.length, 2);
+6 -6
View File
@@ -3,7 +3,7 @@ import badgeFixtures from "fixtures/user-badges";
QUnit.module("model:user-badge");
QUnit.test("createFromJson single", assert => {
QUnit.test("createFromJson single", (assert) => {
const userBadge = UserBadge.createFromJson(
JSON.parse(JSON.stringify(badgeFixtures["/user_badges"]))
);
@@ -25,7 +25,7 @@ QUnit.test("createFromJson single", assert => {
);
});
QUnit.test("createFromJson array", assert => {
QUnit.test("createFromJson array", (assert) => {
const userBadges = UserBadge.createFromJson(
JSON.parse(JSON.stringify(badgeFixtures["/user-badges/:username"]))
);
@@ -37,22 +37,22 @@ QUnit.test("createFromJson array", assert => {
);
});
QUnit.test("findByUsername", async assert => {
QUnit.test("findByUsername", async (assert) => {
const badges = await UserBadge.findByUsername("anne3");
assert.ok(Array.isArray(badges), "returns an array");
});
QUnit.test("findByBadgeId", async assert => {
QUnit.test("findByBadgeId", async (assert) => {
const badges = await UserBadge.findByBadgeId(880);
assert.ok(Array.isArray(badges), "returns an array");
});
QUnit.test("grant", async assert => {
QUnit.test("grant", async (assert) => {
const userBadge = await UserBadge.grant(1, "username");
assert.ok(!Array.isArray(userBadge), "does not return an array");
});
QUnit.test("revoke", async assert => {
QUnit.test("revoke", async (assert) => {
assert.expect(0);
const userBadge = UserBadge.create({ id: 1 });
await userBadge.revoke();
+5 -5
View File
@@ -5,7 +5,7 @@ import User from "discourse/models/user";
QUnit.module("model:user-drafts");
QUnit.test("stream", assert => {
QUnit.test("stream", (assert) => {
const user = User.create({ id: 1, username: "eviltrout" });
const stream = user.get("userDraftsStream");
assert.present(stream, "a user has a drafts stream by default");
@@ -13,15 +13,15 @@ QUnit.test("stream", assert => {
assert.blank(stream.get("content"), "no content by default");
});
QUnit.test("draft", assert => {
QUnit.test("draft", (assert) => {
const drafts = [
UserDraft.create({
draft_key: "topic_1",
post_number: "10"
post_number: "10",
}),
UserDraft.create({
draft_key: NEW_TOPIC_KEY
})
draft_key: NEW_TOPIC_KEY,
}),
];
assert.equal(drafts.length, 2, "drafts count is right");
+2 -2
View File
@@ -3,7 +3,7 @@ import User from "discourse/models/user";
QUnit.module("model: UserStream");
QUnit.test("basics", assert => {
QUnit.test("basics", (assert) => {
var user = User.create({ id: 1, username: "eviltrout" });
var stream = user.get("stream");
assert.present(stream, "a user has a stream by default");
@@ -16,7 +16,7 @@ QUnit.test("basics", assert => {
assert.ok(!stream.get("loaded"), "the stream is not loaded by default");
});
QUnit.test("filterParam", assert => {
QUnit.test("filterParam", (assert) => {
var user = User.create({ id: 1, username: "eviltrout" });
var stream = user.get("stream");
+8 -8
View File
@@ -5,7 +5,7 @@ import pretender from "helpers/create-pretender";
QUnit.module("model:user");
QUnit.test("staff", assert => {
QUnit.test("staff", (assert) => {
var user = User.create({ id: 1, username: "eviltrout" });
assert.ok(!user.get("staff"), "user is not staff");
@@ -17,7 +17,7 @@ QUnit.test("staff", assert => {
assert.ok(user.get("staff"), "admins are staff");
});
QUnit.test("searchContext", assert => {
QUnit.test("searchContext", (assert) => {
var user = User.create({ id: 1, username: "EvilTrout" });
assert.deepEqual(
@@ -27,7 +27,7 @@ QUnit.test("searchContext", assert => {
);
});
QUnit.test("isAllowedToUploadAFile", assert => {
QUnit.test("isAllowedToUploadAFile", (assert) => {
var user = User.create({ trust_level: 0, admin: true });
assert.ok(
user.isAllowedToUploadAFile("image"),
@@ -41,7 +41,7 @@ QUnit.test("isAllowedToUploadAFile", assert => {
);
});
QUnit.test("canMangeGroup", assert => {
QUnit.test("canMangeGroup", (assert) => {
let user = User.create({ admin: true });
let group = Group.create({ automatic: true });
@@ -70,7 +70,7 @@ QUnit.test("canMangeGroup", assert => {
);
});
QUnit.test("resolvedTimezone", assert => {
QUnit.test("resolvedTimezone", (assert) => {
const tz = "Australia/Brisbane";
let user = User.create({ timezone: tz, username: "chuck", id: 111 });
let stub = sandbox.stub(moment.tz, "guess").returns("America/Chicago");
@@ -99,7 +99,7 @@ QUnit.test("resolvedTimezone", assert => {
spy.calledWith("/u/chuck.json", {
type: "PUT",
dataType: "json",
data: { timezone: "America/Chicago" }
data: { timezone: "America/Chicago" },
}),
"if the user has no timezone save it with an AJAX update"
);
@@ -114,7 +114,7 @@ QUnit.test("resolvedTimezone", assert => {
spy.calledWith("/u/howardhamlin.json", {
type: "PUT",
dataType: "json",
data: { timezone: "America/Chicago" }
data: { timezone: "America/Chicago" },
}),
"if the user has no timezone, and the user is not the current user, do NOT save it with an AJAX update"
);
@@ -122,7 +122,7 @@ QUnit.test("resolvedTimezone", assert => {
stub.restore();
});
QUnit.test("muted ids", assert => {
QUnit.test("muted ids", (assert) => {
let user = User.create({ username: "chuck", muted_category_ids: [] });
assert.deepEqual(user.calculateMutedIds(0, 1, "muted_category_ids"), [1]);