mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Allow click-interceptor in tests and add navigation test (#15499)
The app's wrapper element ID is different in tests. `app.rootElement` allows us to consistently obtain the selector in the initializer, so it works correctly regardless of the app's configuration.
This commit is contained in:
parent
c4646264c1
commit
ef37186be3
@ -3,8 +3,9 @@ import interceptClick from "discourse/lib/intercept-click";
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "click-interceptor",
|
name: "click-interceptor",
|
||||||
initialize() {
|
initialize(container, app) {
|
||||||
$("#main").on("click.discourse", "a", interceptClick);
|
this.selector = app.rootElement;
|
||||||
|
$(this.selector).on("click.discourse", "a", interceptClick);
|
||||||
window.addEventListener("hashchange", this.hashChanged);
|
window.addEventListener("hashchange", this.hashChanged);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
$("#main").off("click.discourse", "a", interceptClick);
|
$(this.selector).off("click.discourse", "a", interceptClick);
|
||||||
window.removeEventListener("hashchange", this.hashChanged);
|
window.removeEventListener("hashchange", this.hashChanged);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -2,13 +2,14 @@ import {
|
|||||||
acceptance,
|
acceptance,
|
||||||
exists,
|
exists,
|
||||||
publishToMessageBus,
|
publishToMessageBus,
|
||||||
|
query,
|
||||||
queryAll,
|
queryAll,
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
||||||
import sinon from "sinon";
|
import sinon from "sinon";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import { visit } from "@ember/test-helpers";
|
import { click, currentURL, visit } from "@ember/test-helpers";
|
||||||
|
|
||||||
acceptance("Topic Discovery", function (needs) {
|
acceptance("Topic Discovery", function (needs) {
|
||||||
needs.settings({
|
needs.settings({
|
||||||
@ -134,4 +135,25 @@ acceptance("Topic Discovery", function (needs) {
|
|||||||
"it keeps the query params"
|
"it keeps the query params"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("switching between tabs", async function (assert) {
|
||||||
|
await visit("/latest");
|
||||||
|
assert.strictEqual(
|
||||||
|
query(".topic-list-body .topic-list-item:first-of-type").dataset.topicId,
|
||||||
|
"11557",
|
||||||
|
"shows the correct latest topics"
|
||||||
|
);
|
||||||
|
|
||||||
|
await click(".navigation-container a[href='/top']");
|
||||||
|
assert.strictEqual(currentURL(), "/top", "switches to top");
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
query(".topic-list-body .topic-list-item:first-of-type").dataset.topicId,
|
||||||
|
"13088",
|
||||||
|
"shows the correct top topics"
|
||||||
|
);
|
||||||
|
|
||||||
|
await click(".navigation-container a[href='/categories']");
|
||||||
|
assert.strictEqual(currentURL(), "/categories", "switches to categories");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user