Skip to content

Commit 208d09e

Browse files
author
Dave Syer
committed
Copy application code from older sample
1 parent 37ce197 commit 208d09e

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

src/app/app.component.html

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
<!--The content below is only a placeholder and can be replaced.-->
2-
<div style="text-align:center">
1+
<div style="text-align:center"class="container">
32
<h1>
4-
Welcome to {{ title }}!
3+
Welcome {{title}}!
54
</h1>
6-
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
5+
<div class="container">
6+
<p>Id: <span>{{data.id}}</span></p>
7+
<p>Message: <span>{{data.content}}</span></p>
8+
</div>
79
</div>
8-
<h2>Here are some links to help you start: </h2>
9-
<ul>
10-
<li>
11-
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
12-
</li>
13-
<li>
14-
<h2><a target="_blank" rel="noopener" href="https://github.com/angular/angular-cli/wiki">CLI Documentation</a></h2>
15-
</li>
16-
<li>
17-
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
18-
</li>
19-
</ul>
2010

src/app/app.component.spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { TestBed, async } from '@angular/core/testing';
22
import { AppComponent } from './app.component';
3+
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
34
describe('AppComponent', () => {
45
beforeEach(async(() => {
56
TestBed.configureTestingModule({
7+
imports: [HttpClientTestingModule],
68
declarations: [
79
AppComponent
8-
],
10+
]
911
}).compileComponents();
1012
}));
1113
it('should create the app', async(() => {
@@ -16,12 +18,19 @@ describe('AppComponent', () => {
1618
it(`should have as title 'app'`, async(() => {
1719
const fixture = TestBed.createComponent(AppComponent);
1820
const app = fixture.debugElement.componentInstance;
19-
expect(app.title).toEqual('app');
21+
expect(app.title).toEqual('Demo');
2022
}));
2123
it('should render title in a h1 tag', async(() => {
2224
const fixture = TestBed.createComponent(AppComponent);
2325
fixture.detectChanges();
2426
const compiled = fixture.debugElement.nativeElement;
25-
expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');
27+
expect(compiled.querySelector('h1').textContent).toContain('Welcome Demo!');
28+
}));
29+
it('should fetch data from backend', async(() => {
30+
const http = TestBed.get(HttpTestingController);
31+
const fixture = TestBed.createComponent(AppComponent);
32+
const app = fixture.debugElement.componentInstance;
33+
http.expectOne('resource').flush({id: 'XYZ', content: 'Hello'});
34+
expect(app.data.content).toContain('Hello');
2635
}));
2736
});

src/app/app.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { Component } from '@angular/core';
2+
import { HttpClient } from '@angular/common/http';
23

34
@Component({
45
selector: 'app-root',
56
templateUrl: './app.component.html',
67
styleUrls: ['./app.component.css']
78
})
89
export class AppComponent {
9-
title = 'app';
10+
title = 'Demo';
11+
data = {};
12+
constructor(private http: HttpClient) {
13+
http.get('resource').subscribe(data => this.data = data);
14+
}
1015
}

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
33

44
import { AppComponent } from './app.component';
5+
import { HttpClientModule } from '@angular/common/http';
56

67
@NgModule({
78
declarations: [
89
AppComponent
910
],
1011
imports: [
11-
BrowserModule
12+
BrowserModule,
13+
HttpClientModule
1214
],
1315
providers: [],
1416
bootstrap: [AppComponent]

0 commit comments

Comments
 (0)