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

Also removes _clearSnapshots calls, as those are already being reset in testCleanup
This commit is contained in:
Jarek Radosz 2022-08-16 10:49:09 +02:00 committed by GitHub
parent 53af30ec3f
commit 5c6f8d64f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 88 additions and 103 deletions

View File

@ -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) {

View File

@ -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);
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,
})
);
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");
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);
}
const privateMessageUsers = selectKit("#private-message-users");
assert.strictEqual(privateMessageUsers.header().value(), "codinghorror");
});
test("Loads tags and category from draft payload", async function (assert) {