-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(feedback): Option to make name and email required #9587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c682d2b
isNameRequired and isEmailRequired
c298lee 9086e25
lint
c298lee f185df6
comments
c298lee dc524c2
typo
c298lee d64c9e6
empty field validation
c298lee cd5893c
remove returns
c298lee 421e030
remove returns
c298lee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -10,6 +10,8 @@ function renderDialog({ | |
showEmail = true, | ||
showBranding = false, | ||
isAnonymous = false, | ||
isNameRequired = false, | ||
isEmailRequired = false, | ||
formTitle = 'Feedback', | ||
defaultName = 'Foo Bar', | ||
defaultEmail = '[email protected]', | ||
|
@@ -30,6 +32,8 @@ function renderDialog({ | |
isAnonymous, | ||
showName, | ||
showEmail, | ||
isNameRequired, | ||
isEmailRequired, | ||
showBranding, | ||
defaultName, | ||
defaultEmail, | ||
|
This file contains hidden or 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 |
---|---|---|
|
@@ -9,6 +9,8 @@ function renderForm({ | |
showName = true, | ||
showEmail = true, | ||
isAnonymous = false, | ||
isNameRequired = false, | ||
isEmailRequired = false, | ||
defaultName = 'Foo Bar', | ||
defaultEmail = '[email protected]', | ||
nameLabel = 'Name', | ||
|
@@ -25,6 +27,8 @@ function renderForm({ | |
isAnonymous, | ||
showName, | ||
showEmail, | ||
isNameRequired, | ||
isEmailRequired, | ||
defaultName, | ||
defaultEmail, | ||
nameLabel, | ||
|
@@ -80,13 +84,15 @@ describe('Form', () => { | |
emailPlaceholder: '[email protected]!', | ||
messageLabel: 'Description!', | ||
messagePlaceholder: 'What is the issue?!', | ||
isNameRequired: true, | ||
isEmailRequired: true, | ||
}); | ||
|
||
const nameLabel = formComponent.el.querySelector('label[htmlFor="name"]') as HTMLLabelElement; | ||
const emailLabel = formComponent.el.querySelector('label[htmlFor="email"]') as HTMLLabelElement; | ||
const messageLabel = formComponent.el.querySelector('label[htmlFor="message"]') as HTMLLabelElement; | ||
expect(nameLabel.textContent).toBe('Name!'); | ||
expect(emailLabel.textContent).toBe('Email!'); | ||
expect(nameLabel.textContent).toBe('Name! (required)'); | ||
expect(emailLabel.textContent).toBe('Email! (required)'); | ||
expect(messageLabel.textContent).toBe('Description! (required)'); | ||
|
||
const nameInput = formComponent.el.querySelector('[name="name"]') as HTMLInputElement; | ||
|
@@ -98,18 +104,6 @@ describe('Form', () => { | |
expect(messageInput.placeholder).toBe('What is the issue?!'); | ||
}); | ||
|
||
it('submit is enabled if message is not empty', () => { | ||
const formComponent = renderForm(); | ||
|
||
const message = formComponent.el.querySelector('[name="message"]') as HTMLTextAreaElement; | ||
|
||
message.value = 'Foo (message)'; | ||
message.dispatchEvent(new KeyboardEvent('keyup')); | ||
|
||
message.value = ''; | ||
message.dispatchEvent(new KeyboardEvent('keyup')); | ||
}); | ||
|
||
it('can show error', () => { | ||
const formComponent = renderForm(); | ||
const errorEl = formComponent.el.querySelector('.form__error-container') as HTMLDivElement; | ||
|
@@ -148,6 +142,8 @@ describe('Form', () => { | |
it('does not show name or email inputs for anonymous mode', () => { | ||
const onSubmit = jest.fn(); | ||
const formComponent = renderForm({ | ||
isNameRequired: true, | ||
isEmailRequired: true, | ||
isAnonymous: true, | ||
onSubmit, | ||
}); | ||
|
This file contains hidden or 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 |
---|---|---|
|
@@ -171,6 +171,72 @@ describe('createWidget', () => { | |
expect(shadow.querySelector('.success-message')).toBeNull(); | ||
}); | ||
|
||
it('only submits feedback successfully when all required fields are filled', async () => { | ||
const onSubmitSuccess = jest.fn(() => {}); | ||
const { shadow, widget } = createShadowAndWidget({ | ||
isNameRequired: true, | ||
isEmailRequired: true, | ||
onSubmitSuccess, | ||
}); | ||
|
||
(sendFeedbackRequest as jest.Mock).mockImplementation(() => { | ||
return true; | ||
}); | ||
widget.actor?.el?.dispatchEvent(new Event('click')); | ||
|
||
const nameEl = widget.dialog?.el?.querySelector('[name="name"]') as HTMLInputElement; | ||
const emailEl = widget.dialog?.el?.querySelector('[name="email"]') as HTMLInputElement; | ||
const messageEl = widget.dialog?.el?.querySelector('[name="message"]') as HTMLTextAreaElement; | ||
|
||
nameEl.value = ''; | ||
emailEl.value = ''; | ||
messageEl.value = ''; | ||
|
||
widget.dialog?.el?.querySelector('form')?.dispatchEvent(new Event('submit')); | ||
expect(sendFeedbackRequest).toHaveBeenCalledTimes(0); | ||
|
||
// sendFeedbackRequest is async | ||
await flushPromises(); | ||
expect(onSubmitSuccess).toHaveBeenCalledTimes(0); | ||
|
||
nameEl.value = ''; | ||
emailEl.value = ''; | ||
messageEl.value = 'My feedback'; | ||
|
||
widget.dialog?.el?.querySelector('form')?.dispatchEvent(new Event('submit')); | ||
expect(sendFeedbackRequest).toHaveBeenCalledTimes(0); | ||
|
||
// sendFeedbackRequest is async | ||
await flushPromises(); | ||
expect(onSubmitSuccess).toHaveBeenCalledTimes(0); | ||
|
||
nameEl.value = 'Jane Doe'; | ||
emailEl.value = '[email protected]'; | ||
messageEl.value = 'My feedback'; | ||
|
||
widget.dialog?.el?.querySelector('form')?.dispatchEvent(new Event('submit')); | ||
expect(sendFeedbackRequest).toHaveBeenCalledWith({ | ||
feedback: { | ||
name: 'Jane Doe', | ||
email: '[email protected]', | ||
message: 'My feedback', | ||
url: 'http://localhost/', | ||
replay_id: undefined, | ||
source: 'widget', | ||
}, | ||
}); | ||
|
||
// sendFeedbackRequest is async | ||
await flushPromises(); | ||
expect(onSubmitSuccess).toHaveBeenCalledTimes(1); | ||
|
||
expect(widget.dialog).toBeUndefined(); | ||
expect(shadow.querySelector('.success-message')?.textContent).toBe(SUCCESS_MESSAGE_TEXT); | ||
|
||
jest.runAllTimers(); | ||
expect(shadow.querySelector('.success-message')).toBeNull(); | ||
}); | ||
Comment on lines
+174
to
+238
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 🎉 |
||
|
||
it('submits feedback with error on request', async () => { | ||
const onSubmitError = jest.fn(() => {}); | ||
const { shadow, widget } = createShadowAndWidget({ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good catch, I think maybe
> 0
would read slightly more straightforward