From 3613b53f99f524c712d203bb3b70113a09ccf2bd Mon Sep 17 00:00:00 2001 From: Anna Kutch Date: Sun, 16 Jul 2017 16:10:21 -0400 Subject: [PATCH] Set up routing - move landing info to LandingComponent - add PageNotFoundComponent for 404's - update unit tests - degrade zone.js version to resolve unit test errors: https://github.com/angular/zone.js/issues/832 - alphabetize styles --- package.json | 2 +- src/app/app.component.html | 12 ++--- src/app/app.component.scss | 16 +++---- src/app/app.component.spec.ts | 21 +++++---- src/app/app.module.ts | 13 +++++- src/app/landing/landing.component.html | 1 + src/app/landing/landing.component.scss | 0 src/app/landing/landing.component.spec.ts | 32 +++++++++++++ src/app/landing/landing.component.ts | 15 +++++++ src/app/nav/nav.component.html | 8 ++-- .../page-not-found.component.html | 3 ++ .../page-not-found.component.scss | 1 + .../page-not-found.component.spec.ts | 25 +++++++++++ .../page-not-found.component.ts | 15 +++++++ src/app/routing/routing.module.ts | 45 +++++++++++++++++++ src/styles/_global.scss | 4 ++ 16 files changed, 180 insertions(+), 33 deletions(-) create mode 100644 src/app/landing/landing.component.html create mode 100644 src/app/landing/landing.component.scss create mode 100644 src/app/landing/landing.component.spec.ts create mode 100644 src/app/landing/landing.component.ts create mode 100644 src/app/page-not-found/page-not-found.component.html create mode 100644 src/app/page-not-found/page-not-found.component.scss create mode 100644 src/app/page-not-found/page-not-found.component.spec.ts create mode 100644 src/app/page-not-found/page-not-found.component.ts create mode 100644 src/app/routing/routing.module.ts diff --git a/package.json b/package.json index b411edd..1f4546c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@angular/router": "^4.0.0", "core-js": "^2.4.1", "rxjs": "^5.1.0", - "zone.js": "^0.8.4" + "zone.js": "0.8.12" }, "devDependencies": { "@angular/cli": "1.2.1", diff --git a/src/app/app.component.html b/src/app/app.component.html index f8a873a..c75f8a5 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,15 +1,11 @@
-
-

Hello, I'm Anna

