2021-11-14 08:14:49 -05:00
|
|
|
import {
|
|
|
|
acceptance,
|
|
|
|
exists,
|
|
|
|
query,
|
|
|
|
queryAll,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import { test } from "qunit";
|
|
|
|
import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers";
|
|
|
|
|
|
|
|
const response = (object) => {
|
|
|
|
return [200, { "Content-Type": "text/html; charset=utf-8" }, object];
|
|
|
|
};
|
|
|
|
|
|
|
|
const jsonResponse = (object) => {
|
|
|
|
return [200, { "Content-Type": "application/json; charset=utf-8" }, object];
|
|
|
|
};
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
acceptance("Chat Integration", function (needs) {
|
|
|
|
needs.user();
|
|
|
|
|
|
|
|
needs.pretender((server) => {
|
2021-08-26 09:52:53 -04:00
|
|
|
server.get("/admin/plugins/chat-integration/providers", () => {
|
2019-03-20 06:57:07 -04:00
|
|
|
return jsonResponse({
|
2018-09-12 11:16:18 -04:00
|
|
|
providers: [
|
|
|
|
{
|
|
|
|
name: "dummy",
|
|
|
|
id: "dummy",
|
2020-09-04 07:23:28 -04:00
|
|
|
channel_parameters: [{ key: "somekey", regex: "^\\S+$" }],
|
|
|
|
},
|
|
|
|
],
|
2018-09-12 11:16:18 -04:00
|
|
|
});
|
2017-07-11 10:37:44 -04:00
|
|
|
});
|
2017-10-03 05:42:07 -04:00
|
|
|
|
2021-08-26 09:52:53 -04:00
|
|
|
server.get("/admin/plugins/chat-integration/channels", () => {
|
2019-03-20 06:57:07 -04:00
|
|
|
return jsonResponse({
|
2018-09-12 11:16:18 -04:00
|
|
|
channels: [
|
|
|
|
{
|
|
|
|
id: 97,
|
|
|
|
provider: "dummy",
|
|
|
|
data: { somekey: "#general" },
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
id: 98,
|
|
|
|
channel_id: 97,
|
|
|
|
category_id: null,
|
|
|
|
team_id: null,
|
|
|
|
type: "normal",
|
|
|
|
tags: [],
|
|
|
|
filter: "watch",
|
2020-09-04 07:23:28 -04:00
|
|
|
error_key: null,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2018-09-12 11:16:18 -04:00
|
|
|
});
|
2017-07-11 10:37:44 -04:00
|
|
|
});
|
2017-10-03 05:42:07 -04:00
|
|
|
|
2021-08-26 09:52:53 -04:00
|
|
|
server.post("/admin/plugins/chat-integration/channels", () => {
|
2018-09-12 11:16:18 -04:00
|
|
|
return response({});
|
2017-07-18 15:42:00 -04:00
|
|
|
});
|
2017-10-03 05:42:07 -04:00
|
|
|
|
2021-08-26 09:52:53 -04:00
|
|
|
server.put("/admin/plugins/chat-integration/channels/:id", () => {
|
2018-09-12 11:16:18 -04:00
|
|
|
return response({});
|
2017-08-21 11:46:43 -04:00
|
|
|
});
|
2017-10-03 05:42:07 -04:00
|
|
|
|
2021-08-26 09:52:53 -04:00
|
|
|
server.delete("/admin/plugins/chat-integration/channels/:id", () => {
|
2018-09-12 11:16:18 -04:00
|
|
|
return response({});
|
2017-07-18 15:42:00 -04:00
|
|
|
});
|
2017-10-03 05:42:07 -04:00
|
|
|
|
2021-08-26 09:52:53 -04:00
|
|
|
server.post("/admin/plugins/chat-integration/rules", () => {
|
2018-09-12 11:16:18 -04:00
|
|
|
return response({});
|
2017-07-11 10:37:44 -04:00
|
|
|
});
|
2017-10-03 05:42:07 -04:00
|
|
|
|
2021-08-26 09:52:53 -04:00
|
|
|
server.put("/admin/plugins/chat-integration/rules/:id", () => {
|
2018-09-12 11:16:18 -04:00
|
|
|
return response({});
|
2017-07-11 10:37:44 -04:00
|
|
|
});
|
2017-10-03 05:42:07 -04:00
|
|
|
|
2021-08-26 09:52:53 -04:00
|
|
|
server.delete("/admin/plugins/chat-integration/rules/:id", () => {
|
2018-09-12 11:16:18 -04:00
|
|
|
return response({});
|
2017-07-11 10:37:44 -04:00
|
|
|
});
|
2017-10-03 05:42:07 -04:00
|
|
|
|
2021-08-26 09:52:53 -04:00
|
|
|
server.post("/admin/plugins/chat-integration/test", () => {
|
2018-09-12 11:16:18 -04:00
|
|
|
return response({});
|
2017-07-11 10:37:44 -04:00
|
|
|
});
|
2017-10-03 05:42:07 -04:00
|
|
|
|
2018-09-12 11:16:18 -04:00
|
|
|
server.get("/groups/search.json", () => {
|
2019-03-20 06:57:07 -04:00
|
|
|
return jsonResponse([]);
|
2017-08-01 12:28:12 -04:00
|
|
|
});
|
2020-12-30 13:51:57 -05:00
|
|
|
});
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
test("Rules load successfully", async function (assert) {
|
2021-08-26 09:52:53 -04:00
|
|
|
await visit("/admin/plugins/chat-integration");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
assert.ok(
|
|
|
|
exists("#admin-plugin-chat table"),
|
|
|
|
"it shows the table of rules"
|
|
|
|
);
|
2019-03-20 06:57:07 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.strictEqual(
|
|
|
|
queryAll("#admin-plugin-chat table tr td")[0].innerText.trim(),
|
2020-12-30 13:51:57 -05:00
|
|
|
"All posts and replies",
|
|
|
|
"rule displayed"
|
|
|
|
);
|
|
|
|
});
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
test("Create channel works", async function (assert) {
|
2021-08-26 09:52:53 -04:00
|
|
|
await visit("/admin/plugins/chat-integration");
|
2020-12-30 13:51:57 -05:00
|
|
|
await click("#create-channel");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
assert.ok(
|
|
|
|
exists("#chat-integration-edit-channel-modal"),
|
|
|
|
"it displays the modal"
|
|
|
|
);
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.ok(query("#save-channel").disabled, "it disables the save button");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
await fillIn("#chat-integration-edit-channel-modal input", "#general");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.notOk(query("#save-channel").disabled, "it enables the save button");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
await click("#save-channel");
|
2017-07-18 15:42:00 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.notOk(
|
|
|
|
exists("#chat-integration-edit-channel-modal"),
|
2020-12-30 13:51:57 -05:00
|
|
|
"modal closes on save"
|
|
|
|
);
|
|
|
|
});
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
test("Edit channel works", async function (assert) {
|
2021-08-26 09:52:53 -04:00
|
|
|
await visit("/admin/plugins/chat-integration");
|
2021-11-14 08:14:49 -05:00
|
|
|
await click(".channel-header button");
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
assert.ok(
|
|
|
|
exists("#chat-integration-edit-channel-modal"),
|
|
|
|
"it displays the modal"
|
|
|
|
);
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.notOk(query("#save-channel").disabled, "save is enabled");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
await fillIn("#chat-integration-edit-channel-modal input", " general");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.ok(query("#save-channel").disabled, "it disables the save button");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
await fillIn("#chat-integration-edit-channel-modal input", "#random");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
// Press enter
|
|
|
|
await triggerKeyEvent(
|
|
|
|
"#chat-integration-edit-channel-modal input",
|
|
|
|
"keydown",
|
|
|
|
13
|
|
|
|
);
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.notOk(
|
|
|
|
exists("#chat-integration-edit-channel-modal"),
|
|
|
|
"modal saves on enter"
|
|
|
|
);
|
2017-08-14 09:02:43 -04:00
|
|
|
});
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
test("Create rule works", async function (assert) {
|
2021-08-26 09:52:53 -04:00
|
|
|
await visit("/admin/plugins/chat-integration");
|
2017-07-18 15:42:00 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.ok(exists(".channel-footer button"), "create button is displayed");
|
2017-07-18 15:42:00 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
await click(".channel-footer button");
|
2017-07-18 15:42:00 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
assert.ok(
|
|
|
|
exists("#chat-integration-edit-rule_modal"),
|
|
|
|
"modal opens on edit"
|
|
|
|
);
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.notOk(query("#save-rule").disabled, "save is enabled");
|
2017-07-18 15:42:00 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
await click("#save-rule");
|
2017-07-18 15:42:00 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.notOk(
|
|
|
|
exists("#chat-integration-edit-rule_modal"),
|
2020-12-30 13:51:57 -05:00
|
|
|
"modal closes on save"
|
|
|
|
);
|
|
|
|
});
|
2017-07-18 15:42:00 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
test("Edit rule works", async function (assert) {
|
2021-08-26 09:52:53 -04:00
|
|
|
await visit("/admin/plugins/chat-integration");
|
2017-07-18 15:42:00 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.ok(exists(".edit"), "edit button is displayed");
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
await click(".edit");
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
assert.ok(
|
|
|
|
exists("#chat-integration-edit-rule_modal"),
|
|
|
|
"modal opens on edit"
|
|
|
|
);
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.notOk(query("#save-rule").disabled, "it enables the save button");
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
await click("#save-rule");
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.notOk(
|
|
|
|
exists("#chat-integration-edit-rule_modal"),
|
2020-12-30 13:51:57 -05:00
|
|
|
"modal closes on save"
|
|
|
|
);
|
|
|
|
});
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
test("Delete channel works", async function (assert) {
|
2021-08-26 09:52:53 -04:00
|
|
|
await visit("/admin/plugins/chat-integration");
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.ok(
|
|
|
|
exists(".channel-header .delete-channel"),
|
|
|
|
"delete buttons exists"
|
|
|
|
);
|
|
|
|
await click(".channel-header .delete-channel");
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
assert.ok(exists("div.bootbox"), "modal is displayed");
|
|
|
|
await click("div.bootbox .btn-primary");
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.notOk(exists("div.bootbox"), "modal has closed");
|
2020-12-30 13:51:57 -05:00
|
|
|
});
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
test("Delete rule works", async function (assert) {
|
2021-08-26 09:52:53 -04:00
|
|
|
await visit("/admin/plugins/chat-integration");
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.ok(exists(".delete"));
|
|
|
|
await click(".delete");
|
2020-12-30 13:51:57 -05:00
|
|
|
});
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
test("Test channel works", async function (assert) {
|
2021-08-26 09:52:53 -04:00
|
|
|
await visit("/admin/plugins/chat-integration");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
await click(".btn-chat-test");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
assert.ok(exists("#chat_integration_test_modal"), "it displays the modal");
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.ok(query("#send-test").disabled, "it disables the send button");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
await fillIn("#choose-topic-title", "9318");
|
2021-11-14 08:14:49 -05:00
|
|
|
await click("#chat_integration_test_modal .radio");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
assert.notOk(query("#send-test").disabled, "it enables the send button");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
await click("#send-test");
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2020-12-30 13:51:57 -05:00
|
|
|
assert.ok(
|
|
|
|
exists("#chat_integration_test_modal"),
|
|
|
|
"modal doesn't close on send"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
exists("#modal-alert.alert-success"),
|
|
|
|
"success message displayed"
|
|
|
|
);
|
|
|
|
});
|
2017-10-03 05:42:07 -04:00
|
|
|
});
|