Compare commits

..

2 Commits

Author SHA1 Message Date
Kevin C. Coram f6a8f4ef20
Generate baseline application
Generate a baseline application that uses the same form as the global-form application, but renders it all as a dynamic/nested form in a single component.
2019-09-05 23:24:05 -04:00
Kevin C. Coram 57d46442c6
Refactor move ContactFormService into contact library 2019-09-05 22:56:08 -04:00
38 changed files with 546 additions and 7 deletions

View File

@ -254,6 +254,120 @@
} }
} }
} }
},
"baseline": {
"projectType": "application",
"schematics": {},
"root": "apps/baseline",
"sourceRoot": "apps/baseline/src",
"prefix": "base",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/apps/baseline",
"index": "apps/baseline/src/index.html",
"main": "apps/baseline/src/main.ts",
"polyfills": "apps/baseline/src/polyfills.ts",
"tsConfig": "apps/baseline/tsconfig.app.json",
"aot": false,
"assets": [
"apps/baseline/src/favicon.ico",
"apps/baseline/src/assets"
],
"styles": ["apps/baseline/src/styles.css"],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "apps/baseline/src/environments/environment.ts",
"with": "apps/baseline/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": "baseline:build"
},
"configurations": {
"production": {
"browserTarget": "baseline:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "baseline:build"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"apps/baseline/tsconfig.app.json",
"apps/baseline/tsconfig.spec.json"
],
"exclude": ["**/node_modules/**", "!apps/baseline/**"]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "apps/baseline/jest.config.js",
"tsConfig": "apps/baseline/tsconfig.spec.json",
"setupFile": "apps/baseline/src/test-setup.ts"
}
}
}
},
"baseline-e2e": {
"root": "apps/baseline-e2e",
"sourceRoot": "apps/baseline-e2e/src",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@nrwl/cypress:cypress",
"options": {
"cypressConfig": "apps/baseline-e2e/cypress.json",
"tsConfig": "apps/baseline-e2e/tsconfig.e2e.json",
"devServerTarget": "baseline:serve"
},
"configurations": {
"production": {
"devServerTarget": "baseline:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["apps/baseline-e2e/tsconfig.e2e.json"],
"exclude": ["**/node_modules/**", "!apps/baseline-e2e/**"]
}
}
}
} }
}, },
"cli": { "cli": {

View File

@ -0,0 +1,11 @@
{
"fileServerFolder": ".",
"fixturesFolder": "./src/fixtures",
"integrationFolder": "./src/integration",
"pluginsFile": "./src/plugins/index",
"supportFile": false,
"video": true,
"videosFolder": "../../dist/cypress/apps/baseline-e2e/videos",
"screenshotsFolder": "../../dist/cypress/apps/baseline-e2e/screenshots",
"chromeWebSecurity": false
}

View File

@ -0,0 +1,4 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io"
}

View File

@ -0,0 +1,9 @@
import { getGreeting } from '../support/app.po';
describe('baseline', () => {
beforeEach(() => cy.visit('/'));
it('should display welcome message', () => {
getGreeting().contains('Welcome to baseline!');
});
});

View File

@ -0,0 +1,22 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
const { preprocessTypescript } = require('@nrwl/cypress/plugins/preprocessor');
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
// Preprocess Typescript
on('file:preprocessor', preprocessTypescript(config));
};

View File

@ -0,0 +1 @@
export const getGreeting = () => cy.get('h1');

View File

@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

View File

@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands';

View File

@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc"
},
"include": ["src/**/*.ts"]
}

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["cypress", "node"]
},
"include": ["**/*.ts"]
}

View File

@ -0,0 +1 @@
{ "extends": "../../tslint.json", "rules": [] }

View File

@ -0,0 +1,12 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# You can see what browsers were selected by your queries by running:
# npx browserslist
> 0.5%
last 2 versions
Firefox ESR
not dead
not IE 9-11 # For IE 9-11 support, remove 'not'.

View File

@ -0,0 +1,9 @@
module.exports = {
name: 'baseline',
preset: '../../jest.config.js',
coverageDirectory: '../../coverage/apps/baseline',
snapshotSerializers: [
'jest-preset-angular/AngularSnapshotSerializer.js',
'jest-preset-angular/HTMLCommentSerializer.js',
],
};

View File

View File

@ -0,0 +1,64 @@
<form *ngIf="form" [formGroup]="form">
<ng-container formGroupName="nameGroup">
<div>
<label for="firstName">First Name: </label>
<input name="firstName" formControlName="firstName">
</div>
<div>
<label for="lastName">Last Name: </label>
<input name="lastName" formControlName="lastName">
</div>
<div>
<label for="middleName">Middle Name: </label>
<input name="middleName" formControlName="middleName">
</div>
<div>
<label for="prefix">Prefix: </label>
<input name="prefix" formControlName="prefix">
</div>
<div>
<label for="suffix">Suffix: </label>
<input name="suffix" formControlName="suffix">
</div>
</ng-container>
<ng-container formArrayName="addresses">
<ng-container *ngFor="let addr of addresses.controls; let i=index">
<ng-container [formGroupName]="i">
<div>
<label for="line1">Line 1: </label>
<input name="line1" formControlName="line1">
</div>
<div>
<label for="line2">Line 2: </label>
<input name="line2" formControlName="line2">
</div>
<div>
<label for="city">City: </label>
<input name="city" formControlName="city">
</div>
<div>
<label for="state">State: </label>
<input name="state" formControlName="state">
</div>
<div>
<label for="postalCode">Postal Code: </label>
<input name="postalCode" formControlName="postalCode">
</div>
</ng-container>
</ng-container>
</ng-container>
</form>
<hr />
<pre>
{{ form.value | json }}
</pre>

