--- /dev/null
+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
+ });
+ });
+});
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;
+ }
}
}