Skip to content

Commit

Permalink
Use snapshot testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao committed Jan 6, 2022
1 parent b859cd5 commit a9928e7
Showing 1 changed file with 128 additions and 50 deletions.
178 changes: 128 additions & 50 deletions test/unit/rules/no-action-on-submit-button-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import generateRuleTests from '../../helpers/rule-test-harness.js';

const ERROR_MESSAGE = 'A `<button>` with `type="submit"` should have no click action';

generateRuleTests({
name: 'no-action-on-submit-button',

Expand Down Expand Up @@ -33,82 +31,162 @@ generateRuleTests({
bad: [
{
template: '<button {{action this.handleClick}} />',

result: {
message: ERROR_MESSAGE,
source: '<button {{action this.handleClick}} />',
line: 1,
column: 0,
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
Array [
Object {
"column": 0,
"endColumn": 38,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "A \`<button>\` with \`type=\\"submit\\"\` should have no click action",
"rule": "no-action-on-submit-button",
"severity": 2,
"source": "<button {{action this.handleClick}} />",
},
]
`);
},
},
{
template: '<button {{action this.handleClick on="click"}}/>',

result: {
message: ERROR_MESSAGE,
source: '<button {{action this.handleClick on="click"}}/>',
line: 1,
column: 0,
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
Array [
Object {
"column": 0,
"endColumn": 48,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "A \`<button>\` with \`type=\\"submit\\"\` should have no click action",
"rule": "no-action-on-submit-button",
"severity": 2,
"source": "<button {{action this.handleClick on=\\"click\\"}}/>",
},
]
`);
},
},
{
template: '<button {{on "click" this.handleClick}} />',

result: {
message: ERROR_MESSAGE,
source: '<button {{on "click" this.handleClick}} />',
line: 1,
column: 0,
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
Array [
Object {
"column": 0,
"endColumn": 42,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "A \`<button>\` with \`type=\\"submit\\"\` should have no click action",
"rule": "no-action-on-submit-button",
"severity": 2,
"source": "<button {{on \\"click\\" this.handleClick}} />",
},
]
`);
},
},
{
template: '<button type="submit" {{action this.handleClick}} />',

result: {
message: ERROR_MESSAGE,
source: '<button type="submit" {{action this.handleClick}} />',
line: 1,
column: 0,
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
Array [
Object {
"column": 0,
"endColumn": 52,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "A \`<button>\` with \`type=\\"submit\\"\` should have no click action",
"rule": "no-action-on-submit-button",
"severity": 2,
"source": "<button type=\\"submit\\" {{action this.handleClick}} />",
},
]
`);
},
},
{
template: '<button type="submit" {{action this.handleClick on="click"}} />',

result: {
message: ERROR_MESSAGE,
source: '<button type="submit" {{action this.handleClick on="click"}} />',
line: 1,
column: 0,
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
Array [
Object {
"column": 0,
"endColumn": 63,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "A \`<button>\` with \`type=\\"submit\\"\` should have no click action",
"rule": "no-action-on-submit-button",
"severity": 2,
"source": "<button type=\\"submit\\" {{action this.handleClick on=\\"click\\"}} />",
},
]
`);
},
},
{
template: '<button type="submit" {{action (fn this.someAction "foo")}} />',

result: {
message: ERROR_MESSAGE,
source: '<button type="submit" {{action (fn this.someAction "foo")}} />',
line: 1,
column: 0,
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
Array [
Object {
"column": 0,
"endColumn": 62,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "A \`<button>\` with \`type=\\"submit\\"\` should have no click action",
"rule": "no-action-on-submit-button",
"severity": 2,
"source": "<button type=\\"submit\\" {{action (fn this.someAction \\"foo\\")}} />",
},
]
`);
},
},
{
template: '<button type="submit" {{on "click" this.handleClick}} />',

result: {
message: ERROR_MESSAGE,
source: '<button type="submit" {{on "click" this.handleClick}} />',
line: 1,
column: 0,
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
Array [
Object {
"column": 0,
"endColumn": 56,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "A \`<button>\` with \`type=\\"submit\\"\` should have no click action",
"rule": "no-action-on-submit-button",
"severity": 2,
"source": "<button type=\\"submit\\" {{on \\"click\\" this.handleClick}} />",
},
]
`);
},
},
{
template: '<button type="submit" {{on "click" (fn this.addNumber 123)}} />',

result: {
message: ERROR_MESSAGE,
source: '<button type="submit" {{on "click" (fn this.addNumber 123)}} />',
line: 1,
column: 0,
verifyResults(results) {
expect(results).toMatchInlineSnapshot(`
Array [
Object {
"column": 0,
"endColumn": 63,
"endLine": 1,
"filePath": "layout.hbs",
"line": 1,
"message": "A \`<button>\` with \`type=\\"submit\\"\` should have no click action",
"rule": "no-action-on-submit-button",
"severity": 2,
"source": "<button type=\\"submit\\" {{on \\"click\\" (fn this.addNumber 123)}} />",
},
]
`);
},
},
],
Expand Down

0 comments on commit a9928e7

Please sign in to comment.