-
-
Notifications
You must be signed in to change notification settings - Fork 2
Add Cypress tests for contact form functionality #71
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
base: main
Are you sure you want to change the base?
Changes from all commits
cf6aa87
5a6e19d
3b3a966
eafa336
0d55285
84f7d60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||||||||||||||||||||||||||||||||||
| describe('Test in frontend that the contact form view', () => { | ||||||||||||||||||||||||||||||||||||||||||
| afterEach(() => cy.task('queryDB', 'DELETE FROM #__contact_details')); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| it('can create a contact through a form', () => { | ||||||||||||||||||||||||||||||||||||||||||
| cy.doFrontendLogin(); | ||||||||||||||||||||||||||||||||||||||||||
| cy.visit('/index.php?option=com_contact&view=form&layout=edit'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('#jform_name').type('test contact 1'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('.mb-2 > .btn-primary').click(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| cy.task('queryDB', 'SELECT catid FROM #__contact_details WHERE name = \'test contact 1\'').then((id) => { | ||||||||||||||||||||||||||||||||||||||||||
| cy.visit(`/index.php?option=com_contact&view=category&id=${id[0].catid}`); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| cy.contains('test contact 1').should('exist'); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| it('can send an email on contact form submission', () => { | ||||||||||||||||||||||||||||||||||||||||||
| cy.task('clearEmails'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.db_getUserId().then((id) => cy.db_createContact({ name: 'test contact', user_id: id })) | ||||||||||||||||||||||||||||||||||||||||||
| .then((contact) => { | ||||||||||||||||||||||||||||||||||||||||||
| cy.visit(`/index.php?option=com_contact&view=contact&id=${contact.id}`); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('#jform_contact_name').type('Test User'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('#jform_contact_email').type('testuser@example.com'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('#jform_contact_emailmsg').type('Test Subject'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('#jform_contact_message').type('Test message content'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('button.btn.btn-primary.validate[type="submit"]').click(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| cy.task('getMails').then((mails) => { | ||||||||||||||||||||||||||||||||||||||||||
|
Contributor
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. issue (testing): Differentiate the custom reply test from the non-custom case by asserting plugin-specific behavior. This mostly duplicates the
|
||||||||||||||||||||||||||||||||||||||||||
| expect(mails.length).to.be.greaterThan(0); | ||||||||||||||||||||||||||||||||||||||||||
| cy.wrap(mails[0].body).should('contain', 'Test message content'); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+26
to
+31
Contributor
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. suggestion (testing): Strengthen assertions on the outgoing email (count, recipient, subject) to better prove the behavior. Right now the test only checks that at least one email is sent and that the first email body contains the message text. Please also assert the exact number of emails, that the recipient matches the configured contact address, and that the subject matches (or includes) the submitted
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| it('can send an email on contact form submission with custom reply enabled', () => { | ||||||||||||||||||||||||||||||||||||||||||
| cy.task('clearEmails'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.db_updateExtensionParameter('custom_reply', '1', 'com_contact'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.db_enableExtension('1', 'plg_contact_customreply'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.db_getUserId().then((id) => cy.db_createContact({ name: 'test contact', user_id: id })) | ||||||||||||||||||||||||||||||||||||||||||
| .then((contact) => { | ||||||||||||||||||||||||||||||||||||||||||
| cy.visit(`/index.php?option=com_contact&view=contact&id=${contact.id}`); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('#jform_contact_name').type('Test User'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('#jform_contact_email').type('testuser@example.com'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('#jform_contact_emailmsg').type('Test Subject'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('#jform_contact_message').type('Test message content'); | ||||||||||||||||||||||||||||||||||||||||||
| cy.get('button.btn.btn-primary.validate[type="submit"]').click(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| cy.task('getMails').then((mails) => { | ||||||||||||||||||||||||||||||||||||||||||
| expect(mails.length).to.be.greaterThan(0); | ||||||||||||||||||||||||||||||||||||||||||
| cy.wrap(mails[0].body).should('contain', 'Test message content'); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
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.
suggestion (testing): Consider asserting on the UI success state after form submission, not only on the email side effect.
These tests only assert on the resulting emails, not on the frontend behavior (success message, lack of validation errors, redirect, etc.). Please add a UI assertion (for example,
cy.contains('Thank you for your message')or a selector-based check) to verify the user-facing flow and better protect against regressions where the email is sent but the UI fails.Suggested implementation:
'Thank you for your message', update the string incy.contains(...)to match the real UI copy..alert-success), you can tighten the assertion to something like:cy.get('.alert-success').should('contain', 'Thank you for your message');