This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/acceptance/topic-admin-menu-test.js
Jarek Radosz a17d54d0bf
DEV: De-arrowify tests (#11068)
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)
2020-10-30 17:37:32 +01:00

57 lines
1.8 KiB
JavaScript

import { exists } from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import {
acceptance,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Topic - Admin Menu Anonymous Users", function () {
test("Enter as a regular user", async function (assert) {
await visit("/t/internationalization-localization/280");
assert.ok(exists("#topic"), "The topic was rendered");
assert.ok(
!exists(".toggle-admin-menu"),
"The admin menu button was not rendered"
);
});
});
acceptance("Topic - Admin Menu", function (needs) {
needs.user();
test("Enter as a user with group moderator permissions", async function (assert) {
updateCurrentUser({ moderator: false, admin: false, trust_level: 1 });
await visit("/t/topic-for-group-moderators/2480");
assert.ok(exists("#topic"), "The topic was rendered");
assert.ok(
exists(".toggle-admin-menu"),
"The admin menu button was rendered"
);
});
test("Enter as a user with moderator and admin permissions", async function (assert) {
updateCurrentUser({ moderator: true, admin: true, trust_level: 4 });
await visit("/t/internationalization-localization/280");
assert.ok(exists("#topic"), "The topic was rendered");
assert.ok(
exists(".toggle-admin-menu"),
"The admin menu button was rendered"
);
});
test("Toggle the menu as admin focuses the first item", async function (assert) {
updateCurrentUser({ admin: true });
await visit("/t/internationalization-localization/280");
assert.ok(exists("#topic"), "The topic was rendered");
await click(".toggle-admin-menu");
assert.equal(
document.activeElement,
document.querySelector(".topic-admin-multi-select > button")
);
});
});