REFACTOR: Use the new format for acceptance tests. (#52)

This commit is contained in:
Roman Rizzi 2020-12-30 15:51:57 -03:00 committed by GitHub
parent f4cce75b3a
commit ac90815bdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 174 additions and 158 deletions

View File

@ -1,8 +1,9 @@
import { acceptance } from "helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Chat Integration", {
loggedIn: true,
pretend(server) { acceptance("Chat Integration", function (needs) {
needs.user();
needs.pretender((server) => {
const response = (object) => { const response = (object) => {
return [200, { "Content-Type": "text/html; charset=utf-8" }, object]; return [200, { "Content-Type": "text/html; charset=utf-8" }, object];
}; };
@ -82,22 +83,24 @@ acceptance("Chat Integration", {
server.get("/groups/search.json", () => { server.get("/groups/search.json", () => {
return jsonResponse([]); return jsonResponse([]);
}); });
}, });
});
test("Rules load successfully", async (assert) => { test("Rules load successfully", async (assert) => {
await visit("/admin/plugins/chat"); await visit("/admin/plugins/chat");
assert.ok(exists("#admin-plugin-chat table"), "it shows the table of rules"); assert.ok(
exists("#admin-plugin-chat table"),
"it shows the table of rules"
);
assert.equal( assert.equal(
find("#admin-plugin-chat table tr td").eq(0).text().trim(), find("#admin-plugin-chat table tr td").eq(0).text().trim(),
"All posts and replies", "All posts and replies",
"rule displayed" "rule displayed"
); );
}); });
test("Create channel works", async (assert) => { test("Create channel works", async (assert) => {
await visit("/admin/plugins/chat"); await visit("/admin/plugins/chat");
await click("#create-channel"); await click("#create-channel");
@ -123,9 +126,9 @@ test("Create channel works", async (assert) => {
!exists("#chat-integration-edit-channel-modal"), !exists("#chat-integration-edit-channel-modal"),
"modal closes on save" "modal closes on save"
); );
}); });
test("Edit channel works", async (assert) => { test("Edit channel works", async (assert) => {
await visit("/admin/plugins/chat"); await visit("/admin/plugins/chat");
await click(".channel-header button:first"); await click(".channel-header button:first");
@ -156,9 +159,9 @@ test("Edit channel works", async (assert) => {
"modal saves on enter" "modal saves on enter"
); );
}); });
}); });
test("Create rule works", async (assert) => { test("Create rule works", async (assert) => {
await visit("/admin/plugins/chat"); await visit("/admin/plugins/chat");
assert.ok( assert.ok(
@ -168,7 +171,10 @@ test("Create rule works", async (assert) => {
await click(".channel-footer button:first"); await click(".channel-footer button:first");
assert.ok(exists("#chat-integration-edit-rule_modal"), "modal opens on edit"); 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(find("#save-rule").prop("disabled") === false, "save is enabled");
await click("#save-rule"); await click("#save-rule");
@ -177,16 +183,19 @@ test("Create rule works", async (assert) => {
!exists("#chat-integration-edit-rule_modal"), !exists("#chat-integration-edit-rule_modal"),
"modal closes on save" "modal closes on save"
); );
}); });
test("Edit rule works", async (assert) => { test("Edit rule works", async (assert) => {
await visit("/admin/plugins/chat"); await visit("/admin/plugins/chat");
assert.ok(exists(".edit:first"), "edit button is displayed"); assert.ok(exists(".edit:first"), "edit button is displayed");
await click(".edit:first"); await click(".edit:first");
assert.ok(exists("#chat-integration-edit-rule_modal"), "modal opens on edit"); assert.ok(
exists("#chat-integration-edit-rule_modal"),
"modal opens on edit"
);
assert.ok( assert.ok(
find("#save-rule").prop("disabled") === false, find("#save-rule").prop("disabled") === false,
"it enables the save button" "it enables the save button"
@ -198,9 +207,9 @@ test("Edit rule works", async (assert) => {
!exists("#chat-integration-edit-rule_modal"), !exists("#chat-integration-edit-rule_modal"),
"modal closes on save" "modal closes on save"
); );
}); });
test("Delete channel works", async (assert) => { test("Delete channel works", async (assert) => {
await visit("/admin/plugins/chat"); await visit("/admin/plugins/chat");
assert.ok(exists(".channel-header button:last"), "delete button exists"); assert.ok(exists(".channel-header button:last"), "delete button exists");
@ -210,22 +219,25 @@ test("Delete channel works", async (assert) => {
await click("div.bootbox .btn-primary"); await click("div.bootbox .btn-primary");
assert.ok(exists("div.bootbox") === false, "modal has closed"); assert.ok(exists("div.bootbox") === false, "modal has closed");
}); });
test("Delete rule works", async (assert) => { test("Delete rule works", async (assert) => {
await visit("/admin/plugins/chat"); await visit("/admin/plugins/chat");
assert.ok(exists(".delete:first")); assert.ok(exists(".delete:first"));
await click(".delete:first"); await click(".delete:first");
}); });
test("Test channel works", async (assert) => { test("Test channel works", async (assert) => {
await visit("/admin/plugins/chat"); await visit("/admin/plugins/chat");
await click(".btn-chat-test"); await click(".btn-chat-test");
assert.ok(exists("#chat_integration_test_modal"), "it displays the modal"); assert.ok(exists("#chat_integration_test_modal"), "it displays the modal");
assert.ok(find("#send-test").prop("disabled"), "it disables the send button"); assert.ok(
find("#send-test").prop("disabled"),
"it disables the send button"
);
await fillIn("#choose-topic-title", "9318"); await fillIn("#choose-topic-title", "9318");
await click("#chat_integration_test_modal .radio:first"); await click("#chat_integration_test_modal .radio:first");
@ -241,5 +253,9 @@ test("Test channel works", async (assert) => {
exists("#chat_integration_test_modal"), exists("#chat_integration_test_modal"),
"modal doesn't close on send" "modal doesn't close on send"
); );
assert.ok(exists("#modal-alert.alert-success"), "success message displayed"); assert.ok(
exists("#modal-alert.alert-success"),
"success message displayed"
);
});
}); });