View File

@ -0,0 +1,19 @@
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { ReactiveFormsModule } from '@angular/forms';
import { ContactModule } from '@nested-forms/contact';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule, ContactModule.forRoot()],
declarations: [AppComponent],
}).compileComponents();
}));
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});
});

View File

@ -0,0 +1,44 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import {
Contact,
ContactService,
ContactFormService,
} from '@nested-forms/contact';
import { FormGroup, FormArray } from '@angular/forms';
import { Subscription } from 'rxjs';
@Component({
selector: 'base-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit, OnDestroy {
contact: Contact;
form: FormGroup;
private subscription: Subscription;
constructor(
private service: ContactService,
private formService: ContactFormService,
) {}
public ngOnInit() {
this.subscription = this.service
.loadContact()
.subscribe((data: Contact) => {
this.contact = data;
this.form = this.formService.createForm(data);
});
}
public ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
}
}
get addresses(): FormArray {
return this.form.get('addresses') as FormArray;
}
}

View File

@ -0,0 +1,14 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ReactiveFormsModule } from '@angular/forms';
import { ContactModule } from '@nested-forms/contact';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, ReactiveFormsModule, ContactModule.forRoot()],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}

View File

View File

@ -0,0 +1,3 @@
export const environment = {
production: true,
};

View File

@ -0,0 +1,16 @@
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false,
};
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Baseline</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<base-root></base-root>
</body>
</html>

13
apps/baseline/src/main.ts Normal file
View File

@ -0,0 +1,13 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch(err => console.error(err));

View File

@ -0,0 +1,62 @@
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
*/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
* because those flags need to be set before `zone.js` being loaded, and webpack
* will put import in the top of bundle, so user need to create a separate file
* in this directory (for example: zone-flags.ts), and put the following flags
* into that file, and then add the following code before importing zone.js.
* import './zone-flags.ts';
*
* The flags allowed in zone-flags.ts are listed here.
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*
* (window as any).__Zone_enable_cross_context_check = true;
*
*/
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/

View File

@ -0,0 +1 @@
/* You can add global styles to this file, and also import other style files */

View File

@ -0,0 +1 @@
import 'jest-preset-angular';

View File

@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": []
},
"include": ["**/*.ts"],
"exclude": ["src/test-setup.ts", "**/*.spec.ts"]
}

View File

@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": ["**/*.ts"]
}

View File

@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}

View File

@ -0,0 +1,7 @@
{
"extends": "../../tslint.json",
"rules": {
"directive-selector": [true, "attribute", "base", "camelCase"],
"component-selector": [true, "element", "base", "kebab-case"]
}
}

View File

@ -6,7 +6,6 @@ import { NameComponent } from './name/name.component';
import { AddressListComponent } from './address-list/address-list.component'; import { AddressListComponent } from './address-list/address-list.component';
import { AddressComponent } from './address/address.component'; import { AddressComponent } from './address/address.component';
import { ContactModule } from '@nested-forms/contact'; import { ContactModule } from '@nested-forms/contact';
import { ContactFormService } from './services/contact-form.service';
describe('AppComponent', () => { describe('AppComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
@ -14,10 +13,15 @@ describe('AppComponent', () => {
imports: [ imports: [
RouterTestingModule, RouterTestingModule,
ReactiveFormsModule, ReactiveFormsModule,
ContactModule.forRoot() ContactModule.forRoot(),
], ],
declarations: [AppComponent, NameComponent, AddressComponent, AddressListComponent], declarations: [
providers: [ ContactFormService ], AppComponent,
NameComponent,
AddressComponent,
AddressListComponent,
],
providers: [],
}).compileComponents(); }).compileComponents();
})); }));

View File

@ -1,8 +1,11 @@
import { Component, OnDestroy, OnInit } from '@angular/core'; import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms'; import { FormGroup } from '@angular/forms';
import { Contact, ContactService } from '@nested-forms/contact'; import {
Contact,
ContactService,
ContactFormService,
} from '@nested-forms/contact';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { ContactFormService } from './services/contact-form.service';
@Component({ @Component({
selector: 'nested-forms-root', selector: 'nested-forms-root',

View File

@ -1,3 +1,4 @@
export * from './lib/contact-model'; export * from './lib/contact-model';
export * from './lib/contact.service'; export * from './lib/contact.service';
export * from './lib/services/contact-form.service';
export * from './lib/contact.module'; export * from './lib/contact.module';

View File

@ -1,6 +1,7 @@
import { NgModule, Optional, SkipSelf } from '@angular/core'; import { NgModule, Optional, SkipSelf } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { ContactService } from './contact.service'; import { ContactService } from './contact.service';
import { ContactFormService } from './services/contact-form.service';
@NgModule({ @NgModule({
declarations: [], declarations: [],
@ -22,7 +23,7 @@ export class ContactModule {
static forRoot() { static forRoot() {
return { return {
ngModule: ContactModule, ngModule: ContactModule,
providers: [ ContactService ] providers: [ ContactService, ContactFormService ]
} }
} }
} }

View File

@ -22,6 +22,12 @@
}, },
"global-form": { "global-form": {
"tags": [] "tags": []
},
"baseline-e2e": {
"tags": []
},
"baseline": {
"tags": []
} }
} }
} }