Fix objectUpdatesReducer no expectation tests

Added a expect().nothing() to the test who don't expect anything but just ensure that no error is thrown
This commit is contained in:
Alexandre Vryghem
2023-07-01 13:10:57 +02:00
parent bfaea741d5
commit 3640d75e10
2 changed files with 36 additions and 10 deletions

View File

@@ -12,7 +12,7 @@ import {
SetEditableFieldUpdateAction, SetEditableFieldUpdateAction,
SetValidFieldUpdateAction SetValidFieldUpdateAction
} from './object-updates.actions'; } from './object-updates.actions';
import { OBJECT_UPDATES_TRASH_PATH, objectUpdatesReducer } from './object-updates.reducer'; import { OBJECT_UPDATES_TRASH_PATH, objectUpdatesReducer, ObjectUpdatesState } from './object-updates.reducer';
import { Relationship } from '../../shared/item-relationships/relationship.model'; import { Relationship } from '../../shared/item-relationships/relationship.model';
import { FieldChangeType } from './field-change-type.model'; import { FieldChangeType } from './field-change-type.model';
@@ -56,7 +56,7 @@ const modDate = new Date(2010, 2, 11);
const uuid = identifiable1.uuid; const uuid = identifiable1.uuid;
const url = 'test-object.url/edit'; const url = 'test-object.url/edit';
describe('objectUpdatesReducer', () => { describe('objectUpdatesReducer', () => {
const testState = { const testState: ObjectUpdatesState = {
[url]: { [url]: {
fieldStates: { fieldStates: {
[identifiable1.uuid]: { [identifiable1.uuid]: {
@@ -79,9 +79,6 @@ describe('objectUpdatesReducer', () => {
[identifiable2.uuid]: { [identifiable2.uuid]: {
field: { field: {
uuid: identifiable2.uuid, uuid: identifiable2.uuid,
key: 'dc.titl',
language: null,
value: 'New title'
}, },
changeType: FieldChangeType.ADD changeType: FieldChangeType.ADD
} }
@@ -93,7 +90,7 @@ describe('objectUpdatesReducer', () => {
} }
}; };
const discardedTestState = { const discardedTestState: ObjectUpdatesState = {
[url]: { [url]: {
fieldStates: { fieldStates: {
[identifiable1.uuid]: { [identifiable1.uuid]: {
@@ -139,9 +136,6 @@ describe('objectUpdatesReducer', () => {
[identifiable2.uuid]: { [identifiable2.uuid]: {
field: { field: {
uuid: identifiable2.uuid, uuid: identifiable2.uuid,
key: 'dc.titl',
language: null,
value: 'New title'
}, },
changeType: FieldChangeType.ADD changeType: FieldChangeType.ADD
} }
@@ -173,48 +167,80 @@ describe('objectUpdatesReducer', () => {
const action = new InitializeFieldsAction(url, [identifiable1, identifiable2], modDate); const action = new InitializeFieldsAction(url, [identifiable1, identifiable2], modDate);
// testState has already been frozen above // testState has already been frozen above
objectUpdatesReducer(testState, action); objectUpdatesReducer(testState, action);
// no expect required, deepFreeze will ensure an exception is thrown if the state
// is mutated, and any uncaught exception will cause the test to fail
expect().nothing();
}); });
it('should perform the SET_EDITABLE_FIELD action without affecting the previous state', () => { it('should perform the SET_EDITABLE_FIELD action without affecting the previous state', () => {
const action = new SetEditableFieldUpdateAction(url, uuid, false); const action = new SetEditableFieldUpdateAction(url, uuid, false);
// testState has already been frozen above // testState has already been frozen above
objectUpdatesReducer(testState, action); objectUpdatesReducer(testState, action);
// no expect required, deepFreeze will ensure an exception is thrown if the state
// is mutated, and any uncaught exception will cause the test to fail
expect().nothing();
}); });
it('should perform the ADD_FIELD action without affecting the previous state', () => { it('should perform the ADD_FIELD action without affecting the previous state', () => {
const action = new AddFieldUpdateAction(url, identifiable1update, FieldChangeType.UPDATE); const action = new AddFieldUpdateAction(url, identifiable1update, FieldChangeType.UPDATE);
// testState has already been frozen above // testState has already been frozen above
objectUpdatesReducer(testState, action); objectUpdatesReducer(testState, action);
// no expect required, deepFreeze will ensure an exception is thrown if the state
// is mutated, and any uncaught exception will cause the test to fail
expect().nothing();
}); });
it('should perform the DISCARD action without affecting the previous state', () => { it('should perform the DISCARD action without affecting the previous state', () => {
const action = new DiscardObjectUpdatesAction(url, null); const action = new DiscardObjectUpdatesAction(url, null);
// testState has already been frozen above // testState has already been frozen above
objectUpdatesReducer(testState, action); objectUpdatesReducer(testState, action);
// no expect required, deepFreeze will ensure an exception is thrown if the state
// is mutated, and any uncaught exception will cause the test to fail
expect().nothing();
}); });
it('should perform the REINSTATE action without affecting the previous state', () => { it('should perform the REINSTATE action without affecting the previous state', () => {
const action = new ReinstateObjectUpdatesAction(url); const action = new ReinstateObjectUpdatesAction(url);
// testState has already been frozen above // testState has already been frozen above
objectUpdatesReducer(testState, action); objectUpdatesReducer(testState, action);
// no expect required, deepFreeze will ensure an exception is thrown if the state
// is mutated, and any uncaught exception will cause the test to fail
expect().nothing();
}); });
it('should perform the REMOVE action without affecting the previous state', () => { it('should perform the REMOVE action without affecting the previous state', () => {
const action = new RemoveFieldUpdateAction(url, uuid); const action = new RemoveFieldUpdateAction(url, uuid);
// testState has already been frozen above // testState has already been frozen above
objectUpdatesReducer(testState, action); objectUpdatesReducer(testState, action);
// no expect required, deepFreeze will ensure an exception is thrown if the state
// is mutated, and any uncaught exception will cause the test to fail
expect().nothing();
}); });
it('should perform the REMOVE_FIELD action without affecting the previous state', () => { it('should perform the REMOVE_FIELD action without affecting the previous state', () => {
const action = new RemoveFieldUpdateAction(url, uuid); const action = new RemoveFieldUpdateAction(url, uuid);
// testState has already been frozen above // testState has already been frozen above
objectUpdatesReducer(testState, action); objectUpdatesReducer(testState, action);
// no expect required, deepFreeze will ensure an exception is thrown if the state
// is mutated, and any uncaught exception will cause the test to fail
expect().nothing();
}); });
it('should perform the SELECT_VIRTUAL_METADATA action without affecting the previous state', () => { it('should perform the SELECT_VIRTUAL_METADATA action without affecting the previous state', () => {
const action = new SelectVirtualMetadataAction(url, relationship.uuid, identifiable1.uuid, true); const action = new SelectVirtualMetadataAction(url, relationship.uuid, identifiable1.uuid, true);
// testState has already been frozen above // testState has already been frozen above
objectUpdatesReducer(testState, action); objectUpdatesReducer(testState, action);
// no expect required, deepFreeze will ensure an exception is thrown if the state
// is mutated, and any uncaught exception will cause the test to fail
expect().nothing();
}); });
it('should initialize all fields when the INITIALIZE action is dispatched, based on the payload', () => { it('should initialize all fields when the INITIALIZE action is dispatched, based on the payload', () => {

View File

@@ -77,7 +77,7 @@ export interface DeleteRelationship extends RelationshipIdentifiable {
*/ */
export interface ObjectUpdatesEntry { export interface ObjectUpdatesEntry {
fieldStates: FieldStates; fieldStates: FieldStates;
fieldUpdates: FieldUpdates; fieldUpdates?: FieldUpdates;
virtualMetadataSources: VirtualMetadataSources; virtualMetadataSources: VirtualMetadataSources;
lastModified: Date; lastModified: Date;
patchOperationService?: GenericConstructor<PatchOperationService>; patchOperationService?: GenericConstructor<PatchOperationService>;