Using arrow functions changes `this` context, which is undesired in tests, e.g. it makes it impossible to setup things like pretender (`this.server`) in `beforeEach` hooks. Ember guides always use classic functions in examples (e.g. https://guides.emberjs.com/release/testing/test-types/), and that's what it uses in its own test suite, as do various addons and ember apps. It was also already used in Discourse where `this` was required. Moving forward, it will be needed in more places as we migrate toward ember-cli. (I might later add a custom rule to eslint-discourse-ember to enforce this)
56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
import { queryAll } from "discourse/tests/helpers/qunit-helpers";
|
|
import { exists } from "discourse/tests/helpers/qunit-helpers";
|
|
import { fillIn, click, visit, currentURL } from "@ember/test-helpers";
|
|
import { test } from "qunit";
|
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
acceptance("Admin - Site Texts", function (needs) {
|
|
needs.user();
|
|
|
|
test("search for a key", async function (assert) {
|
|
await visit("/admin/customize/site_texts");
|
|
|
|
await fillIn(".site-text-search", "Test");
|
|
|
|
assert.equal(currentURL(), "/admin/customize/site_texts?q=Test");
|
|
assert.ok(exists(".site-text"));
|
|
assert.ok(exists(".site-text:not(.overridden)"));
|
|
assert.ok(exists(".site-text.overridden"));
|
|
|
|
// Only show overridden
|
|
await click(".search-area .filter-options input");
|
|
assert.equal(
|
|
currentURL(),
|
|
"/admin/customize/site_texts?overridden=true&q=Test"
|
|
);
|
|
|
|
assert.ok(!exists(".site-text:not(.overridden)"));
|
|
assert.ok(exists(".site-text.overridden"));
|
|
});
|
|
|
|
test("edit and revert a site text by key", async function (assert) {
|
|
await visit("/admin/customize/site_texts/site.test");
|
|
|
|
assert.equal(queryAll(".title h3").text(), "site.test");
|
|
assert.ok(!exists(".saved"));
|
|
assert.ok(!exists(".revert-site-text"));
|
|
|
|
// Change the value
|
|
await fillIn(".site-text-value", "New Test Value");
|
|
await click(".save-changes");
|
|
|
|
assert.ok(exists(".saved"));
|
|
assert.ok(exists(".revert-site-text"));
|
|
|
|
// Revert the changes
|
|
await click(".revert-site-text");
|
|
|
|
assert.ok(exists(".bootbox.modal"));
|
|
|
|
await click(".bootbox.modal .btn-primary");
|
|
|
|
assert.ok(!exists(".saved"));
|
|
assert.ok(!exists(".revert-site-text"));
|
|
});
|
|
});
|