mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACA-3765] [ADF] move reusable versioning logic (#5906)
This commit is contained in:
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
import { Directive, Input, ViewContainerRef, TemplateRef } from '@angular/core';
|
import { Directive, Input, ViewContainerRef, TemplateRef } from '@angular/core';
|
||||||
import { VersionCompatibilityService } from '../services/version-compatibility.service';
|
import { VersionCompatibilityService } from '../services/version-compatibility.service';
|
||||||
import { VersionModel } from '../models/product-version.model';
|
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[adf-acs-version]'
|
selector: '[adf-acs-version]'
|
||||||
@@ -38,45 +37,10 @@ export class VersionCompatibilityDirective {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private validateAcsVersion(requiredVersion: string) {
|
private validateAcsVersion(requiredVersion: string) {
|
||||||
if (requiredVersion && this.isVersionSupported(requiredVersion)) {
|
if (requiredVersion && this.versionCompatibilityService.isVersionSupported(requiredVersion)) {
|
||||||
this.viewContainer.createEmbeddedView(this.templateRef);
|
this.viewContainer.createEmbeddedView(this.templateRef);
|
||||||
} else {
|
} else {
|
||||||
this.viewContainer.clear();
|
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);
|
discoveryApiService = TestBed.inject(DiscoveryApiService);
|
||||||
authenticationService = TestBed.inject(AuthenticationService);
|
authenticationService = TestBed.inject(AuthenticationService);
|
||||||
spyOn(discoveryApiService, 'getEcmProductInfo').and.returnValue(of(acsResponceMock));
|
spyOn(discoveryApiService, 'getEcmProductInfo').and.returnValue(of(acsResponceMock));
|
||||||
spyOn(authenticationService, 'isEcmLoggedIn').and.returnValue(true);
|
spyOn(authenticationService, 'isEcmLoggedIn').and.returnValue(true);
|
||||||
versionCompatibilityService = TestBed.inject(VersionCompatibilityService);
|
versionCompatibilityService = TestBed.inject(VersionCompatibilityService);
|
||||||
alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), null);
|
alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), null);
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should get ACS running version', (done) => {
|
|
||||||
versionCompatibilityService = new VersionCompatibilityService(
|
versionCompatibilityService = new VersionCompatibilityService(
|
||||||
alfrescoApiService,
|
alfrescoApiService,
|
||||||
authenticationService,
|
authenticationService,
|
||||||
discoveryApiService
|
discoveryApiService
|
||||||
);
|
);
|
||||||
alfrescoApiService.initialize();
|
await alfrescoApiService.initialize();
|
||||||
setTimeout(() => {
|
});
|
||||||
const acsVersion = versionCompatibilityService.getAcsVersion();
|
|
||||||
expect(acsVersion).toBeDefined();
|
it('should get ACS running version', () => {
|
||||||
expect(acsVersion.display).toBe('7.0.1');
|
const acsVersion = versionCompatibilityService.getAcsVersion();
|
||||||
done();
|
expect(acsVersion).toBeDefined();
|
||||||
}, 100);
|
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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user