REFACTOR: uses more modern patterns to prevent issues (#27)

This commit is contained in:
Joffrey JAFFEUX
2019-03-20 10:57:07 +00:00
committed by David Taylor
parent 56d11903c0
commit cd53275098
13 changed files with 221 additions and 273 deletions
@@ -7,8 +7,16 @@ acceptance("Chat Integration", {
return [200, { "Content-Type": "text/html; charset=utf-8" }, object];
};
const jsonResponse = object => {
return [
200,
{ "Content-Type": "application/json; charset=utf-8" },
object
];
};
server.get("/admin/plugins/chat/providers", () => {
return response({
return jsonResponse({
providers: [
{
name: "dummy",
@@ -20,7 +28,7 @@ acceptance("Chat Integration", {
});
server.get("/admin/plugins/chat/channels", () => {
return response({
return jsonResponse({
channels: [
{
id: 97,
@@ -72,94 +80,72 @@ acceptance("Chat Integration", {
});
server.get("/groups/search.json", () => {
return response([]);
return jsonResponse([]);
});
}
});
test("Rules load successfully", assert => {
visit("/admin/plugins/chat");
test("Rules load successfully", async assert => {
await visit("/admin/plugins/chat");
andThen(() => {
assert.ok(
exists("#admin-plugin-chat table"),
"it shows the table of rules"
);
assert.equal(
find("#admin-plugin-chat table tr td")
.eq(0)
.text()
.trim(),
"All posts and replies",
"rule displayed"
);
});
assert.ok(exists("#admin-plugin-chat table"), "it shows the table of rules");
assert.equal(
find("#admin-plugin-chat table tr td")
.eq(0)
.text()
.trim(),
"All posts and replies",
"rule displayed"
);
});
test("Create channel works", assert => {
visit("/admin/plugins/chat");
test("Create channel works", async assert => {
await visit("/admin/plugins/chat");
await click("#create-channel");
andThen(() => {
click("#create-channel");
});
assert.ok(
exists("#chat-integration-edit-channel-modal"),
"it displays the modal"
);
assert.ok(
find("#save-channel").prop("disabled"),
"it disables the save button"
);
andThen(() => {
assert.ok(
exists("#chat-integration-edit-channel-modal"),
"it displays the modal"
);
assert.ok(
find("#save-channel").prop("disabled"),
"it disables the save button"
);
fillIn("#chat-integration-edit-channel-modal input", "#general");
});
await fillIn("#chat-integration-edit-channel-modal input", "#general");
andThen(() => {
assert.ok(
find("#save-channel").prop("disabled") === false,
"it enables the save button"
);
});
assert.ok(
find("#save-channel").prop("disabled") === false,
"it enables the save button"
);
andThen(() => {
click("#save-channel");
});
await click("#save-channel");
andThen(() => {
assert.ok(
!exists("#chat-integration-edit-channel-modal"),
"modal closes on save"
);
});
assert.ok(
!exists("#chat-integration-edit-channel-modal"),
"modal closes on save"
);
});
test("Edit channel works", assert => {
visit("/admin/plugins/chat");
test("Edit channel works", async assert => {
await visit("/admin/plugins/chat");
await click(".channel-header button:first");
andThen(() => {
click(".channel-header button:first");
});
assert.ok(
exists("#chat-integration-edit-channel-modal"),
"it displays the modal"
);
assert.ok(!find("#save-channel").prop("disabled"), "save is enabled");
andThen(() => {
assert.ok(
exists("#chat-integration-edit-channel-modal"),
"it displays the modal"
);
assert.ok(!find("#save-channel").prop("disabled"), "save is enabled");
fillIn("#chat-integration-edit-channel-modal input", " general");
});
await fillIn("#chat-integration-edit-channel-modal input", " general");
andThen(() => {
assert.ok(
find("#save-channel").prop("disabled"),
"it disables the save button"
);
});
assert.ok(
find("#save-channel").prop("disabled"),
"it disables the save button"
);
andThen(() => {
fillIn("#chat-integration-edit-channel-modal input", "#random");
});
await fillIn("#chat-integration-edit-channel-modal input", "#random");
andThen(() => {
$("#chat-integration-edit-channel-modal input").trigger(
@@ -175,132 +161,88 @@ test("Edit channel works", assert => {
});
});
test("Create rule works", assert => {
visit("/admin/plugins/chat");
test("Create rule works", async assert => {
await visit("/admin/plugins/chat");
andThen(() => {
assert.ok(
exists(".channel-footer button:first"),
"create button is displayed"
);
});
assert.ok(
exists(".channel-footer button:first"),
"create button is displayed"
);
click(".channel-footer button:first");
await click(".channel-footer button:first");
andThen(() => {
assert.ok(
exists("#chat-integration-edit-rule_modal"),
"modal opens on edit"
);
assert.ok(find("#save-rule").prop("disabled") === false, "save is enabled");
});
assert.ok(exists("#chat-integration-edit-rule_modal"), "modal opens on edit");
assert.ok(find("#save-rule").prop("disabled") === false, "save is enabled");
click("#save-rule");
await click("#save-rule");
andThen(() => {
assert.ok(
!exists("#chat-integration-edit-rule_modal"),
"modal closes on save"
);
});
assert.ok(
!exists("#chat-integration-edit-rule_modal"),
"modal closes on save"
);
});
test("Edit rule works", assert => {
visit("/admin/plugins/chat");
test("Edit rule works", async assert => {
await visit("/admin/plugins/chat");
andThen(() => {
assert.ok(exists(".edit:first"), "edit button is displayed");
});
assert.ok(exists(".edit:first"), "edit button is displayed");
click(".edit:first");
await click(".edit:first");
andThen(() => {
assert.ok(
exists("#chat-integration-edit-rule_modal"),
"modal opens on edit"
);
assert.ok(
find("#save-rule").prop("disabled") === false,
"it enables the save button"
);
});
assert.ok(exists("#chat-integration-edit-rule_modal"), "modal opens on edit");
assert.ok(
find("#save-rule").prop("disabled") === false,
"it enables the save button"
);
click("#save-rule");
await click("#save-rule");
andThen(() => {
assert.ok(
!exists("#chat-integration-edit-rule_modal"),
"modal closes on save"
);
});
assert.ok(
!exists("#chat-integration-edit-rule_modal"),
"modal closes on save"
);
});
test("Delete channel works", function(assert) {
visit("/admin/plugins/chat");
test("Delete channel works", async assert => {
await visit("/admin/plugins/chat");
andThen(() => {
assert.ok(exists(".channel-header button:last"), "delete button exists");
click(".channel-header button:last");
});
assert.ok(exists(".channel-header button:last"), "delete button exists");
await click(".channel-header button:last");
andThen(() => {
assert.ok(exists("div.bootbox"), "modal is displayed");
click("div.bootbox .btn-primary");
});
assert.ok(exists("div.bootbox"), "modal is displayed");
await click("div.bootbox .btn-primary");
andThen(() => {
assert.ok(exists("div.bootbox") === false, "modal has closed");
});
assert.ok(exists("div.bootbox") === false, "modal has closed");
});
test("Delete rule works", function(assert) {
visit("/admin/plugins/chat");
test("Delete rule works", async assert => {
await visit("/admin/plugins/chat");
andThen(() => {
assert.ok(exists(".delete:first"));
click(".delete:first");
});
assert.ok(exists(".delete:first"));
await click(".delete:first");
});
test("Test channel works", assert => {
visit("/admin/plugins/chat");
test("Test channel works", async assert => {
await visit("/admin/plugins/chat");
andThen(() => {
click(".btn-chat-test");
});
await click(".btn-chat-test");
andThen(() => {
assert.ok(exists("#chat_integration_test_modal"), "it displays the modal");
assert.ok(
find("#send-test").prop("disabled"),
"it disables the send button"
);
fillIn("#choose-topic-title", "9318");
});
assert.ok(exists("#chat_integration_test_modal"), "it displays the modal");
assert.ok(find("#send-test").prop("disabled"), "it disables the send button");
andThen(() => {
click("#chat_integration_test_modal .radio:first");
});
await fillIn("#choose-topic-title", "9318");
await click("#chat_integration_test_modal .radio:first");
andThen(() => {
assert.ok(
find("#send-test").prop("disabled") === false,
"it enables the send button"
);
});
assert.ok(
find("#send-test").prop("disabled") === false,
"it enables the send button"
);
andThen(() => {
click("#send-test");
});
await click("#send-test");
andThen(() => {
assert.ok(
exists("#chat_integration_test_modal"),
"modal doesn't close on send"
);
assert.ok(
exists("#modal-alert.alert-success"),
"success message displayed"
);
});
assert.ok(
exists("#chat_integration_test_modal"),
"modal doesn't close on send"
);
assert.ok(exists("#modal-alert.alert-success"), "success message displayed");
});