-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
89 changed files
with
3,483 additions
and
3,374 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
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 |
---|---|---|
@@ -1,21 +1,7 @@ | ||
const expect = require("expect"); | ||
const h = require("inferno-hyperscript").default; | ||
const { find, shallow } = require("../Test/Test"); | ||
const { ActionBar } = require("./ActionBar"); | ||
|
||
describe("ActionBar", () => { | ||
it("dispatches action without payload", () => { | ||
const handler = expect.createSpy(); | ||
|
||
/** @type {any} */ | ||
const actionService = { | ||
get: () => ({ handler }), | ||
}; | ||
|
||
const tree = shallow(h(ActionBar, { actionService })); | ||
const button = find(tree, x => x.type === "button"); | ||
|
||
button.props.on_pressed(); | ||
expect(handler).toHaveBeenCalledWith(); | ||
it("renders", () => { | ||
new ActionBar().render(); | ||
}); | ||
}); |
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,53 @@ | ||
const { Button, ReliefStyle } = imports.gi.Gtk; | ||
const Component = require("inferno-component").default; | ||
const { connect } = require("inferno-mobx"); | ||
const { autoBind } = require("../Gjs/autoBind"); | ||
const { h } = require("../Gjs/GtkInferno"); | ||
const ActionBarRm = require("./ActionBarRm").default; | ||
const { ActionService } = require("./ActionService"); | ||
|
||
/** | ||
* @typedef IProps | ||
* @property {{ id: string, label: string, shortcut: string }} action | ||
* @property {ActionService?} [actionService] | ||
* | ||
* @extends Component<IProps> | ||
*/ | ||
class ActionBarItem extends Component { | ||
/** | ||
* @param {IProps} props | ||
*/ | ||
constructor(props) { | ||
super(props); | ||
autoBind(this, ActionBarItem.prototype, __filename); | ||
} | ||
|
||
/** | ||
* @param {Button} button | ||
*/ | ||
ref(button) { | ||
const { get } = /** @type {ActionService} */ (this.props.actionService); | ||
button.connect("pressed", get(this.props.action.id).handler); | ||
} | ||
|
||
render() { | ||
const { id, label, shortcut } = this.props.action; | ||
|
||
if (id === "rm") { | ||
return h(ActionBarRm, { label: shortcut + " " + label }); | ||
} | ||
|
||
return ( | ||
h(Button, { | ||
can_focus: false, | ||
expand: true, | ||
label: shortcut + " " + label, | ||
ref: this.ref, | ||
relief: ReliefStyle.NONE, | ||
}) | ||
); | ||
} | ||
} | ||
|
||
exports.ActionBarItem = ActionBarItem; | ||
exports.default = connect(["actionService"])(ActionBarItem); |
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,37 @@ | ||
const expect = require("expect"); | ||
const { ActionBarItem } = require("./ActionBarItem"); | ||
|
||
describe("ActionBarItem", () => { | ||
it("renders", () => { | ||
const action = { | ||
id: "windowService.exit", | ||
label: "Exit", | ||
shortcut: "Alt+F4", | ||
}; | ||
|
||
new ActionBarItem({ action }).render(); | ||
}); | ||
|
||
it("connects handler", () => { | ||
const handler = expect.createSpy(); | ||
|
||
/** @type {any} */ | ||
const actionService = { | ||
get: () => ({ handler }), | ||
}; | ||
|
||
/** @type {any} */ | ||
const button = { | ||
connect: expect.createSpy(), | ||
}; | ||
|
||
const action = { | ||
id: "windowService.exit", | ||
label: "Exit", | ||
shortcut: "Alt+F4", | ||
}; | ||
|
||
new ActionBarItem({ action, actionService }).ref(button); | ||
expect(button.connect).toHaveBeenCalledWith("pressed", handler); | ||
}); | ||
}); |
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
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
Oops, something went wrong.