2023-12-11 14:00:34 -05:00
|
|
|
import { click, fillIn, triggerEvent, visit } from "@ember/test-helpers";
|
2023-11-29 17:01:31 -05:00
|
|
|
import { test } from "qunit";
|
2023-12-11 14:00:34 -05:00
|
|
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
2021-11-14 08:14:49 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert
|
|
|
|
.dom("#admin-plugin-chat table")
|
|
|
|
.exists("it shows the table of rules");
|
2019-03-20 06:57:07 -04:00
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert
|
|
|
|
.dom("#admin-plugin-chat table tr td")
|
|
|
|
.hasText("All posts and replies", "rule displayed");
|
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("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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert
|
|
|
|
.dom("#chat-integration-edit-channel-modal")
|
|
|
|
.exists("it displays the modal");
|
|
|
|
assert.dom("#save-channel").isDisabled();
|
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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert.dom("#save-channel").isEnabled();
|
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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert
|
|
|
|
.dom("#chat-integration-edit-channel-modal")
|
|
|
|
.doesNotExist("modal closes on save");
|
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("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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert
|
|
|
|
.dom("#chat-integration-edit-channel-modal")
|
|
|
|
.exists("it displays the modal");
|
|
|
|
assert.dom("#save-channel").isEnabled();
|
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");
|
2023-12-11 14:00:34 -05:00
|
|
|
assert.dom("#save-channel").isDisabled();
|
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");
|
2023-12-11 14:00:34 -05:00
|
|
|
assert.dom("#save-channel").isEnabled();
|
2017-07-11 10:37:44 -04:00
|
|
|
|
2021-11-14 08:14:49 -05:00
|
|
|
// Press enter
|
2023-12-11 14:00:34 -05:00
|
|
|
await triggerEvent("#chat-integration-edit-channel-modal", "submit");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom("#chat-integration-edit-channel-modal")
|
|
|
|
.doesNotExist("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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert.dom(".channel-footer button").exists("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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert
|
|
|
|
.dom("#chat-integration-edit-rule_modal")
|
|
|
|
.exists("modal opens on edit");
|
|
|
|
assert.dom("#save-rule").isEnabled();
|
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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert
|
|
|
|
.dom("#chat-integration-edit-rule_modal")
|
|
|
|
.doesNotExist("modal closes on save");
|
2020-12-30 13:51:57 -05:00
|
|
|
});
|
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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert.dom(".edit").exists("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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert
|
|
|
|
.dom("#chat-integration-edit-rule_modal")
|
|
|
|
.exists("modal opens on edit");
|
|
|
|
assert.dom("#save-rule").isEnabled();
|
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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert
|
|
|
|
.dom("#chat-integration-edit-rule_modal")
|
|
|
|
.doesNotExist("modal closes on save");
|
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 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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert
|
|
|
|
.dom(".channel-header .delete-channel")
|
|
|
|
.exists("delete buttons exists");
|
2021-11-14 08:14:49 -05:00
|
|
|
await click(".channel-header .delete-channel");
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert.dom("div.dialog-content").exists("dialog is displayed");
|
2022-10-27 09:16:00 -04:00
|
|
|
await click("div.dialog-content .btn-danger");
|
2017-08-14 09:02:43 -04:00
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert.dom("div.dialog-content").doesNotExist("dialog 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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert.dom(".delete").exists();
|
2021-11-14 08:14:49 -05:00
|
|
|
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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert.dom("#chat_integration_test_modal").exists("it displays the modal");
|
|
|
|
assert.dom("#send-test").isDisabled();
|
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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert.dom("#send-test").isEnabled();
|
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
|
|
|
|
2023-12-11 14:00:34 -05:00
|
|
|
assert
|
|
|
|
.dom("#chat_integration_test_modal")
|
|
|
|
.exists("modal doesn't close on send");
|
|
|
|
assert
|
|
|
|
.dom("#modal-alert.alert-success")
|
|
|
|
.exists("success message displayed");
|
2020-12-30 13:51:57 -05:00
|
|
|
});
|
2017-10-03 05:42:07 -04:00
|
|
|
});
|