From a202ddc1a7190ba9e42edd88f07cb761284dab63 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Thu, 13 Oct 2022 08:18:37 -0700 Subject: [PATCH] LP1839341 follow-up: no console error when reverting to unset value Signed-off-by: Jane Sandberg --- ...g-unit-setting-history-dialog.component.spec.ts | 36 ++++++++++++++++++++ .../org-unit-setting-history-dialog.component.ts | 24 +++++++------ 2 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-history-dialog.component.spec.ts diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-history-dialog.component.spec.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-history-dialog.component.spec.ts new file mode 100644 index 0000000..2959d79 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-history-dialog.component.spec.ts @@ -0,0 +1,36 @@ +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { OrgService } from '@eg/core/org.service'; +import { OuSettingHistoryDialogComponent } from "./org-unit-setting-history-dialog.component"; + +describe('OuSettingHistoryDialogComponent', () => { + let component: OuSettingHistoryDialogComponent; + const mockOrg = { + a: [], + classname: 'acp', + _isfieldmapper: true, + id: () => 22 + }; + + const orgServiceSpy = jasmine.createSpyObj(['get']); + const modalSpy = jasmine.createSpyObj(['open']); + orgServiceSpy.get.and.returnValue(mockOrg); + component = new OuSettingHistoryDialogComponent(orgServiceSpy, modalSpy); + + it('can revert a change back to a null value', () => { + const mockLog = { + original_value: null, + org: 22 + }; + const mockSetting = { + name: 'my.setting' + }; + spyOn(component, 'close'); + component.entry = mockSetting; + component.revert(mockLog); + expect(component.close).toHaveBeenCalledWith({ + setting: {'my.setting': null}, + context: mockOrg, + revert: true + }); + }); +}); diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-history-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-history-dialog.component.ts index 3b297cc..678b031 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-history-dialog.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-history-dialog.component.ts @@ -43,18 +43,20 @@ export class OuSettingHistoryDialogComponent extends DialogComponent implements revert(log) { if (log) { - const intTypes = ['integer', 'currency', 'link']; - if (intTypes.includes(this.entry.dataType)) { - log.original_value = Number(log.original_value); - } else { - log.original_value = log.original_value.replace(/^"(.*)"$/, '$1'); - } - - if (this.entry.dataType === 'bool') { - if (log.original_value.match(/^t/)) { - log.original_value = true; + if (log.original_value) { + const intTypes = ['integer', 'currency', 'link']; + if (intTypes.includes(this.entry.dataType)) { + log.original_value = Number(log.original_value); } else { - log.original_value = false; + log.original_value = log.original_value.replace(/^"(.*)"$/, '$1'); + } + + if (this.entry.dataType === 'bool') { + if (log.original_value.match(/^t/)) { + log.original_value = true; + } else { + log.original_value = false; + } } } -- 1.7.2.5