[835] Auto-save in new Item Submission form breaks the form

Submission form Save button disabled when no pending operations are present
This commit is contained in:
Alessandro Martelli
2020-11-27 16:25:41 +01:00
parent d47f686b95
commit de372896e7
8 changed files with 95 additions and 4 deletions

View File

@@ -1,9 +1,8 @@
import { getTestScheduler } from 'jasmine-marbles';
import { getTestScheduler, hot } from 'jasmine-marbles';
import { TestScheduler } from 'rxjs/testing';
import { of as observableOf } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
import { RequestService } from '../data/request.service';
import { SubmissionPatchRequest } from '../data/request.models';
@@ -22,6 +21,7 @@ import {
} from './json-patch-operations.actions';
import { RequestEntry } from '../data/request.reducer';
import { createFailedRemoteDataObject, createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils';
import { _deepClone } from 'fast-json-patch/lib/helpers';
class TestService extends JsonPatchOperationsService<SubmitDataResponseDefinitionObject, SubmissionPatchRequest> {
protected linkPath = '';
@@ -196,6 +196,32 @@ describe('JsonPatchOperationsService test suite', () => {
});
});
describe('hasPendingOperations', () => {
it('should return true when there are pending operations', () => {
const expected = hot('(x|)', { x: true });
const result = service.hasPendingOperations(testJsonPatchResourceType);
expect(result).toBeObservable(expected);
});
it('should return false when there are not pending operations', () => {
const mockStateNoOp = _deepClone(mockState);
mockStateNoOp['json/patch'][testJsonPatchResourceType].children = [];
store.select.and.returnValue(observableOf(mockStateNoOp['json/patch'][testJsonPatchResourceType]));
const expected = hot('(x|)', { x: false });
const result = service.hasPendingOperations(testJsonPatchResourceType);
expect(result).toBeObservable(expected);
});
});
describe('jsonPatchByResourceID', () => {
it('should call submitJsonPatchOperations method', () => {

View File

@@ -161,6 +161,18 @@ export abstract class JsonPatchOperationsService<ResponseDefinitionDomain, Patch
return this.submitJsonPatchOperations(href$, resourceType);
}
/**
* Select the jsonPatch operation related to the specified resource type.
* @param resourceType
*/
public hasPendingOperations(resourceType: string): Observable<boolean> {
return this.store.select(jsonPatchOperationsByResourceType(resourceType)).pipe(
map((val) => !isEmpty(val) && Object.values(val.children)
.filter((section) => !isEmpty((section as any).body)).length > 0),
distinctUntilChanged(),
);
}
/**
* Make a new JSON Patch request with all operations related to the specified resource id
*