Ng not ejected anymore

This commit is contained in:
Maxime GRIS
2018-02-25 22:01:57 +01:00
parent 1ae6f7aedc
commit 67ab31c458
26 changed files with 473 additions and 733 deletions

View File

@@ -1,7 +1,9 @@
import { TestBed, async } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import { ElectronService } from 'app/providers/electron.service';
import { ElectronService } from './providers/electron.service';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
describe('AppComponent', () => {
beforeEach(async(() => {
@@ -9,10 +11,13 @@ describe('AppComponent', () => {
declarations: [
AppComponent
],
providers : [
ElectronService
providers: [
ElectronService,
{ provide: TranslateService, useClass: TranslateServiceStub }
],
imports: [RouterTestingModule]
imports: [RouterTestingModule,
TranslateModule.forRoot()
]
}).compileComponents();
}));
@@ -22,3 +27,8 @@ describe('AppComponent', () => {
expect(app).toBeTruthy();
}));
});
class TranslateServiceStub {
setDefaultLang(lang: string): void {
}
}

View File

@@ -1,6 +1,7 @@
import { Component } from '@angular/core';
import { ElectronService } from './providers/electron.service';
import { TranslateService } from '@ngx-translate/core';
import { AppConfig } from './app.config';
@Component({
selector: 'app-root',
@@ -12,13 +13,12 @@ export class AppComponent {
private translate: TranslateService) {
translate.setDefaultLang('en');
console.log('AppConfig', AppConfig);
if (electronService.isElectron()) {
console.log('Mode electron');
// Check if electron is correctly injected (see externals in webpack.config.js)
console.log('c', electronService.ipcRenderer);
// Check if nodeJs childProcess is correctly injected (see externals in webpack.config.js)
console.log('c', electronService.childProcess);
console.log('Electron ipcRenderer', electronService.ipcRenderer);
console.log('NodeJS childProcess', electronService.childProcess);
} else {
console.log('Mode web');
}

23
src/app/app.config.ts Normal file
View File

@@ -0,0 +1,23 @@
import { CONF_LOCAL } from '../environments/environment.local';
import { CONF_DEV } from '../environments/environment.dev';
import { CONF_PROD } from '../environments/environment.prod';
const ENV = 'prod';
const LOCAL: String = 'local';
const DEV: String = 'dev';
const PROD: String = 'prod';
let conf: any;
console.log('Env', ENV);
if (ENV === PROD) {
conf = CONF_PROD;
} else if (ENV === DEV) {
conf = CONF_DEV;
} else {
conf = CONF_LOCAL;
}
export const AppConfig = Object.assign({}, conf);

View File

@@ -15,7 +15,7 @@ import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { ElectronService } from './providers/electron.service';
import { WebviewDirective } from 'app/directives/webview.directive';
import { WebviewDirective } from './directives/webview.directive';
import { AppComponent } from './app.component';
import { HomeComponent } from './components/home/home.component';

View File

@@ -1,6 +1,7 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HomeComponent } from './home.component';
import { TranslateModule } from '@ngx-translate/core';
describe('HomeComponent', () => {
let component: HomeComponent;
@@ -8,7 +9,10 @@ describe('HomeComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HomeComponent ]
declarations: [ HomeComponent ],
imports: [
TranslateModule.forRoot()
]
})
.compileComponents();
}));
@@ -23,16 +27,8 @@ describe('HomeComponent', () => {
expect(component).toBeTruthy();
});
it(`should have as title 'App works !'`, async(() => {
fixture = TestBed.createComponent(HomeComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('App works !');
}));
it('should render title in a h1 tag', async(() => {
fixture = TestBed.createComponent(HomeComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('App works !');
expect(compiled.querySelector('h1').textContent).toBeTruthy();
}));
});