mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[ACA-3765] [ADF] move reusable versioning logic (#5906)
This commit is contained in:
parent
a2a2f8c93c
commit
5a820cbecd
@ -17,7 +17,6 @@
|
||||
|
||||
import { Directive, Input, ViewContainerRef, TemplateRef } from '@angular/core';
|
||||
import { VersionCompatibilityService } from '../services/version-compatibility.service';
|
||||
import { VersionModel } from '../models/product-version.model';
|
||||
|
||||
@Directive({
|
||||
selector: '[adf-acs-version]'
|
||||
@ -38,45 +37,10 @@ export class VersionCompatibilityDirective {
|
||||
}
|
||||
|
||||
private validateAcsVersion(requiredVersion: string) {
|
||||
if (requiredVersion && this.isVersionSupported(requiredVersion)) {
|
||||
if (requiredVersion && this.versionCompatibilityService.isVersionSupported(requiredVersion)) {
|
||||
this.viewContainer.createEmbeddedView(this.templateRef);
|
||||
} else {
|
||||
this.viewContainer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private parseVersion(version: string): VersionModel {
|
||||
const major = version.split('.')[0];
|
||||
const minor = version.split('.')[1] || '0';
|
||||
const patch = version.split('.')[2] || '0';
|
||||
|
||||
return {
|
||||
major: major,
|
||||
minor: minor,
|
||||
patch: patch
|
||||
} as VersionModel;
|
||||
}
|
||||
|
||||
private isVersionSupported(requiredVersion: string): boolean {
|
||||
const parsedRequiredVersion = this.parseVersion(requiredVersion);
|
||||
const currentVersion = this.versionCompatibilityService.getAcsVersion();
|
||||
|
||||
let versionSupported = false;
|
||||
|
||||
if (currentVersion) {
|
||||
if (+currentVersion.major > +parsedRequiredVersion.major) {
|
||||
versionSupported = true;
|
||||
} else if (currentVersion.major === parsedRequiredVersion.major &&
|
||||
+currentVersion.minor > +parsedRequiredVersion.minor) {
|
||||
versionSupported = true;
|
||||
} else if (currentVersion.major === parsedRequiredVersion.major &&
|
||||
currentVersion.minor === parsedRequiredVersion.minor &&
|
||||
+currentVersion.patch >= +parsedRequiredVersion.patch) {
|
||||
versionSupported = true;
|
||||
}
|
||||
}
|
||||
|
||||
return versionSupported;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,28 +48,32 @@ describe('VersionCompatibilityService', () => {
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
discoveryApiService = TestBed.inject(DiscoveryApiService);
|
||||
authenticationService = TestBed.inject(AuthenticationService);
|
||||
spyOn(discoveryApiService, 'getEcmProductInfo').and.returnValue(of(acsResponceMock));
|
||||
spyOn(authenticationService, 'isEcmLoggedIn').and.returnValue(true);
|
||||
versionCompatibilityService = TestBed.inject(VersionCompatibilityService);
|
||||
alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), null);
|
||||
|
||||
});
|
||||
|
||||
it('should get ACS running version', (done) => {
|
||||
versionCompatibilityService = new VersionCompatibilityService(
|
||||
alfrescoApiService,
|
||||
authenticationService,
|
||||
discoveryApiService
|
||||
);
|
||||
alfrescoApiService.initialize();
|
||||
setTimeout(() => {
|
||||
const acsVersion = versionCompatibilityService.getAcsVersion();
|
||||
expect(acsVersion).toBeDefined();
|
||||
expect(acsVersion.display).toBe('7.0.1');
|
||||
done();
|
||||
}, 100);
|
||||
await alfrescoApiService.initialize();
|
||||
});
|
||||
|
||||
it('should get ACS running version', () => {
|
||||
const acsVersion = versionCompatibilityService.getAcsVersion();
|
||||
expect(acsVersion).toBeDefined();
|
||||
expect(acsVersion.display).toBe('7.0.1');
|
||||
});
|
||||
|
||||
it('should validate give version', () => {
|
||||
expect(versionCompatibilityService.getAcsVersion()).toEqual({ display: '7.0.1', major: '7', minor: '0', patch: '1' } as any);
|
||||
expect(versionCompatibilityService.isVersionSupported('8.0.0')).toBe(false);
|
||||
expect(versionCompatibilityService.isVersionSupported('7.0.1')).toBe(true);
|
||||
expect(versionCompatibilityService.isVersionSupported('7.0.0')).toBe(true);
|
||||
expect(versionCompatibilityService.isVersionSupported('6.0.0')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
@ -47,7 +47,41 @@ export class VersionCompatibilityService {
|
||||
}
|
||||
}
|
||||
|
||||
public getAcsVersion(): VersionModel {
|
||||
getAcsVersion(): VersionModel {
|
||||
return this.acsVersion;
|
||||
}
|
||||
|
||||
isVersionSupported(requiredVersion: string): boolean {
|
||||
const parsedRequiredVersion = this.parseVersion(requiredVersion);
|
||||
const currentVersion = this.getAcsVersion();
|
||||
|
||||
let versionSupported = false;
|
||||
|
||||
if (currentVersion) {
|
||||
if (+currentVersion.major > +parsedRequiredVersion.major) {
|
||||
versionSupported = true;
|
||||
} else if (currentVersion.major === parsedRequiredVersion.major &&
|
||||
+currentVersion.minor > +parsedRequiredVersion.minor) {
|
||||
versionSupported = true;
|
||||
} else if (currentVersion.major === parsedRequiredVersion.major &&
|
||||
currentVersion.minor === parsedRequiredVersion.minor &&
|
||||
+currentVersion.patch >= +parsedRequiredVersion.patch) {
|
||||
versionSupported = true;
|
||||
}
|
||||
}
|
||||
|
||||
return versionSupported;
|
||||
}
|
||||
|
||||
private parseVersion(version: string): VersionModel {
|
||||
const major = version.split('.')[0];
|
||||
const minor = version.split('.')[1] || '0';
|
||||
const patch = version.split('.')[2] || '0';
|
||||
|
||||
return {
|
||||
major: major,
|
||||
minor: minor,
|
||||
patch: patch
|
||||
} as VersionModel;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user