mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
committed by
Eugenio Romano
parent
90c403ae9e
commit
5c07d5b3e6
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user