DEV: Split tests for user preferences security page into individual file (#19096)

Mixing multiple acceptance tests in a single file makes the acceptance
tests much harder to find.
This commit is contained in:
Alan Guo Xiang Tan 2022-11-18 11:40:05 +08:00 committed by GitHub
parent 4f63bc8ed2
commit 5e516a7d7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 51 deletions

View File

@ -1,6 +1,5 @@
import {
acceptance,
count,
exists,
query,
updateCurrentUser,
@ -572,56 +571,6 @@ acceptance("Ignored users", function (needs) {
});
});
acceptance("User Preferences - Security", function (needs) {
needs.user();
needs.pretender(preferencesPretender);
test("recently connected devices", async function (assert) {
await visit("/u/eviltrout/preferences/security");
assert.strictEqual(
query(
".auth-tokens > .auth-token:nth-of-type(1) .auth-token-device"
).innerText.trim(),
"Linux Computer",
"it should display active token first"
);
assert.strictEqual(
query(".pref-auth-tokens > a:nth-of-type(1)").innerText.trim(),
I18n.t("user.auth_tokens.show_all", { count: 3 }),
"it should display two tokens"
);
assert.strictEqual(
count(".pref-auth-tokens .auth-token"),
2,
"it should display two tokens"
);
await click(".pref-auth-tokens > a:nth-of-type(1)");
assert.strictEqual(
count(".pref-auth-tokens .auth-token"),
3,
"it should display three tokens"
);
const authTokenDropdown = selectKit(".auth-token-dropdown");
await authTokenDropdown.expand();
await authTokenDropdown.selectRowByValue("notYou");
assert.strictEqual(count(".d-modal:visible"), 1, "modal should appear");
await click(".modal-footer .btn-primary");
assert.strictEqual(
count(".pref-password.highlighted"),
1,
"it should highlight password preferences"
);
});
});
acceptance(
"User Preferences for staged user and don't allow tracking prefs",
function (needs) {

View File

@ -0,0 +1,64 @@
import I18n from "I18n";
import { test } from "qunit";
import { click, visit } from "@ember/test-helpers";
import {
acceptance,
count,
query,
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("User Preferences - Security", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.get("/u/eviltrout/activity.json", () => {
return helper.response({});
});
});
test("recently connected devices", async function (assert) {
await visit("/u/eviltrout/preferences/security");
assert.strictEqual(
query(
".auth-tokens > .auth-token:nth-of-type(1) .auth-token-device"
).innerText.trim(),
"Linux Computer",
"it should display active token first"
);
assert.strictEqual(
query(".pref-auth-tokens > a:nth-of-type(1)").innerText.trim(),
I18n.t("user.auth_tokens.show_all", { count: 3 }),
"it should display two tokens"
);
assert.strictEqual(
count(".pref-auth-tokens .auth-token"),
2,
"it should display two tokens"
);
await click(".pref-auth-tokens > a:nth-of-type(1)");
assert.strictEqual(
count(".pref-auth-tokens .auth-token"),
3,
"it should display three tokens"
);
const authTokenDropdown = selectKit(".auth-token-dropdown");
await authTokenDropdown.expand();
await authTokenDropdown.selectRowByValue("notYou");
assert.strictEqual(count(".d-modal:visible"), 1, "modal should appear");
await click(".modal-footer .btn-primary");
assert.strictEqual(
count(".pref-password.highlighted"),
1,
"it should highlight password preferences"
);
});
});