refactor(clickTtPlayerRegistrationService): improve nationality and country selection logic

- Replaced direct option selection with a new method that selects options based on partial label matching, enhancing flexibility in form filling.
- Introduced the _selectOptionByLabelContains method to streamline the selection process for nationality and country fields, improving code maintainability.
This commit is contained in:
Torsten Schulz (local)
2026-03-11 16:34:11 +01:00
parent c1cf903196
commit 79cec02c1a

View File

@@ -412,7 +412,7 @@ class ClickTtPlayerRegistrationService {
if (await nationalitySelect.count()) {
const currentValue = await nationalitySelect.inputValue().catch(() => 'WONoSelectionString');
if (!currentValue || currentValue === 'WONoSelectionString') {
await nationalitySelect.selectOption({ label: /Deutschland/ });
await this._selectOptionByLabelContains(nationalitySelect, 'Deutschland');
}
}
@@ -420,7 +420,7 @@ class ClickTtPlayerRegistrationService {
if (await countrySelect.count()) {
const currentValue = await countrySelect.inputValue().catch(() => 'WONoSelectionString');
if (!currentValue || currentValue === 'WONoSelectionString') {
await countrySelect.selectOption({ label: /Deutschland/ });
await this._selectOptionByLabelContains(countrySelect, 'Deutschland');
}
}
@@ -512,6 +512,27 @@ class ClickTtPlayerRegistrationService {
return true;
}
async _selectOptionByLabelContains(locator, text) {
if (!(await locator.count())) {
return false;
}
const optionValue = await locator.evaluate((select, searchText) => {
const normalizedSearch = String(searchText || '').toLowerCase();
const option = Array.from(select.options).find((entry) =>
String(entry.textContent || '').toLowerCase().includes(normalizedSearch)
);
return option?.value || null;
}, text);
if (!optionValue) {
return false;
}
await locator.selectOption(optionValue);
return true;
}
async _hasTextTarget(page, text) {
const escaped = escapeRegExp(text);
const selectors = [