2019-10-29 15:23:50 -04:00
|
|
|
import EmberObject from "@ember/object";
|
2019-10-29 14:52:36 -04:00
|
|
|
import { next } from "@ember/runloop";
|
2017-12-13 16:12:06 -05:00
|
|
|
import Topic from "discourse/models/topic";
|
2018-11-29 00:51:31 -05:00
|
|
|
import PostStream from "discourse/models/post-stream";
|
|
|
|
import { Placeholder } from "discourse/lib/posts-with-placeholders";
|
2015-08-11 12:27:07 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
moduleFor("controller:topic", "controller:topic", {
|
2019-10-04 10:06:08 -04:00
|
|
|
needs: [
|
|
|
|
"controller:composer",
|
|
|
|
"controller:application",
|
|
|
|
"service:app-events"
|
|
|
|
],
|
2017-06-14 13:57:58 -04:00
|
|
|
beforeEach() {
|
2019-10-04 10:06:08 -04:00
|
|
|
this.registry.injection("controller", "appEvents", "service:app-events");
|
2017-12-13 16:12:06 -05:00
|
|
|
}
|
2014-07-30 17:53:14 -04:00
|
|
|
});
|
2013-06-20 17:20:08 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
QUnit.test("editTopic", function(assert) {
|
|
|
|
const model = Topic.create();
|
|
|
|
const controller = this.subject({ model });
|
2015-02-12 15:37:02 -05:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
assert.not(controller.get("editingTopic"), "we are not editing by default");
|
2013-06-20 17:20:08 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
controller.set("model.details.can_edit", false);
|
|
|
|
controller.send("editTopic");
|
2014-07-30 17:53:14 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("editingTopic"),
|
|
|
|
"calling editTopic doesn't enable editing unless the user can edit"
|
|
|
|
);
|
2013-06-20 17:20:08 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
controller.set("model.details.can_edit", true);
|
|
|
|
controller.send("editTopic");
|
2013-06-20 17:20:08 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
controller.get("editingTopic"),
|
|
|
|
"calling editTopic enables editing if the user can edit"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
assert.equal(controller.get("buffered.title"), model.get("title"));
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("buffered.category_id"),
|
|
|
|
model.get("category_id")
|
|
|
|
);
|
2013-06-20 17:20:08 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
controller.send("cancelEditingTopic");
|
2013-06-20 17:20:08 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("editingTopic"),
|
|
|
|
"cancelling edit mode reverts the property value"
|
|
|
|
);
|
2013-09-04 11:53:00 -04:00
|
|
|
});
|
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
QUnit.test("toggleMultiSelect", function(assert) {
|
|
|
|
const model = Topic.create();
|
|
|
|
const controller = this.subject({ model });
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("multiSelect"),
|
|
|
|
"multi selection mode is disabled by default"
|
|
|
|
);
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
controller.get("selectedPostIds").pushObject(1);
|
|
|
|
assert.equal(controller.get("selectedPostIds.length"), 1);
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
controller.send("toggleMultiSelect");
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
controller.get("multiSelect"),
|
|
|
|
"calling 'toggleMultiSelect' once enables multi selection mode"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
controller.get("selectedPostIds.length"),
|
|
|
|
0,
|
|
|
|
"toggling 'multiSelect' clears 'selectedPostIds'"
|
|
|
|
);
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
controller.get("selectedPostIds").pushObject(2);
|
|
|
|
assert.equal(controller.get("selectedPostIds.length"), 1);
|
|
|
|
|
|
|
|
controller.send("toggleMultiSelect");
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("multiSelect"),
|
|
|
|
"calling 'toggleMultiSelect' twice disables multi selection mode"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
controller.get("selectedPostIds.length"),
|
|
|
|
0,
|
|
|
|
"toggling 'multiSelect' clears 'selectedPostIds'"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("selectedPosts", function(assert) {
|
|
|
|
const postStream = { posts: [{ id: 1 }, { id: 2 }, { id: 3 }] };
|
|
|
|
const model = Topic.create({ postStream });
|
|
|
|
const controller = this.subject({ model });
|
|
|
|
|
|
|
|
controller.set("selectedPostIds", [1, 2, 42]);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("selectedPosts.length"),
|
|
|
|
2,
|
|
|
|
"selectedPosts only contains already loaded posts"
|
|
|
|
);
|
|
|
|
assert.not(
|
|
|
|
controller.get("selectedPosts").some(p => p === undefined),
|
|
|
|
"selectedPosts only contains valid post objects"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("selectedAllPosts", function(assert) {
|
|
|
|
const postStream = { stream: [1, 2, 3] };
|
|
|
|
const model = Topic.create({ postStream });
|
|
|
|
const controller = this.subject({ model });
|
|
|
|
|
|
|
|
controller.set("selectedPostIds", [1, 2]);
|
|
|
|
|
|
|
|
assert.not(controller.get("selectedAllPosts"), "not all posts are selected");
|
|
|
|
|
|
|
|
controller.get("selectedPostIds").pushObject(3);
|
|
|
|
|
|
|
|
assert.ok(controller.get("selectedAllPosts"), "all posts are selected");
|
|
|
|
|
|
|
|
controller.get("selectedPostIds").pushObject(42);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
controller.get("selectedAllPosts"),
|
|
|
|
"all posts (including filtered posts) are selected"
|
|
|
|
);
|
2018-07-12 23:12:35 -04:00
|
|
|
|
|
|
|
model.setProperties({
|
|
|
|
"postStream.isMegaTopic": true,
|
|
|
|
posts_count: 1
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
controller.get("selectedAllPosts"),
|
|
|
|
"it uses the topic's post count for megatopics"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("selectedPostsUsername", function(assert) {
|
|
|
|
const postStream = {
|
|
|
|
posts: [
|
|
|
|
{ id: 1, username: "gary" },
|
|
|
|
{ id: 2, username: "gary" },
|
2018-06-15 11:03:24 -04:00
|
|
|
{ id: 3, username: "lili" }
|
2017-12-13 16:12:06 -05:00
|
|
|
],
|
|
|
|
stream: [1, 2, 3]
|
|
|
|
};
|
|
|
|
|
|
|
|
const model = Topic.create({ postStream });
|
|
|
|
const controller = this.subject({ model });
|
|
|
|
const selectedPostIds = controller.get("selectedPostIds");
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("selectedPostsUsername"),
|
|
|
|
undefined,
|
|
|
|
"no username when no selected posts"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.pushObject(1);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("selectedPostsUsername"),
|
|
|
|
"gary",
|
|
|
|
"username of the selected posts"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.pushObject(2);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("selectedPostsUsername"),
|
|
|
|
"gary",
|
|
|
|
"username of all the selected posts when same user"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.pushObject(3);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("selectedPostsUsername"),
|
|
|
|
undefined,
|
|
|
|
"no username when more than 1 user"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.replace(2, 1, [42]);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("selectedPostsUsername"),
|
|
|
|
undefined,
|
|
|
|
"no username when not already loaded posts are selected"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("showSelectedPostsAtBottom", function(assert) {
|
2019-10-29 15:23:50 -04:00
|
|
|
const site = EmberObject.create({ mobileView: false });
|
2017-12-13 16:12:06 -05:00
|
|
|
const model = Topic.create({ posts_count: 3 });
|
|
|
|
const controller = this.subject({ model, site });
|
|
|
|
|
2017-12-13 16:24:02 -05:00
|
|
|
assert.not(controller.get("showSelectedPostsAtBottom"), "false on desktop");
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
site.set("mobileView", true);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("showSelectedPostsAtBottom"),
|
|
|
|
"requires at least 3 posts on mobile"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
model.set("posts_count", 4);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
controller.get("showSelectedPostsAtBottom"),
|
|
|
|
"true when mobile and more than 3 posts"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("canDeleteSelected", function(assert) {
|
|
|
|
const postStream = {
|
|
|
|
posts: [
|
|
|
|
{ id: 1, can_delete: false },
|
|
|
|
{ id: 2, can_delete: true },
|
|
|
|
{ id: 3, can_delete: true }
|
|
|
|
],
|
|
|
|
stream: [1, 2, 3]
|
|
|
|
};
|
2018-07-06 12:21:00 -04:00
|
|
|
const currentUser = Discourse.User.create({ admin: false });
|
|
|
|
this.registry.register("current-user:main", currentUser, {
|
|
|
|
instantiate: false
|
|
|
|
});
|
|
|
|
this.registry.injection("controller", "currentUser", "current-user:main");
|
2017-12-13 16:12:06 -05:00
|
|
|
const model = Topic.create({ postStream });
|
|
|
|
const controller = this.subject({ model });
|
|
|
|
const selectedPostIds = controller.get("selectedPostIds");
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("canDeleteSelected"),
|
|
|
|
"false when no posts are selected"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.pushObject(1);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("canDeleteSelected"),
|
|
|
|
"false when can't delete one of the selected posts"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.replace(0, 1, [2, 3]);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
controller.get("canDeleteSelected"),
|
|
|
|
"true when all selected posts can be deleted"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.pushObject(1);
|
|
|
|
|
2018-07-06 12:21:00 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("canDeleteSelected"),
|
|
|
|
"false when all posts are selected and user is staff"
|
|
|
|
);
|
|
|
|
|
|
|
|
currentUser.set("admin", true);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
controller.get("canDeleteSelected"),
|
2018-07-06 12:21:00 -04:00
|
|
|
"true when all posts are selected and user is staff"
|
2018-06-15 11:03:24 -04:00
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("Can split/merge topic", function(assert) {
|
|
|
|
const postStream = {
|
2018-01-22 11:48:03 -05:00
|
|
|
posts: [
|
|
|
|
{ id: 1, post_number: 1, post_type: 1 },
|
|
|
|
{ id: 2, post_number: 2, post_type: 4 },
|
|
|
|
{ id: 3, post_number: 3, post_type: 1 }
|
|
|
|
],
|
|
|
|
stream: [1, 2, 3]
|
2017-12-13 16:12:06 -05:00
|
|
|
};
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
const model = Topic.create({
|
|
|
|
postStream,
|
|
|
|
details: { can_move_posts: false }
|
|
|
|
});
|
2017-12-13 16:12:06 -05:00
|
|
|
const controller = this.subject({ model });
|
|
|
|
const selectedPostIds = controller.get("selectedPostIds");
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("canMergeTopic"),
|
|
|
|
"can't merge topic when no posts are selected"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.pushObject(1);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("canMergeTopic"),
|
|
|
|
"can't merge topic when can't move posts"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
model.set("details.can_move_posts", true);
|
|
|
|
|
|
|
|
assert.ok(controller.get("canMergeTopic"), "can merge topic");
|
|
|
|
|
2018-01-22 11:48:03 -05:00
|
|
|
selectedPostIds.removeObject(1);
|
2017-12-13 16:12:06 -05:00
|
|
|
selectedPostIds.pushObject(2);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
controller.get("canMergeTopic"),
|
|
|
|
"can merge topic when 1st post is not a regular post"
|
|
|
|
);
|
2018-01-22 11:48:03 -05:00
|
|
|
|
|
|
|
selectedPostIds.pushObject(3);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
controller.get("canMergeTopic"),
|
|
|
|
"can merge topic when all posts are selected"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test("canChangeOwner", function(assert) {
|
|
|
|
const currentUser = Discourse.User.create({ admin: false });
|
2018-06-15 11:03:24 -04:00
|
|
|
this.registry.register("current-user:main", currentUser, {
|
|
|
|
instantiate: false
|
|
|
|
});
|
2017-12-13 16:12:06 -05:00
|
|
|
this.registry.injection("controller", "currentUser", "current-user:main");
|
|
|
|
|
|
|
|
const postStream = {
|
2018-06-15 11:03:24 -04:00
|
|
|
posts: [{ id: 1, username: "gary" }, { id: 2, username: "lili" }],
|
2017-12-13 16:12:06 -05:00
|
|
|
stream: [1, 2]
|
|
|
|
};
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
const model = Topic.create({ postStream, currentUser: { admin: false } });
|
2017-12-13 16:12:06 -05:00
|
|
|
const controller = this.subject({ model });
|
|
|
|
const selectedPostIds = controller.get("selectedPostIds");
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("canChangeOwner"),
|
|
|
|
"false when no posts are selected"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.pushObject(1);
|
|
|
|
|
|
|
|
assert.not(controller.get("canChangeOwner"), "false when not admin");
|
|
|
|
|
|
|
|
currentUser.set("admin", true);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
controller.get("canChangeOwner"),
|
|
|
|
"true when admin and one post is selected"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.pushObject(2);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("canChangeOwner"),
|
|
|
|
"false when admin but more than 1 user"
|
|
|
|
);
|
2013-09-04 11:53:00 -04:00
|
|
|
});
|
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
QUnit.test("canMergePosts", function(assert) {
|
|
|
|
const postStream = {
|
|
|
|
posts: [
|
|
|
|
{ id: 1, username: "gary", can_delete: true },
|
|
|
|
{ id: 2, username: "lili", can_delete: true },
|
|
|
|
{ id: 3, username: "gary", can_delete: false },
|
2018-06-15 11:03:24 -04:00
|
|
|
{ id: 4, username: "gary", can_delete: true }
|
2017-12-13 16:12:06 -05:00
|
|
|
],
|
|
|
|
stream: [1, 2, 3]
|
|
|
|
};
|
|
|
|
|
|
|
|
const model = Topic.create({ postStream });
|
|
|
|
const controller = this.subject({ model });
|
|
|
|
const selectedPostIds = controller.get("selectedPostIds");
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("canMergePosts"),
|
|
|
|
"false when no posts are selected"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.pushObject(1);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("canMergePosts"),
|
|
|
|
"false when only one post is selected"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.pushObject(2);
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("canMergePosts"),
|
|
|
|
"false when selected posts are from different users"
|
|
|
|
);
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
selectedPostIds.replace(1, 1, [3]);
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.not(
|
|
|
|
controller.get("canMergePosts"),
|
|
|
|
"false when selected posts can't be deleted"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
selectedPostIds.replace(1, 1, [4]);
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.ok(
|
|
|
|
controller.get("canMergePosts"),
|
|
|
|
"true when all selected posts are deletable and by the same user"
|
|
|
|
);
|
2013-09-04 11:53:00 -04:00
|
|
|
});
|
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
QUnit.test("Select/deselect all", function(assert) {
|
|
|
|
const postStream = { stream: [1, 2, 3] };
|
|
|
|
const model = Topic.create({ postStream });
|
|
|
|
const controller = this.subject({ model });
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("selectedPostsCount"),
|
|
|
|
0,
|
|
|
|
"no posts selected by default"
|
|
|
|
);
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
controller.send("selectAll");
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("selectedPostsCount"),
|
|
|
|
postStream.stream.length,
|
|
|
|
"calling 'selectAll' selects all posts"
|
|
|
|
);
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
controller.send("deselectAll");
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
controller.get("selectedPostsCount"),
|
|
|
|
0,
|
|
|
|
"calling 'deselectAll' deselects all posts"
|
|
|
|
);
|
2013-09-04 11:53:00 -04:00
|
|
|
});
|
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
QUnit.test("togglePostSelection", function(assert) {
|
|
|
|
const controller = this.subject();
|
|
|
|
const selectedPostIds = controller.get("selectedPostIds");
|
|
|
|
|
|
|
|
assert.equal(selectedPostIds[0], undefined, "no posts selected by default");
|
2013-09-04 11:53:00 -04:00
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
controller.send("togglePostSelection", { id: 1 });
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
selectedPostIds[0],
|
|
|
|
1,
|
|
|
|
"adds the selected post id if not already selected"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
controller.send("togglePostSelection", { id: 1 });
|
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
assert.equal(
|
|
|
|
selectedPostIds[0],
|
|
|
|
undefined,
|
|
|
|
"removes the selected post id if already selected"
|
|
|
|
);
|
2017-12-13 16:12:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// QUnit.test("selectReplies", function(assert) {
|
|
|
|
// const controller = this.subject();
|
|
|
|
// const selectedPostIds = controller.get("selectedPostIds");
|
|
|
|
//
|
|
|
|
// assert.equal(selectedPostIds[0], undefined, "no posts selected by default");
|
|
|
|
//
|
|
|
|
// controller.send("selectReplies", { id: 42 });
|
|
|
|
//
|
|
|
|
// assert.equal(selectedPostIds[0], 42, "selected post #42");
|
|
|
|
// assert.equal(selectedPostIds[1], 45, "selected post #45");
|
|
|
|
// assert.equal(selectedPostIds[2], 100, "selected post #100");
|
|
|
|
// });
|
|
|
|
|
|
|
|
QUnit.test("selectBelow", function(assert) {
|
2019-10-29 15:23:50 -04:00
|
|
|
const site = EmberObject.create({
|
2019-05-06 09:22:11 -04:00
|
|
|
post_types: { small_action: 3, whisper: 4 }
|
|
|
|
});
|
|
|
|
|
|
|
|
const postStream = {
|
|
|
|
stream: [1, 2, 3, 4, 5, 6, 7, 8],
|
|
|
|
posts: [
|
|
|
|
{ id: 5, cooked: "whisper post", post_type: 4 },
|
|
|
|
{ id: 6, cooked: "a small action", post_type: 3 },
|
|
|
|
{ id: 7, cooked: "", post_type: 4 }
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2017-12-13 16:12:06 -05:00
|
|
|
const model = Topic.create({ postStream });
|
2019-05-06 09:22:11 -04:00
|
|
|
const controller = this.subject({ site, model });
|
|
|
|
let selectedPostIds = controller.get("selectedPostIds");
|
2017-12-13 16:12:06 -05:00
|
|
|
|
|
|
|
assert.equal(selectedPostIds[0], undefined, "no posts selected by default");
|
|
|
|
|
|
|
|
controller.send("selectBelow", { id: 3 });
|
|
|
|
|
|
|
|
assert.equal(selectedPostIds[0], 3, "selected post #3");
|
|
|
|
assert.equal(selectedPostIds[1], 4, "also selected 1st post below post #3");
|
|
|
|
assert.equal(selectedPostIds[2], 5, "also selected 2nd post below post #3");
|
2019-05-06 09:22:11 -04:00
|
|
|
assert.equal(selectedPostIds[3], 8, "also selected 3rd post below post #3");
|
2013-09-04 11:53:00 -04:00
|
|
|
});
|
2018-11-29 00:51:31 -05:00
|
|
|
|
|
|
|
QUnit.test("topVisibleChanged", function(assert) {
|
|
|
|
const postStream = PostStream.create({
|
|
|
|
posts: [{ id: 1 }]
|
|
|
|
});
|
|
|
|
|
|
|
|
const model = Topic.create({ postStream });
|
|
|
|
const controller = this.subject({ model });
|
|
|
|
const placeholder = new Placeholder("post-placeholder");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
controller.send("topVisibleChanged", {
|
|
|
|
post: placeholder
|
|
|
|
}),
|
|
|
|
null,
|
|
|
|
"it should work with a post-placehodler"
|
|
|
|
);
|
|
|
|
});
|
2019-07-12 05:42:57 -04:00
|
|
|
|
|
|
|
QUnit.test(
|
|
|
|
"deletePost - no modal is shown if post does not have replies",
|
|
|
|
function(assert) {
|
|
|
|
/* global server */
|
|
|
|
server.get("/posts/2/reply-ids.json", () => {
|
|
|
|
return [200, { "Content-Type": "application/json" }, []];
|
|
|
|
});
|
|
|
|
|
|
|
|
let destroyed;
|
2019-10-29 15:23:50 -04:00
|
|
|
const post = EmberObject.create({
|
2019-07-12 05:42:57 -04:00
|
|
|
id: 2,
|
|
|
|
post_number: 2,
|
|
|
|
can_delete: true,
|
|
|
|
reply_count: 3,
|
|
|
|
destroy: () => {
|
|
|
|
destroyed = true;
|
|
|
|
return Ember.RSVP.Promise.resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-29 15:23:50 -04:00
|
|
|
const postStream = EmberObject.create({
|
2019-07-12 05:42:57 -04:00
|
|
|
stream: [2, 3, 4],
|
|
|
|
posts: [post, { id: 3 }, { id: 4 }]
|
|
|
|
});
|
|
|
|
|
2019-10-29 15:23:50 -04:00
|
|
|
const currentUser = EmberObject.create({ moderator: true });
|
2019-07-12 05:42:57 -04:00
|
|
|
const model = Topic.create({ postStream });
|
|
|
|
const controller = this.subject({ model, currentUser });
|
|
|
|
|
|
|
|
const done = assert.async();
|
|
|
|
controller.send("deletePost", post);
|
|
|
|
|
2019-10-29 14:52:36 -04:00
|
|
|
next(() => {
|
2019-07-12 05:42:57 -04:00
|
|
|
assert.ok(destroyed, "post was destroyed");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|