Files
PriceUpdaterAppv2/tests/tui/components/HelpOverlay.test.js

161 lines
5.4 KiB
JavaScript

/**
* Unit tests for HelpOverlay component
* Tests help system functionality and context-sensitive help display
* Requirements: 9.2, 9.5
*/
describe("HelpOverlay Component", () => {
test("should have HelpOverlay component available", () => {
const HelpOverlay = require("../../../src/tui/components/common/HelpOverlay.jsx");
expect(typeof HelpOverlay).toBe("function");
});
test("should import required dependencies", () => {
const fs = require("fs");
const path = require("path");
const helpOverlayPath = path.join(
__dirname,
"../../../src/tui/components/common/HelpOverlay.jsx"
);
const helpOverlayContent = fs.readFileSync(helpOverlayPath, "utf8");
// Verify required imports
expect(helpOverlayContent).toContain('require("react")');
expect(helpOverlayContent).toContain('require("ink")');
expect(helpOverlayContent).toContain('require("../../hooks/useHelp.js")');
});
test("should use useHelp hook", () => {
const fs = require("fs");
const path = require("path");
const helpOverlayPath = path.join(
__dirname,
"../../../src/tui/components/common/HelpOverlay.jsx"
);
const helpOverlayContent = fs.readFileSync(helpOverlayPath, "utf8");
expect(helpOverlayContent).toContain("useHelp()");
expect(helpOverlayContent).toContain("getHelpTitle");
expect(helpOverlayContent).toContain("getHelpDescription");
expect(helpOverlayContent).toContain("getAllShortcuts");
});
test("should handle keyboard input for closing", () => {
const fs = require("fs");
const path = require("path");
const helpOverlayPath = path.join(
__dirname,
"../../../src/tui/components/common/HelpOverlay.jsx"
);
const helpOverlayContent = fs.readFileSync(helpOverlayPath, "utf8");
expect(helpOverlayContent).toContain("useInput");
expect(helpOverlayContent).toContain("key.escape");
expect(helpOverlayContent).toContain('input === "h"');
expect(helpOverlayContent).toContain('input === "H"');
expect(helpOverlayContent).toContain('input === "q"');
expect(helpOverlayContent).toContain("onClose()");
});
test("should render help content structure", () => {
const fs = require("fs");
const path = require("path");
const helpOverlayPath = path.join(
__dirname,
"../../../src/tui/components/common/HelpOverlay.jsx"
);
const helpOverlayContent = fs.readFileSync(helpOverlayPath, "utf8");
// Verify help overlay structure
expect(helpOverlayContent).toContain('position: "absolute"');
expect(helpOverlayContent).toContain('backgroundColor: "black"');
expect(helpOverlayContent).toContain('borderStyle: "double"');
expect(helpOverlayContent).toContain('borderColor: "cyan"');
expect(helpOverlayContent).toContain("📖");
expect(helpOverlayContent).toContain("Keyboard Shortcuts:");
expect(helpOverlayContent).toContain("💡 Tips:");
});
test("should display shortcuts dynamically", () => {
const fs = require("fs");
const path = require("path");
const helpOverlayPath = path.join(
__dirname,
"../../../src/tui/components/common/HelpOverlay.jsx"
);
const helpOverlayContent = fs.readFileSync(helpOverlayPath, "utf8");
expect(helpOverlayContent).toContain("shortcuts.map");
expect(helpOverlayContent).toContain("shortcut.key");
expect(helpOverlayContent).toContain("shortcut.description");
});
test("should return null when not visible", () => {
const fs = require("fs");
const path = require("path");
const helpOverlayPath = path.join(
__dirname,
"../../../src/tui/components/common/HelpOverlay.jsx"
);
const helpOverlayContent = fs.readFileSync(helpOverlayPath, "utf8");
expect(helpOverlayContent).toContain("if (!isVisible)");
expect(helpOverlayContent).toContain("return null");
});
test("should include helpful tips", () => {
const fs = require("fs");
const path = require("path");
const helpOverlayPath = path.join(
__dirname,
"../../../src/tui/components/common/HelpOverlay.jsx"
);
const helpOverlayContent = fs.readFileSync(helpOverlayPath, "utf8");
expect(helpOverlayContent).toContain(
"Use Tab to navigate between form fields"
);
expect(helpOverlayContent).toContain(
"Press 'h' on any screen to get context-specific help"
);
expect(helpOverlayContent).toContain(
"Use Esc to go back or cancel operations"
);
expect(helpOverlayContent).toContain(
"Configuration must be complete before running operations"
);
});
});
describe("HelpOverlay Integration", () => {
test("should be integrated into TuiApplication", () => {
const fs = require("fs");
const path = require("path");
const tuiAppPath = path.join(
__dirname,
"../../../src/tui/TuiApplication.jsx"
);
const tuiAppContent = fs.readFileSync(tuiAppPath, "utf8");
expect(tuiAppContent).toContain("HelpOverlay");
expect(tuiAppContent).toContain("isVisible={appState.uiState.helpVisible}");
expect(tuiAppContent).toContain("onClose={hideHelp}");
expect(tuiAppContent).toContain("currentScreen={appState.currentScreen}");
});
test("should have help state in AppProvider", () => {
const fs = require("fs");
const path = require("path");
const appProviderPath = path.join(
__dirname,
"../../../src/tui/providers/AppProvider.jsx"
);
const appProviderContent = fs.readFileSync(appProviderPath, "utf8");
expect(appProviderContent).toContain("helpVisible: false");
expect(appProviderContent).toContain("toggleHelp");
expect(appProviderContent).toContain("showHelp");
expect(appProviderContent).toContain("hideHelp");
});
});