51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
class HotkeyViewerComponent {
|
|
constructor(page) {
|
|
this.page = page;
|
|
}
|
|
|
|
keyContainer() {
|
|
return this.page.locator('.keyContainer');
|
|
}
|
|
|
|
async _findKeyButton(keyLabel) {
|
|
const upper = keyLabel.toUpperCase();
|
|
const buttons = this.keyContainer().locator('> div > div');
|
|
const count = await buttons.count();
|
|
for (let i = 0; i < count; i++) {
|
|
const btn = buttons.nth(i);
|
|
const text = (await btn.textContent()) || '';
|
|
if (text.trim().toUpperCase().startsWith(upper)) return btn;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
async clickKey(keyText) {
|
|
const btn = await this._findKeyButton(keyText);
|
|
if (!btn) throw new Error(`Key "${keyText}" not found`);
|
|
await btn.click({ force: true });
|
|
}
|
|
|
|
async getFirstEntityName(keyText) {
|
|
const btn = await this._findKeyButton(keyText);
|
|
if (!btn) return null;
|
|
const entities = btn.locator('> div');
|
|
if ((await entities.count()) === 0) return null;
|
|
return (await entities.first().textContent()) || '';
|
|
}
|
|
|
|
async getEntityNamesOnKey(keyText) {
|
|
const btn = await this._findKeyButton(keyText);
|
|
if (!btn) return [];
|
|
const entities = btn.locator('> div');
|
|
const count = await entities.count();
|
|
const names = [];
|
|
for (let i = 0; i < count; i++) {
|
|
const text = (await entities.nth(i).textContent()) || '';
|
|
names.push(text.trim());
|
|
}
|
|
return names.filter(Boolean);
|
|
}
|
|
}
|
|
|
|
module.exports = HotkeyViewerComponent;
|