-
-
- - - -
+
+ +
+
diff --git a/src/app/app.component.scss b/src/app/app.component.scss index 9878c62..70713e6 100644 --- a/src/app/app.component.scss +++ b/src/app/app.component.scss @@ -1,21 +1,15 @@ @import '~styles.scss'; - .ak { - display: flex; - flex-direction: row-reverse; - justify-content: space-between; align-items: center; + display: flex; height: 100%; + justify-content: space-between; } -.ak-landing-content { - display: flex; - justify-content: center; +.ak-page { align-items: center; + display: flex; flex-grow: 3; -} - -.ak-pages { - display: none; + justify-content: center; } diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 7373812..b26f09c 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -1,10 +1,14 @@ import { TestBed, async } from '@angular/core/testing'; +import { APP_BASE_HREF } from '@angular/common'; import { AppComponent } from './app.component'; import { NavComponent } from './nav/nav.component'; import { AboutComponent } from './about/about.component'; import { WorkComponent } from './work/work.component'; import { ContactComponent } from './contact/contact.component'; +import { LandingComponent } from './landing/landing.component'; +import { PageNotFoundComponent } from './page-not-found/page-not-found.component'; +import { RoutingModule } from './routing/routing.module'; describe('AppComponent', () => { beforeEach(async(() => { @@ -14,8 +18,16 @@ describe('AppComponent', () => { NavComponent, AboutComponent, WorkComponent, - ContactComponent + ContactComponent, + LandingComponent, + PageNotFoundComponent ], + imports: [ + RoutingModule + ], + providers: [ + { provide: APP_BASE_HREF, useValue: '/' } + ] }).compileComponents(); })); @@ -30,11 +42,4 @@ describe('AppComponent', () => { const app = fixture.debugElement.componentInstance; expect(app.title).toEqual('ak'); })); - - 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("Hello, I'm Anna"); - })); }); diff --git a/src/app/app.module.ts b/src/app/app.module.ts index cea8eb6..911dce2 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,22 +1,31 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; +/* Modules */ +import { RoutingModule } from './routing/routing.module'; + +/* Components */ import { AppComponent } from './app.component'; import { NavComponent } from './nav/nav.component'; import { AboutComponent } from './about/about.component'; import { WorkComponent } from './work/work.component'; import { ContactComponent } from './contact/contact.component'; +import { PageNotFoundComponent } from './page-not-found/page-not-found.component'; +import { LandingComponent } from './landing/landing.component'; @NgModule({ declarations: [ AppComponent, NavComponent, AboutComponent, + ContactComponent, WorkComponent, - ContactComponent + PageNotFoundComponent, + LandingComponent ], imports: [ - BrowserModule + BrowserModule, + RoutingModule ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/landing/landing.component.html b/src/app/landing/landing.component.html new file mode 100644 index 0000000..57d8d8d --- /dev/null +++ b/src/app/landing/landing.component.html @@ -0,0 +1 @@ +

Hello, I'm Anna Kutch

\ No newline at end of file diff --git a/src/app/landing/landing.component.scss b/src/app/landing/landing.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/landing/landing.component.spec.ts b/src/app/landing/landing.component.spec.ts new file mode 100644 index 0000000..7b3f413 --- /dev/null +++ b/src/app/landing/landing.component.spec.ts @@ -0,0 +1,32 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LandingComponent } from './landing.component'; + +describe('LandingComponent', () => { + let component: LandingComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ LandingComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(LandingComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should be created', () => { + expect(component).toBeTruthy(); + }); + + it('should render title in a h1 tag', async(() => { + const fixture = TestBed.createComponent(LandingComponent); + fixture.detectChanges(); + const compiled = fixture.debugElement.nativeElement; + expect(compiled.querySelector('h1').textContent).toContain("Hello, I'm Anna"); + })); +}); diff --git a/src/app/landing/landing.component.ts b/src/app/landing/landing.component.ts new file mode 100644 index 0000000..35f2d6b --- /dev/null +++ b/src/app/landing/landing.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'ak-landing', + templateUrl: './landing.component.html', + styleUrls: ['./landing.component.scss'] +}) +export class LandingComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/nav/nav.component.html b/src/app/nav/nav.component.html index 4db3809..e574f8c 100644 --- a/src/app/nav/nav.component.html +++ b/src/app/nav/nav.component.html @@ -1,10 +1,12 @@ diff --git a/src/app/page-not-found/page-not-found.component.html b/src/app/page-not-found/page-not-found.component.html new file mode 100644 index 0000000..f6a743b --- /dev/null +++ b/src/app/page-not-found/page-not-found.component.html @@ -0,0 +1,3 @@ +

+ Uh oh! Page not found! +

diff --git a/src/app/page-not-found/page-not-found.component.scss b/src/app/page-not-found/page-not-found.component.scss new file mode 100644 index 0000000..91703c6 --- /dev/null +++ b/src/app/page-not-found/page-not-found.component.scss @@ -0,0 +1 @@ +@import '~styles.scss'; \ No newline at end of file diff --git a/src/app/page-not-found/page-not-found.component.spec.ts b/src/app/page-not-found/page-not-found.component.spec.ts new file mode 100644 index 0000000..3917008 --- /dev/null +++ b/src/app/page-not-found/page-not-found.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PageNotFoundComponent } from './page-not-found.component'; + +describe('PageNotFoundComponent', () => { + let component: PageNotFoundComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ PageNotFoundComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(PageNotFoundComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should be created', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/page-not-found/page-not-found.component.ts b/src/app/page-not-found/page-not-found.component.ts new file mode 100644 index 0000000..ea98323 --- /dev/null +++ b/src/app/page-not-found/page-not-found.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'ak-page-not-found', + templateUrl: './page-not-found.component.html', + styleUrls: ['./page-not-found.component.scss'] +}) +export class PageNotFoundComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/routing/routing.module.ts b/src/app/routing/routing.module.ts new file mode 100644 index 0000000..4011fb6 --- /dev/null +++ b/src/app/routing/routing.module.ts @@ -0,0 +1,45 @@ +import { NgModule } from '@angular/core'; +import { Routes, RouterModule } from '@angular/router'; + +import { LandingComponent } from '../landing/landing.component'; +import { AboutComponent } from '../about/about.component'; +import { WorkComponent } from '../work/work.component'; +import { ContactComponent } from '../contact/contact.component'; +import { PageNotFoundComponent } from '../page-not-found/page-not-found.component'; + +const routes: Routes = [ + { + path: 'about', + component: AboutComponent + }, + { + path: 'work', + component: WorkComponent + }, + { + path: 'contact', + component: ContactComponent + }, + { + path: 'home', + component: LandingComponent + }, + { + path: '', + redirectTo: '/home', + pathMatch: 'full' + }, + { + path: '**', + component: PageNotFoundComponent + } +]; + +@NgModule({ + imports: [RouterModule.forRoot(routes)], + exports: [RouterModule] +}) + +export class RoutingModule { + + } diff --git a/src/styles/_global.scss b/src/styles/_global.scss index 81ee593..8702c0c 100644 --- a/src/styles/_global.scss +++ b/src/styles/_global.scss @@ -13,3 +13,7 @@ h1 { font-weight: normal; margin: 0; } + +li { + outline: none; +}