Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/SIL.XForge.Scripture/ClientApp/src/app/shared/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { Router } from '@angular/router';
import { VerseRef } from '@sillsdev/scripture';
import { SFProject } from 'realtime-server/lib/esm/scriptureforge/models/sf-project';
import { SFProjectRole } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-role';
import { createTestProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-test-data';
import { DeltaOperation } from 'rich-text';
import { anything, instance, mock, verify } from 'ts-mockito';
import { SelectableProject } from '../core/models/selectable-project';
import { SFProjectProfileDoc } from '../core/models/sf-project-profile-doc';
import {
booksFromScriptureRange,
checkAppAccess,
compareProjectsForSorting,
expandNumbers,
getBookFileNameDigits,
Expand Down Expand Up @@ -308,4 +314,63 @@ describe('shared utils', () => {
expect(parseDate(true)).toBeUndefined();
});
});
describe('checkAppAccess function', () => {
const userId = 'user01';
const projectRoute = '/projects/project01';

function createProjectDoc(role: SFProjectRole, checkingEnabled: boolean): SFProjectProfileDoc {
return {
id: 'project01',
data: createTestProjectProfile({ userRoles: { [userId]: role }, checkingConfig: { checkingEnabled } })
} as SFProjectProfileDoc;
}

it('leaves the community checking area when checking is disabled', () => {
const router = mock(Router);
checkAppAccess(
createProjectDoc(SFProjectRole.ParatextAdministrator, false),
userId,
`${projectRoute}/checking`,
instance(router)
);
verify(router.navigateByUrl(projectRoute, anything())).once();
expect().nothing();
});

it('stays in the community checking area when checking is enabled', () => {
const router = mock(Router);
checkAppAccess(
createProjectDoc(SFProjectRole.ParatextAdministrator, true),
userId,
`${projectRoute}/checking`,
instance(router)
);
verify(router.navigateByUrl(anything(), anything())).never();
expect().nothing();
});

it('leaves the community checking area when the role cannot access checking', () => {
const router = mock(Router);
checkAppAccess(
createProjectDoc(SFProjectRole.Commenter, true),
userId,
`${projectRoute}/checking`,
instance(router)
);
verify(router.navigateByUrl(projectRoute, anything())).once();
expect().nothing();
});

it('stays in the translate area when checking is disabled', () => {
const router = mock(Router);
checkAppAccess(
createProjectDoc(SFProjectRole.ParatextAdministrator, false),
userId,
`${projectRoute}/translate/MAT/1`,
instance(router)
);
verify(router.navigateByUrl(anything(), anything())).never();
expect().nothing();
});
});
});
5 changes: 4 additions & 1 deletion src/SIL.XForge.Scripture/ClientApp/src/app/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ export function checkAppAccess(
void router.navigateByUrl(route, { replaceUrl: true });
return;
}
if (pathname.includes('checking') && !roleCanAccessCommunityChecking(projectRole)) {
if (
pathname.includes('checking') &&
(!projectDoc.data.checkingConfig.checkingEnabled || !roleCanAccessCommunityChecking(projectRole))
) {
void router.navigateByUrl(route, { replaceUrl: true });
}
}
Expand Down
Loading