Differenzansicht 13-pipes
im Vergleich zu 12-validation

← Zurück zur Ãœbersicht | Demo | Quelltext auf GitHub
src/app/admin/book-create/book-create.component.spec.ts CHANGED
@@ -1,3 +1,4 @@
 
1
  import { ComponentFixture, TestBed } from '@angular/core/testing';
2
 
3
  import { BookCreateComponent } from './book-create.component';
@@ -8,7 +9,8 @@ describe('BookCreateComponent', () => {
8
 
9
  beforeEach(async () => {
10
  await TestBed.configureTestingModule({
11
- declarations: [ BookCreateComponent ]
 
12
  })
13
  .compileComponents();
14
 
1
+ import { HttpClientTestingModule } from '@angular/common/http/testing';
2
  import { ComponentFixture, TestBed } from '@angular/core/testing';
3
 
4
  import { BookCreateComponent } from './book-create.component';
9
 
10
  beforeEach(async () => {
11
  await TestBed.configureTestingModule({
12
+ imports: [HttpClientTestingModule],
13
+ declarations: [BookCreateComponent]
14
  })
15
  .compileComponents();
16
 
src/app/admin/book-edit/book-edit.component.spec.ts CHANGED
@@ -1,4 +1,6 @@
 
1
  import { ComponentFixture, TestBed } from '@angular/core/testing';
 
2
 
3
  import { BookEditComponent } from './book-edit.component';
4
 
@@ -8,7 +10,8 @@ describe('BookEditComponent', () => {
8
 
9
  beforeEach(async () => {
10
  await TestBed.configureTestingModule({
11
- declarations: [ BookEditComponent ]
 
12
  })
13
  .compileComponents();
14
 
1
+ import { HttpClientTestingModule } from '@angular/common/http/testing';
2
  import { ComponentFixture, TestBed } from '@angular/core/testing';
3
+ import { RouterTestingModule } from '@angular/router/testing';
4
 
5
  import { BookEditComponent } from './book-edit.component';
6
 
10
 
11
  beforeEach(async () => {
12
  await TestBed.configureTestingModule({
13
+ imports: [HttpClientTestingModule, RouterTestingModule],
14
+ declarations: [BookEditComponent]
15
  })
16
  .compileComponents();
17
 
src/app/admin/book-form/book-form.component.spec.ts CHANGED
@@ -1,4 +1,6 @@
 
1
  import { ComponentFixture, TestBed } from '@angular/core/testing';
 
2
 
3
  import { BookFormComponent } from './book-form.component';
4
 
@@ -8,7 +10,8 @@ describe('BookFormComponent', () => {
8
 
9
  beforeEach(async () => {
10
  await TestBed.configureTestingModule({
11
- declarations: [ BookFormComponent ]
 
12
  })
13
  .compileComponents();
14
 
1
+ import { HttpClientTestingModule } from '@angular/common/http/testing';
2
  import { ComponentFixture, TestBed } from '@angular/core/testing';
3
+ import { ReactiveFormsModule } from '@angular/forms';
4
 
5
  import { BookFormComponent } from './book-form.component';
6
 
10
 
11
  beforeEach(async () => {
12
  await TestBed.configureTestingModule({
13
+ imports: [HttpClientTestingModule, ReactiveFormsModule],
14
+ declarations: [BookFormComponent]
15
  })
16
  .compileComponents();
17
 
src/app/admin/form-errors/form-errors.component.spec.ts CHANGED
@@ -1,4 +1,5 @@
1
  import { ComponentFixture, TestBed } from '@angular/core/testing';
 
2
 
3
  import { FormErrorsComponent } from './form-errors.component';
4
 
@@ -8,7 +9,9 @@ describe('FormErrorsComponent', () => {
8
 
9
  beforeEach(async () => {
10
  await TestBed.configureTestingModule({
11
- declarations: [ FormErrorsComponent ]
 
 
12
  })
13
  .compileComponents();
14
 
1
  import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+ import { FormGroupDirective, ReactiveFormsModule } from '@angular/forms';
3
 
4
  import { FormErrorsComponent } from './form-errors.component';
5
 
9
 
10
  beforeEach(async () => {
11
  await TestBed.configureTestingModule({
12
+ imports: [ReactiveFormsModule],
13
+ declarations: [FormErrorsComponent],
14
+ providers: [FormGroupDirective]
15
  })
16
  .compileComponents();
17
 
src/app/admin/shared/async-validators.service.spec.ts CHANGED
@@ -1,3 +1,4 @@
 
1
  import { TestBed } from '@angular/core/testing';
2
 
3
  import { AsyncValidatorsService } from './async-validators.service';
@@ -6,7 +7,9 @@ describe('AsyncValidatorsService', () => {
6
  let service: AsyncValidatorsService;
7
 
8
  beforeEach(() => {
9
- TestBed.configureTestingModule({});
 
 
10
  service = TestBed.inject(AsyncValidatorsService);
11
  });
12
 
1
+ import { HttpClientTestingModule } from '@angular/common/http/testing';
2
  import { TestBed } from '@angular/core/testing';
3
 
4
  import { AsyncValidatorsService } from './async-validators.service';
7
  let service: AsyncValidatorsService;
8
 
9
  beforeEach(() => {
10
+ TestBed.configureTestingModule({
11
+ imports: [HttpClientTestingModule],
12
+ });
13
  service = TestBed.inject(AsyncValidatorsService);
14
  });
15
 
src/app/books/book-details/book-details.component.html CHANGED
@@ -10,11 +10,11 @@
10
  </div>
11
  <div>
12
  <h2>ISBN</h2>
13
- {{ book.isbn }}
14
  </div>
15
  <div *ngIf="book.published">
16
  <h2>Published</h2>
17
- {{ book.published }}
18
  </div>
19
  </div>
20
  <h2>Description</h2>
10
  </div>
11
  <div>
12
  <h2>ISBN</h2>
13
+ {{ book.isbn | isbn }}
14
  </div>
15
  <div *ngIf="book.published">
16
  <h2>Published</h2>
17
+ {{ book.published | date:'longDate' }}
18
  </div>
19
  </div>
20
  <h2>Description</h2>
src/app/books/book-details/book-details.component.spec.ts CHANGED
@@ -1,4 +1,6 @@
 
1
  import { ComponentFixture, TestBed } from '@angular/core/testing';
 
2
 
3
  import { BookDetailsComponent } from './book-details.component';
4
 
@@ -8,7 +10,8 @@ describe('BookDetailsComponent', () => {
8
 
9
  beforeEach(async () => {
10
  await TestBed.configureTestingModule({
11
- declarations: [ BookDetailsComponent ]
 
12
  })
13
  .compileComponents();
14
 
1
+ import { HttpClientTestingModule } from '@angular/common/http/testing';
2
  import { ComponentFixture, TestBed } from '@angular/core/testing';
3
+ import { RouterTestingModule } from '@angular/router/testing';
4
 
5
  import { BookDetailsComponent } from './book-details.component';
6
 
10
 
11
  beforeEach(async () => {
12
  await TestBed.configureTestingModule({
13
+ imports: [HttpClientTestingModule, RouterTestingModule],
14
+ declarations: [BookDetailsComponent]
15
  })
16
  .compileComponents();
17
 
src/app/books/book-list/book-list.component.spec.ts CHANGED
@@ -1,3 +1,4 @@
 
1
  import { ComponentFixture, TestBed } from '@angular/core/testing';
2
 
3
  import { BookListComponent } from './book-list.component';
@@ -8,7 +9,8 @@ describe('BookListComponent', () => {
8
 
9
  beforeEach(async () => {
10
  await TestBed.configureTestingModule({
11
- declarations: [ BookListComponent ]
 
12
  })
13
  .compileComponents();
14
 
1
+ import { HttpClientTestingModule } from '@angular/common/http/testing';
2
  import { ComponentFixture, TestBed } from '@angular/core/testing';
3
 
4
  import { BookListComponent } from './book-list.component';
9
 
10
  beforeEach(async () => {
11
  await TestBed.configureTestingModule({
12
+ imports: [HttpClientTestingModule],
13
+ declarations: [BookListComponent]
14
  })
15
  .compileComponents();
16
 
src/app/books/book-list-item/book-list-item.component.html CHANGED
@@ -9,5 +9,5 @@
9
  {{ author }}
10
  </li>
11
  </ul>
12
- <div>ISBN {{ book.isbn }}</div>
13
  </a>
9
  {{ author }}
10
  </li>
11
  </ul>
12
+ <div>ISBN {{ book.isbn | isbn }}</div>
13
  </a>
src/app/books/books.module.ts CHANGED
@@ -5,12 +5,14 @@ import { BooksRoutingModule } from './books-routing.module';
5
  import { BookListComponent } from './book-list/book-list.component';
6
  import { BookListItemComponent } from './book-list-item/book-list-item.component';
7
  import { BookDetailsComponent } from './book-details/book-details.component';
 
8
 
9
  @NgModule({
10
  declarations: [
11
  BookListComponent,
12
  BookListItemComponent,
13
- BookDetailsComponent
 
14
  ],
15
  imports: [
16
  CommonModule,
5
  import { BookListComponent } from './book-list/book-list.component';
6
  import { BookListItemComponent } from './book-list-item/book-list-item.component';
7
  import { BookDetailsComponent } from './book-details/book-details.component';
8
+ import { IsbnPipe } from './shared/isbn.pipe';
9
 
10
  @NgModule({
11
  declarations: [
12
  BookListComponent,
13
  BookListItemComponent,
14
+ BookDetailsComponent,
15
+ IsbnPipe
16
  ],
17
  imports: [
18
  CommonModule,
src/app/books/shared/isbn.pipe.spec.ts ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { IsbnPipe } from './isbn.pipe';
2
+
3
+ describe('IsbnPipe', () => {
4
+
5
+ let pipe: IsbnPipe;
6
+
7
+ beforeEach(() => {
8
+ pipe = new IsbnPipe();
9
+ });
10
+
11
+ it('should format an ISBN with a dash', () => {
12
+ expect(pipe.transform('9783864909467'))
13
+ .toBe('978-3864909467');
14
+ });
15
+
16
+ it('should ignore empty values', () => {
17
+ expect(pipe.transform('')).toBe('');
18
+ });
19
+ });
src/app/books/shared/isbn.pipe.ts ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Pipe, PipeTransform } from '@angular/core';
2
+
3
+ @Pipe({
4
+ name: 'isbn'
5
+ })
6
+ export class IsbnPipe implements PipeTransform {
7
+
8
+ transform(value: string): string {
9
+ if (!value) { return ''; }
10
+ return `${value.substring(0, 3)}-${value.substring(3)}`;
11
+ }
12
+
13
+ }
src/app/search/search.component.spec.ts CHANGED
@@ -1,3 +1,4 @@
 
1
  import { ComponentFixture, TestBed } from '@angular/core/testing';
2
 
3
  import { SearchComponent } from './search.component';
@@ -8,6 +9,7 @@ describe('SearchComponent', () => {
8
 
9
  beforeEach(async () => {
10
  await TestBed.configureTestingModule({
 
11
  declarations: [ SearchComponent ]
12
  })
13
  .compileComponents();
1
+ import { HttpClientTestingModule } from '@angular/common/http/testing';
2
  import { ComponentFixture, TestBed } from '@angular/core/testing';
3
 
4
  import { SearchComponent } from './search.component';
9
 
10
  beforeEach(async () => {
11
  await TestBed.configureTestingModule({
12
+ imports: [HttpClientTestingModule],
13
  declarations: [ SearchComponent ]
14
  })
15
  .compileComponents();
src/app/shared/book-store.service.spec.ts CHANGED
@@ -1,4 +1,5 @@
1
  import { TestBed } from '@angular/core/testing';
 
2
 
3
  import { BookStoreService } from './book-store.service';
4
 
@@ -6,7 +7,9 @@ describe('BookStoreService', () => {
6
  let service: BookStoreService;
7
 
8
  beforeEach(() => {
9
- TestBed.configureTestingModule({});
 
 
10
  service = TestBed.inject(BookStoreService);
11
  });
12
 
1
  import { TestBed } from '@angular/core/testing';
2
+ import { HttpClientTestingModule } from '@angular/common/http/testing';
3
 
4
  import { BookStoreService } from './book-store.service';
5
 
7
  let service: BookStoreService;
8
 
9
  beforeEach(() => {
10
+ TestBed.configureTestingModule({
11
+ imports: [HttpClientTestingModule],
12
+ });
13
  service = TestBed.inject(BookStoreService);
14
  });
15