From 24356e339b3707478c0c914df7fddbaca620c574 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Tue, 30 Nov 2021 13:01:39 +0100 Subject: [PATCH] DEV: Fix pending posts page, make tests work in legacy env (#15132) * Running the tests only in the ember cli env hid the fact that the pending posts feature wasn't working in the legacy environment * Tests were using ember-cli-only APIs while there are widely used testing APIs in Discourse that support both ember envs * `ember-test-selectors` was in both dependencies and devDependencies in discourse/package.json * `qunit-dom` in package.json was not only unused but also defunct, as it wasn't pulled into the legacy env app A followup to #14501, and #15128. --- .../pending.hbs => user-activity-pending.hbs} | 2 +- app/assets/javascripts/discourse/package.json | 3 +- .../tests/acceptance/pending-posts-test.js | 19 +++---- .../tests/acceptance/sticky-avatars-test.js | 28 ++++------ .../components/empty-state-test.js | 27 ++++------ .../components/pending-post-test.js | 54 +++++++++---------- package.json | 1 - 7 files changed, 55 insertions(+), 79 deletions(-) rename app/assets/javascripts/discourse/app/templates/{user-activity/pending.hbs => user-activity-pending.hbs} (67%) diff --git a/app/assets/javascripts/discourse/app/templates/user-activity/pending.hbs b/app/assets/javascripts/discourse/app/templates/user-activity-pending.hbs similarity index 67% rename from app/assets/javascripts/discourse/app/templates/user-activity/pending.hbs rename to app/assets/javascripts/discourse/app/templates/user-activity-pending.hbs index ee48832b71f..2b39f3fa6c6 100644 --- a/app/assets/javascripts/discourse/app/templates/user-activity/pending.hbs +++ b/app/assets/javascripts/discourse/app/templates/user-activity-pending.hbs @@ -1,5 +1,5 @@ diff --git a/app/assets/javascripts/discourse/package.json b/app/assets/javascripts/discourse/package.json index d8a89ee421d..ef1539fb101 100644 --- a/app/assets/javascripts/discourse/package.json +++ b/app/assets/javascripts/discourse/package.json @@ -81,7 +81,6 @@ ] }, "devDependencies": { - "ember-exam": "6.1.0", - "ember-test-selectors": "^6.0.0" + "ember-exam": "6.1.0" } } diff --git a/app/assets/javascripts/discourse/tests/acceptance/pending-posts-test.js b/app/assets/javascripts/discourse/tests/acceptance/pending-posts-test.js index 05bb8b58801..3644b0eea3c 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/pending-posts-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/pending-posts-test.js @@ -1,31 +1,26 @@ -import { acceptance } from "discourse/tests/helpers/qunit-helpers"; +import { + acceptance, + count, + exists, +} from "discourse/tests/helpers/qunit-helpers"; import { test } from "qunit"; import { click, visit } from "@ember/test-helpers"; -import { setupApplicationTest as EMBER_CLI_ENV } from "ember-qunit"; acceptance("Pending posts - no existing pending posts", function (needs) { - if (!EMBER_CLI_ENV) { - return; // dom helpers not available in legacy env - } - needs.user(); test("No link to pending posts", async function (assert) { await visit("/u/eviltrout"); - assert.dom(".action-list").doesNotIncludeText("Pending"); + assert.ok(!exists(".action-list [href='/u/eviltrout/activity/pending']")); }); }); acceptance("Pending posts - existing pending posts", function (needs) { - if (!EMBER_CLI_ENV) { - return; // dom helpers not available in legacy env - } - needs.user({ pending_posts_count: 2 }); test("Navigate to pending posts", async function (assert) { await visit("/u/eviltrout"); await click("[href='/u/eviltrout/activity/pending']"); - assert.dom(".user-stream-item").exists({ count: 2 }); + assert.strictEqual(count(".user-stream-item"), 2); }); }); diff --git a/app/assets/javascripts/discourse/tests/acceptance/sticky-avatars-test.js b/app/assets/javascripts/discourse/tests/acceptance/sticky-avatars-test.js index e4542dc8bbf..042f8232f55 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sticky-avatars-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sticky-avatars-test.js @@ -1,28 +1,18 @@ -import { acceptance } from "discourse/tests/helpers/qunit-helpers"; +import { acceptance, query } from "discourse/tests/helpers/qunit-helpers"; import { skip } from "qunit"; -import { find, scrollTo, visit, waitUntil } from "@ember/test-helpers"; -import { setupApplicationTest as EMBER_CLI_ENV } from "ember-qunit"; - -acceptance("Sticky Avatars", function (needs) { - if (!EMBER_CLI_ENV) { - return; // helpers not available in legacy env - } - - const container = document.getElementById("ember-testing-container"); - - needs.hooks.beforeEach(function () { - container.scrollTop = 0; - }); +import { visit } from "@ember/test-helpers"; +acceptance("Sticky Avatars", function () { skip("Adds sticky avatars when scrolling up", async function (assert) { + const container = document.getElementById("ember-testing-container"); + container.scrollTo(0, 0); + await visit("/t/internationalization-localization/280"); + container.scrollTo(0, 800); + container.scrollTo(0, 700); - await scrollTo(container, 0, 800); - await scrollTo(container, 0, 700); - - await waitUntil(() => find(".sticky-avatar")); assert.ok( - find("#post_5").parentElement.classList.contains("sticky-avatar"), + query("#post_5").parentElement.classList.contains("sticky-avatar"), "Sticky avatar is applied" ); }); diff --git a/app/assets/javascripts/discourse/tests/integration/components/empty-state-test.js b/app/assets/javascripts/discourse/tests/integration/components/empty-state-test.js index bfeaadcea6a..3c504caf2ba 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/empty-state-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/empty-state-test.js @@ -1,23 +1,18 @@ -import { module, test } from "qunit"; -import { setupRenderingTest } from "ember-qunit"; -import { render } from "@ember/test-helpers"; +import { discourseModule, query } from "discourse/tests/helpers/qunit-helpers"; +import componentTest, { + setupRenderingTest, +} from "discourse/tests/helpers/component-test"; import hbs from "htmlbars-inline-precompile"; -const LEGACY_ENV = !setupRenderingTest; - -module("Integration | Component | empty-state", function (hooks) { - if (LEGACY_ENV) { - return; - } - +discourseModule("Integration | Component | empty-state", function (hooks) { setupRenderingTest(hooks); - test("it renders", async function (assert) { - await render(hbs` - - `); + componentTest("it renders", { + template: hbs``, - assert.dom("[data-test-title]").hasText("title"); - assert.dom("[data-test-body]").hasText("body"); + test(assert) { + assert.strictEqual(query("[data-test-title]").textContent, "title"); + assert.strictEqual(query("[data-test-body]").textContent, "body"); + }, }); }); diff --git a/app/assets/javascripts/discourse/tests/integration/components/pending-post-test.js b/app/assets/javascripts/discourse/tests/integration/components/pending-post-test.js index 55d4ab43a1f..85be0e9dffd 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/pending-post-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/pending-post-test.js @@ -1,37 +1,35 @@ -import { module, test } from "qunit"; -import { setupRenderingTest } from "ember-qunit"; -import { render } from "@ember/test-helpers"; +import { discourseModule, query } from "discourse/tests/helpers/qunit-helpers"; +import componentTest, { + setupRenderingTest, +} from "discourse/tests/helpers/component-test"; import hbs from "htmlbars-inline-precompile"; -import PendingPost from "discourse/models/pending-post"; import createStore from "discourse/tests/helpers/create-store"; -const LEGACY_ENV = !setupRenderingTest; - -module("Integration | Component | pending-post", function (hooks) { - if (LEGACY_ENV) { - return; - } - +discourseModule("Integration | Component | pending-post", function (hooks) { setupRenderingTest(hooks); - test("it renders", async function (assert) { - const store = createStore(); - store.createRecord("category", { id: 2 }); - const post = PendingPost.create({ - id: 1, - topic_url: "topic-url", - username: "USERNAME", - category_id: 2, - raw_text: "**bold text**", - }); - this.set("post", post); + componentTest("it renders", { + template: hbs``, - await render(hbs``); + beforeEach() { + const store = createStore(); + store.createRecord("category", { id: 2 }); + const post = store.createRecord("pending-post", { + id: 1, + topic_url: "topic-url", + username: "USERNAME", + category_id: 2, + raw_text: "**bold text**", + }); + this.set("post", post); + }, - assert.equal( - this.element.querySelector("p.excerpt").textContent.trim(), - "bold text", - "renders the cooked text" - ); + test(assert) { + assert.strictEqual( + query("p.excerpt").textContent.trim(), + "bold text", + "renders the cooked text" + ); + }, }); }); diff --git a/package.json b/package.json index e71e86bdd16..7881bcf8f94 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,6 @@ "pretender": "^3.4.7", "puppeteer": "1.20", "qunit": "2.8.0", - "qunit-dom": "^2.0.0", "route-recognizer": "^0.3.3", "sinon": "^9.0.2", "squoosh": "discourse/squoosh#dc9649d"