-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use environment variable to config demonstrator
- Loading branch information
1 parent
6e0e4aa
commit 2e443de
Showing
9 changed files
with
150 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.editorconfig | ||
.git | ||
.gitignore | ||
.idea | ||
README.md | ||
coverage | ||
dist | ||
node_modules |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface Settings { | ||
mvizServerUrl: string; | ||
} |
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,67 @@ | ||
import { | ||
HttpClientTestingModule, | ||
HttpTestingController, | ||
} from '@angular/common/http/testing'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { Settings } from '../models/settings'; | ||
|
||
import { SettingsInitializerService } from './settings-initializer.service'; | ||
import { SettingsService } from './settings.service'; | ||
|
||
describe('SettingsInitializerService', () => { | ||
let service: SettingsInitializerService; | ||
let httpMock: HttpTestingController; | ||
let settingsService: SettingsService; | ||
|
||
const testSettings: Settings = { | ||
mvizServerUrl: 'baseUrl', | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
}); | ||
|
||
service = TestBed.get(SettingsInitializerService); | ||
httpMock = TestBed.get(HttpTestingController); | ||
settingsService = TestBed.get(SettingsService); | ||
}); | ||
|
||
afterEach(() => { | ||
httpMock.verify(); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should initialize settings', (done) => { | ||
service.initializeSettings().then(() => { | ||
expect(settingsService.settings).toEqual(testSettings); | ||
done(); | ||
}); | ||
|
||
const request = httpMock.expectOne('assets/settings.json'); | ||
expect(request.request.method).toBe('GET'); | ||
request.flush(testSettings); | ||
}); | ||
|
||
it('should not initialize settings if get settings.json failed', (done) => { | ||
service | ||
.initializeSettings() | ||
.then(() => { | ||
done.fail(new Error('this was expected to fail')); | ||
}) | ||
.catch(() => { | ||
expect(settingsService.settings).toBeUndefined(); | ||
done(); | ||
}); | ||
|
||
const request = httpMock.expectOne('assets/settings.json'); | ||
expect(request.request.method).toBe('GET'); | ||
request.flush(testSettings, { | ||
status: 500, | ||
statusText: 'Some Weird Server Error', | ||
}); | ||
}); | ||
}); |
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,27 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { Settings } from '../models/settings'; | ||
import { SettingsService } from './settings.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class SettingsInitializerService { | ||
constructor( | ||
private http: HttpClient, | ||
private settings: SettingsService | ||
) { } | ||
|
||
initializeSettings(): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
this.http.get('assets/settings.json').subscribe( | ||
(response) => { | ||
this.settings.settings = response as Settings; | ||
resolve(); | ||
}, | ||
(error) => reject(error), | ||
); | ||
}); | ||
} | ||
} |
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,12 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { SettingsService } from './settings.service'; | ||
|
||
describe('SettingsService', () => { | ||
beforeEach(() => TestBed.configureTestingModule({})); | ||
|
||
it('should be created', () => { | ||
const service: SettingsService = TestBed.get(SettingsService); | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
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,10 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { Settings } from '../models/settings'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class SettingsService { | ||
settings: Settings; | ||
} |
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,3 @@ | ||
{ | ||
"mvizServerUrl": "http://localhost:3001/" | ||
} |