From 79cec02c1a5fa7fa086f611438fca7662eb0851c Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 11 Mar 2026 16:34:11 +0100 Subject: [PATCH] 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. --- .../clickTtPlayerRegistrationService.js | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/backend/services/clickTtPlayerRegistrationService.js b/backend/services/clickTtPlayerRegistrationService.js index 486345ac..0cf2bb56 100644 --- a/backend/services/clickTtPlayerRegistrationService.js +++ b/backend/services/clickTtPlayerRegistrationService.js @@ -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 = [