Skip to content

Commit e4a91e7

Browse files
committed
[TLC-674] New duplicate data service, object reducer tests
1 parent ca32314 commit e4a91e7

4 files changed

Lines changed: 53 additions & 3 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { SubmissionDuplicateDataService } from './submission-duplicate-data.service';
2+
import { FindListOptions } from '../data/find-list-options.model';
3+
import { RequestParam } from '../cache/models/request-param.model';
4+
5+
/**
6+
* Basic tests for the submission-duplicate-data.service.ts service
7+
*/
8+
describe('SubmissionDuplicateDataService', () => {
9+
const duplicateDataService = new SubmissionDuplicateDataService(null, null, null, null);
10+
11+
// Test the findDuplicates method to make sure that a call results in an expected
12+
// call to searchBy, using the 'findByItem' search method
13+
describe('findDuplicates', () => {
14+
beforeEach(() => {
15+
spyOn(duplicateDataService, 'searchBy');
16+
});
17+
18+
it('should call searchBy with the correct arguments', () => {
19+
// Set up expected search parameters and find options
20+
const searchParams = [];
21+
searchParams.push(new RequestParam('uuid', 'test'));
22+
let findListOptions = new FindListOptions();
23+
findListOptions.searchParams = searchParams;
24+
// Perform test search using uuid 'test' using the findDuplicates method
25+
const result = duplicateDataService.findDuplicates('test', new FindListOptions(), true, true);
26+
// Expect searchBy('findByItem'...) to have been used as SearchData impl with the expected options (uuid=test)
27+
expect(duplicateDataService.searchBy).toHaveBeenCalledWith('findByItem', findListOptions, true, true);
28+
});
29+
});
30+
});

src/app/shared/mocks/submission.mock.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,10 @@ export const mockSubmissionState: SubmissionObjectState = Object.assign({}, {
11141114
isLoading: false,
11151115
isValid: false,
11161116
removePending: false
1117-
} as any
1117+
} as any,
1118+
'duplicates': {
1119+
potentialDuplicates: []
1120+
} as any,
11181121
},
11191122
isLoading: false,
11201123
savePending: false,

src/app/submission/objects/submission-objects.actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ export type SubmissionObjectAction = DisableSectionAction
867867
| InitSubmissionFormAction
868868
| ResetSubmissionFormAction
869869
| CancelSubmissionFormAction
870+
| CleanDuplicateDetectionAction
870871
| CompleteInitSubmissionFormAction
871872
| ChangeSubmissionCollectionAction
872873
| SaveAndDepositSubmissionAction

src/app/submission/objects/submission-objects.reducer.spec.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { submissionObjectReducer, SubmissionObjectState } from './submission-objects.reducer';
22
import {
33
CancelSubmissionFormAction,
4-
ChangeSubmissionCollectionAction,
4+
ChangeSubmissionCollectionAction, CleanDuplicateDetectionAction,
55
CompleteInitSubmissionFormAction,
66
DeleteSectionErrorsAction,
77
DeleteUploadedFileAction,
@@ -273,7 +273,7 @@ describe('submissionReducer test suite', () => {
273273
expect(newState[826].sections.traditionalpagetwo.enabled).toBeTruthy();
274274
});
275275

276-
it('should enable submission section properly', () => {
276+
it('should disable submission section properly', () => {
277277

278278
let action: SubmissionObjectAction = new EnableSectionAction(submissionId, 'traditionalpagetwo');
279279
let newState = submissionObjectReducer(initState, action);
@@ -644,4 +644,20 @@ describe('submissionReducer test suite', () => {
644644
expect(newState[826].sections.upload.data).toEqual(expectedState);
645645
});
646646

647+
it('should enable duplicates section properly', () => {
648+
649+
let action: SubmissionObjectAction = new EnableSectionAction(submissionId, 'duplicates');
650+
let newState = submissionObjectReducer(initState, action);
651+
652+
expect(newState[826].sections.duplicates.enabled).toBeTruthy();
653+
});
654+
655+
it('should clean duplicates section properly', () => {
656+
657+
let action = new CleanDuplicateDetectionAction(submissionId);
658+
let newState = submissionObjectReducer(initState, action);
659+
660+
expect(newState[826].sections.duplicates.enabled).toBeFalsy();
661+
});
662+
647663
});

0 commit comments

Comments
 (0)