This is an automated email from the ASF dual-hosted git repository.
vatsrahul1001 pushed a commit to branch v3-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-4-test by this push:
new df376a64688 [v3-4-test] UI: Name the Security menu links by their
translated label (#77474) (#77595)
df376a64688 is described below
commit df376a646881d4e56958b8e53cf0791a4290e975
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Nov 25 21:23:48 2026 +0530
[v3-4-test] UI: Name the Security menu links by their translated label
(#77474) (#77595)
(cherry picked from commit 9b7a265a8d89e590e6b05581f8b7924cbf89ca73)
Co-authored-by: Pushkal Gupta <[email protected]>
---
.../ui/src/layouts/Nav/SecurityButton.test.tsx | 77 ++++++++++++++++++++++
.../airflow/ui/src/layouts/Nav/SecurityButton.tsx | 14 ++--
2 files changed, 87 insertions(+), 4 deletions(-)
diff --git
a/airflow-core/src/airflow/ui/src/layouts/Nav/SecurityButton.test.tsx
b/airflow-core/src/airflow/ui/src/layouts/Nav/SecurityButton.test.tsx
new file mode 100644
index 00000000000..56e6b694dae
--- /dev/null
+++ b/airflow-core/src/airflow/ui/src/layouts/Nav/SecurityButton.test.tsx
@@ -0,0 +1,77 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import "@testing-library/jest-dom/vitest";
+import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
+
+import i18n from "src/i18n/config";
+import { Wrapper } from "src/utils/Wrapper";
+
+import { SecurityButton } from "./SecurityButton";
+
+const mocks = vi.hoisted(() => ({ useAuthLinksServiceGetAuthMenus: vi.fn() }));
+
+vi.mock("openapi/queries", () => ({
+ useAuthLinksServiceGetAuthMenus: mocks.useAuthLinksServiceGetAuthMenus,
+}));
+
+const withMenuItems = (items: Array<{ href: string; text: string }>) =>
+ mocks.useAuthLinksServiceGetAuthMenus.mockReturnValue({
+ data: { authorized_menu_items: [], extra_menu_items: items },
+ isLoading: false,
+ });
+
+const openMenu = async () => {
+ fireEvent.click(screen.getByRole("button", { name: "nav.security" }));
+ await waitFor(() =>
expect(screen.getAllByRole("menuitem").length).toBeGreaterThan(0));
+};
+
+beforeAll(() => {
+ // AppWrapper fetches the locale files over HTTP and jsdom does not serve
them, so without a
+ // bundle `translate` hands back the key and there is no translated wording
to assert on.
+ i18n.addResourceBundle("en", "common", { security: { users: "Benutzer" } },
true, true);
+});
+
+beforeEach(() => {
+ mocks.useAuthLinksServiceGetAuthMenus.mockReset();
+});
+
+describe("SecurityButton", () => {
+ it("names each link by its translated label, not the English text the API
sent", async () => {
+ withMenuItems([{ href: "/auth/users/list/", text: "Users" }]);
+
+ render(<SecurityButton />, { wrapper: Wrapper });
+ await openMenu();
+
+ // An aria-label overrides the visible text, so naming the link from the
API's own English
+ // left a screen reader reading "Users" while the menu showed the
translated word.
+ expect(screen.getByRole("menuitem", { name: "Benutzer"
})).toBeInTheDocument();
+ expect(screen.queryByRole("menuitem", { name: "Users"
})).not.toBeInTheDocument();
+ });
+
+ it("falls back to the item's own text when the auth manager sends one we
have no key for", async () => {
+ withMenuItems([{ href: "/auth/audit-logs/list/", text: "Audit Logs" }]);
+
+ render(<SecurityButton />, { wrapper: Wrapper });
+ await openMenu();
+
+ expect(screen.getByRole("menuitem", { name: "Audit Logs"
})).toBeInTheDocument();
+ expect(screen.queryByText("security.audit-logs")).not.toBeInTheDocument();
+ });
+});
diff --git a/airflow-core/src/airflow/ui/src/layouts/Nav/SecurityButton.tsx
b/airflow-core/src/airflow/ui/src/layouts/Nav/SecurityButton.tsx
index d5de0efcc02..3250a2ab609 100644
--- a/airflow-core/src/airflow/ui/src/layouts/Nav/SecurityButton.tsx
+++ b/airflow-core/src/airflow/ui/src/layouts/Nav/SecurityButton.tsx
@@ -38,7 +38,13 @@ export const SecurityButton = () => {
const securityItems = authLinks.extra_menu_items.map(({ text }) => {
const securityKey = text.toLowerCase().replace(" ", "-");
- return { path: `security/${securityKey}`, securityKey, text };
+ // The auth manager sends each item's English text rather than a key, and
only the five FAB
+ // sends have one. Anything else is better off showing that text than the
key it resolves to.
+ return {
+ label: translate(`security.${securityKey}`, { defaultValue: text }),
+ path: `security/${securityKey}`,
+ text,
+ };
});
return (
@@ -51,10 +57,10 @@ export const SecurityButton = () => {
/>
}
>
- {securityItems.map(({ path, securityKey, text }) => (
+ {securityItems.map(({ label, path, text }) => (
<Menu.Item asChild key={text} value={text}>
- <Link aria-label={text} to={path}>
- {translate(`security.${securityKey}`)}
+ <Link aria-label={label} to={path}>
+ {label}
</Link>
</Menu.Item>
))}