Skip to content

A platform for community discussion. Free, open, simple.

DEV: Use afterEach instead of try/finally (#17944)

Jarek Radosz5c6f8d64f91b
diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js
index 3743d61c559..d22ba940de8 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/composer-actions-test.js
@@ -10,7 +10,6 @@ import { click, fillIn, visit } from "@ember/test-helpers";
import Draft from "discourse/models/draft";
import I18n from "I18n";
import { Promise } from "rsvp";
-import { _clearSnapshots } from "select-kit/components/composer-actions";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import sinon from "sinon";
import { test } from "qunit";
@@ -423,53 +422,49 @@ acceptance("Composer Actions With New Topic Draft", function (needs) {
needs.site({
can_tag_topics: true,
});
- needs.hooks.beforeEach(() => _clearSnapshots());
- needs.hooks.afterEach(() => _clearSnapshots());
+
+ needs.hooks.afterEach(() => toggleCheckDraftPopup(false));
test("shared draft", async function (assert) {
stubDraftResponse();
- try {
- toggleCheckDraftPopup(true);
+ toggleCheckDraftPopup(true);
- const composerActions = selectKit(".composer-actions");
- const tags = selectKit(".mini-tag-chooser");
+ const composerActions = selectKit(".composer-actions");
+ const tags = selectKit(".mini-tag-chooser");
- await visit("/");
- await click("#create-topic");
+ await visit("/");
+ await click("#create-topic");
- await fillIn(
- "#reply-title",
- "This is the new text for the title using 'quotes'"
- );
+ await fillIn(
+ "#reply-title",
+ "This is the new text for the title using 'quotes'"
+ );
- await fillIn(".d-editor-input", "This is the new text for the post");
- await tags.expand();
- await tags.selectRowByValue("monkey");
- await composerActions.expand();
- await composerActions.selectRowByValue("shared_draft");
+ await fillIn(".d-editor-input", "This is the new text for the post");
+ await tags.expand();
+ await tags.selectRowByValue("monkey");
+ await composerActions.expand();
+ await composerActions.selectRowByValue("shared_draft");
- assert.strictEqual(tags.header().value(), "monkey", "tags are not reset");
+ assert.strictEqual(tags.header().value(), "monkey", "tags are not reset");
- assert.strictEqual(
- query("#reply-title").value,
- "This is the new text for the title using 'quotes'"
- );
+ assert.strictEqual(
+ query("#reply-title").value,
+ "This is the new text for the title using 'quotes'"
+ );
- assert.strictEqual(
- query("#reply-control .btn-primary.create .d-button-label").innerText,
- I18n.t("composer.create_shared_draft")
- );
- assert.strictEqual(
- count(".composer-actions svg.d-icon-far-clipboard"),
- 1,
- "shared draft icon is visible"
- );
+ assert.strictEqual(
+ query("#reply-control .btn-primary.create .d-button-label").innerText,
+ I18n.t("composer.create_shared_draft")
+ );
+ assert.strictEqual(
+ count(".composer-actions svg.d-icon-far-clipboard"),
+ 1,
+ "shared draft icon is visible"
+ );
- assert.strictEqual(count("#reply-control.composing-shared-draft"), 1);
- await click(".modal-footer .btn.btn-default");
- } finally {
- toggleCheckDraftPopup(false);
- }
+ assert.strictEqual(count("#reply-control.composing-shared-draft"), 1);
+ await click(".modal-footer .btn.btn-default");
});
test("reply_as_new_topic with new_topic draft", async function (assert) {
diff --git a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
index 705caa4a8dc..c5b539b4db8 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/composer-test.js
@@ -57,6 +57,8 @@ acceptance("Composer", function (needs) {
});
});
+ needs.hooks.afterEach(() => toggleCheckDraftPopup(false));
+
test("composer controls", async function (assert) {
await visit("/");
assert.ok(exists("#create-topic"), "the create button is visible");
@@ -721,96 +723,84 @@ acceptance("Composer", function (needs) {
});
test("Checks for existing draft", async function (assert) {
- try {
- toggleCheckDraftPopup(true);
+ toggleCheckDraftPopup(true);
- await visit("/t/internationalization-localization/280");
+ await visit("/t/internationalization-localization/280");
- await click(".topic-post:nth-of-type(1) button.show-more-actions");
- await click(".topic-post:nth-of-type(1) button.edit");
+ await click(".topic-post:nth-of-type(1) button.show-more-actions");
+ await click(".topic-post:nth-of-type(1) button.edit");
- assert.strictEqual(
- query(".modal-body").innerText,
- I18n.t("drafts.abandon.confirm")
- );
+ assert.strictEqual(
+ query(".modal-body").innerText,
+ I18n.t("drafts.abandon.confirm")
+ );
- await click(".modal-footer .btn.btn-default");
- } finally {
- toggleCheckDraftPopup(false);
- }
+ await click(".modal-footer .btn.btn-default");
});
test("Can switch states without abandon popup", async function (assert) {
- try {
- toggleCheckDraftPopup(true);
+ toggleCheckDraftPopup(true);
- await visit("/t/internationalization-localization/280");
+ await visit("/t/internationalization-localization/280");
- const longText = "a".repeat(256);
+ const longText = "a".repeat(256);
- sinon.stub(Draft, "get").returns(
- Promise.resolve({
- draft: null,
- draft_sequence: 0,
- })
- );
+ sinon.stub(Draft, "get").returns(
+ Promise.resolve({
+ draft: null,
+ draft_sequence: 0,
+ })
+ );
- await click(".btn-primary.create.btn");
+ await click(".btn-primary.create.btn");
- await fillIn(".d-editor-input", longText);
+ await fillIn(".d-editor-input", longText);
- assert.ok(
- exists(
- '.action-title a[href="/t/internationalization-localization/280"]'
- ),
- "the mode should be: reply to post"
- );
+ assert.ok(
+ exists(
+ '.action-title a[href="/t/internationalization-localization/280"]'
+ ),
+ "the mode should be: reply to post"
+ );
- await click("article#post_3 button.reply");
+ await click("article#post_3 button.reply");
- const composerActions = selectKit(".composer-actions");
- await composerActions.expand();
- await composerActions.selectRowByValue("reply_as_new_topic");
+ const composerActions = selectKit(".composer-actions");
+ await composerActions.expand();
+ await composerActions.selectRowByValue("reply_as_new_topic");
- assert.ok(!exists(".modal-body"), "abandon popup shouldn't come");
+ assert.ok(!exists(".modal-body"), "abandon popup shouldn't come");
- assert.ok(
- query(".d-editor-input").value.includes(longText),
- "entered text should still be there"
- );
+ assert.ok(
+ query(".d-editor-input").value.includes(longText),
+ "entered text should still be there"
+ );
- assert.ok(
- !exists(
- '.action-title a[href="/t/internationalization-localization/280"]'
- ),
- "mode should have changed"
- );
- } finally {
- toggleCheckDraftPopup(false);
- }
+ assert.ok(
+ !exists(
+ '.action-title a[href="/t/internationalization-localization/280"]'
+ ),
+ "mode should have changed"
+ );
});
test("Loading draft also replaces the recipients", async function (assert) {
- try {
- toggleCheckDraftPopup(true);
-
- sinon.stub(Draft, "get").returns(
- Promise.resolve({
- draft:
- '{"reply":"hello","action":"privateMessage","title":"hello","categoryId":null,"archetypeId":"private_message","metaData":null,"recipients":"codinghorror","composerTime":9159,"typingTime":2500}',
- draft_sequence: 0,
- })
- );
-
- await visit("/u/charlie");
- await click("button.compose-pm");
- await click(".modal .btn-default");
-
- const privateMessageUsers = selectKit("#private-message-users");
- assert.strictEqual(privateMessageUsers.header().value(), "codinghorror");
- } finally {
- toggleCheckDraftPopup(false);
- }
+ toggleCheckDraftPopup(true);
+
+ sinon.stub(Draft, "get").returns(
+ Promise.resolve({
+ draft:
+ '{"reply":"hello","action":"privateMessage","title":"hello","categoryId":null,"archetypeId":"private_message","metaData":null,"recipients":"codinghorror","composerTime":9159,"typingTime":2500}',
+ draft_sequence: 0,
+ })
+ );
+
+ await visit("/u/charlie");
+ await click("button.compose-pm");
+ await click(".modal .btn-default");
+
+ const privateMessageUsers = selectKit("#private-message-users");
+ assert.strictEqual(privateMessageUsers.header().value(), "codinghorror");
});
test("Loads tags and category from draft payload", async function (assert) {