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.
This commit is contained in:
Jarek Radosz 2021-11-30 13:01:39 +01:00 committed by GitHub
parent fced35de15
commit 24356e339b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 79 deletions

View File

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

View File

@ -81,7 +81,6 @@
]
},
"devDependencies": {
"ember-exam": "6.1.0",
"ember-test-selectors": "^6.0.0"
"ember-exam": "6.1.0"
}
}

View File

@ -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);
});
});

View File

@ -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"
);
});

View File

@ -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");
},
});
});

View File

@ -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"
);
},
});
});

View File

@ -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"