[ADF-4457] StorageService should be independent of AppConfigService (#4712)

* [ADF-4457] StorageService should be independent of AppConfigService

* [ADF-4457] Fix e2e tests

* [ADF-4457] Fix e2e tests

* [ADF-4457] Improve storage service workflow

* Fix linting

* Fix unit tests

* Fix e2e test

* Add missing class to constructor

* Fix e2e test

* Rebase branch

* Improve unit test

* fix test
This commit is contained in:
davidcanonieto
2019-06-25 16:21:13 +01:00
committed by Eugenio Romano
parent 90c403ae9e
commit 5c07d5b3e6
29 changed files with 432 additions and 369 deletions

View File

@@ -29,69 +29,81 @@ describe('StorageService', () => {
const key = 'test_key';
const value = 'test_value';
setupTestBed({
imports: [CoreTestingModule],
providers: [
{ provide: AppConfigService, useClass: AppConfigServiceMock }
]
});
describe('StorageService', () => {
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
appConfig = TestBed.get(AppConfigService);
appConfig.config = {
application: {
storagePrefix: 'ADF_APP'
}
};
storage = TestBed.get(StorageService);
});
beforeEach(() => {
appConfig = TestBed.get(AppConfigService);
appConfig.config = {
application: {
storagePrefix: 'ADF_APP'
}
};
storage = TestBed.get(StorageService);
});
it('should get the prefix for the storage from app config', (done) => {
appConfig.load().then(() => {
expect(storage.storagePrefix).toBe('ADF_APP_');
done();
it('should get the prefix for the storage from app config', (done) => {
appConfig.load().then(() => {
expect(storage.prefix).toBe('ADF_APP_');
done();
});
});
it('should set a property with the prefix in the local storage', (done) => {
storage.clear();
appConfig.load().then(() => {
storage.setItem(key, value);
const storageKey = localStorage.key(0);
expect(storageKey).toBe('ADF_APP_' + key);
expect(localStorage.getItem(storageKey)).toBe(value);
done();
});
});
it('should be able to get a property from the local storage', (done) => {
storage.clear();
appConfig.load().then(() => {
storage.setItem(key, value);
expect(storage.getItem(key)).toBe(value);
done();
});
});
});
it('should set an empty prefix when the it is not defined in the app config', (done) => {
appConfig.config.application.storagePrefix = '';
appConfig.load().then(() => {
expect(storage.storagePrefix).toBe('');
done();
describe('StorageService', () => {
setupTestBed({
imports: [CoreTestingModule]
});
});
it('should set a property with the prefix in the local storage', (done) => {
storage.clear();
appConfig.load().then(() => {
storage.setItem(key, value);
expect(localStorage.hasOwnProperty('ADF_APP_' + key)).not.toBe(null);
expect(localStorage.getItem('ADF_APP_' + key)).toBe(value);
done();
beforeEach(() => {
appConfig = TestBed.get(AppConfigService);
appConfig.config = {
application: {
storagePrefix: ''
}
};
storage = TestBed.get(StorageService);
});
});
it('should set a property without a prefix in the local storage', (done) => {
storage.clear();
appConfig.config.application.storagePrefix = '';
appConfig.load().then(() => {
storage.setItem(key, value);
expect(localStorage.hasOwnProperty(key)).not.toBe(null);
expect(localStorage.getItem(key)).toBe(value);
done();
it('should set an empty prefix when the it is not defined in the app config', (done) => {
appConfig.load().then(() => {
expect(storage.prefix).toBe('');
done();
});
});
});
it('should be able to get a property from the local storage', (done) => {
storage.clear();
it('should set a property without a prefix in the local storage', (done) => {
appConfig.load().then(() => {
storage.setItem(key, value);
appConfig.load().then(() => {
storage.setItem(key, value);
expect(storage.getItem(key)).toBe(value);
done();
expect(localStorage.getItem(key)).toBe(value);
done();
});
});
});
});