-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add form submission and reset behavior to Button (#3603)
* add button submit and reset fix * adding tests * remove debugger statements * remove duplicate proxy attachment code * make methods private Co-authored-by: nicholasrice <nicholasrice@users.noreply.github.com>
- Loading branch information
1 parent
c145e8e
commit f646343
Showing
5 changed files
with
146 additions
and
35 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
54 changes: 54 additions & 0 deletions
54
packages/web-components/fast-foundation/src/button/button.spec.ts
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,54 @@ | ||
import { expect } from "chai"; | ||
import { customElement, html, DOM } from "@microsoft/fast-element"; | ||
import { classNames } from "@microsoft/fast-web-utilities"; | ||
import { Button } from "./button"; | ||
|
||
@customElement({ | ||
name: "test-button", | ||
template: html` | ||
<slot></slot> | ||
`, | ||
}) | ||
class TestElement extends Button {} | ||
|
||
describe("Button", () => { | ||
describe("of type 'submit'", () => { | ||
it("should submit the parent form when clicked", () => { | ||
let wasSumbitted = false; | ||
let event: any; | ||
const form = document.createElement("form"); | ||
const submit = document.createElement("test-button"); | ||
submit.setAttribute("type", "submit"); | ||
form.appendChild(submit); | ||
form.addEventListener("submit", e => { | ||
e.preventDefault(); | ||
wasSumbitted = true; | ||
event = e; | ||
}); | ||
document.body.appendChild(form); | ||
|
||
submit.click(); | ||
|
||
expect(wasSumbitted).to.equal(true); | ||
expect(event.submitter).to.equal(submit["proxy"] as any); | ||
}); | ||
}); | ||
|
||
describe("of type 'reset'", () => { | ||
it("should submit the parent form when clicked", () => { | ||
let wasReset = false; | ||
const form = document.createElement("form"); | ||
const reset = document.createElement("test-button"); | ||
reset.setAttribute("type", "reset"); | ||
form.appendChild(reset); | ||
document.body.appendChild(form); | ||
form.addEventListener("reset", () => { | ||
wasReset = true; | ||
}); | ||
|
||
reset.click(); | ||
|
||
expect(wasReset).to.equal(true); | ||
}); | ||
}); | ||
}); |
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