2016-01-04 15:18:09 -05:00
|
|
|
import { moduleForWidget, widgetTest } from "helpers/widget-test";
|
|
|
|
import Topic from "discourse/models/topic";
|
|
|
|
import Post from "discourse/models/post";
|
|
|
|
|
|
|
|
moduleForWidget("post-stream");
|
|
|
|
|
|
|
|
function postStreamTest(name, attrs) {
|
|
|
|
widgetTest(name, {
|
2016-11-25 15:38:45 -05:00
|
|
|
template: `{{mount-widget widget="post-stream" args=(hash posts=posts)}}`,
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2017-09-25 13:18:26 -04:00
|
|
|
const site = this.container.lookup("site:main");
|
|
|
|
let posts = attrs.posts.call(this);
|
|
|
|
posts.forEach((p) => p.set("site", site));
|
|
|
|
this.set("posts", posts);
|
2016-01-04 15:18:09 -05:00
|
|
|
},
|
|
|
|
test: attrs.test,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
postStreamTest("basics", {
|
|
|
|
posts() {
|
|
|
|
const site = this.container.lookup("site:main");
|
2020-07-16 13:22:13 -04:00
|
|
|
const topic = Topic.create();
|
|
|
|
topic.set("details.created_by", { id: 123 });
|
2016-01-04 15:18:09 -05:00
|
|
|
return [
|
2016-04-20 15:29:27 -04:00
|
|
|
Post.create({
|
|
|
|
topic,
|
|
|
|
id: 1,
|
|
|
|
post_number: 1,
|
|
|
|
user_id: 123,
|
|
|
|
primary_group_name: "trout",
|
|
|
|
avatar_template: "/images/avatar.png",
|
2016-01-04 15:18:09 -05:00
|
|
|
}),
|
|
|
|
Post.create({
|
|
|
|
topic,
|
|
|
|
id: 2,
|
|
|
|
post_number: 2,
|
|
|
|
post_type: site.get("post_types.moderator_action"),
|
2018-06-15 11:03:24 -04:00
|
|
|
}),
|
2016-01-04 15:18:09 -05:00
|
|
|
Post.create({ topic, id: 3, post_number: 3, hidden: true }),
|
|
|
|
Post.create({
|
|
|
|
topic,
|
|
|
|
id: 4,
|
|
|
|
post_number: 4,
|
|
|
|
post_type: site.get("post_types.whisper"),
|
|
|
|
}),
|
2016-04-20 15:29:27 -04:00
|
|
|
Post.create({
|
|
|
|
topic,
|
|
|
|
id: 5,
|
|
|
|
post_number: 5,
|
|
|
|
wiki: true,
|
|
|
|
via_email: true,
|
|
|
|
}),
|
|
|
|
Post.create({
|
|
|
|
topic,
|
|
|
|
id: 6,
|
|
|
|
post_number: 6,
|
|
|
|
via_email: true,
|
|
|
|
is_auto_generated: true,
|
|
|
|
}),
|
2016-01-04 15:18:09 -05:00
|
|
|
];
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.equal(find(".post-stream").length, 1);
|
|
|
|
assert.equal(find(".topic-post").length, 6, "renders all posts");
|
2016-01-04 15:18:09 -05:00
|
|
|
|
|
|
|
// look for special class bindings
|
|
|
|
assert.equal(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".topic-post:eq(0).topic-owner").length,
|
2016-01-04 15:18:09 -05:00
|
|
|
1,
|
|
|
|
"it applies the topic owner class"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".topic-post:eq(0).group-trout").length,
|
2016-01-04 15:18:09 -05:00
|
|
|
1,
|
|
|
|
"it applies the primary group class"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".topic-post:eq(0).regular").length,
|
2016-01-04 15:18:09 -05:00
|
|
|
1,
|
|
|
|
"it applies the regular class"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".topic-post:eq(1).moderator").length,
|
2016-01-04 15:18:09 -05:00
|
|
|
1,
|
|
|
|
"it applies the moderator class"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".topic-post:eq(2).post-hidden").length,
|
2016-01-04 15:18:09 -05:00
|
|
|
1,
|
|
|
|
"it applies the hidden class"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".topic-post:eq(3).whisper").length,
|
2016-01-04 15:18:09 -05:00
|
|
|
1,
|
|
|
|
"it applies the whisper class"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".topic-post:eq(4).wiki").length,
|
2016-01-04 15:18:09 -05:00
|
|
|
1,
|
|
|
|
"it applies the wiki class"
|
|
|
|
);
|
|
|
|
|
|
|
|
// it renders an article for the body with appropriate attributes
|
2019-02-25 10:04:55 -05:00
|
|
|
assert.equal(find("article#post_2").length, 1);
|
|
|
|
assert.equal(find("article[data-user-id=123]").length, 1);
|
|
|
|
assert.equal(find("article[data-post-id=3]").length, 1);
|
|
|
|
assert.equal(find("article#post_5.via-email").length, 1);
|
|
|
|
assert.equal(find("article#post_6.is-auto-generated").length, 1);
|
2016-01-04 15:18:09 -05:00
|
|
|
|
|
|
|
assert.equal(
|
2019-02-25 10:04:55 -05:00
|
|
|
find("article:eq(0) .main-avatar").length,
|
2016-01-04 15:18:09 -05:00
|
|
|
1,
|
|
|
|
"renders the main avatar"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
postStreamTest("deleted posts", {
|
|
|
|
posts() {
|
2020-07-16 13:22:13 -04:00
|
|
|
const topic = Topic.create();
|
|
|
|
topic.set("details.created_by", { id: 123 });
|
2016-01-04 15:18:09 -05:00
|
|
|
return [
|
2016-02-11 16:51:50 -05:00
|
|
|
Post.create({
|
|
|
|
topic,
|
|
|
|
id: 1,
|
|
|
|
post_number: 1,
|
|
|
|
deleted_at: new Date().toString(),
|
|
|
|
}),
|
2016-01-04 15:18:09 -05:00
|
|
|
];
|
|
|
|
},
|
|
|
|
|
|
|
|
test(assert) {
|
|
|
|
assert.equal(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".topic-post.deleted").length,
|
2016-01-04 15:18:09 -05:00
|
|
|
1,
|
|
|
|
"it applies the deleted class"
|
|
|
|
);
|
|
|
|
assert.equal(
|
2019-02-25 10:04:55 -05:00
|
|
|
find(".deleted-user-avatar").length,
|
2016-01-04 15:18:09 -05:00
|
|
|
1,
|
|
|
|
"it has the trash avatar"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|