From 7334ce89b5daabba9fa5d1c0c940ebc38aecbc9a Mon Sep 17 00:00:00 2001 From: Maxime GRIS Date: Fri, 5 May 2017 22:38:28 +0200 Subject: [PATCH] Add routing module --- package.json | 8 ++++---- src/app/app-routing.module.ts | 16 ++++++++++++++++ src/app/app.component.html | 5 +---- src/app/app.component.scss | 8 -------- src/app/app.component.spec.ts | 13 ------------- src/app/app.component.ts | 3 --- src/app/app.module.ts | 9 +++++++-- src/app/home/home.component.html | 3 +++ src/app/home/home.component.scss | 8 ++++++++ src/app/home/home.component.spec.ts | 38 +++++++++++++++++++++++++++++++++++++ src/app/home/home.component.ts | 16 ++++++++++++++++ 11 files changed, 93 insertions(+), 34 deletions(-) create mode 100644 src/app/app-routing.module.ts create mode 100644 src/app/home/home.component.html create mode 100644 src/app/home/home.component.scss create mode 100644 src/app/home/home.component.spec.ts create mode 100644 src/app/home/home.component.ts diff --git a/package.json b/package.json index 3a5f125..530906d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-electron", - "version": "1.3.0", + "version": "1.3.", "description": "Angular 4 with Electron (Typescript + SASS + Hot Reload)", "homepage": "https://github.com/maximegris/angular-electron", "author": { @@ -17,14 +17,14 @@ "private": true, "scripts": { "ng": "ng", + "lint": "ng lint", "start": "webpack --watch", "test": "karma start ./karma.conf.js", - "lint": "ng lint", "e2e": "protractor ./protractor.conf.js", - "build": "webpack --display-error-details && copyfiles main.js dist", - "build:prod": "cross-env NODE_ENV='production' npm run build", "prepree2e": "npm start", "pree2e": "webdriver-manager update --standalone false --gecko false --quiet", + "build": "webpack --display-error-details && copyfiles main.js dist", + "build:prod": "cross-env NODE_ENV='production' npm run build", "electron:serve": "electron . --serve", "electron:dev": "npm run build && electron dist/main.js", "electron:prod": "npm run build:prod && electron dist/main.js", diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts new file mode 100644 index 0000000..c51f095 --- /dev/null +++ b/src/app/app-routing.module.ts @@ -0,0 +1,16 @@ +import { HomeComponent } from './home/home.component'; +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +const routes: Routes = [ + { + path: '', + component: HomeComponent + } +]; + +@NgModule({ + imports: [RouterModule.forRoot(routes)], + exports: [RouterModule] +}) +export class AppRoutingModule { } diff --git a/src/app/app.component.html b/src/app/app.component.html index 91907a5..0680b43 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,4 +1 @@ -

- {{title}} -

- + diff --git a/src/app/app.component.scss b/src/app/app.component.scss index b3a28ec..e69de29 100644 --- a/src/app/app.component.scss +++ b/src/app/app.component.scss @@ -1,8 +0,0 @@ -.title { - color: black; - margin:0; - padding:50px 20px; - background: url(../assets/background.jpg) no-repeat center fixed; - -webkit-background-size: cover; /* pour anciens Chrome et Safari */ - background-size: cover; /* version standardisée */ -} diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index c740bcd..7bb264e 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -16,17 +16,4 @@ describe('AppComponent', () => { const app = fixture.debugElement.componentInstance; expect(app).toBeTruthy(); })); - - it(`should have as title 'app works!'`, async(() => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.debugElement.componentInstance; - expect(app.title).toEqual('app works!'); - })); - - it('should render title in a h1 tag', async(() => { - const fixture = TestBed.createComponent(AppComponent); - fixture.detectChanges(); - const compiled = fixture.debugElement.nativeElement; - expect(compiled.querySelector('h1').textContent).toContain('app works!'); - })); }); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index d0fb20b..fd7c2ec 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -8,13 +8,10 @@ import * as childProcess from 'child_process'; styleUrls: ['./app.component.scss'] }) export class AppComponent { - title = `App works !`; - constructor() { // Check if electron is correctly injected (see externals in webpack.config.js) console.log('c', ipcRenderer); // Check if nodeJs childProcess is correctly injected (see externals in webpack.config.js) console.log('c', childProcess); - } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 67ae491..ce15844 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -4,15 +4,20 @@ import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { AppComponent } from './app.component'; +import { HomeComponent } from './home/home.component'; + +import { AppRoutingModule } from './app-routing.module'; @NgModule({ declarations: [ - AppComponent + AppComponent, + HomeComponent ], imports: [ BrowserModule, FormsModule, - HttpModule + HttpModule, + AppRoutingModule ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html new file mode 100644 index 0000000..4b0fa09 --- /dev/null +++ b/src/app/home/home.component.html @@ -0,0 +1,3 @@ +

+ {{title}} +

diff --git a/src/app/home/home.component.scss b/src/app/home/home.component.scss new file mode 100644 index 0000000..48064e6 --- /dev/null +++ b/src/app/home/home.component.scss @@ -0,0 +1,8 @@ +.title { + color: black; + margin:0; + padding:50px 20px; + background: url(../../assets/background.jpg) no-repeat center fixed; + -webkit-background-size: cover; /* pour anciens Chrome et Safari */ + background-size: cover; /* version standardisée */ +} diff --git a/src/app/home/home.component.spec.ts b/src/app/home/home.component.spec.ts new file mode 100644 index 0000000..c836313 --- /dev/null +++ b/src/app/home/home.component.spec.ts @@ -0,0 +1,38 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HomeComponent } from './home.component'; + +describe('HomeComponent', () => { + let component: HomeComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ HomeComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(HomeComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); + + it(`should have as title 'App works !'`, async(() => { + const fixture = TestBed.createComponent(HomeComponent); + const app = fixture.debugElement.componentInstance; + expect(app.title).toEqual('aApp works !'); + })); + + it('should render title in a h1 tag', async(() => { + const fixture = TestBed.createComponent(HomeComponent); + fixture.detectChanges(); + const compiled = fixture.debugElement.nativeElement; + expect(compiled.querySelector('h1').textContent).toContain('App works !'); + })); +}); diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts new file mode 100644 index 0000000..edf1531 --- /dev/null +++ b/src/app/home/home.component.ts @@ -0,0 +1,16 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-home', + templateUrl: './home.component.html', + styleUrls: ['./home.component.scss'] +}) +export class HomeComponent implements OnInit { + title = `App works !`; + + constructor() { } + + ngOnInit() { + } + +}