Skip to content

Commit

Permalink
Set up routing
Browse files Browse the repository at this point in the history
- move landing info to LandingComponent
- add PageNotFoundComponent for 404's
- update unit tests
- degrade zone.js version to resolve unit test errors: angular/zone.js#832
- alphabetize styles
  • Loading branch information
akutch committed Jul 16, 2017
1 parent 8e89217 commit 3613b53
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 4 additions & 8 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<div class="ak">
<div class="ak-landing-content">
<h1>Hello, I'm Anna</h1>
</div>

<!-- navigation -->
<ak-nav class="ak-nav"></ak-nav>

<!-- pages -->
<section class="ak-pages">
<ak-about></ak-about>
<ak-work></ak-work>
<ak-contact></ak-contact>
</section>
<div class="ak-page">
<router-outlet></router-outlet>
</div>

</div>
16 changes: 5 additions & 11 deletions src/app/app.component.scss
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 13 additions & 8 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand All @@ -14,8 +18,16 @@ describe('AppComponent', () => {
NavComponent,
AboutComponent,
WorkComponent,
ContactComponent
ContactComponent,
LandingComponent,
PageNotFoundComponent
],
imports: [
RoutingModule
],
providers: [
{ provide: APP_BASE_HREF, useValue: '/' }
]
}).compileComponents();
}));

Expand All @@ -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");
}));
});
13 changes: 11 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
1 change: 1 addition & 0 deletions src/app/landing/landing.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello, I'm Anna Kutch</h1>
Empty file.
32 changes: 32 additions & 0 deletions src/app/landing/landing.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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<LandingComponent>;

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");
}));
});
15 changes: 15 additions & 0 deletions src/app/landing/landing.component.ts
Original file line number Diff line number Diff line change
@@ -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() {
}

}
8 changes: 5 additions & 3 deletions src/app/nav/nav.component.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<nav>
<ul class="ak-nav-items">
<li class="ak-nav-item">About</li>
<li routerLink="home" class="ak-nav-item">Home</li>
<li class="ak-nav-line"></li>
<li class="ak-nav-item">Work</li>
<li routerLink="about" class="ak-nav-item">About</li>
<li class="ak-nav-line"></li>
<li class="ak-nav-item">Contact</li>
<li routerLink="work" class="ak-nav-item">Work</li>
<li class="ak-nav-line"></li>
<li routerLink="contact" class="ak-nav-item">Contact</li>
<li class="ak-nav-line"></li>
</ul>
</nav>
3 changes: 3 additions & 0 deletions src/app/page-not-found/page-not-found.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>
Uh oh! Page not found!
</p>
1 change: 1 addition & 0 deletions src/app/page-not-found/page-not-found.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import '~styles.scss';
25 changes: 25 additions & 0 deletions src/app/page-not-found/page-not-found.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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<PageNotFoundComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PageNotFoundComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(PageNotFoundComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should be created', () => {
expect(component).toBeTruthy();
});
});
15 changes: 15 additions & 0 deletions src/app/page-not-found/page-not-found.component.ts
Original file line number Diff line number Diff line change
@@ -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() {
}

}
45 changes: 45 additions & 0 deletions src/app/routing/routing.module.ts
Original file line number Diff line number Diff line change
@@ -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 {

}
4 changes: 4 additions & 0 deletions src/styles/_global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ h1 {
font-weight: normal;
margin: 0;
}

li {
outline: none;
}

0 comments on commit 3613b53

Please sign in to comment.