Skip to content

Commit

Permalink
[TLC-277] Fixes to support unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kshepherd committed Jul 20, 2022
1 parent f43e601 commit 0a193b8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/app/shared/testing/sections-service.stub.ts
Expand Up @@ -17,6 +17,7 @@ export class SectionsServiceStub {
updateSectionData = jasmine.createSpy('updateSectionData');
setSectionError = jasmine.createSpy('setSectionError');
setSectionStatus = jasmine.createSpy('setSectionStatus');
isSectionActive = jasmine.createSpy('isSectionActive');
computeSectionConfiguredMetadata = jasmine.createSpy('computeSectionConfiguredMetadata');
getShownSectionErrors = jasmine.createSpy('getShownSectionErrors');
getSectionServerErrors = jasmine.createSpy('getSectionServerErrors');
Expand Down
Expand Up @@ -69,6 +69,7 @@ describe('submissionReducer test suite', () => {
sections: Object.create(null),
isLoading: true,
savePending: false,
saveDecisionPending: false,
depositPending: false,
}
};
Expand Down
Expand Up @@ -55,7 +55,7 @@ export class DetectDuplicateService {
* @param {boolean} isWorkFlow
* If TRUE the submission scope is the 'workflow'; 'workspace' otherwise.
* @return Observable<Object>
* Returns the list of the possible duplications
* Returns the list of the possible duplicates
*/
getDuplicateMatchesByScope(submissionId: string, sectionId: string, isWorkFlow: boolean): Observable<WorkspaceitemSectionDetectDuplicateObject> {
return this.getDuplicateMatches(submissionId, sectionId).pipe(
Expand Down
5 changes: 4 additions & 1 deletion src/app/submission/submission.service.spec.ts
Expand Up @@ -43,6 +43,8 @@ import { environment } from '../../environments/environment';
import { SubmissionJsonPatchOperationsService } from '../core/submission/submission-json-patch-operations.service';
import { SubmissionJsonPatchOperationsServiceStub } from '../shared/testing/submission-json-patch-operations-service.stub';
import {NotificationOptions} from '../shared/notifications/models/notification-options.model';
import {getMockScrollToService} from '../shared/mocks/scroll-to-service.mock';
import {ScrollToService} from '@nicky-lenaers/ngx-scroll-to';

describe('SubmissionService test suite', () => {
const collectionId = '43fe1f8c-09a6-4fcf-9c78-5d4fed8f2c8f';
Expand Down Expand Up @@ -388,6 +390,7 @@ describe('SubmissionService test suite', () => {
{ provide: Router, useValue: router },
{ provide: SubmissionRestService, useValue: restService },
{ provide: ActivatedRoute, useValue: new MockActivatedRoute() },
{ provide: ScrollToService, useValue: getMockScrollToService() },
{ provide: SearchService, useValue: searchService },
{ provide: RequestService, useValue: requestServce },
{ provide: SubmissionJsonPatchOperationsService, useValue: submissionJsonPatchOperationsService },
Expand Down Expand Up @@ -879,7 +882,7 @@ describe('SubmissionService test suite', () => {

expect((service as any).notificationsService.info).toHaveBeenCalledWith(null, 'submission.sections.general.metadata-extracted-new-section', null, true);
}));
it('should use the correct message when the sectionId is equal to \'detect-duplicte\'', fakeAsync(() => {
it('should use the correct message when the sectionId is equal to \'detect-duplicate\'', fakeAsync(() => {
const dtSetctionId = 'detect-duplicate';
spyOn((service as any).translate, 'get').and.returnValue(observableOf(dtSetctionId));
spyOn((service as any).notificationsService, 'warning');
Expand Down
21 changes: 19 additions & 2 deletions src/app/submission/submission.service.ts
Expand Up @@ -46,6 +46,8 @@ import { environment } from '../../environments/environment';
import { SubmissionJsonPatchOperationsService } from '../core/submission/submission-json-patch-operations.service';
import { SubmissionSectionObject } from './objects/submission-section-object.model';
import { SubmissionError } from './objects/submission-error.model';
import {ScrollToConfigOptions, ScrollToService} from '@nicky-lenaers/ngx-scroll-to';
import {NotificationOptions} from '../shared/notifications/models/notification-options.model';

/**
* A service that provides methods used in submission process.
Expand All @@ -65,13 +67,15 @@ export class SubmissionService {

private workspaceLinkPath = 'workspaceitems';
private workflowLinkPath = 'workflowitems';

/**
* Initialize service variables
* @param {NotificationsService} notificationsService
* @param {SubmissionRestService} restService
* @param {Router} router
* @param {RouteService} routeService
* @param {Store<SubmissionState>} store
* @param {ScrollToService} scrollToService
* @param {TranslateService} translate
* @param {SearchService} searchService
* @param {RequestService} requestService
Expand All @@ -82,6 +86,7 @@ export class SubmissionService {
protected router: Router,
protected routeService: RouteService,
protected store: Store<SubmissionState>,
protected scrollToService: ScrollToService,
protected translate: TranslateService,
protected searchService: SearchService,
protected requestService: RequestService,
Expand Down Expand Up @@ -498,8 +503,20 @@ export class SubmissionService {
* The section type
*/
notifyNewSection(submissionId: string, sectionId: string, sectionType?: SectionsType) {
const m = this.translate.instant('submission.sections.general.metadata-extracted-new-section', { sectionId });
this.notificationsService.info(null, m, null, true);
if (sectionType === SectionsType.DetectDuplicate || sectionId === 'detect-duplicate') {
this.setActiveSection(submissionId, sectionId);
const msg = this.translate.instant('submission.sections.detect-duplicate.duplicate-detected', {sectionId});
this.notificationsService.warning(null, msg, new NotificationOptions(10000));
const config: ScrollToConfigOptions = {
target: sectionId,
offset: -70
};

this.scrollToService.scrollTo(config);
} else {
const m = this.translate.instant('submission.sections.general.metadata-extracted-new-section', {sectionId});
this.notificationsService.info(null, m, null, true);
}
}

/**
Expand Down

0 comments on commit 0a193b8

Please sign in to comment.