-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add validate method, add test. Resolve #129
- Loading branch information
Showing
3 changed files
with
69 additions
and
1 deletion.
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
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 Form from "../../../src/classes/Form"; | ||
|
||
describe("Form validate", () => { | ||
|
||
test("Should return true if not validate functions was provided.", () => { | ||
const form = new Form(); | ||
expect(form.validate()).toBe(true) | ||
}) | ||
test("Should return false in first execute if child validate function return false", () => { | ||
const form = new Form(); | ||
const child = { | ||
name: "address", | ||
count: -1, | ||
validate() { | ||
return this.count++ >= 0 | ||
} | ||
} | ||
form.subscribe(child); | ||
expect(form.validate()).toBe(false); | ||
expect(form.validate()).toBe(true); | ||
}) | ||
test("Should be true if all children return true", () => { | ||
const form = new Form(); | ||
for(let i = 0; i < 10; i++) { | ||
form.subscribe({ | ||
name: `dep-${i}`, | ||
validate() { | ||
return true | ||
} | ||
}) | ||
} | ||
expect(form.validate()).toBe(true) | ||
}) | ||
test("Child form with children validation items", () => { | ||
const form = new Form(); | ||
const child = new Form({ | ||
name: "address" | ||
}) | ||
form.subscribe(child) | ||
child.subscribe({ | ||
name: "city", | ||
index: 0, | ||
validate() { | ||
console.log(this.index > 0) | ||
|
||
return this.index++ > 0 | ||
} | ||
}) | ||
|
||
expect(form.validate()).toBe(false) | ||
expect(form.validate()).toBe(true) | ||
}) | ||
|
||
}) |