Skip to content

Commit 89e0fd9

Browse files
committed
Fix what ain't broke. Apply await patterns in other spec files
1 parent 44b0234 commit 89e0fd9

File tree

14 files changed

+157
-181
lines changed

14 files changed

+157
-181
lines changed

src/SIL.XForge.Scripture/ClientApp/src/app/checking/chapter-audio-dialog/chapter-audio-dialog.component.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,18 +368,18 @@ describe('ChapterAudioDialogComponent', () => {
368368
expect(result.timingData[1].to).toEqual(1.296);
369369
}));
370370

371-
it('will not save or upload if there is no audio', fakeAsync(() => {
371+
it('will not save or upload if there is no audio', fakeAsync(async () => {
372372
env.component.prepareTimingFileUpload(env.timingFile);
373-
env.component.save();
373+
await env.component.save();
374374
env.fixture.detectChanges();
375375

376376
expect(env.numberOfTimesDialogClosed).toEqual(0);
377377
expect(env.wrapperAudio.classList.contains('invalid')).toBe(true);
378378
}));
379379

380-
it('will not save or upload if there is no timing data', fakeAsync(() => {
380+
it('will not save or upload if there is no timing data', fakeAsync(async () => {
381381
env.component.audioUpdate(env.audioFile);
382-
env.component.save();
382+
await env.component.save();
383383
env.fixture.detectChanges();
384384

385385
expect(env.numberOfTimesDialogClosed).toEqual(0);
@@ -478,15 +478,15 @@ describe('ChapterAudioDialogComponent', () => {
478478
expect(env.wrapperTiming.classList.contains('valid')).toBe(true);
479479
}));
480480

481-
it('will not try to save dialog if offline', fakeAsync(() => {
481+
it('will not try to save dialog if offline', fakeAsync(async () => {
482482
env.onlineStatus = false;
483483
env.component.audioUpdate(env.audioFile);
484484
tick();
485485
env.component.prepareTimingFileUpload(env.timingFile);
486486
tick();
487487

488488
// SUT
489-
env.component.save();
489+
await env.component.save();
490490
tick();
491491
env.fixture.detectChanges();
492492
flush();

src/SIL.XForge.Scripture/ClientApp/src/app/my-projects/my-projects.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ describe('MyProjectsComponent', () => {
104104
expect(env.router.url).toEqual('/projects/sf-cbntt');
105105
}));
106106

107-
it('user cannot join a project while offline', fakeAsync(() => {
107+
it('user cannot join a project while offline', fakeAsync(async () => {
108108
const env = new TestEnvironment();
109109
env.waitUntilLoaded();
110110
env.onlineStatus = false;
111111
expect(env.messageOffline).not.toBeNull();
112112
expect(env.buttonForUnconnectedProject('pt-connButNotThisUser').nativeElement.disabled).toBe(true);
113-
env.component.joinProject('sf-cbntt');
113+
await env.component.joinProject('sf-cbntt');
114114
tick();
115115
env.fixture.detectChanges();
116116
verify(mockedNoticeService.show(anything())).once();

src/SIL.XForge.Scripture/ClientApp/src/app/shared/text/text.component.spec.ts

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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 => {

src/SIL.XForge.Scripture/ClientApp/src/app/sync/sync-progress/sync-progress.component.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('SyncProgressComponent', () => {
5151

5252
it('does not initialize if app is offline', fakeAsync(async () => {
5353
const env = new TestEnvironment({ userId: 'user01' });
54-
env.setupProjectDoc();
54+
await env.setupProjectDoc();
5555
env.onlineStatus = false;
5656
verify(mockedProjectService.subscribe('sourceProject02', anything())).never();
5757
expect(await env.getMode()).toBe('indeterminate');
@@ -60,7 +60,7 @@ describe('SyncProgressComponent', () => {
6060
it('ignores source if source project is invalid', fakeAsync(async () => {
6161
when(mockedProjectService.onlineGetProjectRole('invalid_source')).thenResolve(SFProjectRole.None);
6262
const env = new TestEnvironment({ userId: 'user01', sourceProject: 'invalid_source' });
63-
env.setupProjectDoc();
63+
await env.setupProjectDoc();
6464
verify(mockedProjectService.onlineGetProjectRole('invalid_source')).once();
6565
await env.updateSyncProgress(0.5, 'testProject01');
6666
expect(env.host.inProgress).toBe(true);
@@ -72,7 +72,7 @@ describe('SyncProgressComponent', () => {
7272

7373
it('should show progress when sync is active', fakeAsync(async () => {
7474
const env = new TestEnvironment({ userId: 'user01' });
75-
env.setupProjectDoc();
75+
await env.setupProjectDoc();
7676
// Simulate sync starting
7777
await env.updateSyncProgress(0, 'testProject01');
7878
expect(env.progressBar).not.toBeNull();
@@ -93,7 +93,7 @@ describe('SyncProgressComponent', () => {
9393
sourceProject: 'sourceProject02',
9494
translationSuggestionsEnabled: true
9595
});
96-
env.setupProjectDoc();
96+
await env.setupProjectDoc();
9797
await env.checkCombinedProgress();
9898
expect(env.syncStatus).not.toBeNull();
9999
tick();
@@ -105,15 +105,15 @@ describe('SyncProgressComponent', () => {
105105
sourceProject: 'sourceProject02',
106106
translationSuggestionsEnabled: false
107107
});
108-
env.setupProjectDoc();
108+
await env.setupProjectDoc();
109109
await env.checkCombinedProgress();
110110
expect(env.syncStatus).not.toBeNull();
111111
tick();
112112
}));
113113

114114
it('does not access source project if user does not have a paratext role', fakeAsync(async () => {
115115
const env = new TestEnvironment({ userId: 'user02', sourceProject: 'sourceProject02' });
116-
env.setupProjectDoc();
116+
await env.setupProjectDoc();
117117
await env.updateSyncProgress(0, 'testProject01');
118118
await env.updateSyncProgress(0, 'sourceProject02');
119119
verify(mockedProjectService.subscribe('sourceProject02', anything())).never();
@@ -124,10 +124,10 @@ describe('SyncProgressComponent', () => {
124124
await env.emitSyncComplete(true, 'testProject01');
125125
}));
126126

127-
it('does not throw error if get project role times out', fakeAsync(() => {
127+
it('does not throw error if get project role times out', fakeAsync(async () => {
128128
const env = new TestEnvironment({ userId: 'user01', sourceProject: 'sourceProject02' });
129129
when(mockedProjectService.onlineGetProjectRole('sourceProject02')).thenReject(new Error('504: Gateway Timeout'));
130-
env.setupProjectDoc();
130+
await env.setupProjectDoc();
131131
verify(mockedProjectService.onlineGetProjectRole('sourceProject02')).once();
132132
verify(mockedProjectService.subscribe('sourceProject02', anything())).never();
133133
verify(mockedErrorReportingService.silentError(anything(), anything())).once();
@@ -147,8 +147,8 @@ class HostComponent {
147147

148148
constructor(private readonly projectService: SFProjectService) {}
149149

150-
setProjectDoc(): void {
151-
this.projectService.subscribe('testProject01', new DocSubscription('spec')).then(doc => (this.projectDoc = doc));
150+
async setProjectDoc(): Promise<void> {
151+
this.projectDoc = await this.projectService.subscribe('testProject01', new DocSubscription('spec'));
152152
}
153153
}
154154

@@ -272,8 +272,8 @@ class TestEnvironment {
272272
this.fixture.detectChanges();
273273
}
274274

275-
setupProjectDoc(): void {
276-
this.host.setProjectDoc();
275+
async setupProjectDoc(): Promise<void> {
276+
await this.host.setProjectDoc();
277277
tick();
278278
this.fixture.detectChanges();
279279
tick();

src/SIL.XForge.Scripture/ClientApp/src/app/translate/draft-generation/draft-sources/draft-sources.component.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe('DraftSourcesComponent', () => {
174174
verify(mockedDialogService.confirm(anything(), anything(), anything())).never();
175175

176176
// SUT
177-
env.component.save();
177+
await env.component.save();
178178
tick();
179179
verify(mockedSFProjectService.onlineUpdateSettings(env.activatedProjectDoc.id, anything())).once();
180180
const actualSettingsChangeRequest: SFProjectSettings = capture(
@@ -219,7 +219,7 @@ describe('DraftSourcesComponent', () => {
219219
verify(mockedDialogService.confirm(anything(), anything(), anything())).once();
220220

221221
// SUT
222-
env.component.save();
222+
await env.component.save();
223223
tick();
224224
verify(mockedSFProjectService.onlineUpdateSettings(env.activatedProjectDoc.id, anything())).once();
225225
const actualSettingsChangeRequest: SFProjectSettings = capture(
@@ -262,7 +262,7 @@ describe('DraftSourcesComponent', () => {
262262
tick();
263263

264264
// SUT
265-
env.component.save();
265+
await env.component.save();
266266
tick();
267267
verify(mockedSFProjectService.onlineUpdateSettings(env.activatedProjectDoc.id, anything())).once();
268268
const actualSettingsChangeRequest: SFProjectSettings = capture(
@@ -291,7 +291,7 @@ describe('DraftSourcesComponent', () => {
291291
);
292292

293293
// SUT
294-
env.component.save();
294+
await env.component.save();
295295
tick();
296296
verify(mockedSFProjectService.onlineUpdateSettings(env.activatedProjectDoc.id, anything())).once();
297297
}));
@@ -339,7 +339,7 @@ describe('DraftSourcesComponent', () => {
339339

340340
env.component.onTrainingDataSelect([{ dataId: 'test1' } as TrainingData, { dataId: 'test2' } as TrainingData]);
341341

342-
env.component.save();
342+
await env.component.save();
343343
tick();
344344
verify(mockedSFProjectService.onlineUpdateSettings(env.activatedProjectDoc.id, anything())).once();
345345
const actualSettingsChangeRequest: SFProjectSettings = capture(
@@ -363,7 +363,7 @@ describe('DraftSourcesComponent', () => {
363363

364364
const newFile = { dataId: 'test1' } as TrainingData;
365365
env.component.onTrainingDataSelect([newFile]);
366-
env.component.save();
366+
await env.component.save();
367367

368368
verify(mockTrainingDataService.createTrainingDataAsync(newFile)).once();
369369
}));
@@ -387,7 +387,7 @@ describe('DraftSourcesComponent', () => {
387387
expect(env.component.availableTrainingFiles.length).toEqual(2);
388388

389389
env.component.onTrainingDataSelect([savedFile1]);
390-
env.component.save();
390+
await env.component.save();
391391
tick();
392392

393393
verify(mockTrainingDataService.deleteTrainingDataAsync(savedFile2)).once();

src/SIL.XForge.Scripture/ClientApp/src/app/translate/editor/editor.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2546,7 +2546,7 @@ describe('EditorComponent', () => {
25462546
const insert: string = 'abc';
25472547
const deltaOps: DeltaOperation[] = [{ retain: remoteEditTextPos }, { insert: insert }];
25482548
const textDoc: TextDoc = await env.getTextDoc(new TextDocId('project01', 40, 1));
2549-
textDoc.submit(new Delta(deltaOps));
2549+
await textDoc.submit(new Delta(deltaOps));
25502550

25512551
env.wait();
25522552
expect(env.getNoteThreadEditorPosition('dataid02')).toEqual(notePosition);

0 commit comments

Comments
 (0)