-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06bbd75
commit e68960b
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,26 @@ | ||
import React from "react"; | ||
import PopupOverlay from "../popup/PopupOverlay.mjs"; | ||
|
||
const h = React.createElement; | ||
|
||
const MenuBarTrigger = () => { | ||
return h("box", { | ||
height: 1, | ||
clickable: true, | ||
mouse: true, | ||
autoFocus: false, | ||
style: PopupOverlay.style, | ||
onClick: () => { | ||
process.stdin.emit("keypress", undefined, { | ||
name: "f9", | ||
ctrl: false, | ||
meta: false, | ||
shift: false, | ||
}); | ||
}, | ||
}); | ||
}; | ||
|
||
MenuBarTrigger.displayName = "MenuBarTrigger"; | ||
|
||
export default MenuBarTrigger; |
This file contains 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 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,78 @@ | ||
/** | ||
* @typedef {import("@farjs/blessed").Widgets.Events.IKeyEventArg} IKeyEventArg | ||
*/ | ||
import React from "react"; | ||
import TestRenderer from "react-test-renderer"; | ||
import { assertComponents } from "react-assert"; | ||
import assert from "node:assert/strict"; | ||
import mockFunction from "mock-fn"; | ||
import PopupOverlay from "../../src/popup/PopupOverlay.mjs"; | ||
import MenuBarTrigger from "../../src/menu/MenuBarTrigger.mjs"; | ||
|
||
const h = React.createElement; | ||
|
||
const { describe, it } = await (async () => { | ||
// @ts-ignore | ||
const module = process.isBun ? "bun:test" : "node:test"; | ||
// @ts-ignore | ||
return process.isBun // @ts-ignore | ||
? Promise.resolve({ describe: (_, fn) => fn(), it: test }) | ||
: import(module); | ||
})(); | ||
|
||
describe("MenuBarTrigger.test.mjs", () => { | ||
it("should emit keypress event when onClick", () => { | ||
//given | ||
const onKey = mockFunction((name, ctrl, meta, shift) => { | ||
//then | ||
assert.deepEqual(name, "f9"); | ||
assert.deepEqual(ctrl, false); | ||
assert.deepEqual(meta, false); | ||
assert.deepEqual(shift, false); | ||
}); | ||
/** @type {(ch: object, key: IKeyEventArg) => void} */ | ||
const listener = (_, key) => { | ||
//cleanup | ||
process.stdin.removeListener("keypress", listener); | ||
|
||
//then | ||
onKey(key.name, key.ctrl, key.meta, key.shift); | ||
}; | ||
process.stdin.on("keypress", listener); | ||
|
||
const renderer = TestRenderer.create(h(MenuBarTrigger)); | ||
const clickable = renderer.root.findByType("box"); | ||
|
||
//when | ||
clickable.props.onClick(); | ||
|
||
//then | ||
assert.deepEqual(onKey.times, 1); | ||
}); | ||
|
||
it("should render component", () => { | ||
//when | ||
const result = TestRenderer.create(h(MenuBarTrigger)).root; | ||
|
||
//then | ||
assertMenuBarTrigger(result); | ||
}); | ||
}); | ||
|
||
/** | ||
* @param {TestRenderer.ReactTestInstance} result | ||
*/ | ||
function assertMenuBarTrigger(result) { | ||
assert.deepEqual(MenuBarTrigger.displayName, "MenuBarTrigger"); | ||
|
||
assertComponents( | ||
result.children, | ||
h("box", { | ||
height: 1, | ||
clickable: true, | ||
mouse: true, | ||
autoFocus: false, | ||
style: PopupOverlay.style, | ||
}) | ||
); | ||
} |