Skip to content

fix(e2e): fix broken employment MultiSelect selector after IconButton refactor#1599

Draft
sinatragianpaolo wants to merge 6 commits into
developfrom
fix-e2e-tests
Draft

fix(e2e): fix broken employment MultiSelect selector after IconButton refactor#1599
sinatragianpaolo wants to merge 6 commits into
developfrom
fix-e2e-tests

Conversation

@sinatragianpaolo
Copy link
Copy Markdown
Contributor

@sinatragianpaolo sinatragianpaolo commented Apr 28, 2026

Causa

Il test employment.spec.ts › It should have a number > 0 as an output falliva deterministicamente (3/3 tentativi) a causa di un selettore fragile basato sul conteggio di SVG.

Il selettore originale era:

.getByLabel('Employment status')
.locator('svg')
.nth(2)
.click();

L'intento era aprire la dropdown del MultiSelect cliccando il suo chevron. Il selettore funzionava quando il pulsante di eliminazione dell'accordion era un Button con testo + icona (struttura al momento della scrittura del test, giugno 2025).

Cosa ha rotto il test

Il commit d0067ea99 (settembre 2025) ha sostituito il Button con testo con un IconButton che contiene solo il TrashIcon SVG:

- <Button isBasic isDanger>
-   <Button.StartIcon><TrashIcon /></Button.StartIcon>
-   {t('__PLAN_PAGE_MODULE_EMPLOYMENT_REMOVE_BUTTON')}  ← testo, nessun SVG aggiuntivo nell'header
- </Button>

+ <IconButton isDanger>
+   <TrashIcon />  ← SVG aggiunto nell'header
+ </IconButton>

Questo ha aggiunto un SVG nell'header dell'accordion, spostando l'indice del chevron del MultiSelect da nth(2) a nth(3). Il click finiva sul chevron dell'accordion, che lo collassava invece di aprire la dropdown. UNEMPLOYED non veniva mai selezionato e il PATCH body restituiva ['EMPLOYEE', 'STUDENT'] invece di ['EMPLOYEE', 'STUDENT', 'UNEMPLOYED'].

Fix

Sostituito il selettore SVG-based con getByRole('combobox'), che punta direttamente all'elemento interattivo del MultiSelect indipendentemente dalla struttura degli SVG circostanti.

// prima
.getByLabel('Employment status').locator('svg').nth(2).click()

// dopo
.getByRole('combobox').click()

Rimosso anche un commento errato (// Find the locality module) copiato dal test di locality.

Target the StyledTrigger element directly instead of the outer wrapper,
whose onClick is a no-op in non-editable mode, causing intermittent
failures when the click coordinates miss the inner trigger in CI.
Also wait for the option to be visible before clicking it.
…put correctly

The MultiSelect component uses isAutocomplete which renders the listbox via a
portal (listboxAppendToNode={document.body}). Clicking a portal option causes
mousedown to blur the combobox input before the click registers, making the
test flaky in CI. The trigger click also leaves focus on the wrapper div, not
the inner input, so keyboard.type() was going to the wrong element.

Fix: after opening the dropdown, wait for the input[role="combobox"] to be
visible, fill it to filter options, then use keyboard ArrowDown+Enter to select
via the input:keyDown:Enter path — no mousedown on the portal option.
…loyment test

After fill(), React needs two renders to propagate inputValue→matchingOptions→
aria-hidden on non-matching options. In CI this happens too slowly, so ArrowDown
was firing before Garden v9's ne.values updated, causing navigation to land on
Employee instead of Unemployed.

Fix: wait for getByRole('option').toHaveCount(1) before pressing ArrowDown.
Hidden options receive aria-hidden=true and drop out of getByRole results, so
count=1 reliably signals that Downshift's navigation pool is ready.
@marcbon
Copy link
Copy Markdown
Collaborator

marcbon commented May 4, 2026

ho approvato, ma ancora uno dei test e2e fallisce. metto in draft, da fixare @sinatragianpaolo

@marcbon marcbon marked this pull request as draft May 4, 2026 07:53
@marcbon marcbon added growth bug Something isn't working labels May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working growth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants