Skip to content

Commit c376d09

Browse files
committed
test: add tests
1 parent 2f815ba commit c376d09

File tree

4 files changed

+429
-0
lines changed

4 files changed

+429
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const { ruleTester } = require('../_helper')
2+
const rule = require('../../lib/rules/headline-image-missing-alt')
3+
const { TEST_BLOCK_FILE } = require('../../lib/helpers/is-block-file')
4+
5+
ruleTester.run('headline-image-missing-alt', rule, {
6+
valid: [
7+
{
8+
code: `
9+
<template>
10+
<img src="foo" />
11+
</template>
12+
`,
13+
filename: 'test.vue',
14+
},
15+
{
16+
code: `
17+
<template>
18+
<img :src="article.headline" />
19+
</template>
20+
`,
21+
filename: 'test.vue',
22+
},
23+
{
24+
code: `
25+
<template>
26+
<img :src="article.headline" :alt="article.headlineAlt" />
27+
</template>
28+
`,
29+
filename: TEST_BLOCK_FILE,
30+
},
31+
],
32+
invalid: [
33+
{
34+
code: `
35+
<template>
36+
<img :src="article.headline" />
37+
</template>
38+
`,
39+
output: `
40+
<template>
41+
<img :alt="article.headlineAlt" :src="article.headline" />
42+
</template>
43+
`,
44+
filename: TEST_BLOCK_FILE,
45+
errors: [
46+
{
47+
messageId: 'missingAlt',
48+
},
49+
],
50+
},
51+
{
52+
code: `
53+
<template>
54+
<img :src="article.headline" alt="article.headlineAlt" />
55+
</template>
56+
`,
57+
output: `
58+
<template>
59+
<img :src="article.headline" :alt="article.headlineAlt" />
60+
</template>
61+
`,
62+
filename: TEST_BLOCK_FILE,
63+
errors: [
64+
{
65+
messageId: 'foundLiteralAlt',
66+
},
67+
],
68+
},
69+
],
70+
})
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const { ruleTester } = require('../_helper')
2+
const rule = require('../../lib/rules/link-element-no-literal-href')
3+
4+
ruleTester.run('no-block-type', rule, {
5+
valid: [
6+
{
7+
code: `
8+
<template>
9+
<LinkElement :href="foo" />
10+
</template>
11+
`,
12+
filename: 'test.vue',
13+
},
14+
{
15+
code: `
16+
<template>
17+
<LinkElement />
18+
</template>
19+
`,
20+
filename: 'test.vue',
21+
},
22+
{
23+
code: `
24+
<template>
25+
<LinkElement href="/" />
26+
</template>
27+
`,
28+
filename: 'test.vue',
29+
},
30+
],
31+
invalid: [
32+
{
33+
code: `
34+
<template>
35+
<LinkElement href="foo" />
36+
</template>
37+
`,
38+
filename: 'test.vue',
39+
errors: [{ messageId: 'literalHref' }],
40+
},
41+
{
42+
code: `
43+
<template>
44+
<LinkElement href="https://example.com" />
45+
</template>
46+
`,
47+
filename: 'test.vue',
48+
errors: [{ messageId: 'literalHref' }],
49+
},
50+
],
51+
})
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
const { ruleTester } = require('../_helper')
2+
const rule = require('../../lib/rules/no-preview-text-with-slot')
3+
4+
ruleTester.run('no-preview-text-with-slot', rule, {
5+
valid: [
6+
{
7+
code: `
8+
<template>
9+
<Content>
10+
<Paragraph />
11+
</Content>
12+
</template>
13+
`,
14+
filename: 'test.vue',
15+
},
16+
{
17+
code: `
18+
<template>
19+
<Content>
20+
<Paragraph></Paragraph>
21+
<Paragraph />
22+
</Content>
23+
</template>
24+
`,
25+
filename: 'test.vue',
26+
},
27+
{
28+
code: `
29+
<template>
30+
<Content>
31+
<Paragraph></Paragraph>
32+
<Header1 underline />
33+
<Header2 />
34+
<Blockquote></Blockquote>
35+
</Content>
36+
</template>
37+
`,
38+
filename: 'test.vue',
39+
},
40+
],
41+
invalid: [
42+
{
43+
code: `
44+
<template>
45+
<Content>
46+
<Paragraph>foo</Paragraph>
47+
</Content>
48+
</template>
49+
`,
50+
output: `
51+
<template>
52+
<Content>
53+
<Paragraph/>
54+
</Content>
55+
</template>
56+
`,
57+
filename: 'test.vue',
58+
errors: [{ messageId: 'passingWithSlot' }],
59+
},
60+
{
61+
code: `
62+
<template>
63+
<Content>
64+
<Paragraph>foo</Paragraph>
65+
<Paragraph>bar</Paragraph>
66+
</Content>
67+
</template>
68+
`,
69+
output: `
70+
<template>
71+
<Content>
72+
<Paragraph/>
73+
<Paragraph/>
74+
</Content>
75+
</template>
76+
`,
77+
filename: 'test.vue',
78+
errors: [{ messageId: 'passingWithSlot' }, { messageId: 'passingWithSlot' }],
79+
},
80+
{
81+
code: `
82+
<template>
83+
<Content>
84+
<Paragraph>foo</Paragraph>
85+
<Header1>header1</Header1>
86+
<Paragraph>bar</Paragraph>
87+
<Header2>header1</Header2>
88+
<Paragraph>baz</Paragraph>
89+
<Blockquote>blockquote</Blockquote>
90+
</Content>
91+
</template>
92+
`,
93+
output: `
94+
<template>
95+
<Content>
96+
<Paragraph/>
97+
<Header1/>
98+
<Paragraph/>
99+
<Header2/>
100+
<Paragraph/>
101+
<Blockquote/>
102+
</Content>
103+
</template>
104+
`,
105+
filename: 'test.vue',
106+
errors: [
107+
{ messageId: 'passingWithSlot' },
108+
{ messageId: 'passingWithSlot' },
109+
{ messageId: 'passingWithSlot' },
110+
{ messageId: 'passingWithSlot' },
111+
{ messageId: 'passingWithSlot' },
112+
{ messageId: 'passingWithSlot' },
113+
],
114+
},
115+
{
116+
code: `
117+
<template>
118+
<Content>
119+
<Paragraph>foo</Paragraph>
120+
<Header1 :fontSize="36">header1</Header1>
121+
<Paragraph>bar</Paragraph>
122+
<Header2 :fontSize="28">header1</Header2>
123+
<Paragraph>baz</Paragraph>
124+
<Blockquote>blockquote</Blockquote>
125+
</Content>
126+
</template>
127+
`,
128+
output: `
129+
<template>
130+
<Content>
131+
<Paragraph/>
132+
<Header1 :fontSize="36"/>
133+
<Paragraph/>
134+
<Header2 :fontSize="28"/>
135+
<Paragraph/>
136+
<Blockquote/>
137+
</Content>
138+
</template>
139+
`,
140+
filename: 'test.vue',
141+
errors: [
142+
{ messageId: 'passingWithSlot' },
143+
{ messageId: 'passingWithSlot' },
144+
{ messageId: 'passingWithSlot' },
145+
{ messageId: 'passingWithSlot' },
146+
{ messageId: 'passingWithSlot' },
147+
{ messageId: 'passingWithSlot' },
148+
],
149+
},
150+
],
151+
})

0 commit comments

Comments
 (0)