|
1 | 1 | import { assertSuccess, assertAnnotated } from './testHelper';
|
2 | 2 |
|
3 |
| -describe('no-input-rename', () => { |
4 |
| - describe('invalid directive input property', () => { |
5 |
| - it('should fail, when a directive input property is renamed', () => { |
6 |
| - let source = ` |
7 |
| - class ButtonComponent { |
8 |
| - @Input('labelAttribute') label: string; |
9 |
| - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
10 |
| - }`; |
11 |
| - assertAnnotated({ |
12 |
| - ruleName: 'no-input-rename', |
13 |
| - message: 'In the class "ButtonComponent", the directive input property "label" should not be renamed.' + |
14 |
| - 'Please, consider the following use "@Input() label: string"', |
15 |
| - source |
| 3 | +const ruleName = 'no-input-rename'; |
| 4 | + |
| 5 | +const getMessage = (className: string, propertyName: string): string => { |
| 6 | + return `In the class "${className}", the directive input property "${propertyName}" should not be renamed.`; |
| 7 | +}; |
| 8 | + |
| 9 | +describe(ruleName, () => { |
| 10 | + describe('failure', () => { |
| 11 | + describe('Component', () => { |
| 12 | + it('should fail when a input property is renamed', () => { |
| 13 | + const source = ` |
| 14 | + @Component |
| 15 | + class TestComponent { |
| 16 | + @Input('labelAttribute') label: string; |
| 17 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 18 | + } |
| 19 | + `; |
| 20 | + |
| 21 | + assertAnnotated({ |
| 22 | + ruleName, |
| 23 | + message: getMessage('TestComponent', 'label'), |
| 24 | + source |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should fail when input property is fake renamed', () => { |
| 29 | + const source = ` |
| 30 | + @Component |
| 31 | + class TestComponent { |
| 32 | + @Input('label') label: string; |
| 33 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 34 | + } |
| 35 | + `; |
| 36 | + |
| 37 | + assertAnnotated({ |
| 38 | + ruleName, |
| 39 | + message: getMessage('TestComponent', 'label'), |
| 40 | + source |
| 41 | + }); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe('Directive', () => { |
| 46 | + it('should fail when a input property is renamed', () => { |
| 47 | + const source = ` |
| 48 | + @Directive |
| 49 | + class TestDirective { |
| 50 | + @Input('labelText') label: string; |
| 51 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 52 | + } |
| 53 | + `; |
| 54 | + |
| 55 | + assertAnnotated({ |
| 56 | + ruleName, |
| 57 | + message: getMessage('TestDirective', 'label'), |
| 58 | + source |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + it(`should fail when input property is renamed and it's different from directive's selector`, () => { |
| 63 | + const source = ` |
| 64 | + @Directive({ |
| 65 | + selector: '[label], label2' |
| 66 | + }) |
| 67 | + class TestDirective { |
| 68 | + @Input('label') labelText: string; |
| 69 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 70 | + } |
| 71 | + `; |
| 72 | + |
| 73 | + assertAnnotated({ |
| 74 | + ruleName, |
| 75 | + message: getMessage('TestDirective', `labelText`), |
| 76 | + source |
| 77 | + }); |
16 | 78 | });
|
17 | 79 | });
|
18 | 80 | });
|
19 | 81 |
|
20 |
| - describe('valid directive input property', () => { |
21 |
| - it('should succeed, when a directive input property is properly used', () => { |
22 |
| - let source = ` |
23 |
| - class ButtonComponent { |
24 |
| - @Input() label: string; |
25 |
| - }`; |
26 |
| - assertSuccess('no-input-rename', source); |
| 82 | + describe('success', () => { |
| 83 | + describe('Component', () => { |
| 84 | + it('should succeed when a input property is not renamed', () => { |
| 85 | + const source = ` |
| 86 | + @Component |
| 87 | + class TestComponent { |
| 88 | + @Input() label: string; |
| 89 | + } |
| 90 | + `; |
| 91 | + |
| 92 | + assertSuccess(ruleName, source); |
| 93 | + }); |
27 | 94 | });
|
28 | 95 |
|
29 |
| - it('should succeed, when a directive input property rename is the same as the name of the property', () => { |
30 |
| - let source = ` |
31 |
| - class ButtonComponent { |
32 |
| - @Input('label') label: string; |
33 |
| - }`; |
34 |
| - assertSuccess('no-input-rename', source); |
| 96 | + describe('Directive', () => { |
| 97 | + it('should succeed when the directive name is also an input property', () => { |
| 98 | + const source = ` |
| 99 | + @Directive({ |
| 100 | + selector: '[label], label2' |
| 101 | + }) |
| 102 | + class TestDirective { |
| 103 | + @Input('labelText') label: string; |
| 104 | + } |
| 105 | + `; |
| 106 | + |
| 107 | + assertSuccess(ruleName, source); |
| 108 | + }); |
35 | 109 | });
|
36 | 110 | });
|
37 | 111 | });
|
0 commit comments