@@ -30,37 +30,49 @@ describe('NotificationComponent', () => {
30
30
fixture . detectChanges ( ) ;
31
31
}
32
32
33
- it ( 'should display the message' , ( ) => {
34
- configTestingModule ( ) ;
35
- createComponent ( ) ;
36
- expect ( fixture . nativeElement . innerHTML ) . toContain ( 'Help Angular by taking a <strong>1 minute survey</strong>!' ) ;
37
- } ) ;
33
+ describe ( 'content projection' , ( ) => {
34
+ it ( 'should display the message text' , ( ) => {
35
+ configTestingModule ( ) ;
36
+ createComponent ( ) ;
37
+ expect ( fixture . nativeElement . innerHTML ) . toContain ( 'Version 6 of Angular Now Available!' ) ;
38
+ } ) ;
38
39
39
- it ( 'should display an icon' , ( ) => {
40
- configTestingModule ( ) ;
41
- createComponent ( ) ;
42
- const iconElement = fixture . debugElement . query ( By . css ( '.icon' ) ) ;
43
- expect ( iconElement . properties [ 'svgIcon' ] ) . toEqual ( 'insert_comment' ) ;
44
- expect ( iconElement . attributes [ 'aria-label' ] ) . toEqual ( 'Survey' ) ;
40
+ it ( 'should render HTML elements' , ( ) => {
41
+ configTestingModule ( ) ;
42
+ createComponent ( ) ;
43
+ const button = fixture . debugElement . query ( By . css ( '.action-button' ) ) ;
44
+ expect ( button . nativeElement . textContent ) . toEqual ( 'Learn More' ) ;
45
+ } ) ;
46
+
47
+ it ( 'should process Angular directives' , ( ) => {
48
+ configTestingModule ( ) ;
49
+ createComponent ( ) ;
50
+ const badSpans = fixture . debugElement . queryAll ( By . css ( '.bad' ) ) ;
51
+ expect ( badSpans . length ) . toEqual ( 0 ) ;
52
+ } ) ;
45
53
} ) ;
46
54
47
- it ( 'should display a button ' , ( ) => {
55
+ it ( 'should call dismiss() when the message link is clicked, if dismissOnContentClick is true ' , ( ) => {
48
56
configTestingModule ( ) ;
49
57
createComponent ( ) ;
50
- const button = fixture . debugElement . query ( By . css ( '.action-button' ) ) ;
51
- expect ( button . nativeElement . textContent ) . toEqual ( 'Go to survey' ) ;
58
+ spyOn ( component , 'dismiss' ) ;
59
+ component . dismissOnContentClick = true ;
60
+ const message : HTMLSpanElement = fixture . debugElement . query ( By . css ( '.messageholder' ) ) . nativeElement ;
61
+ message . click ( ) ;
62
+ expect ( component . dismiss ) . toHaveBeenCalled ( ) ;
52
63
} ) ;
53
64
54
- it ( 'should call dismiss when the message link is clicked' , ( ) => {
65
+ it ( 'should not call dismiss() when the message link is clicked, if dismissOnContentClick is false ' , ( ) => {
55
66
configTestingModule ( ) ;
56
67
createComponent ( ) ;
57
68
spyOn ( component , 'dismiss' ) ;
58
- fixture . debugElement . query ( By . css ( 'a' ) ) . triggerEventHandler ( 'click' , null ) ;
59
- fixture . detectChanges ( ) ;
60
- expect ( component . dismiss ) . toHaveBeenCalled ( ) ;
69
+ component . dismissOnContentClick = false ;
70
+ const message : HTMLSpanElement = fixture . debugElement . query ( By . css ( '.messageholder' ) ) . nativeElement ;
71
+ message . click ( ) ;
72
+ expect ( component . dismiss ) . not . toHaveBeenCalled ( ) ;
61
73
} ) ;
62
74
63
- it ( 'should call dismiss when the close button is clicked' , ( ) => {
75
+ it ( 'should call dismiss() when the close button is clicked' , ( ) => {
64
76
configTestingModule ( ) ;
65
77
createComponent ( ) ;
66
78
spyOn ( component , 'dismiss' ) ;
@@ -104,13 +116,15 @@ describe('NotificationComponent', () => {
104
116
@Component ( {
105
117
template : `
106
118
<aio-notification
107
- icon="insert_comment"
108
- iconLabel="Survey"
109
- buttonText="Go to survey"
110
- actionUrl="https://bit.ly/angular-survey-2018"
111
119
notificationId="survey-january-2018"
112
120
expirationDate="2018-01-22">
113
- Help Angular by taking a <strong>1 minute survey</strong>!
121
+ <span class="messageholder">
122
+ <a href="https://blog.angular.io/version-6-0-0-of-angular-now-available-cc56b0efa7a4">
123
+ <span *ngIf="false" class="bad">This should not appear</span>
124
+ <span class="message">Version 6 of Angular Now Available!</span>
125
+ <span class="action-button">Learn More</span>
126
+ </a>
127
+ </span>
114
128
</aio-notification>`
115
129
} )
116
130
class TestComponent {
0 commit comments