From 0a7e1c2ca0d4c7c2023964af079b94da7f4c6d04 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Wed, 1 Mar 2023 04:58:07 -0800 Subject: [PATCH] LP1983628: Add editor for item notes Test plan: 1. Open your favorite bib record in the staff catalog 2. On the item table tab, find a barcode and click "Edit" 3. Press the Item Notes button. 4. Add a note with a title and value. 5. Press Apply Changes 6. Press Apply All and Save 7. Press the Item Notes button again. 8. Without this commit, you will not have a way to edit these notes. With this commit, you will have an edit button. 9. Confirm that you can Back out of the editor without making changes 10. Confirm that you can make changes and they persist. This commit also adds a test to confirm that this fm-editor won't inadvertently fetch every single row in asset.copy (as a linked field). Signed-off-by: Jane Sandberg Signed-off-by: Elaine Hardy Signed-off-by: Jason Boyer --- .../share/fm-editor/fm-editor.component.ts | 2 - .../src/app/share/fm-editor/fm-editor.spec.ts | 66 +++++++++++ .../holdings/copy-notes-dialog.component.html | 105 ++++++++++-------- .../holdings/copy-notes-dialog.component.ts | 16 ++- .../copy-notes-edit.component.html | 12 ++ .../copy-notes-edit.component.spec.ts | 37 ++++++ .../copy-notes-edit.component.ts | 13 +++ .../staff/share/holdings/holdings.module.ts | 6 +- 8 files changed, 207 insertions(+), 50 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.spec.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/share/holdings/copy-notes-edit/copy-notes-edit.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/share/holdings/copy-notes-edit/copy-notes-edit.component.spec.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/share/holdings/copy-notes-edit/copy-notes-edit.component.ts diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts index 77273ef721..c2594572f3 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts @@ -4,7 +4,6 @@ import {NgForm} from '@angular/forms'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {Observable} from 'rxjs'; import {map} from 'rxjs/operators'; -import {AuthService} from '@eg/core/auth.service'; import {PcrudService} from '@eg/core/pcrud.service'; import {OrgService} from '@eg/core/org.service'; import {DialogComponent} from '@eg/share/dialog/dialog.component'; @@ -262,7 +261,6 @@ export class FmRecordEditorComponent constructor( private modal: NgbModal, // required for passing to parent private idl: IdlService, - private auth: AuthService, private toast: ToastService, private format: FormatService, private org: OrgService, diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.spec.ts b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.spec.ts new file mode 100644 index 0000000000..5188408cb9 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.spec.ts @@ -0,0 +1,66 @@ +import { IdlService } from "@eg/core/idl.service"; +import { NgbModal } from "@ng-bootstrap/ng-bootstrap"; +import { ToastService } from "@eg/share/toast/toast.service"; +import { FmRecordEditorComponent } from "./fm-editor.component" +import { FormatService } from "@eg/core/format.service"; +import { OrgService } from "@eg/core/org.service"; +import { PcrudService } from "@eg/core/pcrud.service"; +import { waitForAsync } from "@angular/core/testing"; +import { of } from "rxjs"; + +describe('FmRecordEditorComponent', () => { + let component: FmRecordEditorComponent; + const mockPcrud = jasmine.createSpyObj(['retrieve']); + beforeEach(() => { + const mockModal = jasmine.createSpyObj(['open']); + const mockIdl = jasmine.createSpyObj(['pkeyMatches', 'getClassSelector', 'sortIdlFields'], {classes: { + 'mock': { + label: 'Mock Class', + fields: [ + {datatype: 'link', name: 'linked_field', class: 'linked'} + ] + }, + 'linked': {pkey: 'id'} + }}); + mockIdl.pkeyMatches.and.returnValue(true); + mockIdl.getClassSelector.and.returnValue('label'); + const mockToast = jasmine.createSpyObj(['success']); + const mockFormat = jasmine.createSpyObj([], {wsOrgTimezone: 'America/Los_Angeles'}); + const mockOrg = jasmine.createSpyObj(['get']); + mockPcrud.retrieve.and.callFake((fmClass, pkey) => { + if (fmClass === 'mock') { + return of({ + a: [], + classname: 'mock', + _isfieldmapper: true, + 'linked_field': () => 456 + }); + } else { + return of({ + id: () => 456, + label: () => 'My Config Value' + }); + } + }); + + component = new FmRecordEditorComponent( + mockModal, mockIdl, mockToast, mockFormat, mockOrg, mockPcrud + ); + + }) + describe('hidden fields', () => { + it('fetches only one row of linked values', waitForAsync(() => { + component.idlClass = 'mock'; + component.readonlyFields = 'linked_field'; + component.mode = 'update'; + component.displayMode = 'inline'; + component.recordId = 123; + component.ngOnInit(); + // wait for ngOnInit to do its work + setTimeout(() => { + expect(mockPcrud.retrieve).toHaveBeenCalledWith('mock', 123); + expect(mockPcrud.retrieve).toHaveBeenCalledWith('linked', 456); + }, 100) + })); + }); +}); diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-notes-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-notes-dialog.component.html index d15ee7aa61..93f58508ad 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-notes-dialog.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-notes-dialog.component.html @@ -15,60 +15,73 @@ -