-
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.
Merge pull request #58 from gisce/button_grup
Button grup
- Loading branch information
Showing
6 changed files
with
115 additions
and
1 deletion.
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,31 @@ | ||
import Button from "./Button"; | ||
import ContainerWidget from "./ContainerWidget"; | ||
|
||
class ButtonGroup extends ContainerWidget { | ||
|
||
_defaultName: string = ""; | ||
get defaultName(): string { | ||
return this._defaultName; | ||
} | ||
|
||
get defaultButton(): Button | undefined { | ||
return this.buttons.find(button => button.id === this.defaultName); | ||
} | ||
|
||
get secondaryButtons(): Button[] { | ||
return this.buttons.filter(button => button.id !== this.defaultName); | ||
} | ||
|
||
get buttons(): Button[] { | ||
return this._container.rows[0] as Button[]; | ||
} | ||
|
||
constructor(props: any) { | ||
super(props); | ||
if (props.default) { | ||
this._defaultName = props.default; | ||
} | ||
} | ||
} | ||
|
||
export default ButtonGroup; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import ButtonGroup from "../ButtonGroup"; | ||
import WidgetFactory from "../WidgetFactory"; | ||
import Button from "../Button"; | ||
|
||
describe("A ButtonsGroup widget", () => { | ||
it("should have an id corresponding to button name", () => { | ||
const widgetFactory = new WidgetFactory(); | ||
const props = { | ||
name: "defaultButtonGroup", | ||
}; | ||
|
||
const widget = widgetFactory.createWidget("buttonGroup", props); | ||
expect(widget.id).toBe("defaultButtonGroup"); | ||
}); | ||
|
||
describe("Getting child buttons", () => { | ||
|
||
let buttonGroup: ButtonGroup; | ||
|
||
beforeAll(() => { | ||
const btn1 = new Button({name: "btn1", type: "object", icon: "gtk-execute", string: "Button 1"}); | ||
const btn2 = new Button({name: "btn2", type: "object", icon: "gtk-execute", string: "Button 2"}); | ||
const btn3 = new Button({name: "btn3", type: "object", icon: "gtk-execute", string: "Button 3"}); | ||
buttonGroup = new ButtonGroup({name: "btnGroup", default: "btn1"}); | ||
buttonGroup.container.rows[0].push(...[btn1, btn2, btn3]); | ||
}) | ||
|
||
it("should have child buttons", () => { | ||
expect(buttonGroup.buttons).toHaveLength(3); | ||
}); | ||
|
||
it("should have this default button", () => { | ||
expect(buttonGroup.defaultButton?.id).toBe("btn1"); | ||
}); | ||
|
||
it("should have this secondary buttons", () => { | ||
expect(buttonGroup.secondaryButtons).toHaveLength(2); | ||
expect(buttonGroup.secondaryButtons[0].id).toBe("btn2"); | ||
expect(buttonGroup.secondaryButtons[1].id).toBe("btn3"); | ||
}); | ||
|
||
}); | ||
}); |
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