|
| 1 | +import { ERROR_BORDER_COLOR } from '../support/constants' |
| 2 | + |
| 3 | +describe('<button>', () => { |
| 4 | + before(() => { |
| 5 | + cy.visit('/test/index.html') |
| 6 | + }) |
| 7 | + beforeEach(() => { |
| 8 | + cy.visit('/test/index.html') |
| 9 | + }) |
| 10 | + |
| 11 | + it('should not have buttons with interactive content inside', () => { |
| 12 | + cy.visit('/test/index.html') |
| 13 | + |
| 14 | + const noneElements = ['audio[controls]', 'embed', 'iframe', 'img[usemap]', 'input:not([type="hidden"])', 'object[usemap]', 'select', 'textarea', 'video[controls]'] |
| 15 | + // removed "button" from afterElements because browser was correcting the issue |
| 16 | + const afterElements = ['details', 'label'] |
| 17 | + const beforeElements = [] |
| 18 | + |
| 19 | + noneElements.forEach((el) => { |
| 20 | + cy.get(`button ${el}`).each((element) => { |
| 21 | + cy.get(element).should('have.css', 'border-color', 'rgb(255, 0, 0)') |
| 22 | + }) |
| 23 | + }) |
| 24 | + |
| 25 | + afterElements.forEach((el) => { |
| 26 | + cy.get(`button ${el}`).each((element) => { |
| 27 | + if (element) { |
| 28 | + cy.get(element).after('content').should('eq', `ERROR (E0000): Ensure that <${el}> is not a child of <button>.`) |
| 29 | + } |
| 30 | + }) |
| 31 | + }) |
| 32 | + |
| 33 | + beforeElements.forEach((el) => { |
| 34 | + cy.get(`button ${el}`).each((element) => { |
| 35 | + if (element) { |
| 36 | + cy.get(element).before('content').should('eq', `ERROR: Ensure that <${el}> is not a child of <button> as it is an invalid HTML.`) |
| 37 | + } |
| 38 | + }) |
| 39 | + }) |
| 40 | + }) |
| 41 | + |
| 42 | + it('should not have empty buttons', () => { |
| 43 | + cy.visit('/test/index.html') |
| 44 | + |
| 45 | + cy.get('button:not( [aria-label] ):not( [aria-labelledby] ):empty').each((element) => { |
| 46 | + cy.get(element).after('content').should('eq', 'ERROR (E0001): Ensure that <button> has meaningful content or is labelled appropriately.') |
| 47 | + }) |
| 48 | + }) |
| 49 | +}) |
0 commit comments