[TLC-674] New duplicate data service, object reducer tests

This commit is contained in:
Kim Shepherd
2024-03-04 14:29:26 +13:00
parent ca32314951
commit e4a91e7261
4 changed files with 53 additions and 3 deletions

View File

@@ -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);
});
});
});

View File

@@ -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,

View File

@@ -867,6 +867,7 @@ export type SubmissionObjectAction = DisableSectionAction
| InitSubmissionFormAction
| ResetSubmissionFormAction
| CancelSubmissionFormAction
| CleanDuplicateDetectionAction
| CompleteInitSubmissionFormAction
| ChangeSubmissionCollectionAction
| SaveAndDepositSubmissionAction

View File

@@ -1,7 +1,7 @@
import { submissionObjectReducer, SubmissionObjectState } from './submission-objects.reducer';
import {
CancelSubmissionFormAction,
ChangeSubmissionCollectionAction,
ChangeSubmissionCollectionAction, CleanDuplicateDetectionAction,
CompleteInitSubmissionFormAction,
DeleteSectionErrorsAction,
DeleteUploadedFileAction,
@@ -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);
@@ -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();
});
});