Skip to content

Commit

Permalink
(step 22-solution) feat: add solution for unit-tests exercice
Browse files Browse the repository at this point in the history
(step 22-solution) feat: migration angular v4 to angular v7
  • Loading branch information
Nicoss54 committed Dec 11, 2018
1 parent 1102d0f commit dd76765
Show file tree
Hide file tree
Showing 68 changed files with 1,954 additions and 0 deletions.
127 changes: 127 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -4599,6 +4599,133 @@
}
}
}
},
"unit-tests-solution": {
"root": "steps/unit-tests-solution/",
"sourceRoot": "steps/unit-tests-solution/src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/unit-tests-solution",
"index": "steps/unit-tests-solution/src/index.html",
"main": "steps/unit-tests-solution/src/main.ts",
"polyfills": "steps/unit-tests-solution/src/polyfills.ts",
"tsConfig": "steps/unit-tests-solution/tsconfig.app.json",
"assets": [
"steps/unit-tests-solution/src/favicon.ico",
"steps/unit-tests-solution/src/assets"
],
"styles": [
"steps/unit-tests-solution/src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "steps/unit-tests-solution/src/environments/environment.ts",
"with": "steps/unit-tests-solution/src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "unit-tests-solution:build"
},
"configurations": {
"production": {
"browserTarget": "unit-tests-solution:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "unit-tests-solution:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "steps/unit-tests-solution/src/test.ts",
"polyfills": "steps/unit-tests-solution/src/polyfills.ts",
"tsConfig": "steps/unit-tests-solution/tsconfig.spec.json",
"karmaConfig": "steps/unit-tests-solution/karma.conf.js",
"styles": [
"steps/unit-tests-solution/src/styles.css"
],
"scripts": [],
"assets": [
"steps/unit-tests-solution/src/favicon.ico",
"steps/unit-tests-solution/src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"steps/unit-tests-solution/tsconfig.app.json",
"steps/unit-tests-solution/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"unit-tests-solution-e2e": {
"root": "steps/unit-tests-solution-e2e/",
"projectType": "application",
"prefix": "",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "steps/unit-tests-solution-e2e/protractor.conf.js",
"devServerTarget": "unit-tests-solution:serve"
},
"configurations": {
"production": {
"devServerTarget": "unit-tests-solution:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "steps/unit-tests-solution-e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "angular-200",
Expand Down
11 changes: 11 additions & 0 deletions steps/unit-tests-solution/browserslist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file is currently used by autoprefixer to adjust CSS to support the below specified browsers
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
#
# For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed

> 0.5%
last 2 versions
Firefox ESR
not dead
not IE 9-11
31 changes: 31 additions & 0 deletions steps/unit-tests-solution/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
46 changes: 46 additions & 0 deletions steps/unit-tests-solution/src/app/app.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
mat-toolbar.extend-toolbar {
background-color: #0168ab;
background-image: url('/assets/images/bg_right.png');
background-repeat: no-repeat;
background-position: right;
top: 0px;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
width: 100%;
z-index: 1;
color: white;
margin-bottom: 10px;
}

mat-toolbar .flex {
flex: 1 1 auto;
}

mat-toolbar a {
color: inherit;
text-decoration: none;
height: 100%;
margin: 0px 10px 0px 10px;
border-bottom: 2px solid transparent;
font-size: 1.1em;
font-weight: normal;
font-family: 'Open Sans', sans-serif;
}

mat-toolbar a:not(.active):hover {
border-bottom: 2px solid white;
}

mat-toolbar a img {
height: 100%;
margin-left: -60px;
}

mat-toolbar-row:nth-child(1) {
margin-bottom: 66px;
}
mat-toolbar-row:nth-child(2) {
padding-left: 30px;
text-align: center;
height: 56px;
margin-top: 56px;
}
11 changes: 11 additions & 0 deletions steps/unit-tests-solution/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<mat-toolbar class="extend-toolbar">
<span>
<a [routerLink]="['/']"> <img src="assets/images/logo-sfeir.svg" aria-label="sfeir" alt="Sfeir" /> </a>
</span>

<span class="flex"></span>

<span> <a href="javascript:void(0);">Maps</a> <a [routerLink]="['/people']">List</a> </span>
</mat-toolbar>

<router-outlet></router-outlet>
10 changes: 10 additions & 0 deletions steps/unit-tests-solution/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from '@angular/core';

@Component({
selector: 'sfeir-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class PeopleAppComponent {
constructor() {}
}
67 changes: 67 additions & 0 deletions steps/unit-tests-solution/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// CORE DEPS
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { ReactiveFormsModule } from '@angular/forms';
// MATERIAL DESIGN MODULES
import {
MatToolbarModule,
MatCardModule,
MatTabsModule,
MatButtonModule,
MatInputModule,
MatCheckboxModule,
MatRadioModule,
MatIconModule,
MatListModule,
MatDialogModule
} from '@angular/material';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { APP_ROUTES } from './app.routes';

import { PeopleAppComponent } from './app.component';
import { HomeComponent } from './home';
import { PeopleComponent } from './people';
import { CardComponent } from './shared/card';
import { AddDialogComponent } from './people/add-dialog/add-dialog.component';
import { FormComponent } from './shared/form';
import { UpdateComponent } from './update/update.component';
import { PeopleService } from './shared/people-service';
import { NaPipe } from './shared/na-pipe';
import { SfeirBadgeDirective } from './shared/badge';

@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
MatToolbarModule,
MatCardModule,
MatTabsModule,
MatButtonModule,
MatInputModule,
MatCheckboxModule,
MatRadioModule,
MatIconModule,
MatListModule,
MatDialogModule,
HttpClientModule,
APP_ROUTES,
ReactiveFormsModule
],
declarations: [
PeopleAppComponent,
HomeComponent,
PeopleComponent,
CardComponent,
AddDialogComponent,
FormComponent,
UpdateComponent,
NaPipe,
SfeirBadgeDirective
],
entryComponents: [AddDialogComponent],
providers: [PeopleService],
bootstrap: [PeopleAppComponent]
})
export class AppModule {}
15 changes: 15 additions & 0 deletions steps/unit-tests-solution/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { RouterModule, Routes } from '@angular/router';

// APP COMPONENTS
import { HomeComponent } from './home/index';
import { PeopleComponent } from './people/index';
import { UpdateComponent } from './update/index';

const ROUTES: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'people', component: PeopleComponent },
{ path: 'edit/:id', component: UpdateComponent }
];

export const APP_ROUTES = RouterModule.forRoot(ROUTES, { useHash: true });
10 changes: 10 additions & 0 deletions steps/unit-tests-solution/src/app/home/home.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
h1 {
text-align: center;
}

section {
display: flex;
flex-flow: row wrap;
align-items: center;
justify-content: center;
}
3 changes: 3 additions & 0 deletions steps/unit-tests-solution/src/app/home/home.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<section><sfeir-card [person]="person" (personDelete)="random()"></sfeir-card></section>

<button mat-fab (click)="random()"><i class="material-icons">autorenew</i></button>
34 changes: 34 additions & 0 deletions steps/unit-tests-solution/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../environments/environment';

const BASE_URL = 'http://localhost:9000';

@Component({
selector: 'sfeir-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
private _person: any = {};

constructor(private _http: HttpClient) {}

/**
* OnInit implementation
*/
ngOnInit() {
this._http.get(`${BASE_URL}/api/peoples/`).subscribe(people => (this._person = people[0]));
}

/**
* Returns random people
*/
random() {
this._http.get(`${BASE_URL}/api/peoples/random`).subscribe(person => (this._person = person));
}

get person(): any {
return this._person;
}
}
1 change: 1 addition & 0 deletions steps/unit-tests-solution/src/app/home/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './home.component';
2 changes: 2 additions & 0 deletions steps/unit-tests-solution/src/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './app.component';
export * from './app.module';
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<sfeir-form (submit)="onSave($event)" (cancel)="onCancel()"></sfeir-form>
Loading

0 comments on commit dd76765

Please sign in to comment.