From 3099bb13824e1b07e20ec766aaedd5a6e0351eac Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Tue, 10 Jan 2023 16:59:14 -0800 Subject: [PATCH] LP1999401: Don't apply magic statuses from holdings editor templates 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 . 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 --- .../staff/cat/volcopy/copy-attrs.component.spec.ts | 48 ++++++++++++++++++++++ .../app/staff/cat/volcopy/copy-attrs.component.ts | 12 +----- 2 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.spec.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 index 0000000000..1236b2a69a --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.spec.ts @@ -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(['clone']); + const orgMock = jasmine.createSpyObj(['get']); + const authServiceMock = jasmine.createSpyObj(['user']); + const formatServiceMock = jasmine.createSpyObj(['transform']); + const storeServiceMock = jasmine.createSpyObj(['setLocalItem']); + const fileExportServiceMock = jasmine.createSpyObj(['exportFile']); + const toastServiceMock = jasmine.createSpyObj(['success']); + const volCopyServiceMock = jasmine.createSpyObj(['copyStatIsMagic']); + + beforeEach(() => { + component = new CopyAttrsComponent(idlMock, orgMock, authServiceMock, + formatServiceMock, storeServiceMock, fileExportServiceMock, + toastServiceMock, volCopyServiceMock); + component.copyTemplateCbox = jasmine.createSpyObj(['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(); + })); + }); + }) +}); diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts index 624e7bcf18..a1eafa9368 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts @@ -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 = new EventEmitter(); 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 => { -- 2.11.0