-
Notifications
You must be signed in to change notification settings - Fork 1
fix(admin): prevent no-op tenant saves and cover settings states #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seonghobae
merged 6 commits into
worktree-fix-frontend-build-break
from
worktree-fix-adminpanel-coverage
Aug 23, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6074407
test(admin): cover AdminPanel (previously zero coverage)
seonghobae 7f6383e
fix(frontend): use OIDC return-url helpers on the login button
seonghobae f08beb8
fix(admin): guard no-op saves and announce results
seonghobae 9e29567
merge: stack AdminPanel coverage after PR #426
seonghobae 56884cc
docs(storybook): inventory tenant settings
seonghobae 82ae39b
merge: refresh PR #426 stack base
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import type { Meta, StoryObj } from "@storybook/react-vite"; | ||
| import { AdminPanel } from "./AdminPanel"; | ||
|
|
||
| const meta = { | ||
| title: "Admin/AdminPanel", | ||
| component: AdminPanel, | ||
| args: { | ||
| currentBrandName: "LineageWeave", | ||
| onBrandNameChange: () => undefined, | ||
| accessToken: "demo-access-token", | ||
| }, | ||
| } satisfies Meta<typeof AdminPanel>; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default: Story = {}; | ||
|
|
||
| // Edge case: a long tenant brand name near the input's practical width. | ||
| export const LongBrandName: Story = { | ||
| args: { | ||
| currentBrandName: "A Very Long Tenant Brand Name For Layout Testing Purposes", | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import { act, fireEvent, render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
| import { AdminPanel } from "./AdminPanel"; | ||
| import * as api from "../api"; | ||
|
|
||
| describe("AdminPanel", () => { | ||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it("ignores unchanged and whitespace-only submissions", async () => { | ||
| const updateSpy = vi.spyOn(api, "updateTenantConfig"); | ||
| render( | ||
| <AdminPanel currentBrandName="LineageWeave" onBrandNameChange={vi.fn()} accessToken="token" />, | ||
| ); | ||
| const button = screen.getByRole("button", { name: "Save settings" }); | ||
| const input = screen.getByRole("textbox", { name: "Tenant brand name" }); | ||
| const form = button.closest("form"); | ||
|
|
||
| expect(button).toBeDisabled(); | ||
| fireEvent.submit(form!); | ||
| await userEvent.clear(input); | ||
| await userEvent.type(input, " "); | ||
| expect(button).toBeDisabled(); | ||
| fireEvent.submit(form!); | ||
| expect(updateSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("saves a changed brand name and reports it back to the caller", async () => { | ||
| const timeoutSpy = vi.spyOn(globalThis, "setTimeout"); | ||
| const updateSpy = vi | ||
| .spyOn(api, "updateTenantConfig") | ||
| .mockResolvedValue({ brandName: "Renamed Corp" }); | ||
| const onBrandNameChange = vi.fn(); | ||
| render( | ||
| <AdminPanel currentBrandName="LineageWeave" onBrandNameChange={onBrandNameChange} accessToken="token" />, | ||
| ); | ||
|
|
||
| const input = screen.getByRole("textbox", { name: "Tenant brand name" }); | ||
| await userEvent.clear(input); | ||
| await userEvent.type(input, "Renamed Corp"); | ||
| await userEvent.click(screen.getByRole("button", { name: "Save settings" })); | ||
|
|
||
| expect(updateSpy).toHaveBeenCalledWith("token", "Renamed Corp"); | ||
| expect(await screen.findByRole("status")).toHaveTextContent("Settings saved!"); | ||
| expect(onBrandNameChange).toHaveBeenCalledWith("Renamed Corp"); | ||
| const timeoutIndex = timeoutSpy.mock.calls.findIndex((call) => call[1] === 3000); | ||
| expect(timeoutIndex).toBeGreaterThanOrEqual(0); | ||
| clearTimeout(timeoutSpy.mock.results[timeoutIndex].value); | ||
| act(() => (timeoutSpy.mock.calls[timeoutIndex][0] as () => void)()); | ||
| expect(screen.queryByRole("status")).toBeNull(); | ||
| }); | ||
|
|
||
| it("shows an error and leaves the form editable when the save fails", async () => { | ||
| vi.spyOn(api, "updateTenantConfig").mockRejectedValue(new Error("Failed to update settings")); | ||
| render( | ||
| <AdminPanel currentBrandName="LineageWeave" onBrandNameChange={vi.fn()} accessToken="token" />, | ||
| ); | ||
|
|
||
| const input = screen.getByRole("textbox", { name: "Tenant brand name" }); | ||
| await userEvent.clear(input); | ||
| await userEvent.type(input, "Renamed Corp"); | ||
| await userEvent.click(screen.getByRole("button", { name: "Save settings" })); | ||
|
|
||
| expect(await screen.findByRole("alert")).toHaveTextContent("Failed to update settings"); | ||
| expect(screen.getByRole("button", { name: "Save settings" })).not.toBeDisabled(); | ||
| }); | ||
|
|
||
| it("uses the actionable fallback when a failure has no message", async () => { | ||
| vi.spyOn(api, "updateTenantConfig").mockRejectedValue(new Error("")); | ||
| render( | ||
| <AdminPanel currentBrandName="LineageWeave" onBrandNameChange={vi.fn()} accessToken="token" />, | ||
| ); | ||
|
|
||
| const input = screen.getByRole("textbox", { name: "Tenant brand name" }); | ||
| await userEvent.clear(input); | ||
| await userEvent.type(input, "Renamed Corp"); | ||
| await userEvent.click(screen.getByRole("button", { name: "Save settings" })); | ||
|
|
||
| expect(await screen.findByRole("alert")).toHaveTextContent("Failed to update settings"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.