LP1839341 follow-up: no console error when reverting to unset value
authorJane Sandberg <sandbergja@gmail.com>
Thu, 13 Oct 2022 15:18:37 +0000 (08:18 -0700)
committerJane Sandberg <sandbergja@gmail.com>
Thu, 13 Oct 2022 16:05:44 +0000 (09:05 -0700)
Signed-off-by: Jane Sandberg <sandbergja@gmail.com>

Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-history-dialog.component.spec.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-history-dialog.component.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 (file)
index 0000000..2959d79
--- /dev/null
@@ -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<OrgService>(['get']);
+    const modalSpy = jasmine.createSpyObj<NgbModal>(['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
+        });
+    });
+});
index 3b297cc..678b031 100644 (file)
@@ -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;
+                    }
                 }
             }