Skip to content

A platform for community discussion. Free, open, simple.

DEV: Centralise user preferences security test into a single file (#19121)

Alan Guo Xiang Tand3366a909250
diff --git a/app/assets/javascripts/discourse/app/components/user-preferences/user-api-keys.hbs b/app/assets/javascripts/discourse/app/components/user-preferences/user-api-keys.hbs
index 96833b93a32..9244ab49480 100644
--- a/app/assets/javascripts/discourse/app/components/user-preferences/user-api-keys.hbs
+++ b/app/assets/javascripts/discourse/app/components/user-preferences/user-api-keys.hbs
@@ -1,24 +1,33 @@
{{#if @model.userApiKeys}}
- <div class="control-group apps">
- <label class="control-label">{{i18n "user.apps"}}</label>
+ <div class="control-group pref-user-api-keys">
+ <label class="control-label pref-user-api-keys__label">{{i18n "user.apps"}}</label>
+
<div class="controls">
{{#each @model.userApiKeys as |key|}}
<div>
- <span>{{key.application_name}}</span>
+ <span class="pref-user-api-keys__application-name">{{key.application_name}}</span>
+
{{#if key.revoked}}
<DButton @action={{route-action "undoRevokeApiKey"}} @actionParam={{key}} @class="btn" @label="user.undo_revoke_access" />
{{else}}
<DButton @action={{route-action "revokeApiKey"}} @actionParam={{key}} @class="btn" @label="user.revoke_access" />
{{/if}}
+
<p>
- <ul>
+ <ul class="pref-user-api-keys__scopes-list">
{{#each key.scopes as |scope|}}
- <li>{{scope}}</li>
+ <li class="pref-user-api-keys__scopes-list-item">{{scope}}</li>
{{/each}}
</ul>
</p>
- <p><span>{{i18n "user.api_approved"}}</span> {{bound-date key.created_at}}</p>
- <p><span>{{i18n "user.api_last_used_at"}}</span> {{bound-date key.last_used_at}}</p>
+
+ <p class="pref-user-api-keys__created-at">
+ <span>{{i18n "user.api_approved"}}</span> {{bound-date key.created_at}}
+ </p>
+
+ <p class="pref-user-api-keys__last-used-at">
+ <span>{{i18n "user.api_last_used_at"}}</span> {{bound-date key.last_used_at}}
+ </p>
</div>
{{/each}}
</div>
diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-new-menu-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-new-menu-test.js
deleted file mode 100644
index eb1d11f37b3..00000000000
--- a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-new-menu-test.js
+++ /dev/null
@@ -1,41 +0,0 @@
-import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
-import { visit } from "@ember/test-helpers";
-import { test } from "qunit";
-
-acceptance(
- "New User Menu - Horizontal nav and preferences relocation",
- function (needs) {
- needs.user({
- redesigned_user_page_nav_enabled: true,
- user_api_keys: [
- {
- id: 1,
- application_name: "Discourse Hub",
- scopes: ["Read and clear notifications"],
- created_at: "2020-11-14T00:57:09.093Z",
- last_used_at: "2022-09-22T18:55:41.672Z",
- },
- ],
- });
-
- test("Horizontal user nav exists", async function (assert) {
- await visit("/u/eviltrout/preferences");
- assert.ok(exists(".horizontal-overflow-nav"), "horizontal nav exists");
- });
-
- test("User Tracking page exists", async function (assert) {
- await visit("/u/eviltrout/preferences");
- assert.ok(exists(".nav-tracking"), "the new tracking page link exists");
- });
-
- test("User Categories page no longer exists", async function (assert) {
- await visit("/u/eviltrout/preferences");
- assert.ok(!exists(".nav-categories"), "Categories tab no longer exists");
- });
-
- test("Can view user api keys on security page", async function (assert) {
- await visit("/u/eviltrout/preferences/security");
- assert.ok(exists(".control-group.apps"), "User can see apps section");
- });
- }
-);
diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-security-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-security-test.js
index 5f2e533ceee..8eddd0c3ce0 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/user-preferences-security-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/user-preferences-security-test.js
@@ -4,7 +4,9 @@ import { click, visit } from "@ember/test-helpers";
import {
acceptance,
count,
+ exists,
query,
+ updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
@@ -61,4 +63,43 @@ acceptance("User Preferences - Security", function (needs) {
"it should highlight password preferences"
);
});
+
+ test("Viewing user api keys when user has redesign user page navigation enabled", async function (assert) {
+ updateCurrentUser({
+ redesigned_user_page_nav_enabled: true,
+ user_api_keys: [
+ {
+ id: 1,
+ application_name: "Discourse Hub",
+ scopes: ["Read and clear notifications"],
+ created_at: "2020-11-14T00:57:09.093Z",
+ last_used_at: "2022-09-15T18:55:41.672Z",
+ },
+ ],
+ });
+
+ await visit("/u/eviltrout/preferences/security");
+
+ assert.strictEqual(
+ query(".pref-user-api-keys__application-name").innerText.trim(),
+ "Discourse Hub",
+ "displays the application name for the API key"
+ );
+
+ assert.strictEqual(
+ query(".pref-user-api-keys__scopes-list-item").innerText.trim(),
+ "Read and clear notifications",
+ "displays the scope for the API key"
+ );
+
+ assert.ok(
+ exists(".pref-user-api-keys__created-at"),
+ "displays the created at date for the API key"
+ );
+
+ assert.ok(
+ exists(".pref-user-api-keys__last-used-at"),
+ "displays the last used at date for the API key"
+ );
+ });
});