mirror of https://github.com/grafana/grafana
Chore: add some basic validation tests for our eslint rules (#75284)
* add some basic validation tests for our eslint rules * add 1 more valid casepull/75381/head
parent
c70623fb85
commit
06d89e1929
@ -0,0 +1,47 @@ |
||||
import { RuleTester } from 'eslint'; |
||||
|
||||
import noAriaLabelE2ESelector from '../rules/no-aria-label-e2e-selectors.cjs'; |
||||
|
||||
RuleTester.setDefaultConfig({ |
||||
parserOptions: { |
||||
ecmaVersion: 2018, |
||||
sourceType: 'module', |
||||
ecmaFeatures: { |
||||
jsx: true, |
||||
}, |
||||
}, |
||||
}); |
||||
|
||||
const ruleTester = new RuleTester(); |
||||
|
||||
ruleTester.run('eslint no-aria-label-e2e-selector', noAriaLabelE2ESelector, { |
||||
valid: [ |
||||
{ |
||||
code: `<div aria-label="foo" />`, |
||||
}, |
||||
{ |
||||
code: `<div aria-label={"foo"} />`, |
||||
}, |
||||
{ |
||||
code: ` |
||||
import { someOtherImport } from './some-other-location'; |
||||
|
||||
<div aria-label={someOtherImport} /> |
||||
`,
|
||||
}, |
||||
], |
||||
invalid: [ |
||||
{ |
||||
code: ` |
||||
import { selectors } from '@grafana/e2e-selectors'; |
||||
|
||||
<div aria-label={selectors.pages.AddDashboard.addNewPanel} /> |
||||
`,
|
||||
errors: [ |
||||
{ |
||||
message: 'Use data-testid for E2E selectors instead of aria-label', |
||||
}, |
||||
], |
||||
}, |
||||
], |
||||
}); |
@ -0,0 +1,56 @@ |
||||
import { RuleTester } from 'eslint'; |
||||
|
||||
import noBorderRadiusLiteral from '../rules/no-border-radius-literal.cjs'; |
||||
|
||||
RuleTester.setDefaultConfig({ |
||||
parserOptions: { |
||||
ecmaVersion: 2018, |
||||
sourceType: 'module', |
||||
ecmaFeatures: { |
||||
jsx: true, |
||||
}, |
||||
}, |
||||
}); |
||||
|
||||
const ruleTester = new RuleTester(); |
||||
|
||||
ruleTester.run('eslint no-border-radius-literal', noBorderRadiusLiteral, { |
||||
valid: [ |
||||
{ |
||||
code: `css({ borderRadius: theme.shape.radius.default })`, |
||||
}, |
||||
{ |
||||
code: `css({ borderRadius: theme.shape.radius.circle })`, |
||||
}, |
||||
{ |
||||
code: `css({ borderRadius: theme.shape.radius.pill })`, |
||||
}, |
||||
], |
||||
|
||||
invalid: [ |
||||
{ |
||||
code: `css({ borderRadius: '2px' })`, |
||||
errors: [ |
||||
{ |
||||
message: 'Prefer using theme.shape.radius tokens instead of literal values.', |
||||
}, |
||||
], |
||||
}, |
||||
{ |
||||
code: `css({ lineHeight: 1 }, { borderRadius: '2px' })`, |
||||
errors: [ |
||||
{ |
||||
message: 'Prefer using theme.shape.radius tokens instead of literal values.', |
||||
}, |
||||
], |
||||
}, |
||||
{ |
||||
code: `css([{ lineHeight: 1 }, { borderRadius: '2px' }])`, |
||||
errors: [ |
||||
{ |
||||
message: 'Prefer using theme.shape.radius tokens instead of literal values.', |
||||
}, |
||||
], |
||||
}, |
||||
], |
||||
}); |
Loading…
Reference in new issue