DEV: Fix a test leak (#15135)

The leak was introduced in #11722 and a test was added that relied on it in #14563

This PR fixes the leak (bookmarks-test), fixes the test that relied on it (fast-edit-test), and repleces some ad-hoc code with cloneJSON helper (other files)
This commit is contained in:
Jarek Radosz 2021-11-30 03:45:26 +01:00 committed by GitHub
parent 7e5f52a163
commit 6662101208
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 12 deletions

View File

@ -10,6 +10,7 @@ import I18n from "I18n";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { test } from "qunit";
import topicFixtures from "discourse/tests/fixtures/topic";
import { cloneJSON } from "discourse-common/lib/object";
async function openBookmarkModal(postNumber = 1) {
if (exists(`#post_${postNumber} button.show-more-actions`)) {
@ -58,7 +59,7 @@ async function testTopicLevelBookmarkButtonIcon(assert, postNumber) {
acceptance("Bookmarking", function (needs) {
needs.user();
const topicResponse = topicFixtures["/t/280/1.json"];
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
topicResponse.post_stream.posts[0].cooked += `<span data-date="2036-01-15" data-time="00:35:00" class="discourse-local-date cooked-date past" data-timezone="Europe/London">
<span>
<svg class="fa d-icon d-icon-globe-americas svg-icon" xmlns="http://www.w3.org/2000/svg">

View File

@ -1,29 +1,36 @@
import {
acceptance,
exists,
queryAll,
query,
selectText,
} from "discourse/tests/helpers/qunit-helpers";
import { click, fillIn, triggerKeyEvent, visit } from "@ember/test-helpers";
import { test } from "qunit";
import postFixtures from "discourse/tests/fixtures/post";
import { cloneJSON } from "discourse-common/lib/object";
acceptance("Fast Edit", function (needs) {
needs.user();
needs.settings({
enable_fast_edit: true,
});
needs.pretender((server, helper) => {
server.get("/posts/419", () => {
return helper.response(cloneJSON(postFixtures["/posts/398"]));
});
});
test("Fast edit button works", async function (assert) {
await visit("/t/internationalization-localization/280");
const textNode = document.querySelector("#post_1 .cooked p").childNodes[0];
const textNode = query("#post_1 .cooked p").childNodes[0];
await selectText(textNode, 9);
await click(".quote-button .quote-edit-label");
assert.ok(exists("#fast-edit-input"), "fast editor is open");
assert.strictEqual(
queryAll("#fast-edit-input").val(),
query("#fast-edit-input").value,
"Any plans",
"contains selected text"
);
@ -37,14 +44,14 @@ acceptance("Fast Edit", function (needs) {
test("Works with keyboard shortcut", async function (assert) {
await visit("/t/internationalization-localization/280");
const textNode = document.querySelector("#post_1 .cooked p").childNodes[0];
const textNode = query("#post_1 .cooked p").childNodes[0];
await selectText(textNode, 9);
await triggerKeyEvent(document, "keypress", "e".charCodeAt(0));
assert.ok(exists("#fast-edit-input"), "fast editor is open");
assert.strictEqual(
queryAll("#fast-edit-input").val(),
query("#fast-edit-input").value,
"Any plans",
"contains selected text"
);
@ -58,7 +65,7 @@ acceptance("Fast Edit", function (needs) {
test("Opens full composer for multi-line selection", async function (assert) {
await visit("/t/internationalization-localization/280");
const textNode = document.querySelector("#post_1 .cooked");
const textNode = query("#post_2 .cooked");
await selectText(textNode);
await click(".quote-button .quote-edit-label");

View File

@ -29,9 +29,8 @@ function pressEnter(element, modifier) {
acceptance("flagging", function (needs) {
needs.user();
needs.pretender((server, helper) => {
const userResponse = Object.assign({}, userFixtures["/u/charlie.json"]);
server.get("/u/uwe_keim.json", () => {
return helper.response(userResponse);
return helper.response(userFixtures["/u/charlie.json"]);
});
server.get("/admin/users/255.json", () => {
return helper.response({

View File

@ -3,12 +3,13 @@ import { click, visit } from "@ember/test-helpers";
import User from "discourse/models/user";
import { test } from "qunit";
import userFixtures from "discourse/tests/fixtures/user-fixtures";
import { cloneJSON } from "discourse-common/lib/object";
acceptance("User Card - Show Local Time", function (needs) {
needs.user();
needs.settings({ display_local_time_in_user_card: true });
needs.pretender((server, helper) => {
let cardResponse = Object.assign({}, userFixtures["/u/charlie/card.json"]);
const cardResponse = cloneJSON(userFixtures["/u/charlie/card.json"]);
delete cardResponse.user.timezone;
server.get("/u/charlie/card.json", () => helper.response(cardResponse));
});

View File

@ -1,11 +1,12 @@
import { module, test } from "qunit";
import UserBadge from "discourse/models/user-badge";
import badgeFixtures from "discourse/tests/fixtures/user-badges";
import { cloneJSON } from "discourse-common/lib/object";
module("Unit | Model | user-badge", function () {
test("createFromJson single", function (assert) {
const userBadge = UserBadge.createFromJson(
JSON.parse(JSON.stringify(badgeFixtures["/user_badges"]))
cloneJSON(badgeFixtures["/user_badges"])
);
assert.ok(!Array.isArray(userBadge), "does not return an array");
assert.strictEqual(
@ -27,7 +28,7 @@ module("Unit | Model | user-badge", function () {
test("createFromJson array", function (assert) {
const userBadges = UserBadge.createFromJson(
JSON.parse(JSON.stringify(badgeFixtures["/user-badges/:username"]))
cloneJSON(badgeFixtures["/user-badges/:username"])
);
assert.ok(Array.isArray(userBadges), "returns an array");
assert.strictEqual(