DEV: Fix imports in tests, minor clean up (#93)

Still doesn't work with ember cli though.
This commit is contained in:
Jarek Radosz 2021-11-14 14:14:49 +01:00 committed by GitHub
parent 08dd442c1c
commit 369ca14711
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 106 deletions

7
.gitignore vendored
View File

@ -1,8 +1 @@
auto_generated/
.DS_Store
node_modules/
.rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml
node_modules node_modules
yarn-error.log
.rubocop-https---raw-githubusercontent-com-discourse-*

1
.prettierrc Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -2,11 +2,7 @@ import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import { import computed, { observes, on } from "discourse-common/utils/decorators";
default as computed,
observes,
on,
} from "discourse-common/utils/decorators";
export default Ember.Controller.extend(ModalFunctionality, { export default Ember.Controller.extend(ModalFunctionality, {
@on("init") @on("init")

View File

@ -1,6 +1,6 @@
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
import { default as computed, on } from "discourse-common/utils/decorators"; import computed, { on } from "discourse-common/utils/decorators";
export default Ember.Controller.extend(ModalFunctionality, { export default Ember.Controller.extend(ModalFunctionality, {
saveDisabled: false, saveDisabled: false,

View File

@ -2,7 +2,7 @@ import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
import { default as computed, on } from "discourse-common/utils/decorators"; import computed, { on } from "discourse-common/utils/decorators";
export default Ember.Controller.extend(ModalFunctionality, { export default Ember.Controller.extend(ModalFunctionality, {
@on("init") @on("init")

View File

@ -1,10 +1,7 @@
import I18n from "I18n"; import I18n from "I18n";
import RestModel from "discourse/models/rest"; import RestModel from "discourse/models/rest";
import Category from "discourse/models/category"; import Category from "discourse/models/category";
import { import computed, { observes } from "discourse-common/utils/decorators";
default as computed,
observes,
} from "discourse-common/utils/decorators";
export default RestModel.extend({ export default RestModel.extend({
@computed("channel.provider") @computed("channel.provider")

View File

@ -45,14 +45,14 @@
<div class="modal-footer"> <div class="modal-footer">
{{d-button id="save-channel" {{d-button id="save-channel"
class="btn-primary btn-large" class="btn-primary btn-large"
action="save" action=(action "save")
title="chat_integration.edit_channel_modal.save" title="chat_integration.edit_channel_modal.save"
label="chat_integration.edit_channel_modal.save" label="chat_integration.edit_channel_modal.save"
disabled=saveDisabled disabled=saveDisabled
}} }}
{{d-button class="btn-large" {{d-button class="btn-large"
action="cancel" action=(action "cancel")
title="chat_integration.edit_channel_modal.cancel" title="chat_integration.edit_channel_modal.cancel"
label="chat_integration.edit_channel_modal.cancel" label="chat_integration.edit_channel_modal.cancel"
}} }}

View File

@ -105,7 +105,7 @@
<div class="modal-footer"> <div class="modal-footer">
{{d-button id="save-rule" {{d-button id="save-rule"
class="btn-primary btn-large" class="btn-primary btn-large"
action="save" action=(action "save")
actionParam=model.rule actionParam=model.rule
title="chat_integration.edit_rule_modal.save" title="chat_integration.edit_rule_modal.save"
label="chat_integration.edit_rule_modal.save" label="chat_integration.edit_rule_modal.save"

View File

@ -18,7 +18,7 @@
}} }}
{{d-button {{d-button
class="cancel" class="cancel delete-channel"
action=(action "deleteChannel") action=(action "deleteChannel")
actionParam=channel actionParam=channel
icon="trash-alt" icon="trash-alt"

View File

@ -1,21 +1,24 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; 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];
};
acceptance("Chat Integration", function (needs) { acceptance("Chat Integration", function (needs) {
needs.user(); needs.user();
needs.pretender((server) => { needs.pretender((server) => {
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,
];
};
server.get("/admin/plugins/chat-integration/providers", () => { server.get("/admin/plugins/chat-integration/providers", () => {
return jsonResponse({ return jsonResponse({
providers: [ providers: [
@ -85,7 +88,7 @@ acceptance("Chat Integration", function (needs) {
}); });
}); });
test("Rules load successfully", async (assert) => { test("Rules load successfully", async function (assert) {
await visit("/admin/plugins/chat-integration"); await visit("/admin/plugins/chat-integration");
assert.ok( assert.ok(
@ -93,14 +96,14 @@ acceptance("Chat Integration", function (needs) {
"it shows the table of rules" "it shows the table of rules"
); );
assert.equal( assert.strictEqual(
find("#admin-plugin-chat table tr td").eq(0).text().trim(), queryAll("#admin-plugin-chat table tr td")[0].innerText.trim(),
"All posts and replies", "All posts and replies",
"rule displayed" "rule displayed"
); );
}); });
test("Create channel works", async (assert) => { test("Create channel works", async function (assert) {
await visit("/admin/plugins/chat-integration"); await visit("/admin/plugins/chat-integration");
await click("#create-channel"); await click("#create-channel");
@ -108,144 +111,125 @@ acceptance("Chat Integration", function (needs) {
exists("#chat-integration-edit-channel-modal"), exists("#chat-integration-edit-channel-modal"),
"it displays the modal" "it displays the modal"
); );
assert.ok( assert.ok(query("#save-channel").disabled, "it disables the save button");
find("#save-channel").prop("disabled"),
"it disables the save button"
);
await fillIn("#chat-integration-edit-channel-modal input", "#general"); await fillIn("#chat-integration-edit-channel-modal input", "#general");
assert.ok( assert.notOk(query("#save-channel").disabled, "it enables the save button");
find("#save-channel").prop("disabled") === false,
"it enables the save button"
);
await click("#save-channel"); await click("#save-channel");
assert.ok( assert.notOk(
!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 function (assert) {
await visit("/admin/plugins/chat-integration"); await visit("/admin/plugins/chat-integration");
await click(".channel-header button:first"); await click(".channel-header button");
assert.ok( assert.ok(
exists("#chat-integration-edit-channel-modal"), exists("#chat-integration-edit-channel-modal"),
"it displays the modal" "it displays the modal"
); );
assert.ok(!find("#save-channel").prop("disabled"), "save is enabled"); assert.notOk(query("#save-channel").disabled, "save is enabled");
await fillIn("#chat-integration-edit-channel-modal input", " general"); await fillIn("#chat-integration-edit-channel-modal input", " general");
assert.ok( assert.ok(query("#save-channel").disabled, "it disables the save button");
find("#save-channel").prop("disabled"),
"it disables the save button"
);
await fillIn("#chat-integration-edit-channel-modal input", "#random"); await fillIn("#chat-integration-edit-channel-modal input", "#random");
andThen(() => { // Press enter
$("#chat-integration-edit-channel-modal input").trigger( await triggerKeyEvent(
$.Event("keydown", { keyCode: 13 }) "#chat-integration-edit-channel-modal input",
); // Press enter "keydown",
}); 13
andThen(() => {
assert.ok(
!exists("#chat-integration-edit-channel-modal"),
"modal saves on enter"
);
});
});
test("Create rule works", async (assert) => {
await visit("/admin/plugins/chat-integration");
assert.ok(
exists(".channel-footer button:first"),
"create button is displayed"
); );
await click(".channel-footer button:first"); assert.notOk(
exists("#chat-integration-edit-channel-modal"),
"modal saves on enter"
);
});
test("Create rule works", async function (assert) {
await visit("/admin/plugins/chat-integration");
assert.ok(exists(".channel-footer button"), "create button is displayed");
await click(".channel-footer button");
assert.ok( assert.ok(
exists("#chat-integration-edit-rule_modal"), exists("#chat-integration-edit-rule_modal"),
"modal opens on edit" "modal opens on edit"
); );
assert.ok(find("#save-rule").prop("disabled") === false, "save is enabled"); assert.notOk(query("#save-rule").disabled, "save is enabled");
await click("#save-rule"); await click("#save-rule");
assert.ok( assert.notOk(
!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 function (assert) {
await visit("/admin/plugins/chat-integration"); await visit("/admin/plugins/chat-integration");
assert.ok(exists(".edit:first"), "edit button is displayed"); assert.ok(exists(".edit"), "edit button is displayed");
await click(".edit:first"); await click(".edit");
assert.ok( assert.ok(
exists("#chat-integration-edit-rule_modal"), exists("#chat-integration-edit-rule_modal"),
"modal opens on edit" "modal opens on edit"
); );
assert.ok( assert.notOk(query("#save-rule").disabled, "it enables the save button");
find("#save-rule").prop("disabled") === false,
"it enables the save button"
);
await click("#save-rule"); await click("#save-rule");
assert.ok( assert.notOk(
!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 function (assert) {
await visit("/admin/plugins/chat-integration"); await visit("/admin/plugins/chat-integration");
assert.ok(exists(".channel-header button:last"), "delete button exists"); assert.ok(
await click(".channel-header button:last"); exists(".channel-header .delete-channel"),
"delete buttons exists"
);
await click(".channel-header .delete-channel");
assert.ok(exists("div.bootbox"), "modal is displayed"); assert.ok(exists("div.bootbox"), "modal is displayed");
await click("div.bootbox .btn-primary"); await click("div.bootbox .btn-primary");
assert.ok(exists("div.bootbox") === false, "modal has closed"); assert.notOk(exists("div.bootbox"), "modal has closed");
}); });
test("Delete rule works", async (assert) => { test("Delete rule works", async function (assert) {
await visit("/admin/plugins/chat-integration"); await visit("/admin/plugins/chat-integration");
assert.ok(exists(".delete:first")); assert.ok(exists(".delete"));
await click(".delete:first"); await click(".delete");
}); });
test("Test channel works", async (assert) => { test("Test channel works", async function (assert) {
await visit("/admin/plugins/chat-integration"); await visit("/admin/plugins/chat-integration");
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( assert.ok(query("#send-test").disabled, "it disables the send button");
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");
assert.ok( assert.notOk(query("#send-test").disabled, "it enables the send button");
find("#send-test").prop("disabled") === false,
"it enables the send button"
);
await click("#send-test"); await click("#send-test");