A platform for community discussion. Free, open, simple.
DEV: Fix pending posts page, make tests work in legacy env (#15132)
Jarek Radosz24356e339b37
diff --git a/app/assets/javascripts/discourse/app/templates/user-activity/pending.hbs b/app/assets/javascripts/discourse/app/templates/user-activity-pending.hbssimilarity index 67%rename from app/assets/javascripts/discourse/app/templates/user-activity/pending.hbsrename to app/assets/javascripts/discourse/app/templates/user-activity-pending.hbsindex 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 @@<ul class="user-stream">- {{#each @model as |pending_post|}}+ {{#each this.model as |pending_post|}}<PendingPost @post={{pending_post}} />{{/each}}</ul>diff --git a/app/assets/javascripts/discourse/package.json b/app/assets/javascripts/discourse/package.jsonindex 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.jsindex 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.jsindex 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) {- await visit("/t/internationalization-localization/280");+ const container = document.getElementById("ember-testing-container");+ container.scrollTo(0, 0);- await scrollTo(container, 0, 800);- await scrollTo(container, 0, 700);+ await visit("/t/internationalization-localization/280");+ container.scrollTo(0, 800);+ container.scrollTo(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.jsindex 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`- <EmptyState @title="title" @body="body" />- `);+ componentTest("it renders", {+ template: hbs`<EmptyState @title="title" @body="body" />`,- 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.jsindex 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`<PendingPost @post={{this.post}}/>`,- await render(hbs`<PendingPost @post={{this.post}}/>`);+ 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.jsonindex 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"