1- import { Component , ViewChild } from '@angular/core' ;
21import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
32
43import { MessageStripComponent } from './message-strip.component' ;
54
6- @Component ( {
7- template : ` <fd-message-strip> A dismissible normal message strip.</fd-message-strip> ` ,
8- standalone : true ,
9- imports : [ MessageStripComponent ]
10- } )
11- class TestMessageStripComponent {
12- @ViewChild ( MessageStripComponent , { static : true } )
13- messageStripComponent : MessageStripComponent ;
14- }
15-
165describe ( 'MessageStripComponent' , ( ) => {
176 let component : MessageStripComponent ;
18- let fixture : ComponentFixture < TestMessageStripComponent > ;
7+ let fixture : ComponentFixture < MessageStripComponent > ;
198
209 beforeEach ( waitForAsync ( ( ) => {
2110 TestBed . configureTestingModule ( {
22- imports : [ TestMessageStripComponent ]
11+ imports : [ MessageStripComponent ]
2312 } ) . compileComponents ( ) ;
2413 } ) ) ;
2514
2615 beforeEach ( ( ) => {
27- fixture = TestBed . createComponent ( TestMessageStripComponent ) ;
28- component = fixture . componentInstance . messageStripComponent ;
16+ fixture = TestBed . createComponent ( MessageStripComponent ) ;
17+ component = fixture . componentInstance ;
2918 fixture . detectChanges ( ) ;
3019 } ) ;
3120
@@ -34,14 +23,14 @@ describe('MessageStripComponent', () => {
3423 } ) ;
3524
3625 it ( 'should Add no-icon modifier class' , ( ) => {
37- component . noIcon = true ;
26+ fixture . componentRef . setInput ( ' noIcon' , ' true' ) ;
3827 component . buildComponentCssClass ( ) ;
3928 fixture . detectChanges ( ) ;
4029 expect ( component . elementRef . nativeElement . classList . contains ( 'fd-message-strip--no-icon' ) ) . toBe ( true ) ;
4130 } ) ;
4231
4332 it ( 'should apply a type' , ( ) => {
44- component . type = 'success' ;
33+ fixture . componentRef . setInput ( ' type' , 'success' ) ;
4534 component . buildComponentCssClass ( ) ;
4635 fixture . detectChanges ( ) ;
4736 expect ( component . elementRef . nativeElement . classList . contains ( 'fd-message-strip--success' ) ) . toBe ( true ) ;
@@ -54,64 +43,60 @@ describe('MessageStripComponent', () => {
5443 } ) ;
5544
5645 it ( 'should set aria-label attribute if provided' , ( ) => {
57- component . ariaLabel = 'Test label' ;
46+ fixture . componentRef . setInput ( ' ariaLabel' , 'Test label' ) ;
5847 fixture . detectChanges ( ) ;
59- const hostElement = fixture . nativeElement . querySelector ( 'fd-message-strip' ) ;
60- expect ( hostElement . getAttribute ( 'aria-label' ) ) . toBe ( 'Test label' ) ;
48+ expect ( component . elementRef . nativeElement . getAttribute ( 'aria-label' ) ) . toBe ( 'Test label' ) ;
6149 } ) ;
6250
6351 it ( 'should set width style if provided' , ( ) => {
64- component . width = '200px' ;
52+ fixture . componentRef . setInput ( ' width' , '200px' ) ;
6553 fixture . detectChanges ( ) ;
66- const hostElement = fixture . nativeElement . querySelector ( 'fd-message-strip' ) ;
67- expect ( hostElement . style . width ) . toBe ( '200px' ) ;
54+ expect ( component . elementRef . nativeElement . style . width ) . toBe ( '200px' ) ;
6855 } ) ;
6956
7057 it ( 'should set min-width style if provided' , ( ) => {
71- component . minWidth = '500px' ;
58+ fixture . componentRef . setInput ( ' minWidth' , '500px' ) ;
7259 fixture . detectChanges ( ) ;
73- const hostElement = fixture . nativeElement . querySelector ( 'fd-message-strip' ) ;
74- expect ( hostElement . style . minWidth ) . toBe ( '500px' ) ;
60+ expect ( component . elementRef . nativeElement . style . minWidth ) . toBe ( '500px' ) ;
7561 } ) ;
7662
7763 it ( 'should set margin-bottom style if provided' , ( ) => {
78- component . marginBottom = '10px' ;
64+ fixture . componentRef . setInput ( ' marginBottom' , '10px' ) ;
7965 fixture . detectChanges ( ) ;
80- const hostElement = fixture . nativeElement . querySelector ( 'fd-message-strip' ) ;
81- expect ( hostElement . style . marginBottom ) . toBe ( '10px' ) ;
66+ expect ( component . elementRef . nativeElement . style . marginBottom ) . toBe ( '10px' ) ;
8267 } ) ;
8368
8469 it ( 'should set id attribute if provided' , ( ) => {
85- component . id = 'test-id' ;
70+ fixture . componentRef . setInput ( 'id' , 'test-id' ) ;
8671 fixture . detectChanges ( ) ;
87- const hostElement = fixture . nativeElement . querySelector ( 'fd-message-strip' ) ;
88- expect ( hostElement . getAttribute ( 'id' ) ) . toBe ( 'test-id' ) ;
72+ expect ( component . elementRef . nativeElement . getAttribute ( 'id' ) ) . toBe ( 'test-id' ) ;
8973 } ) ;
9074
9175 it ( 'should set role="note" on the host element' , ( ) => {
92- const hostElement = fixture . nativeElement . querySelector ( 'fd-message-strip' ) ;
93- expect ( hostElement . getAttribute ( 'role' ) ) . toBe ( 'note' ) ;
76+ expect ( component . elementRef . nativeElement . getAttribute ( 'role' ) ) . toBe ( 'note' ) ;
9477 } ) ;
9578
9679 it ( 'should set aria-labelledby attribute on the host element' , ( ) => {
97- const hostElement = fixture . nativeElement . querySelector ( 'fd-message-strip' ) ;
98- expect ( hostElement . hasAttribute ( 'aria-labelledby' ) ) . toBe ( true ) ;
99- expect ( hostElement . getAttribute ( 'aria-labelledby' ) ) . toBe (
100- `${ component . id } -hidden-text ${ component . id } -content-text`
80+ expect ( component . elementRef . nativeElement . getAttribute ( 'aria-labelledby' ) ) . toBe (
81+ `${ component . id ( ) } -hidden-text ${ component . id ( ) } -content-text`
82+ ) ;
83+ expect ( component . elementRef . nativeElement . hasAttribute ( 'aria-labelledby' ) ) . toBe ( true ) ;
84+ expect ( component . elementRef . nativeElement . getAttribute ( 'aria-labelledby' ) ) . toBe (
85+ `${ component . id ( ) } -hidden-text ${ component . id ( ) } -content-text`
10186 ) ;
10287 } ) ;
10388
10489 it ( 'should set custom aria-labelledby attribute on the host element if ariaLabelledBy input provided' , ( ) => {
105- component . ariaLabelledBy = 'custom-id' ;
90+ fixture . componentRef . setInput ( ' ariaLabelledBy' , 'custom-id' ) ;
10691 fixture . detectChanges ( ) ;
107- const hostElement = fixture . nativeElement . querySelector ( 'fd-message-strip' ) ;
108- expect ( hostElement . hasAttribute ( 'aria-labelledby' ) ) . toBe ( true ) ;
109- expect ( hostElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( component . ariaLabelledBy ) ;
92+ expect ( component . elementRef . nativeElement . hasAttribute ( 'aria-labelledby' ) ) . toBe ( true ) ;
93+ expect ( component . elementRef . nativeElement . getAttribute ( 'aria-labelledby' ) ) . toBe ( component . ariaLabelledBy ( ) ) ;
11094 } ) ;
11195
11296 it ( 'should set an id attribute on the message strip text container' , ( ) => {
11397 fixture . detectChanges ( ) ;
114- const contentText = component . elementRef . nativeElement . querySelector ( '.fd-message-strip__text' ) ;
115- expect ( contentText . getAttribute ( 'id' ) ) . toBe ( `${ component . id } -content-text` ) ;
98+ expect ( component . elementRef . nativeElement . querySelector ( '.fd-message-strip__text' ) . getAttribute ( 'id' ) ) . toBe (
99+ `${ component . id ( ) } -content-text`
100+ ) ;
116101 } ) ;
117102} ) ;
0 commit comments