Skip to content

Commit 32028bb

Browse files
authored
Be specific about draft ability in app.component.spec (#3445)
Avoid a potential race in what menu items test 'navigate to last project' finds by specifying NmtDraftAuthGuard.allowTransition. As such, expect a 10th menu item of "Generate draft". This test also slightly increases the coupling of the named menu items in the comment with the count of menu items expected, as well as changing from "Manage questions" to "My progress".
1 parent 9fb088b commit 32028bb

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ import { SF_TYPE_REGISTRY } from './core/models/sf-type-registry';
4444
import { SFProjectService } from './core/sf-project.service';
4545
import { NavigationComponent } from './navigation/navigation.component';
4646
import { GlobalNoticesComponent } from './shared/global-notices/global-notices.component';
47-
import { SettingsAuthGuard, SyncAuthGuard, UsersAuthGuard } from './shared/project-router.guard';
47+
import { NmtDraftAuthGuard, SettingsAuthGuard, SyncAuthGuard, UsersAuthGuard } from './shared/project-router.guard';
4848
import { paratextUsersFromRoles } from './shared/test-utils';
4949

5050
const mockedAuthService = mock(AuthService);
5151
const mockedUserService = mock(UserService);
5252
const mockedSettingsAuthGuard = mock(SettingsAuthGuard);
5353
const mockedSyncAuthGuard = mock(SyncAuthGuard);
5454
const mockedUsersAuthGuard = mock(UsersAuthGuard);
55+
const mockedNmtDraftAuthGuard = mock(NmtDraftAuthGuard);
5556
const mockedSFProjectService = mock(SFProjectService);
5657
const mockedCookieService = mock(CookieService);
5758
const mockedLocationService = mock(LocationService);
@@ -102,6 +103,7 @@ describe('AppComponent', () => {
102103
{ provide: SettingsAuthGuard, useMock: mockedSettingsAuthGuard },
103104
{ provide: SyncAuthGuard, useMock: mockedSyncAuthGuard },
104105
{ provide: UsersAuthGuard, useMock: mockedUsersAuthGuard },
106+
{ provide: NmtDraftAuthGuard, useMock: mockedNmtDraftAuthGuard },
105107
{ provide: SFProjectService, useMock: mockedSFProjectService },
106108
{ provide: CookieService, useMock: mockedCookieService },
107109
{ provide: LocationService, useMock: mockedLocationService },
@@ -129,9 +131,20 @@ describe('AppComponent', () => {
129131

130132
expect(env.isDrawerVisible).toEqual(true);
131133
expect(env.selectedProjectId).toEqual('project01');
132-
// Translate | Overview | Edit & review | Community Checking | Manage questions | Questions & answers |
133-
// Synchronize | Users | Settings
134-
expect(env.menuLength).toEqual(9);
134+
135+
const expectedMenuItemCount = [
136+
'Translate',
137+
'Overview',
138+
'Edit & review',
139+
'Generate draft',
140+
'Community Checking',
141+
'My progress',
142+
'Questions & answers',
143+
'Sync with Paratext',
144+
'Users',
145+
'Settings'
146+
].length;
147+
expect(env.menuLength).toEqual(expectedMenuItemCount);
135148
verify(mockedUserService.setCurrentProjectId(anything(), 'project01')).once();
136149
tick();
137150
}));
@@ -143,8 +156,15 @@ describe('AppComponent', () => {
143156

144157
expect(env.isDrawerVisible).toEqual(true);
145158
expect(env.selectedProjectId).toEqual('project02');
146-
// Expect: Community Checking | Manage Questions | Overview | Sync | Settings | Users
147-
expect(env.menuLength).toEqual(6);
159+
const expectedMenuItemCount: number = [
160+
'Community Checking',
161+
'My progress',
162+
'Overview',
163+
'Sync with Paratext',
164+
'Settings',
165+
'Users'
166+
].length;
167+
expect(env.menuLength).toEqual(expectedMenuItemCount);
148168
verify(mockedUserService.setCurrentProjectId(anything(), 'project02')).once();
149169
discardPeriodicTasks();
150170
}));
@@ -700,6 +720,7 @@ class TestEnvironment {
700720
when(mockedSettingsAuthGuard.allowTransition(anything())).thenReturn(this.canSeeSettings$);
701721
when(mockedSyncAuthGuard.allowTransition(anything())).thenReturn(this.canSync$);
702722
when(mockedUsersAuthGuard.allowTransition(anything())).thenReturn(this.canSeeUsers$);
723+
when(mockedNmtDraftAuthGuard.allowTransition(anything())).thenReturn(this.canSeeGenerateDraft$);
703724
when(mockedI18nService.localeCode).thenReturn('en');
704725
when(mockedUrlService.helps).thenReturn('helps');
705726
when(mockedUrlService.announcementPage).thenReturn('community-announcements');

0 commit comments

Comments
 (0)