11import { LiveRegionService } from './live-region.service' ;
2- import { fakeAsync , tick , flush } from '@angular/core/testing' ;
2+ import { fakeAsync , tick } from '@angular/core/testing' ;
33import { UUIDService } from '../../core/shared/uuid.service' ;
4+ import { getAccessibilitySettingsServiceStub } from '../../accessibility/accessibility-settings.service.stub' ;
5+ import { AccessibilitySettingsService } from '../../accessibility/accessibility-settings.service' ;
6+ import { of } from 'rxjs' ;
47
58describe ( 'liveRegionService' , ( ) => {
69 let service : LiveRegionService ;
10+ let accessibilitySettingsService : AccessibilitySettingsService ;
711
812 beforeEach ( ( ) => {
13+ accessibilitySettingsService = getAccessibilitySettingsServiceStub ( ) ;
14+
15+ accessibilitySettingsService . getAsNumber = jasmine . createSpy ( 'getAsNumber' ) . and . returnValue ( of ( 100 ) ) ;
16+
917 service = new LiveRegionService (
1018 new UUIDService ( ) ,
19+ accessibilitySettingsService ,
1120 ) ;
1221 } ) ;
1322
@@ -81,13 +90,16 @@ describe('liveRegionService', () => {
8190 expect ( results [ 2 ] ) . toEqual ( [ 'Message One' , 'Message Two' ] ) ;
8291
8392 service . clear ( ) ;
84- flush ( ) ;
93+ tick ( 200 ) ;
8594
8695 expect ( results . length ) . toEqual ( 4 ) ;
8796 expect ( results [ 3 ] ) . toEqual ( [ ] ) ;
8897 } ) ) ;
8998
9099 it ( 'should not pop messages added after clearing within timeOut period' , fakeAsync ( ( ) => {
100+ // test expects a clear rate of 30 seconds
101+ accessibilitySettingsService . getAsNumber = jasmine . createSpy ( 'getAsNumber' ) . and . returnValue ( of ( 30000 ) ) ;
102+
91103 const results : string [ ] [ ] = [ ] ;
92104
93105 service . getMessages$ ( ) . subscribe ( ( messages ) => {
@@ -114,45 +126,6 @@ describe('liveRegionService', () => {
114126 expect ( results . length ) . toEqual ( 5 ) ;
115127 expect ( results [ 4 ] ) . toEqual ( [ ] ) ;
116128 } ) ) ;
117-
118- it ( 'should respect configured timeOut' , fakeAsync ( ( ) => {
119- const results : string [ ] [ ] = [ ] ;
120-
121- service . getMessages$ ( ) . subscribe ( ( messages ) => {
122- results . push ( messages ) ;
123- } ) ;
124-
125- expect ( results . length ) . toEqual ( 1 ) ;
126- expect ( results [ 0 ] ) . toEqual ( [ ] ) ;
127-
128- const timeOutMs = 500 ;
129- service . setMessageTimeOutMs ( timeOutMs ) ;
130-
131- service . addMessage ( 'Message One' ) ;
132- tick ( timeOutMs - 1 ) ;
133-
134- expect ( results . length ) . toEqual ( 2 ) ;
135- expect ( results [ 1 ] ) . toEqual ( [ 'Message One' ] ) ;
136-
137- tick ( 1 ) ;
138-
139- expect ( results . length ) . toEqual ( 3 ) ;
140- expect ( results [ 2 ] ) . toEqual ( [ ] ) ;
141-
142- const timeOutMsTwo = 50000 ;
143- service . setMessageTimeOutMs ( timeOutMsTwo ) ;
144-
145- service . addMessage ( 'Message Two' ) ;
146- tick ( timeOutMsTwo - 1 ) ;
147-
148- expect ( results . length ) . toEqual ( 4 ) ;
149- expect ( results [ 3 ] ) . toEqual ( [ 'Message Two' ] ) ;
150-
151- tick ( 1 ) ;
152-
153- expect ( results . length ) . toEqual ( 5 ) ;
154- expect ( results [ 4 ] ) . toEqual ( [ ] ) ;
155- } ) ) ;
156129 } ) ;
157130
158131 describe ( 'liveRegionVisibility' , ( ) => {
0 commit comments