huskies: merge 488_story_web_ui_shows_project_name_in_browser_tab_with_huskies_favicon
This commit is contained in:
@@ -345,6 +345,59 @@ describe("App", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("sets document title to Huskies when no project is open", async () => {
|
||||
mockedApi.getCurrentProject.mockResolvedValue(null);
|
||||
|
||||
await renderApp();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(document.title).toBe("Huskies");
|
||||
});
|
||||
});
|
||||
|
||||
it("sets document title to project name when a project is open", async () => {
|
||||
mockedApi.getCurrentProject.mockResolvedValue("/home/user/reclaimer");
|
||||
|
||||
await renderApp();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(document.title).toBe("reclaimer | Huskies");
|
||||
});
|
||||
});
|
||||
|
||||
it("resets document title to Huskies after closing project", async () => {
|
||||
mockedApi.openProject.mockResolvedValue("/home/user/myproject");
|
||||
mockedApi.closeProject.mockResolvedValue(true);
|
||||
|
||||
await renderApp();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
screen.getByPlaceholderText(/\/path\/to\/project/i),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
const input = screen.getByPlaceholderText(
|
||||
/\/path\/to\/project/i,
|
||||
) as HTMLInputElement;
|
||||
await userEvent.clear(input);
|
||||
await userEvent.type(input, "/home/user/myproject");
|
||||
|
||||
const openButton = screen.getByRole("button", { name: /open project/i });
|
||||
await userEvent.click(openButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(document.title).toBe("myproject | Huskies");
|
||||
});
|
||||
|
||||
const closeButton = await waitFor(() => screen.getByText("✕"));
|
||||
await userEvent.click(closeButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(document.title).toBe("Huskies");
|
||||
});
|
||||
});
|
||||
|
||||
it("handles Enter key to trigger project open", async () => {
|
||||
mockedApi.openProject.mockResolvedValue("/home/user/myproject");
|
||||
|
||||
|
||||
@@ -51,6 +51,17 @@ function App() {
|
||||
});
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (projectPath) {
|
||||
const projectName =
|
||||
projectPath.replace(/\\/g, "/").split("/").filter(Boolean).pop() ??
|
||||
projectPath;
|
||||
document.title = `${projectName} | Huskies`;
|
||||
} else {
|
||||
document.title = "Huskies";
|
||||
}
|
||||
}, [projectPath]);
|
||||
|
||||
React.useEffect(() => {
|
||||
api
|
||||
.getKnownProjects()
|
||||
|
||||
Reference in New Issue
Block a user