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