Warning, /firebird/firebird-ng/src/app/utils/config-property.spec.ts is written in an unsupported language. File is not indexed.
0001 import {ConfigProperty} from "./config-property"
0002
0003 describe('ConfigProperty', () => {
0004 let configProperty: ConfigProperty<string>;
0005 let mockSaveCallback: jasmine.Spy;
0006 let defaultValue: string;
0007 let key: string;
0008
0009 beforeEach(() => {
0010 key = 'testKey';
0011 defaultValue = 'default';
0012 mockSaveCallback = jasmine.createSpy('saveCallback');
0013
0014 configProperty = new ConfigProperty<string>(key, defaultValue, mockSaveCallback);
0015 });
0016
0017 it('should initialize with default value if no value in localStorage', () => {
0018 localStorage.removeItem(key);
0019 configProperty = new ConfigProperty<string>(key, defaultValue);
0020 expect(configProperty.value).toBe(defaultValue);
0021 });
0022
0023 it('should use stored value if available', () => {
0024 const storedValue = "stored";
0025 localStorage.setItem(key, storedValue);
0026 configProperty = new ConfigProperty<string>(key, defaultValue);
0027 expect(configProperty.value).toBe(storedValue);
0028 });
0029
0030 it('should call saveCallback when setting value', () => {
0031 const newValue = 'new value';
0032 configProperty.value = newValue;
0033 expect(configProperty.value).toBe(newValue);
0034 expect(mockSaveCallback).toHaveBeenCalled();
0035 });
0036
0037 it('should not change value if validator fails', () => {
0038 const badValue = 'bad';
0039 configProperty = new ConfigProperty<string>(key, defaultValue, mockSaveCallback, (value) => false);
0040 configProperty.value = badValue;
0041
0042 expect(configProperty.value).toBe(defaultValue); // Still the default, not the bad value
0043 expect(mockSaveCallback).not.toHaveBeenCalled();
0044 });
0045
0046 // Additional tests to cover other scenarios...
0047 });