Repository navigation
fix(web): stop settings pages from saving changes the admin can't see #4696
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
+503
−98
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3dc268d
fix(web): stop settings pages from saving changes the admin can't see
Quick104 e7b8151
fix(web): mark kept rows and keep only the edited ones
Quick104 d93afbd
fix(web): drop the Jellyfin Web switch-off when its API draft goes
Quick104 f4ff246
fix(web): one rule for the Jellyfin Web switch-off; keep saved device…
Quick104 844b85f
fix(web): keep a kept device picker from adding NVENC-incompatible paths
Quick104 1b4f2ba
fix(web): mark the changed devices in a kept device picker
Quick104 ebd7e19
fix(web): treat a device toggle back to the saved list as no change
Quick104 c5c64cd
test(web): check that only the unrelated edit survives a Redis takeover
Quick104 92bb206
test(web): stage the Redis number with the switch-off in the takeover…
Quick104 9c49a5a
fix(web): keep a device revert staged while a save settles
Quick104 6ea774b
fix(web): let a kept device picker always reach the saved list
Quick104 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
65 changes: 65 additions & 0 deletions
65
web/src/pages/admin-settings/CompatibilityProxiesSettings.test.tsx
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,65 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { beforeEach, expect, it, vi } from "vitest"; | ||
|
|
||
| import CompatibilityProxiesSettings from "./CompatibilityProxiesSettings"; | ||
|
|
||
| const SETTINGS = { | ||
| "jellyfin_compat.enabled": "true", | ||
| "jellyfin_compat.web_enabled": "true", | ||
| "jellyfin_compat.public_url": "https://media.example.com", | ||
| }; | ||
|
|
||
| const { sensitiveStatus } = vi.hoisted(() => ({ | ||
| sensitiveStatus: { | ||
| current: { configured: [], managed_by_env: [] } as { | ||
| configured: string[]; | ||
| managed_by_env: string[]; | ||
| managed_by_env_vars?: Record<string, string>; | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock("@/hooks/queries/admin/settings", () => ({ | ||
| useAdminServerSettings: () => ({ data: SETTINGS, isLoading: false }), | ||
| useAdminSensitiveStatus: () => ({ data: sensitiveStatus.current, isError: false }), | ||
| useUpdateServerSettings: () => ({ mutateAsync: vi.fn(), isPending: false }), | ||
| useJellyfinCompatStatus: () => ({ | ||
| data: { enabled: true, web_enabled: true, api_state: "running", web_state: "missing" }, | ||
| isLoading: false, | ||
| }), | ||
| useInstallJellyfinCompatWeb: () => ({ mutate: vi.fn(), isPending: false }), | ||
| useRemoveJellyfinCompatWeb: () => ({ mutate: vi.fn(), isPending: false }), | ||
| useUpdateJellyfinCompatSettings: () => ({ mutate: vi.fn(), isPending: false }), | ||
| })); | ||
|
|
||
| vi.mock("@/hooks/useRestartKeys", () => ({ useRestartKeys: () => ({ has: () => false }) })); | ||
|
|
||
| beforeEach(() => { | ||
| sensitiveStatus.current = { configured: [], managed_by_env: [] }; | ||
| }); | ||
|
|
||
| it("stages nothing when the Jellyfin API is switched off and back on", async () => { | ||
| render(<CompatibilityProxiesSettings />); | ||
| const api = screen.getByRole("switch", { name: "Allow Jellyfin apps to connect" }); | ||
| await userEvent.click(api); | ||
| await userEvent.click(api); | ||
|
|
||
| expect(screen.queryByText(/unsaved change/)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("takes back the Jellyfin Web switch-off once the environment sets the API switch", async () => { | ||
| const { rerender } = render(<CompatibilityProxiesSettings />); | ||
| await userEvent.click(screen.getByRole("switch", { name: "Allow Jellyfin apps to connect" })); | ||
| expect(screen.getByText("2 unsaved changes")).toBeInTheDocument(); | ||
|
|
||
| // A restart with SILO_JELLYFIN_ENABLED set: the form drops the API draft. | ||
| sensitiveStatus.current = { | ||
| configured: [], | ||
| managed_by_env: ["jellyfin_compat.enabled"], | ||
| managed_by_env_vars: { "jellyfin_compat.enabled": "SILO_JELLYFIN_ENABLED" }, | ||
| }; | ||
| rerender(<CompatibilityProxiesSettings />); | ||
|
|
||
| expect(screen.queryByText(/unsaved change/)).not.toBeInTheDocument(); | ||
| }); |
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,107 @@ | ||
| import { render, screen, within } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { MemoryRouter } from "react-router"; | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import PlaybackSettings from "./PlaybackSettings"; | ||
|
|
||
| window.HTMLElement.prototype.hasPointerCapture ??= () => false; | ||
| window.HTMLElement.prototype.setPointerCapture ??= () => {}; | ||
| window.HTMLElement.prototype.releasePointerCapture ??= () => {}; | ||
| window.HTMLElement.prototype.scrollIntoView ??= () => {}; | ||
|
|
||
| const A = "/dev/dri/renderD128"; | ||
| const B = "/dev/dri/renderD129"; | ||
| const C = "/dev/dri/renderD130"; | ||
|
|
||
| const { settings } = vi.hoisted(() => ({ | ||
| settings: { current: {} as Record<string, string> }, | ||
| })); | ||
|
|
||
| vi.mock("@/hooks/queries/admin/settings", () => ({ | ||
| useAdminServerSettings: () => ({ data: settings.current, isLoading: false }), | ||
| useAdminSensitiveStatus: () => ({ data: { configured: [], managed_by_env: [] }, isError: false }), | ||
| useUpdateServerSettings: () => ({ mutateAsync: vi.fn(), isPending: false }), | ||
| })); | ||
| vi.mock("@/hooks/queries/admin/system", () => ({ | ||
| useHWAccelDetection: () => ({ | ||
| data: { | ||
| resolved: "vaapi", | ||
| render_device_details: [ | ||
| { path: A, description: "GPU A" }, | ||
| { path: B, description: "GPU B" }, | ||
| { path: C, description: "GPU C" }, | ||
| ], | ||
| }, | ||
| isLoading: false, | ||
| }), | ||
| })); | ||
| vi.mock("@/hooks/queries/admin/nodes", () => ({ | ||
| useAdminNodes: () => ({ data: [], isSuccess: true }), | ||
| })); | ||
| vi.mock("@/hooks/queries/admin/libraries", () => ({ | ||
| useLibraryCapabilities: () => ({ data: { trickplay: false } }), | ||
| })); | ||
| vi.mock("@/hooks/queries/admin/markers", () => ({ | ||
| useAdminMarkerCapabilities: () => ({ data: undefined }), | ||
| })); | ||
| vi.mock("@/hooks/queries/admin/trickplay", () => ({ | ||
| useAdminTrickplayLibraries: () => ({ data: [], isSuccess: true }), | ||
| })); | ||
| vi.mock("@/hooks/useRestartKeys", () => ({ useRestartKeys: () => ({ has: () => false }) })); | ||
| vi.mock("./MarkerTasksCard", () => ({ MarkerTasksCard: () => null })); | ||
|
|
||
| const page = ( | ||
| <MemoryRouter> | ||
| <PlaybackSettings /> | ||
| </MemoryRouter> | ||
| ); | ||
|
|
||
| async function openDevices() { | ||
| const transcoding = within(screen.getByRole("group", { name: "Transcoding" })); | ||
| await userEvent.click(transcoding.getByRole("button", { name: /Advanced/ })); | ||
| } | ||
|
|
||
| async function switchToNvenc() { | ||
| await userEvent.click(screen.getByRole("combobox", { name: "Hardware acceleration" })); | ||
| await userEvent.click(screen.getByRole("option", { name: "NVIDIA NVENC" })); | ||
| } | ||
|
|
||
| describe("hardware device picker kept for an unsaved change", () => { | ||
| beforeEach(() => { | ||
| // Disclosures remember being opened; start every case collapsed. | ||
| localStorage.clear(); | ||
| settings.current = { "playback.hw_accel": "vaapi", "playback.hw_device": A }; | ||
| }); | ||
|
|
||
| it("under NVENC only takes the staged device back off", async () => { | ||
| render(page); | ||
| await openDevices(); | ||
| await userEvent.click(screen.getByRole("switch", { name: "GPU B" })); | ||
| await switchToNvenc(); | ||
|
|
||
| // A render path NVENC can't use can't be added, and the staged one can | ||
| // go back off. | ||
| expect(screen.getByRole("switch", { name: "GPU C" })).toBeDisabled(); | ||
| await userEvent.click(screen.getByRole("switch", { name: "GPU B" })); | ||
|
|
||
| expect(screen.queryByRole("switch", { name: "GPU B" })).not.toBeInTheDocument(); | ||
| expect(screen.getByText("1 unsaved change")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("can restore a saved list that differs from the staged one only in order", async () => { | ||
| const { rerender } = render(page); | ||
| await openDevices(); | ||
| await userEvent.click(screen.getByRole("switch", { name: "GPU B" })); | ||
| // Someone else saves the same devices in the other order. | ||
| settings.current = { "playback.hw_accel": "vaapi", "playback.hw_device": `${B},${A}` }; | ||
| rerender(page); | ||
| await switchToNvenc(); | ||
|
|
||
| await userEvent.click(screen.getByRole("switch", { name: "GPU A" })); | ||
| await userEvent.click(screen.getByRole("switch", { name: "GPU A" })); | ||
|
|
||
| expect(screen.queryByRole("switch", { name: "GPU A" })).not.toBeInTheDocument(); | ||
| expect(screen.getByText("1 unsaved change")).toBeInTheDocument(); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
Oops, something went wrong.
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.