Skip to content

Commit 4e9c622

Browse files
test(button): add e2e test for async type change
Removes test for syncing disabled state of visible and hidden button that unreliably passed. Adds test for syncing type of visible and hidden button.
1 parent fb273ab commit 4e9c622

1 file changed

Lines changed: 16 additions & 35 deletions

File tree

packages/angular/test/base/e2e/src/lazy/form.spec.ts

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -283,49 +283,30 @@ test.describe('Form', () => {
283283
await expect(control).toHaveClass(/ng-invalid/);
284284
});
285285

286-
test('should keep hidden submit button disabled state in sync', async ({ page }) => {
287-
288-
// Get the disabled state of both visible and hidden button
289-
const getDisabledState = () =>
286+
test('should keep hidden button type in sync with visible button', async ({ page }) => {
287+
288+
// Get type of the hidden button
289+
const getHiddenType = () =>
290290
page.evaluate(() => {
291-
const visible = document.querySelector(
292-
'#submit-button'
293-
) as HTMLIonButtonElement;
294-
295291
const hidden = document.querySelector(
296-
'form button[type="submit"][style*="display: none"]'
292+
'form button[style*="display: none"]'
297293
) as HTMLButtonElement;
298294

299-
return {
300-
visible: visible?.disabled,
301-
hidden: hidden?.disabled,
302-
};
295+
return hidden?.type;
303296
});
304-
305-
// Ensure disabled state of both visible and hidden button
306-
// Should match each other and expected
307-
const expectDisabledStatesMatch = async (expected: boolean) => {
308-
const state = await getDisabledState();
309-
expect(state.visible).toBe(expected);
310-
expect(state.hidden).toBe(expected);
311-
expect(state.visible).toBe(state.hidden);
312-
return state;
313-
};
314-
315-
// Initial state - should be disabled and both match
316-
await expectDisabledStatesMatch(true);
317-
318-
// Set form values - should be enabled
319-
await page.locator('#set-values').click();
320297

321-
// After set values - should be enabled and both match
322-
await expectDisabledStatesMatch(false);
298+
// Type should be submit to start
299+
expect(await getHiddenType()).toBe('submit');
323300

324-
// User clicks submit button
325-
await page.locator('#submit-button').click();
301+
// Set type of visible button to reset
302+
await page.locator('#submit-button').evaluate((el: HTMLIonButtonElement) => {
303+
el.type = 'reset';
304+
});
326305

327-
// Form should submit successfully
328-
await expect(page.locator('#submit')).toHaveText('true');
306+
// Expect hidden button type to be reset
307+
await expect
308+
.poll(async () => await getHiddenType())
309+
.toBe('reset');
329310
});
330311
});
331312

0 commit comments

Comments
 (0)