Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions locales/en/mod_management.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,15 @@
"label": "Properties",
"general": "General",
"advanced": "Advanced",
"close": "Close properties",
"toggle": "Properties",
"manageCategories": "Manage categories",
"open": "Properties",
"noSelection": "Select a mod to see its properties",
"count": "{{count}} mod selected",
"count_plural": "{{count}} mods selected",
"byAuthor": "by {{author}}",
"adult": "Adult",
"showDescription": "Show description",
"hideDescription": "Hide description",
"copy": "Copy {{label}}",
"copied": "Copied to clipboard",
"copyFailed": "Couldn't copy to the clipboard",
Expand Down
13 changes: 10 additions & 3 deletions src/renderer/src/extensions/category_management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@ function init(context: IExtensionContext): boolean {
context.registerReducer(["persistent", "categories"], categoryReducer);

context.registerDialog("categories", CategoryDialog);
context.registerAction("mod-icons", 80, "categories", { pinned: true }, "Categories", () => {
context.api.store.dispatch(setDialogVisible("categories"));
});
context.registerAction(
"mod-icons",
80,
"categories",
{ pinned: true },
"Manage categories",
() => {
context.api.store.dispatch(setDialogVisible("categories"));
},
);

context.registerTableAttribute("mods", {
id: "category",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,51 @@ describe("ModPropertiesCard", () => {
expect(screen.getByTestId("mod-properties-card-footer")).toBeInTheDocument();
});

it("shows its whole description a click away", async () => {
it("shows its whole description in a modal a click away", async () => {
renderCard({ name: "SkyUI", isAdult: false, description: "[b]An interface[/b]" });
expect(screen.queryByTestId("mod-properties-description")).toBeNull();
expect(screen.queryByRole("dialog")).toBeNull();

await userEvent.click(screen.getByTestId("mod-properties-description-toggle"));

expect(screen.getByTestId("mod-properties-description")).toBeInTheDocument();
const dialog = screen.getByRole("dialog");
expect(dialog).toContainElement(screen.getByTestId("mod-properties-description"));
expect(
screen.getByTestId("mod-properties-description").querySelector("b, strong"),
).not.toBeNull();
});

it("closes the description's modal", async () => {
renderCard({ name: "SkyUI", isAdult: false, description: "An interface" });
await userEvent.click(screen.getByTestId("mod-properties-description-toggle"));

await userEvent.keyboard("{Escape}");

expect(screen.queryByRole("dialog")).toBeNull();
});

it("stands in for images from outside Nexus Mods where the mod has a page", async () => {
renderCard({
name: "SkyUI",
isAdult: false,
description: "[img]https://i.imgur.com/a.png[/img]",
pageUrl: "https://www.nexusmods.com/skyrimspecialedition/mods/12604",
});
await userEvent.click(screen.getByTestId("mod-properties-description-toggle"));

expect(screen.getByTestId("external-image-placeholder")).toBeInTheDocument();
});

it("leaves out images from outside Nexus Mods where the mod has no page", async () => {
renderCard({
name: "SkyUI",
isAdult: false,
description: "[img]https://i.imgur.com/a.png[/img]",
});
await userEvent.click(screen.getByTestId("mod-properties-description-toggle"));

expect(screen.queryByTestId("external-image-placeholder")).toBeNull();
});

it("offers no description where it has none", () => {
renderCard({ name: "SkyUI", isAdult: false });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";

import { Button } from "@/ui/components/button/Button";
import { AdultAwareImage } from "@/ui/components/image/AdultAwareImage";
import { Modal } from "@/ui/components/modal/Modal";
import { BBCode } from "@/ui/components/prose/bbcode/BBCode";
import { Typography } from "@/ui/components/typography/Typography";

Expand All @@ -15,10 +16,10 @@ interface IModPropertiesCardProps {

/**
* The mod as Browse's mod card shows one, heading the Properties panel: its picture with its
* status tag, its name and summary, its whole description a click away, as the legacy pane has
* it, then its author and whether it's adult. Its picture blurs as the user has asked, if it's
* adult; a mod without one shows the broken picture icon, as its row's thumbnail does. The
* description shows no images from outside Nexus Mods, as there's no room to stand in for them.
* status tag, its name and summary, its whole description a click away in a modal, then its
* author and whether it's adult. Its picture blurs as the user has asked, if it's adult; a mod
* without one shows the broken picture icon, as its row's thumbnail does. The description's images
* from outside Nexus Mods show as placeholders opening its page, or not at all without one.
*/
export const ModPropertiesCard = ({ card }: IModPropertiesCardProps) => {
const { t } = useTranslation("mod_management");
Expand Down Expand Up @@ -52,25 +53,39 @@ export const ModPropertiesCard = ({ card }: IModPropertiesCardProps) => {
</div>

{!!card.description && (
<div className="flex flex-col items-start gap-y-2">
<>
<Button
appearance="weak"
appearance="subdued"
brand="neutral"
className="self-start"
data-testid="mod-properties-description-toggle"
size="sm"
onClick={() => setShowDescription(!showDescription)}
onClick={() => setShowDescription(true)}
>
{showDescription
? t("modsTable::properties::hideDescription")
: t("modsTable::properties::showDescription")}
{t("modsTable::properties::showDescription")}
</Button>

{showDescription && (
<div className="w-full" data-testid="mod-properties-description">
<BBCode bbcode={card.description} isFromAdultContent={card.isAdult} size="sm" />
<Modal
isOpen={showDescription}
size="lg"
title={card.name}
onClose={() => setShowDescription(false)}
>
<div
className="max-h-[60vh] overflow-y-auto pr-2"
data-testid="mod-properties-description"
>
<BBCode
bbcode={card.description}
externalImagePlaceholders={
card.pageUrl ? { websiteUrl: card.pageUrl } : undefined
}
isFromAdultContent={card.isAdult}
size="sm"
/>
</div>
)}
</div>
</Modal>
</>
)}

{(!!card.author || card.isAdult) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ONE_MOD: IModProperties = {
summary: "A friendlier menu.",
author: "schlangster",
isAdult: false,
status: "downloaded",
status: "update",
},
sections: [
{
Expand Down Expand Up @@ -73,16 +73,11 @@ const REGISTERED = {
values: {} as unknown as RegisteredValues,
};

const renderPanel = (properties: IModProperties, onClose = vi.fn(), registered = REGISTERED) => {
const renderPanel = (properties: IModProperties, registered = REGISTERED) => {
vi.mocked(useModProperties).mockReturnValue(properties);
return render(
<Provider store={makeModsTableStore()}>
<ModPropertiesPanel
memberships={MEMBERSHIPS}
mods={MODS}
registered={registered}
onClose={onClose}
/>
<ModPropertiesPanel memberships={MEMBERSHIPS} mods={MODS} registered={registered} />
</Provider>,
);
};
Expand Down Expand Up @@ -137,7 +132,7 @@ const renderRegistered = (
},
],
};
const open = () => renderPanel(properties, vi.fn(), registered);
const open = () => renderPanel(properties, registered);
return { view: open(), open, attribute, extension, externalData, values: registered.values };
};

Expand All @@ -158,7 +153,7 @@ describe("ModPropertiesPanel", () => {

const general = screen.getByRole("tabpanel");
expect(within(general).getByTestId("mod-properties-card")).toBeInTheDocument();
expect(within(general).getByTestId("mod-status-downloaded")).toBeInTheDocument();
expect(within(general).getByTestId("mod-status-update")).toBeInTheDocument();
expect(within(general).getByTestId("mod-property-version")).toHaveTextContent("5.2");
expect(within(general).queryByTestId("mod-property-archiveName")).not.toBeInTheDocument();
});
Expand All @@ -175,6 +170,35 @@ describe("ModPropertiesPanel", () => {
expect(screen.queryByTestId("mod-properties-card")).not.toBeInTheDocument();
});

it("starts a tab it switches to at its top", async () => {
renderPanel(ONE_MOD);
const scrollArea = screen.getByTestId("mod-properties-scroll-area");
scrollArea.scrollTop = 400;

await userEvent.click(screen.getAllByRole("tab")[1]);

expect(scrollArea.scrollTop).toBe(0);
});

it("keeps its tabs out of what scrolls", () => {
renderPanel(ONE_MOD);

const scrollArea = screen.getByTestId("mod-properties-scroll-area");
expect(scrollArea).not.toContainElement(screen.getByRole("tablist"));
expect(scrollArea).toContainElement(screen.getByTestId("mod-properties-card"));
});

it("keeps several mods' count out of what scrolls", () => {
renderPanel({
count: 3,
sections: [{ id: "organise", tab: "general", layout: "list", properties: [CATEGORY] }],
});

const scrollArea = screen.getByTestId("mod-properties-scroll-area");
expect(scrollArea).not.toContainElement(screen.getByTestId("mod-properties-count"));
expect(scrollArea).toContainElement(screen.getByRole("button", { name: /^Category/ }));
});

it("has no Advanced tab with nothing on it", () => {
renderPanel({ ...ONE_MOD, sections: ONE_MOD.sections.filter(({ tab }) => tab === "general") });

Expand Down Expand Up @@ -306,13 +330,4 @@ describe("ModPropertiesPanel", () => {
expect(externalData).not.toHaveBeenCalled();
expect(tableHears).not.toHaveBeenCalled();
});

it("closes", async () => {
const onClose = vi.fn();
renderPanel(ONE_MOD, onClose);

await userEvent.click(screen.getByTestId("mod-properties-close"));

expect(onClose).toHaveBeenCalledTimes(1);
});
});
Loading