forked from JohnPhamous/eslint-plugin-ss-wa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
82 lines (78 loc) · 2.41 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const rules = require("./index");
const RuleTester = require("eslint").RuleTester;
RuleTester.setDefaultConfig({
parserOptions: {
ecmaVersion: 6,
ecmaFeatures: {
jsx: true,
},
},
});
const ruleTester = new RuleTester();
const missingIdError = [{ messageId: "missingId" }];
const typeCheckRule = rules["rules"]["onclick-requires-data-client-id"];
ruleTester.run("type-check", typeCheckRule, {
valid: [
{
code: "<button>Click Me</button>",
},
{
code: "<div>Click Me</div>",
},
{
code:
'<div onClick={() => {onClickHandler()}} data-client-id="123" data-dd-action-name="123">Click Me</div>',
},
{
code:
'<div onClick={onClickHandler} data-client-id="abc" data-dd-action-name="abc">Click Me</div>',
},
{
code:
'<button onClick={onClickHandler} data-client-id="abc" data-dd-action-name="abc">Click Me</button>',
},
{
code: `<Checkbox checkedState={false} onClick={onCheckboxClickHandler} clientId={'id'} data-dd-action-name="id"/>`,
},
{
code: `<Checkbox checkedState={false} onClick={onCheckboxClickHandler} data-client-id={'id'} data-dd-action-name="id"/>`,
},
{
code: `<Checkbox checkedState={false} onClick={onCheckboxClickHandler} data-client-type={'type'} data-dd-action-name="type"/>`,
},
{
code: `<Checkbox checkedState={false} data-client-type={'type'} data-dd-action-name="type"/>`,
},
{
code: `<Checkbox checkedState={false} data-client-id={'type'} data-dd-action-name="type"/>`,
},
{
code: `<Checkbox checkedState={false} clientId={'type'} data-dd-action-name="type"/>`,
},
],
invalid: [
{
code: "<button onClick={clickHandler}>Click Me</button>",
errors: missingIdError,
},
{
code: "<div onClick={clickHandler}>Click Me</div>",
errors: missingIdError,
},
{
code: "<div onClick={() => {clickHandler()}}>Click Me</div>",
errors: missingIdError,
},
{
code:
'<div onClick={() => {clickHandler()}} data-client-id="">Click Me</div>',
errors: missingIdError,
},
{
code:
// eslint-disable-next-line no-template-curly-in-string
"<button className={`${classes.kebabButton} ${className}`} onClick={onClick} aria-label={ariaLabel}><MoreVertIcon classes={{ root: classes.kebabIcon }} /></button>",
errors: missingIdError,
},
],
});