mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 06:35:24 +00:00
fix: open settings goes to the plugin's page and hides when it has none
This commit is contained in:
1 parent
d1ddcd3ff9
commit
60024bdd4e
6 files changed
+96
-5
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
hasSettingsPage,
|
||||
hasVisibleFields,
|
||||
} from "@/settings/settings-fields-util";
|
||||
import type { PluginSettingsField } from "@/api/plugins-api";
|
||||
|
||||
const field = (hidden = false) =>
|
||||
({ key: "a", type: "string", hidden }) as unknown as PluginSettingsField;
|
||||
|
||||
describe("hasVisibleFields", () => {
|
||||
it("ignores hidden fields", () => {
|
||||
expect(hasVisibleFields([field(true)])).toBe(false);
|
||||
expect(hasVisibleFields([field(true), field()])).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("hasSettingsPage", () => {
|
||||
it("needs an enabled plugin", () => {
|
||||
expect(
|
||||
hasSettingsPage(
|
||||
{ enabled: false, contributes: { settings: { user: [field()] } } },
|
||||
true,
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("is false with no settings or only hidden ones", () => {
|
||||
expect(hasSettingsPage({ enabled: true, contributes: null }, true)).toBe(
|
||||
false,
|
||||
);
|
||||
expect(
|
||||
hasSettingsPage(
|
||||
{ enabled: true, contributes: { settings: { user: [field(true)] } } },
|
||||
true,
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("counts admin settings only for admins", () => {
|
||||
const plugin = {
|
||||
enabled: true,
|
||||
contributes: { settings: { admin: [field()] } },
|
||||
};
|
||||
expect(hasSettingsPage(plugin, true)).toBe(true);
|
||||
expect(hasSettingsPage(plugin, false)).toBe(false);
|
||||
});
|
||||
|
||||
it("counts user settings for anyone", () => {
|
||||
expect(
|
||||
hasSettingsPage(
|
||||
{ enabled: true, contributes: { settings: { user: [field()] } } },
|
||||
false,
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user