Skip to content

Commit

Permalink
Simplify cancel button test case setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Sep 25, 2023
1 parent 96f4cc9 commit 1b2e059
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions src/www/views/contact_view/support_form/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,36 +106,34 @@ describe('SupportForm', () => {
});
});

describe('clicking cancel button', () => {
let el: SupportForm;
let emailInput: HTMLInputElement;
let cancelButton: HTMLElement;

beforeEach(async () => {
el = await fixture(
html`
<support-form></support-form>
`
);
emailInput = el.shadowRoot!.querySelector('mwc-textfield[name="Email"')!;
await setValue(emailInput, '[email protected]');
cancelButton = el.shadowRoot!.querySelector('mwc-button[label="Cancel"]')!;
});
it('clicking cancel button resets the form', async () => {
const el: SupportForm = await fixture(
html`
<support-form></support-form>
`
);
const emailInput: HTMLInputElement = el.shadowRoot!.querySelector('mwc-textfield[name="Email"')!;
await setValue(emailInput, '[email protected]');

it('resets the form', async () => {
cancelButton.click();
await nextFrame();
const cancelButton: HTMLElement = el.shadowRoot!.querySelector('mwc-button[label="Cancel"]')!;
cancelButton.click();
await nextFrame();

expect(emailInput.value).toBe('');
});
expect(emailInput.value).toBe('');
});

it('emits form cancel event', async () => {
const listener = oneEvent(el, 'cancel');
it('emits form cancel event', async () => {
const el: SupportForm = await fixture(
html`
<support-form></support-form>
`
);
const listener = oneEvent(el, 'cancel');

cancelButton.click();
const cancelButton: HTMLElement = el.shadowRoot!.querySelector('mwc-button[label="Cancel"]')!;
cancelButton.click();

const {detail} = await listener;
expect(detail).toBeTrue();
});
const {detail} = await listener;
expect(detail).toBeTrue();
});
});

0 comments on commit 1b2e059

Please sign in to comment.