@@ -64,7 +64,7 @@ describe('TextComponent', () => {
6464 mockedConsole . reset ( ) ;
6565 } ) ;
6666
67- it ( 'shows proper placeholder messages for situations' , fakeAsync ( ( ) => {
67+ it ( 'shows proper placeholder messages for situations' , fakeAsync ( async ( ) => {
6868 // Suppose a user comes to a page with a text component, which has no content to show. The placeholder will be a
6969 // 'no-content' indication, or that specified as a placeholder Input. Here we will not specify the placeholder
7070 // input.
@@ -85,7 +85,7 @@ describe('TextComponent', () => {
8585
8686 // The user goes to a location. The id input is set to a particular location. The text component is now expected to
8787 // have content, so the placeholder should be 'loading'.
88- env . runWithDelayedGetText ( env . matTextDocId , ( ) => {
88+ await env . runWithDelayedGetText ( env . matTextDocId , ( ) => {
8989 env . id = env . matTextDocId ;
9090 env . waitForEditor ( ) ;
9191 expect ( env . component . placeholder ) . toEqual ( 'text.loading' ) ;
@@ -95,7 +95,7 @@ describe('TextComponent', () => {
9595 // why they can't see the content if and while it has not loaded yet.
9696 env . onlineStatus = false ;
9797 env . waitForEditor ( ) ;
98- env . runWithDelayedGetText ( env . lukTextDocId , ( ) => {
98+ await env . runWithDelayedGetText ( env . lukTextDocId , ( ) => {
9999 env . id = env . lukTextDocId ;
100100 env . waitForEditor ( ) ;
101101 expect ( env . component . placeholder ) . toEqual ( 'text.not_available_offline' ) ;
@@ -107,7 +107,7 @@ describe('TextComponent', () => {
107107 } ) ;
108108
109109 // The user goes to a location that the project does not have. The placeholder should indicate 'no-content'.
110- env . runWithDelayedGetText ( env . notPresentTextDocId , ( ) => {
110+ await env . runWithDelayedGetText ( env . notPresentTextDocId , ( ) => {
111111 env . id = env . notPresentTextDocId ;
112112 env . waitForEditor ( ) ;
113113 expect ( env . component . placeholder ) . toEqual ( 'text.book_does_not_exist' ) ;
@@ -119,7 +119,7 @@ describe('TextComponent', () => {
119119 env . waitForEditor ( ) ;
120120 env . onlineStatus = false ;
121121 env . waitForEditor ( ) ;
122- env . runWithDelayedGetText ( env . notPresentTextDocId , ( ) => {
122+ await env . runWithDelayedGetText ( env . notPresentTextDocId , ( ) => {
123123 env . id = env . notPresentTextDocId ;
124124 env . waitForEditor ( ) ;
125125 expect ( env . component . placeholder ) . toEqual ( 'text.book_does_not_exist' ) ;
@@ -160,7 +160,7 @@ describe('TextComponent', () => {
160160 expect ( env2 . component . placeholder ) . toEqual ( 'text.permission_denied' ) ;
161161 } ) ) ;
162162
163- it ( 'placeholder uses specified placeholder input' , fakeAsync ( ( ) => {
163+ it ( 'placeholder uses specified placeholder input' , fakeAsync ( async ( ) => {
164164 // TextComponent allows a placeholder to be specified to override the default no-content message.
165165
166166 // Suppose a user comes to a page with a text component, which has no content to show. The placeholder will be the
@@ -182,14 +182,14 @@ describe('TextComponent', () => {
182182
183183 // The user goes to a location. The id input is set to a particular location. The text component is now expected to
184184 // have content, so the placeholder should be 'loading'.
185- env . runWithDelayedGetText ( env . matTextDocId , ( ) => {
185+ await env . runWithDelayedGetText ( env . matTextDocId , ( ) => {
186186 env . id = env . matTextDocId ;
187187 env . waitForEditor ( ) ;
188188 expect ( env . component . placeholder ) . toEqual ( 'text.loading' ) ;
189189 } ) ;
190190
191191 // The user goes to a location that the project does not have. The placeholder should indicate 'no-content'.
192- env . runWithDelayedGetText ( env . notPresentTextDocId , ( ) => {
192+ await env . runWithDelayedGetText ( env . notPresentTextDocId , ( ) => {
193193 env . id = env . notPresentTextDocId ;
194194 env . waitForEditor ( ) ;
195195 expect ( env . component . placeholder ) . toEqual ( 'my custom no-content message' ) ;
@@ -202,7 +202,7 @@ describe('TextComponent', () => {
202202 expect ( env . component . placeholder ) . toEqual ( 'my custom no-content message' ) ;
203203 } ) ) ;
204204
205- it ( 'shows book is empty placeholder messages' , fakeAsync ( ( ) => {
205+ it ( 'shows book is empty placeholder messages' , fakeAsync ( async ( ) => {
206206 // Suppose the user navigates to a text location. We fetch the text, but some aspect of the received TextDoc
207207 // indicates that it is considered "empty". The placeholder will indicate this.
208208
@@ -213,12 +213,10 @@ describe('TextComponent', () => {
213213
214214 const textDocIdWithEmpty : TextDocId = env . matTextDocId ;
215215
216- let textDocBeingGotten : TextDoc = { } as TextDoc ;
217- instance ( mockedProjectService )
218- . getText ( textDocIdWithEmpty . toString ( ) , new DocSubscription ( 'spec' ) )
219- . then ( ( value : TextDoc ) => {
220- textDocBeingGotten = value ;
221- } ) ;
216+ const textDocBeingGotten : TextDoc = await instance ( mockedProjectService ) . getText (
217+ textDocIdWithEmpty . toString ( ) ,
218+ new DocSubscription ( 'spec' )
219+ ) ;
222220 tick ( ) ;
223221 // The textdoc will have an undefined data field.
224222 Object . defineProperty ( textDocBeingGotten , 'data' , {
@@ -1459,48 +1457,39 @@ describe('TextComponent', () => {
14591457 expect ( wasLoaded ) . toBeUndefined ( ) ;
14601458 } ) ) ;
14611459
1462- it ( 'knows if project has book with chapter' , fakeAsync ( ( ) => {
1460+ it ( 'knows if project has book with chapter' , fakeAsync ( async ( ) => {
14631461 const env : TestEnvironment = new TestEnvironment ( ) ;
14641462 env . fixture . detectChanges ( ) ;
14651463 env . id = new TextDocId ( 'project01' , 40 , 1 ) ;
14661464 tick ( ) ;
14671465 env . fixture . detectChanges ( ) ;
14681466
1469- let result : boolean | undefined ;
1470- env . component . projectHasText ( ) . then ( res => {
1471- result = res ;
1472- } ) ;
1467+ const result : boolean = await env . component . projectHasText ( ) ;
14731468 tick ( ) ;
14741469 expect ( result ) . toBe ( true ) ;
14751470 } ) ) ;
14761471
1477- it ( 'knows if project does not have chapter' , fakeAsync ( ( ) => {
1472+ it ( 'knows if project does not have chapter' , fakeAsync ( async ( ) => {
14781473 const env : TestEnvironment = new TestEnvironment ( ) ;
14791474 env . fixture . detectChanges ( ) ;
14801475 env . id = new TextDocId ( 'project01' , 40 , 99 ) ; // Non-existent chapter
14811476 tick ( ) ;
14821477 env . fixture . detectChanges ( ) ;
14831478
1484- let result : boolean | undefined ;
1485- env . component . projectHasText ( ) . then ( res => {
1486- result = res ;
1487- } ) ;
1479+ const result : boolean = await env . component . projectHasText ( ) ;
14881480 tick ( ) ;
14891481
14901482 expect ( result ) . toBe ( false ) ;
14911483 } ) ) ;
14921484
1493- it ( 'knows if project does not have book' , fakeAsync ( ( ) => {
1485+ it ( 'knows if project does not have book' , fakeAsync ( async ( ) => {
14941486 const env : TestEnvironment = new TestEnvironment ( ) ;
14951487 env . fixture . detectChanges ( ) ;
14961488 env . id = new TextDocId ( 'project01' , 3 , 1 ) ; // Non-existent book
14971489 tick ( ) ;
14981490 env . fixture . detectChanges ( ) ;
14991491
1500- let result : boolean | undefined ;
1501- env . component . projectHasText ( ) . then ( res => {
1502- result = res ;
1503- } ) ;
1492+ const result : boolean = await env . component . projectHasText ( ) ;
15041493 tick ( ) ;
15051494
15061495 expect ( result ) . toBe ( false ) ;
@@ -2061,14 +2050,12 @@ class TestEnvironment {
20612050
20622051 /** Run the specified code while waiting for getText() to resolve. This allows the placeholder to be examined while
20632052 * waiting for getText(), rather than examining the placeholder after getText() finishes. */
2064- runWithDelayedGetText ( textDocId : TextDocId , code : ( ) => void ) : void {
2053+ async runWithDelayedGetText ( textDocId : TextDocId , code : ( ) => void ) : Promise < void > {
20652054 let resolver : ( _ : TextDoc ) => void = _ => { } ;
2066- let textDocBeingGotten : TextDoc = { } as TextDoc ;
2067- instance ( mockedProjectService )
2068- . getText ( textDocId . toString ( ) , new DocSubscription ( 'spec' ) )
2069- . then ( ( value : TextDoc ) => {
2070- textDocBeingGotten = value ;
2071- } ) ;
2055+ const textDocBeingGotten : TextDoc = await instance ( mockedProjectService ) . getText (
2056+ textDocId . toString ( ) ,
2057+ new DocSubscription ( 'spec' )
2058+ ) ;
20722059 tick ( ) ;
20732060 when ( mockedProjectService . getText ( textDocId , anything ( ) ) ) . thenReturn (
20742061 new Promise ( resolve => {
0 commit comments