|
1 | 1 | import { assertAnnotated, assertSuccess } from './testHelper'; |
2 | 2 |
|
3 | 3 | describe('directive-class-suffix', () => { |
4 | | - describe('invalid directive class suffix', () => { |
5 | | - it('should fail when directive class is with the wrong suffix', () => { |
6 | | - let source = ` |
| 4 | + describe('invalid directive class suffix', () => { |
| 5 | + it('should fail when directive class is with the wrong suffix', () => { |
| 6 | + let source = ` |
7 | 7 | @Directive({ |
8 | 8 | selector: 'sgBarFoo' |
9 | 9 | }) |
10 | 10 | class Test {} |
11 | 11 | ~~~~ |
12 | 12 | `; |
13 | | - assertAnnotated({ |
14 | | - ruleName: 'directive-class-suffix', |
15 | | - message: 'The name of the class Test should end with the suffix Directive (https://angular.io/styleguide#style-02-03)', |
16 | | - source |
17 | | - }); |
18 | | - }); |
| 13 | + assertAnnotated({ |
| 14 | + ruleName: 'directive-class-suffix', |
| 15 | + message: 'The name of the class Test should end with the suffix Directive (https://angular.io/styleguide#style-02-03)', |
| 16 | + source |
| 17 | + }); |
19 | 18 | }); |
20 | 19 |
|
21 | | - describe('valid directive class name', () => { |
22 | | - it('should succeed when the directive class name ends with Directive', () => { |
23 | | - let source = ` |
| 20 | + it('should fail when directive class is with the wrong suffix', () => { |
| 21 | + let source = ` |
| 22 | + @Directive({ |
| 23 | + selector: 'sgBarFoo' |
| 24 | + }) |
| 25 | + class Test {} |
| 26 | + ~~~~ |
| 27 | + `; |
| 28 | + assertAnnotated({ |
| 29 | + ruleName: 'directive-class-suffix', |
| 30 | + message: 'The name of the class Test should end with the suffix ' + |
| 31 | + 'Directive, Page, Validator (https://angular.io/styleguide#style-02-03)', |
| 32 | + source, |
| 33 | + options: ['Directive', 'Page', 'Validator'] |
| 34 | + }); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + describe('valid directive class name', () => { |
| 39 | + it('should succeed when the directive class name ends with Directive', () => { |
| 40 | + let source = ` |
24 | 41 | @Directive({ |
25 | 42 | selector: 'sgBarFoo' |
26 | 43 | }) |
27 | 44 | class TestDirective {}`; |
28 | | - assertSuccess('directive-class-suffix', source); |
29 | | - }); |
| 45 | + assertSuccess('directive-class-suffix', source); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should succeed when the directive class name ends with Validator and implements Validator', () => { |
| 49 | + const source = ` |
| 50 | + @Directive({ |
| 51 | + selector: 'sgBarFoo' |
| 52 | + }) |
| 53 | + class TestValidator implements Validator {}`; |
| 54 | + assertSuccess('directive-class-suffix', source); |
30 | 55 | }); |
31 | 56 |
|
32 | | - describe('not called decorator', () => { |
33 | | - it('should not fail when @Directive is not called', () => { |
34 | | - let source = ` |
| 57 | + it('should succeed when the directive class name ends with Validator and implements AsyncValidator', () => { |
| 58 | + const source = ` |
| 59 | + @Directive({ |
| 60 | + selector: 'sgBarFoo' |
| 61 | + }) |
| 62 | + class TestValidator implements AsyncValidator {}`; |
| 63 | + assertSuccess('directive-class-suffix', source); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + describe('not called decorator', () => { |
| 68 | + it('should not fail when @Directive is not called', () => { |
| 69 | + let source = ` |
35 | 70 | @Directive |
36 | 71 | class TestDirective {}`; |
37 | | - assertSuccess('directive-class-suffix', source); |
38 | | - }); |
| 72 | + assertSuccess('directive-class-suffix', source); |
39 | 73 | }); |
| 74 | + }); |
40 | 75 |
|
41 | | - describe('valid directive class', () => { |
42 | | - it('should succeed when is used @Component decorator', () => { |
43 | | - let source = ` |
| 76 | + describe('valid directive class', () => { |
| 77 | + it('should succeed when is used @Component decorator', () => { |
| 78 | + let source = ` |
44 | 79 | @Component({ |
45 | 80 | selector: 'sg-foo-bar' |
46 | 81 | }) |
47 | 82 | class TestComponent {}`; |
48 | | - assertSuccess('directive-class-suffix', source); |
49 | | - }); |
| 83 | + assertSuccess('directive-class-suffix', source); |
50 | 84 | }); |
| 85 | + }); |
51 | 86 |
|
52 | | - describe('valid pipe class', () => { |
53 | | - it('should succeed when is used @Pipe decorator', () => { |
54 | | - let source = ` |
| 87 | + describe('valid pipe class', () => { |
| 88 | + it('should succeed when is used @Pipe decorator', () => { |
| 89 | + let source = ` |
55 | 90 | @Pipe({ |
56 | 91 | selector: 'sg-test-pipe' |
57 | 92 | }) |
58 | 93 | class TestPipe {}`; |
59 | | - assertSuccess('directive-class-suffix', source); |
60 | | - }); |
| 94 | + assertSuccess('directive-class-suffix', source); |
61 | 95 | }); |
| 96 | + }); |
62 | 97 |
|
63 | | - describe('valid service class', () => { |
64 | | - it('should succeed when is used @Injectable decorator', () => { |
65 | | - let source = ` |
| 98 | + describe('valid service class', () => { |
| 99 | + it('should succeed when is used @Injectable decorator', () => { |
| 100 | + let source = ` |
66 | 101 | @Injectable() |
67 | 102 | class TestService {}`; |
68 | | - assertSuccess('directive-class-suffix', source); |
69 | | - }); |
| 103 | + assertSuccess('directive-class-suffix', source); |
70 | 104 | }); |
| 105 | + }); |
71 | 106 |
|
72 | | - describe('valid empty class', () => { |
73 | | - it('should succeed when the class is empty', () => { |
74 | | - let source = ` |
| 107 | + describe('valid empty class', () => { |
| 108 | + it('should succeed when the class is empty', () => { |
| 109 | + let source = ` |
75 | 110 | class TestEmpty {}`; |
76 | | - assertSuccess('directive-class-suffix', source); |
77 | | - }); |
| 111 | + assertSuccess('directive-class-suffix', source); |
78 | 112 | }); |
| 113 | + }); |
79 | 114 |
|
80 | | - describe('changed suffix', () => { |
81 | | - it('should suceed when different sufix is set', () => { |
82 | | - let source = ` |
| 115 | + describe('changed suffix', () => { |
| 116 | + it('should suceed when different sufix is set', () => { |
| 117 | + let source = ` |
83 | 118 | @Directive({ |
84 | 119 | selector: 'sgBarFoo' |
85 | 120 | }) |
86 | 121 | class TestPage {}`; |
87 | | - assertSuccess('directive-class-suffix', source, ['Page']); |
88 | | - }); |
| 122 | + assertSuccess('directive-class-suffix', source, ['Page']); |
| 123 | + }); |
89 | 124 |
|
90 | | - it('should fail when different sufix is set and doesnt match', () => { |
91 | | - let source = ` |
| 125 | + it('should fail when different sufix is set and doesnt match', () => { |
| 126 | + let source = ` |
92 | 127 | @Directive({ |
93 | 128 | selector: 'sgBarFoo' |
94 | 129 | }) |
95 | 130 | class TestPage {} |
96 | 131 | ~~~~~~~~ |
97 | 132 | `; |
98 | | - assertAnnotated({ |
99 | | - ruleName: 'directive-class-suffix', |
100 | | - message: 'The name of the class TestPage should end with the suffix Directive (https://angular.io/styleguide#style-02-03)', |
101 | | - source, |
102 | | - options: ['Directive'] |
103 | | - }); |
104 | | - }); |
| 133 | + assertAnnotated({ |
| 134 | + ruleName: 'directive-class-suffix', |
| 135 | + message: 'The name of the class TestPage should end with the suffix Directive (https://angular.io/styleguide#style-02-03)', |
| 136 | + source, |
| 137 | + options: ['Directive'] |
| 138 | + }); |
| 139 | + }); |
105 | 140 |
|
106 | | - it('should fail when different sufix is set and doesnt match', () => { |
107 | | - let source = ` |
| 141 | + it('should fail when different sufix is set and doesnt match', () => { |
| 142 | + let source = ` |
108 | 143 | @Directive({ |
109 | 144 | selector: 'sgBarFoo' |
110 | 145 | }) |
111 | 146 | class TestDirective {} |
112 | 147 | ~~~~~~~~~~~~~ |
113 | 148 | `; |
114 | | - assertAnnotated({ |
115 | | - ruleName: 'directive-class-suffix', |
116 | | - message: 'The name of the class TestDirective should end with the suffix Page (https://angular.io/styleguide#style-02-03)', |
117 | | - source, |
118 | | - options: ['Page'] |
119 | | - }); |
120 | | - }); |
| 149 | + assertAnnotated({ |
| 150 | + ruleName: 'directive-class-suffix', |
| 151 | + message: 'The name of the class TestDirective should end with the suffix Page (https://angular.io/styleguide#style-02-03)', |
| 152 | + source, |
| 153 | + options: ['Page'] |
| 154 | + }); |
121 | 155 | }); |
| 156 | + }); |
122 | 157 | }); |
0 commit comments