mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-04-30 00:00:04 +08:00
Update types, tests
This commit is contained in:
@@ -31,17 +31,26 @@ class Utilities {
|
||||
Utilities.bindMethods(Utilities, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve button type
|
||||
*
|
||||
* @param {string} button The button's layout name
|
||||
* @return {string} The button type
|
||||
*/
|
||||
getButtonType(button: string): string {
|
||||
return button.includes("{") && button.includes("}") && button !== "{//}"
|
||||
? "functionBtn"
|
||||
: "standardBtn";
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds default classes to a given button
|
||||
*
|
||||
* @param {string} button The button's layout name
|
||||
* @return {string} The classes to be added to the button
|
||||
*/
|
||||
getButtonClass(button: string) {
|
||||
const buttonTypeClass =
|
||||
button.includes("{") && button.includes("}") && button !== "{//}"
|
||||
? "functionBtn"
|
||||
: "standardBtn";
|
||||
getButtonClass(button: string): string {
|
||||
const buttonTypeClass = this.getButtonType(button);
|
||||
const buttonWithoutBraces = button.replace("{", "").replace("}", "");
|
||||
let buttonNormalized = "";
|
||||
|
||||
@@ -418,7 +427,7 @@ class Utilities {
|
||||
* Determines whether pointer events are supported
|
||||
*/
|
||||
pointerEventsSupported() {
|
||||
return window.PointerEvent;
|
||||
return !!window.PointerEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -453,6 +462,18 @@ class Utilities {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Split array into chunks
|
||||
*/
|
||||
chunkArray<T>(arr: T[], size: number): T[][] {
|
||||
return [...Array(Math.ceil(arr.length / size))].map((_, i) =>
|
||||
arr.slice(size * i, size + size * i)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reusable empty function
|
||||
*/
|
||||
static noop = () => {};
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@ it('Keyboard mergeDisplay will work', () => {
|
||||
it('Keyboard function buttons will work', () => {
|
||||
setDOM();
|
||||
|
||||
new Keyboard();
|
||||
const keyboard = new Keyboard();
|
||||
|
||||
testLayoutFctButtons((fctBtnCount, fctBtnHasOnclickCount) => {
|
||||
testLayoutFctButtons(keyboard, (fctBtnCount, fctBtnHasOnclickCount) => {
|
||||
expect(fctBtnCount).toBe(fctBtnHasOnclickCount);
|
||||
});
|
||||
}, keyboard);
|
||||
});
|
||||
|
||||
it('Keyboard {bksp} button will work', () => {
|
||||
|
||||
Reference in New Issue
Block a user