-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: show front and backend versions (#726)
* feat: show frontend and backend versions, frontend version in browser tab is now correct * refactor: remove unused service * test: add unit tests for setting versions * refactor: remove comments
- Loading branch information
1 parent
9bae99b
commit 23646a2
Showing
11 changed files
with
169 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,46 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { AppComponent } from './app.component'; | ||
import { provideHttpClientTesting } from '@angular/common/http/testing'; | ||
import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; | ||
import { Title } from '@angular/platform-browser'; | ||
import { VersionService } from './shared/services/version.service'; | ||
import { provideRouter } from '@angular/router'; | ||
|
||
class MockVersionService { | ||
getFrontendVersion = jasmine.createSpy('getFrontendVersion').and.returnValue(Promise.resolve('1.0-TEST')); | ||
} | ||
|
||
describe('AppComponent', () => { | ||
let component: AppComponent; | ||
let fixture: ComponentFixture<AppComponent>; | ||
let titleService: Title; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [RouterTestingModule, NgbNavModule, AppComponent], | ||
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()], | ||
providers: [ | ||
provideHttpClient(withInterceptorsFromDi()), | ||
provideHttpClientTesting(), | ||
provideRouter([]), | ||
{ provide: VersionService, useClass: MockVersionService }, | ||
Title, | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(AppComponent); | ||
component = fixture.componentInstance; | ||
titleService = TestBed.inject(Title); | ||
}); | ||
|
||
it('should create the app', () => { | ||
const fixture = TestBed.createComponent(AppComponent); | ||
const app = fixture.componentInstance; | ||
expect(app).toBeTruthy(); | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it(`should have as title 'ladybug'`, () => { | ||
const fixture = TestBed.createComponent(AppComponent); | ||
const app = fixture.componentInstance; | ||
expect(app.title).toEqual('ladybug'); | ||
it('should set the title correctly based on frontend version from version service', async () => { | ||
spyOn(titleService, 'setTitle'); | ||
|
||
await component.fetchAndSetFrontendVersion(); | ||
|
||
expect(titleService.setTitle).toHaveBeenCalledWith('Ladybug - v1.0-TEST'); | ||
expect(component.frontendVersion).toEqual('1.0-TEST'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/app/shared/services/node-link-strategy.service.spec.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { VersionService } from './version.service'; | ||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; | ||
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; | ||
|
||
describe('VersionService', () => { | ||
let service: VersionService; | ||
|
||
let httpTestingController: HttpTestingController; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()], | ||
}); | ||
service = TestBed.inject(VersionService); | ||
httpTestingController = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should set version from package.json', async () => { | ||
const frontendVersionPromise = service.getFrontendVersion(); | ||
const backendVersionPromise = service.getBackendVersion(); | ||
const mockPackageJson = { version: '1.0-TEST' }; | ||
|
||
const frontendVersionReq = httpTestingController.expectOne(service.packageJsonPath); | ||
|
||
const backendVersionReg = httpTestingController.expectOne('api/testtool/version'); | ||
frontendVersionReq.flush(mockPackageJson); | ||
backendVersionReg.flush('3.0-TEST'); | ||
|
||
const frontendVersion = await frontendVersionPromise; | ||
const backendVersion = await backendVersionPromise; | ||
|
||
expect(frontendVersion).toEqual('1.0-TEST'); | ||
expect(backendVersion).toEqual('3.0-TEST'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpService } from './http.service'; | ||
import { firstValueFrom } from 'rxjs'; | ||
import { HttpClient } from '@angular/common/http'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class VersionService { | ||
packageJsonPath = 'assets/package.json'; | ||
frontendVersion?: string; | ||
backendVersion?: string; | ||
|
||
constructor( | ||
private httpService: HttpService, | ||
private httpClient: HttpClient, | ||
) {} | ||
|
||
async getFrontendVersion() { | ||
if (!this.frontendVersion) { | ||
try { | ||
const packageJson = await firstValueFrom(this.httpClient.get<{ version: string }>(this.packageJsonPath)); | ||
if (packageJson) { | ||
this.frontendVersion = packageJson.version; | ||
} | ||
} catch (error) { | ||
console.error('package.json could not be found in assets', error); | ||
} | ||
} | ||
return this.frontendVersion!; | ||
} | ||
|
||
async getBackendVersion() { | ||
if (!this.backendVersion) { | ||
this.backendVersion = await firstValueFrom(this.httpService.getBackendVersion()); | ||
} | ||
return this.backendVersion; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters