-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core/button): pass through submit related events (#578)
- Loading branch information
1 parent
e0dc0fb
commit 3301a0d
Showing
6 changed files
with
134 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import { newSpecPage } from '@stencil/core/testing'; | ||
import { fireEvent } from '@testing-library/dom'; | ||
import { Button } from './button'; | ||
|
||
describe('button', () => { | ||
it('form submit', async (done) => { | ||
const page = await newSpecPage({ | ||
components: [Button], | ||
html: ` | ||
<form> | ||
<input type="text" /> | ||
<ix-button type="submit">Submit</ix-button>s | ||
</form> | ||
`, | ||
}); | ||
|
||
await page.waitForChanges(); | ||
const btn = page.doc | ||
.querySelector('ix-button[type="submit"]') | ||
.shadowRoot.querySelector('button'); | ||
|
||
const form = page.doc.querySelector('form'); | ||
|
||
const onSubmit = jest.fn(() => { | ||
done(); | ||
}); | ||
|
||
form.addEventListener('submit', onSubmit); | ||
fireEvent.click(btn); | ||
|
||
expect(onSubmit).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Siemens AG | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import { newSpecPage } from '@stencil/core/testing'; | ||
import { fireEvent } from '@testing-library/dom'; | ||
import { Button } from '../button'; | ||
|
||
describe('button', () => { | ||
it('should not be clickable with disabled prop', async () => { | ||
const page = await newSpecPage({ | ||
components: [Button], | ||
html: `<ix-button disabled>Example</ix-button>`, | ||
}); | ||
|
||
await page.waitForChanges(); | ||
const btn = page.doc.querySelector('ix-button'); | ||
expect(btn.className).toContain('disabled'); | ||
}); | ||
|
||
it('should submit form if type is submit', async () => { | ||
const page = await newSpecPage({ | ||
components: [Button], | ||
html: ` | ||
<form> | ||
<input name="some_input" /> | ||
<ix-button type="submit">Example</ix-button> | ||
</form> | ||
`, | ||
}); | ||
|
||
await page.waitForChanges(); | ||
const submitButton = page.doc | ||
.querySelector('ix-button') | ||
.shadowRoot.querySelector('button'); | ||
const form = page.doc.querySelector('form'); | ||
|
||
const onSubmit = jest.fn(); | ||
|
||
form.addEventListener('submit', onSubmit); | ||
|
||
fireEvent.click(submitButton); | ||
|
||
expect(onSubmit).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters