|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const rule = require('../../../lib/rules/prefer-button-component'); |
| 4 | +const RuleTester = require('eslint').RuleTester; |
| 5 | + |
| 6 | +const parserOptions = { |
| 7 | + ecmaVersion: 2018, |
| 8 | + // sourceType: 'module', |
| 9 | + ecmaFeatures: { |
| 10 | + jsx: true, |
| 11 | + }, |
| 12 | +}; |
| 13 | + |
| 14 | +const ruleTester = new RuleTester({ parserOptions }); |
| 15 | + |
| 16 | +ruleTester.run('prefer-button-component', rule, { |
| 17 | + valid: [ |
| 18 | + { |
| 19 | + code: ` |
| 20 | + const button = () => (<va-button |
| 21 | + id="cancel" |
| 22 | + onClick={handlers.onCancel} |
| 23 | + text="Cancel" |
| 24 | + />) |
| 25 | + `, |
| 26 | + } |
| 27 | + ], |
| 28 | + invalid: [ |
| 29 | + { |
| 30 | + code: ` |
| 31 | + const button = () => ( |
| 32 | + <button |
| 33 | + className="foo" |
| 34 | + id="bar" |
| 35 | + onClick={() => window.print()} |
| 36 | + > |
| 37 | + Print this page |
| 38 | + </button> |
| 39 | + ) |
| 40 | + `, |
| 41 | + errors: [ |
| 42 | + { |
| 43 | + message: |
| 44 | + 'The <va-button> Web Component should be used instead of the button HTML element.' |
| 45 | + }, |
| 46 | + ], |
| 47 | + }, |
| 48 | + { |
| 49 | + code: ` |
| 50 | + const button = () => (<button |
| 51 | + onClick={() => window.print()} |
| 52 | + > |
| 53 | + {variable} |
| 54 | + </button>) |
| 55 | + `, |
| 56 | + errors: [ |
| 57 | + { |
| 58 | + message: |
| 59 | + 'The <va-button> Web Component should be used instead of the button HTML element.' |
| 60 | + }, |
| 61 | + ], |
| 62 | + }, |
| 63 | + { |
| 64 | + code: ` |
| 65 | + const button = () => (<button |
| 66 | + onClick={() => window.print()} |
| 67 | + > |
| 68 | + Some plain text next to a {variable} |
| 69 | + </button>) |
| 70 | + `, |
| 71 | + errors: [ |
| 72 | + { |
| 73 | + message: |
| 74 | + 'The <va-button> Web Component should be used instead of the button HTML element.' |
| 75 | + }, |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + code: ` |
| 80 | + const button = () => (<button |
| 81 | + onClick={() => window.print()} |
| 82 | + > |
| 83 | + <span>Button Text</span> |
| 84 | + </button>) |
| 85 | + `, |
| 86 | + errors: [ |
| 87 | + { |
| 88 | + message: |
| 89 | + 'The <va-button> Web Component should be used instead of the button HTML element.' |
| 90 | + }, |
| 91 | + ], |
| 92 | + }, |
| 93 | + { |
| 94 | + code: ` |
| 95 | + const button = () => ( |
| 96 | + <input type="button">Click me</input> |
| 97 | + ) |
| 98 | + `, |
| 99 | + errors: [ |
| 100 | + { |
| 101 | + message: |
| 102 | + 'The <va-button> Web Component should be used instead of the button HTML element.' |
| 103 | + }, |
| 104 | + ], |
| 105 | + }, |
| 106 | + { |
| 107 | + code: ` |
| 108 | + const button = () => ( |
| 109 | + <input type="button" value="Click me" /> |
| 110 | + ) |
| 111 | + `, |
| 112 | + errors: [ |
| 113 | + { |
| 114 | + message: |
| 115 | + 'The <va-button> Web Component should be used instead of the button HTML element.' |
| 116 | + }, |
| 117 | + ], |
| 118 | + }, |
| 119 | + ], |
| 120 | +}); |
0 commit comments