LP1999401: Don't apply magic statuses from holdings editor templates
authorJane Sandberg <js7389@princeton.edu>
Wed, 11 Jan 2023 00:59:14 +0000 (16:59 -0800)
committerMichele Morgan <mmorgan@noblenet.org>
Fri, 3 Mar 2023 16:25:30 +0000 (11:25 -0500)
1. Create a new template in the holdings template editor with a few
different values in various fields.
2. Include a "magic" status in your template (like Lost or In
Transit).  To select it, you can type the first few characters
then press <Tab>.
3. Save your template.
4. Apply your template to an item.
5. Note that the copy status has changed to a magic status.
6. Apply this patch.
7. Try applying your template to another item.
8. Note that the copy status field doesn't change this time,
but other fields from your template should still apply.

Signed-off-by: Jane Sandberg <sandbergja@gmail.com>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.spec.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts

diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.spec.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.spec.ts
new file mode 100644 (file)
index 0000000..1236b2a
--- /dev/null
@@ -0,0 +1,48 @@
+import { QueryList } from "@angular/core";
+import { waitForAsync } from "@angular/core/testing";
+import { AuthService } from "@eg/core/auth.service";
+import { FormatService } from "@eg/core/format.service";
+import { IdlService } from "@eg/core/idl.service";
+import { OrgService } from "@eg/core/org.service";
+import { StoreService } from "@eg/core/store.service";
+import { ComboboxComponent } from "@eg/share/combobox/combobox.component";
+import { ToastService } from "@eg/share/toast/toast.service";
+import { FileExportService } from "@eg/share/util/file-export.service";
+import { CopyAttrsComponent } from "./copy-attrs.component";
+import { VolCopyService } from "./volcopy.service";
+
+describe('CopyAttrsComponent', () => {
+    let component: CopyAttrsComponent;
+    const idlMock = jasmine.createSpyObj<IdlService>(['clone']);
+    const orgMock = jasmine.createSpyObj<OrgService>(['get']);
+    const authServiceMock = jasmine.createSpyObj<AuthService>(['user']);
+    const formatServiceMock = jasmine.createSpyObj<FormatService>(['transform']);
+    const storeServiceMock = jasmine.createSpyObj<StoreService>(['setLocalItem']);
+    const fileExportServiceMock = jasmine.createSpyObj<FileExportService>(['exportFile']);
+    const toastServiceMock = jasmine.createSpyObj<ToastService>(['success']);
+    const volCopyServiceMock = jasmine.createSpyObj<VolCopyService>(['copyStatIsMagic']);
+
+    beforeEach(() => {
+        component = new CopyAttrsComponent(idlMock, orgMock, authServiceMock,
+            formatServiceMock, storeServiceMock, fileExportServiceMock,
+            toastServiceMock, volCopyServiceMock);
+        component.copyTemplateCbox = jasmine.createSpyObj<ComboboxComponent>(['entries']);
+        component.copyTemplateCbox.selected = {id: 0};
+    });
+    describe('#applyTemplate', () => {
+        describe('status field', () => {
+            it('does not apply a magic status to an item', waitForAsync(() => {
+                let template = { "status": 1 };
+                volCopyServiceMock.templates = [template];
+                volCopyServiceMock.copyStatIsMagic.and.returnValue(true);
+                component.batchAttrs = new QueryList();
+
+                spyOn(component, 'applyTemplate').and.callThrough();
+                spyOn(component, 'applyCopyValue').and.callThrough();
+
+                component.applyTemplate();
+                expect(component.applyCopyValue).not.toHaveBeenCalled();
+            }));
+        });
+    })
+});
index 624e7bc..a1eafa9 100644 (file)
@@ -1,15 +1,10 @@
 import {Component, Input, OnInit, AfterViewInit, ViewChild,
     EventEmitter, Output, QueryList, ViewChildren} from '@angular/core';
-import {Router, ActivatedRoute} from '@angular/router';
 import {SafeUrl} from '@angular/platform-browser';
 import {IdlObject, IdlService} from '@eg/core/idl.service';
-import {EventService} from '@eg/core/event.service';
 import {OrgService} from '@eg/core/org.service';
 import {StoreService} from '@eg/core/store.service';
-import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
-import {PcrudService} from '@eg/core/pcrud.service';
-import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
 import {VolCopyContext} from './volcopy';
 import {VolCopyService} from './volcopy.service';
 import {FormatService} from '@eg/core/format.service';
@@ -95,15 +90,9 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
     @Output() canSaveChange: EventEmitter<boolean> = new EventEmitter<boolean>();
 
     constructor(
-        private router: Router,
-        private route: ActivatedRoute,
-        private evt: EventService,
         private idl: IdlService,
         private org: OrgService,
-        private net: NetService,
         private auth: AuthService,
-        private pcrud: PcrudService,
-        private holdings: HoldingsService,
         private format: FormatService,
         private store: StoreService,
         private fileExport: FileExportService,
@@ -555,6 +544,7 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
             const value = template[field];
 
             if (value === null || value === undefined) { return; }
+            if (field === 'status' && this.volcopy.copyStatIsMagic(value)) { return; }
 
             if (field === 'statcats') {
                 Object.keys(value).forEach(catId => {