|
| 1 | +const HTMLHint = require('../../dist/htmlhint.js').HTMLHint |
| 2 | + |
| 3 | +const ruleId = 'form-method-require' |
| 4 | +const ruleOptions = {} |
| 5 | + |
| 6 | +ruleOptions[ruleId] = true |
| 7 | + |
| 8 | +describe(`Rules: ${ruleId}`, () => { |
| 9 | + it('Form with method="get" should not result in an error', () => { |
| 10 | + const code = '<form method="get"></form>' |
| 11 | + const messages = HTMLHint.verify(code, ruleOptions) |
| 12 | + expect(messages.length).toBe(0) |
| 13 | + }) |
| 14 | + |
| 15 | + it('Form with method="post" should not result in an error', () => { |
| 16 | + const code = '<form method="post"></form>' |
| 17 | + const messages = HTMLHint.verify(code, ruleOptions) |
| 18 | + expect(messages.length).toBe(0) |
| 19 | + }) |
| 20 | + |
| 21 | + it('Form with method="dialog" should not result in an error', () => { |
| 22 | + const code = '<form method="dialog"></form>' |
| 23 | + const messages = HTMLHint.verify(code, ruleOptions) |
| 24 | + expect(messages.length).toBe(0) |
| 25 | + }) |
| 26 | + |
| 27 | + it('Form without method attribute should result in an error', () => { |
| 28 | + const code = '<form></form>' |
| 29 | + const messages = HTMLHint.verify(code, ruleOptions) |
| 30 | + expect(messages.length).toBe(1) |
| 31 | + expect(messages[0].rule.id).toBe(ruleId) |
| 32 | + expect(messages[0].line).toBe(1) |
| 33 | + expect(messages[0].col).toBe(6) |
| 34 | + expect(messages[0].type).toBe('warning') |
| 35 | + expect(messages[0].message).toBe( |
| 36 | + 'The method attribute must be present on <form> elements.' |
| 37 | + ) |
| 38 | + }) |
| 39 | + |
| 40 | + it('Form with invalid method value should result in an error', () => { |
| 41 | + const code = '<form method="invalid"></form>' |
| 42 | + const messages = HTMLHint.verify(code, ruleOptions) |
| 43 | + expect(messages.length).toBe(1) |
| 44 | + expect(messages[0].rule.id).toBe(ruleId) |
| 45 | + expect(messages[0].line).toBe(1) |
| 46 | + expect(messages[0].col).toBe(6) |
| 47 | + expect(messages[0].type).toBe('warning') |
| 48 | + expect(messages[0].message).toBe( |
| 49 | + 'The method attribute of <form> must have a valid value: "get", "post", or "dialog".' |
| 50 | + ) |
| 51 | + }) |
| 52 | + |
| 53 | + it('Form with uppercase method value should not result in an error', () => { |
| 54 | + const code = '<form method="POST"></form>' |
| 55 | + const messages = HTMLHint.verify(code, ruleOptions) |
| 56 | + expect(messages.length).toBe(0) |
| 57 | + }) |
| 58 | + |
| 59 | + it('Other elements should not be affected by this rule', () => { |
| 60 | + const code = '<div>Not a form</div><input type="text">' |
| 61 | + const messages = HTMLHint.verify(code, ruleOptions) |
| 62 | + expect(messages.length).toBe(0) |
| 63 | + }) |
| 64 | +}) |
0 commit comments