-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better error messages for standalone contact forms
Refs #20
- Loading branch information
Showing
5 changed files
with
196 additions
and
10 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
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 |
---|---|---|
|
@@ -219,6 +219,75 @@ describe('RecrasContactForm', () => { | |
expect(sorted[1]).toEqual(packs[0]); | ||
expect(sorted[2]).toEqual(packs[1]); | ||
}); | ||
}) | ||
}); | ||
|
||
describe('getRequiredFields', () => { | ||
let rc; | ||
|
||
beforeEach(async () => { | ||
rc = new RecrasContactForm(new RecrasOptions({ | ||
element: this.mainEl, | ||
form_id: 1, | ||
recras_hostname: 'demo.recras.nl', | ||
})); | ||
await rc.showForm(); | ||
}); | ||
|
||
it('only returns required fields', () => { | ||
const els = rc.getRequiredFields(); | ||
expect(els.length).toBeGreaterThan(0); | ||
for (const el of els) { | ||
expect(el.getAttribute('required')).not.toBeNull(); | ||
} | ||
}); | ||
}); | ||
|
||
describe('getInvalidFields', () => { | ||
let rc; | ||
|
||
beforeEach(async () => { | ||
rc = new RecrasContactForm(new RecrasOptions({ | ||
element: this.mainEl, | ||
form_id: 1, | ||
recras_hostname: 'demo.recras.nl', | ||
})); | ||
await rc.showForm(); | ||
}); | ||
|
||
it('returns invalid fields', () => { | ||
let elEmail = rc.findElement('[type="email"]'); | ||
elEmail.value = 'invalid'; | ||
|
||
let invalid = rc.getInvalidFields(); | ||
expect(invalid.length).toBe(1); | ||
expect(invalid[0]).toBe(elEmail); | ||
|
||
elEmail.value = '[email protected]'; | ||
|
||
invalid = rc.getInvalidFields(); | ||
expect(invalid.length).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('isEmpty', () => { | ||
let rc; | ||
|
||
beforeEach(async () => { | ||
rc = new RecrasContactForm(new RecrasOptions({ | ||
element: this.mainEl, | ||
form_id: 5, | ||
recras_hostname: 'demo.recras.nl', | ||
})); | ||
await rc.showForm(); | ||
}); | ||
|
||
it('returns if form is empty', () => { | ||
expect(rc.isEmpty()).toBe(true); | ||
let elEmail = rc.findElement('[type="email"]'); | ||
elEmail.value = '[email protected]'; | ||
|
||
expect(rc.isEmpty()).toBe(false); | ||
}); | ||
}); | ||
}); | ||
}); |