Skip to content

Commit

Permalink
[TLC-674] New duplicate data service, object reducer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kshepherd committed Mar 4, 2024
1 parent ca32314 commit e4a91e7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/app/core/submission/submission-duplicate-data.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { SubmissionDuplicateDataService } from './submission-duplicate-data.service';
import { FindListOptions } from '../data/find-list-options.model';
import { RequestParam } from '../cache/models/request-param.model';

/**
* Basic tests for the submission-duplicate-data.service.ts service
*/
describe('SubmissionDuplicateDataService', () => {
const duplicateDataService = new SubmissionDuplicateDataService(null, null, null, null);

// Test the findDuplicates method to make sure that a call results in an expected
// call to searchBy, using the 'findByItem' search method
describe('findDuplicates', () => {
beforeEach(() => {
spyOn(duplicateDataService, 'searchBy');
});

it('should call searchBy with the correct arguments', () => {
// Set up expected search parameters and find options
const searchParams = [];
searchParams.push(new RequestParam('uuid', 'test'));
let findListOptions = new FindListOptions();
findListOptions.searchParams = searchParams;
// Perform test search using uuid 'test' using the findDuplicates method
const result = duplicateDataService.findDuplicates('test', new FindListOptions(), true, true);
// Expect searchBy('findByItem'...) to have been used as SearchData impl with the expected options (uuid=test)
expect(duplicateDataService.searchBy).toHaveBeenCalledWith('findByItem', findListOptions, true, true);
});
});
});
5 changes: 4 additions & 1 deletion src/app/shared/mocks/submission.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,10 @@ export const mockSubmissionState: SubmissionObjectState = Object.assign({}, {
isLoading: false,
isValid: false,
removePending: false
} as any
} as any,
'duplicates': {
potentialDuplicates: []
} as any,
},
isLoading: false,
savePending: false,
Expand Down
1 change: 1 addition & 0 deletions src/app/submission/objects/submission-objects.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ export type SubmissionObjectAction = DisableSectionAction
| InitSubmissionFormAction
| ResetSubmissionFormAction
| CancelSubmissionFormAction
| CleanDuplicateDetectionAction
| CompleteInitSubmissionFormAction
| ChangeSubmissionCollectionAction
| SaveAndDepositSubmissionAction
Expand Down
20 changes: 18 additions & 2 deletions src/app/submission/objects/submission-objects.reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { submissionObjectReducer, SubmissionObjectState } from './submission-objects.reducer';
import {
CancelSubmissionFormAction,
ChangeSubmissionCollectionAction,
ChangeSubmissionCollectionAction, CleanDuplicateDetectionAction,
CompleteInitSubmissionFormAction,
DeleteSectionErrorsAction,
DeleteUploadedFileAction,
Expand Down Expand Up @@ -273,7 +273,7 @@ describe('submissionReducer test suite', () => {
expect(newState[826].sections.traditionalpagetwo.enabled).toBeTruthy();
});

it('should enable submission section properly', () => {
it('should disable submission section properly', () => {

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

it('should enable duplicates section properly', () => {

let action: SubmissionObjectAction = new EnableSectionAction(submissionId, 'duplicates');
let newState = submissionObjectReducer(initState, action);

expect(newState[826].sections.duplicates.enabled).toBeTruthy();
});

it('should clean duplicates section properly', () => {

let action = new CleanDuplicateDetectionAction(submissionId);
let newState = submissionObjectReducer(initState, action);

expect(newState[826].sections.duplicates.enabled).toBeFalsy();
});

});

0 comments on commit e4a91e7

Please sign in to comment.