Add Cypress tests for contact form functionality#71
Conversation
This test suite verifies the functionality of the contact form, including creating a contact and sending an email upon submission.
Reviewer's GuideAdds Cypress end-to-end coverage for the Joomla contact form, including contact creation and email delivery (with and without the CustomReply plugin), and wires the CustomReply plugin into the user factory for testability while ensuring email-related tests clear the mail state first. Sequence diagram for CustomReply plugin wiring with UserFactorysequenceDiagram
participant Container
participant CustomReplyProvider
participant CustomReply
Container->>CustomReplyProvider: get PluginInterface
CustomReplyProvider->>CustomReply: __construct subject config
CustomReplyProvider->>CustomReply: setApplication
CustomReplyProvider->>Container: get DatabaseDriver
CustomReplyProvider->>CustomReply: setDatabase
CustomReplyProvider->>Container: get UserFactoryInterface
CustomReplyProvider->>CustomReply: setUserFactory
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Removed email clearing task before visiting login page.
There was a problem hiding this comment.
Hey - I've found 3 issues, and left some high level feedback:
- The two email submission tests duplicate the same sequence of visiting the contact page and filling/submitting the form; consider extracting a shared helper (e.g.
submitContactForm({ name, email, subject, message })) to make the tests shorter and easier to maintain. - The test that enables the
plg_contact_customreplyplugin and updatescustom_replydoes not reset these settings afterward, which could leak state into other tests; consider reverting these configuration changes in anafterEachor using a dedicated DB reset step for extension settings.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The two email submission tests duplicate the same sequence of visiting the contact page and filling/submitting the form; consider extracting a shared helper (e.g. `submitContactForm({ name, email, subject, message })`) to make the tests shorter and easier to maintain.
- The test that enables the `plg_contact_customreply` plugin and updates `custom_reply` does not reset these settings afterward, which could leak state into other tests; consider reverting these configuration changes in an `afterEach` or using a dedicated DB reset step for extension settings.
## Individual Comments
### Comment 1
<location path="tests/cypress/integration/plugins/ContactCustomReply.cy.js" line_range="26-31" />
<code_context>
+ });
+ });
+
+ 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) => {
+ expect(mails.length).to.be.greaterThan(0);
+ cy.wrap(mails[0].body).should('contain', 'Test message content');
</code_context>
<issue_to_address>
**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 `Test Subject`. These checks will better guard against regressions in email routing or templating.
```suggestion
cy.get('button.btn.btn-primary.validate[type="submit"]').click();
cy.task('getMails').then((mails) => {
expect(mails).to.have.length(1);
const mail = mails[0];
if (contact.email_to) {
expect(mail.to).to.contain(contact.email_to);
}
expect(mail.subject).to.contain('Test Subject');
expect(mail.body).to.contain('Test message content');
});
```
</issue_to_address>
### Comment 2
<location path="tests/cypress/integration/plugins/ContactCustomReply.cy.js" line_range="35-28" />
<code_context>
+ });
+ });
+
+ 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');
</code_context>
<issue_to_address>
**issue (testing):** Differentiate the custom reply test from the non-custom case by asserting plugin-specific behavior.
This mostly duplicates the `can send an email on contact form submission` test, just with the plugin enabled. To validate the custom reply behavior, please add at least one assertion that’s specific to the plugin, such as:
- Expecting an extra email (e.g., admin + auto-reply).
- Verifying one email is sent to `testuser@example.com`.
- Checking for text or a marker introduced by the custom reply plugin.
Otherwise, the test can still pass even if the custom reply logic is broken, as long as the base contact email works.
</issue_to_address>
### Comment 3
<location path="tests/cypress/integration/plugins/ContactCustomReply.cy.js" line_range="25-26" />
<code_context>
+ 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) => {
</code_context>
<issue_to_address>
**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:
```javascript
cy.get('#jform_contact_message').type('Test message content');
cy.get('button.btn.btn-primary.validate[type="submit"]').click();
// Assert on the UI success state to verify the user-facing flow
cy.contains('Thank you for your message').should('be.visible');
cy.task('getMails').then((mails) => {
```
1. If the actual success message text in your Joomla setup differs from `'Thank you for your message'`, update the string in `cy.contains(...)` to match the real UI copy.
2. Alternatively, if there's a stable success-alert selector (e.g. `.alert-success`), you can tighten the assertion to something like:
`cy.get('.alert-success').should('contain', 'Thank you for your message');`
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| 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.
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 Test Subject. These checks will better guard against regressions in email routing or templating.
| 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'); | |
| }); | |
| cy.get('button.btn.btn-primary.validate[type="submit"]').click(); | |
| cy.task('getMails').then((mails) => { | |
| expect(mails).to.have.length(1); | |
| const mail = mails[0]; | |
| if (contact.email_to) { | |
| expect(mail.to).to.contain(contact.email_to); | |
| } | |
| expect(mail.subject).to.contain('Test Subject'); | |
| expect(mail.body).to.contain('Test message content'); | |
| }); |
| cy.get('#jform_contact_message').type('Test message content'); | ||
| cy.get('button.btn.btn-primary.validate[type="submit"]').click(); | ||
|
|
||
| cy.task('getMails').then((mails) => { |
There was a problem hiding this comment.
issue (testing): Differentiate the custom reply test from the non-custom case by asserting plugin-specific behavior.
This mostly duplicates the can send an email on contact form submission test, just with the plugin enabled. To validate the custom reply behavior, please add at least one assertion that’s specific to the plugin, such as:
- Expecting an extra email (e.g., admin + auto-reply).
- Verifying one email is sent to
testuser@example.com. - Checking for text or a marker introduced by the custom reply plugin.
Otherwise, the test can still pass even if the custom reply logic is broken, as long as the base contact email works.
| cy.get('#jform_contact_message').type('Test message content'); | ||
| cy.get('button.btn.btn-primary.validate[type="submit"]').click(); |
There was a problem hiding this comment.
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:
cy.get('#jform_contact_message').type('Test message content');
cy.get('button.btn.btn-primary.validate[type="submit"]').click();
// Assert on the UI success state to verify the user-facing flow
cy.contains('Thank you for your message').should('be.visible');
cy.task('getMails').then((mails) => {- If the actual success message text in your Joomla setup differs from
'Thank you for your message', update the string incy.contains(...)to match the real UI copy. - Alternatively, if there's a stable success-alert selector (e.g.
.alert-success), you can tighten the assertion to something like:
cy.get('.alert-success').should('contain', 'Thank you for your message');
This test suite verifies the functionality of the contact form, including creating a contact and sending an email upon submission.
Summary by Sourcery
Add frontend contact form Cypress coverage and wire the contact custom reply plugin to the user factory for email handling.
New Features:
Enhancements:
Tests: