1

Add missing DOM ids to rails/mailers/email.html template by nfedyashev · Pull Re...

 2 years ago
source link: https://github.com/rails/rails/pull/42470
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Summary

Instead of using Capybara/Selenium my team uses Cypress for all end to end tests. We have a test that checks that all Mailer Preview actions of all mailers could be opened and rendered without an error. This helped us to catch bugs earlier because there are lots of mailer and mailer actions.

The issue that we faced was that important most of the dd elements like(to, from, subject etc) were really hard to get to in DOM because they didn't have a unique selector. This PR fixes it.

Below is what our Cypress test look like:

context('Mailer Preview', () => {
  it('works for all mailer actions', () => {
    cy.visit('/rails/mailers')

    cy.get('li a').each($a => {
      const href = $a.attr('href');
      cy.log(href)
      cy.visit(href)

      cy.get('#from').then($dd => {
        cy.log('FROM :' + $dd.get(0).innerText)
        //expect($dd.get(0).innerText).to.eq('[email protected]')
      })

      cy.get('#to').then($dd => {
        cy.log('TO: ' + $dd.get(0).innerText)
        //expect($dd.get(0).innerText).to.eq('[email protected]')
      })

      cy.get('#subject').then($dd => {
        cy.log('SUBJECT: ' + $dd.get(0).innerText)
        //expect($dd.get(0).innerText).to.eq('Test subject')
      })

      cy.get('#mime_type').then($dd => {
        cy.log('MIME TYPE: ' + $dd.get(0).innerText)
        //expect($dd.get(0).innerText).to.eq('HTML email')
      })

      cy.get('[download="icon.png"]').should('exist')
    })
  })
})

Other Information

Attachment elements weren't updated because they already have download attribute with a file name.
I've used markup validator from https://validator.w3.org/ and it didn't find any errors or warnings related to this update.

Below is a screenshot of a very simplified test run in Cypress:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK