Skip to content

Commit a79494d

Browse files
committed
feature: add an example and testing module
1 parent f199ca2 commit a79494d

11 files changed

+125
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { TestBed } from '@angular/core/testing';
2+
import { AppComponent } from './app.component';
3+
4+
describe('AppComponent', () => {
5+
beforeEach(async () => {
6+
await TestBed.configureTestingModule({
7+
imports: [AppComponent],
8+
}).compileComponents();
9+
});
10+
11+
it('should create the app', () => {
12+
const fixture = TestBed.createComponent(AppComponent);
13+
const app = fixture.componentInstance;
14+
expect(app).toBeTruthy();
15+
});
16+
17+
it(`should have the 'terminal' title`, () => {
18+
const fixture = TestBed.createComponent(AppComponent);
19+
const app = fixture.componentInstance;
20+
expect(app.title).toEqual('terminal');
21+
});
22+
23+
it('should render title', () => {
24+
const fixture = TestBed.createComponent(AppComponent);
25+
fixture.detectChanges();
26+
const compiled = fixture.nativeElement as HTMLElement;
27+
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, terminal');
28+
});
29+
});
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Component } from '@angular/core';
2+
import { AngularSerialService, provideAngularSerial, provideAngularSerialTest } from '../../../angular-serial/src';
3+
import { Observable, scan } from 'rxjs';
4+
import { AsyncPipe } from '@angular/common';
5+
6+
@Component({
7+
selector: 'app-root',
8+
standalone: true,
9+
imports: [AsyncPipe],
10+
providers: [provideAngularSerialTest(i => `Hello ${i}!\n`)],
11+
template: `
12+
<button (click)="open()">Open</button>
13+
<input #inputField
14+
type="text"
15+
(keydown.enter)="write(inputField.value); inputField.value=''"
16+
placeholder="Type and press Enter">
17+
<div>
18+
<textarea [value]="data$ | async" readonly></textarea>
19+
</div>
20+
`
21+
})
22+
export class AppComponent {
23+
24+
data$: Observable<string>;
25+
26+
constructor(private serial: AngularSerialService) {
27+
this.data$ = this.serial.read().pipe(
28+
scan((acc, value) => acc + value, '')
29+
);
30+
}
31+
32+
open(): void {
33+
this.serial.open().subscribe()
34+
}
35+
36+
write(value: string): void {
37+
this.serial.write(value).subscribe();
38+
}
39+
40+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ApplicationConfig } from '@angular/core';
2+
3+
4+
export const appConfig: ApplicationConfig = {
5+
providers: []
6+
};

projects/terminal/src/assets/.gitkeep

Whitespace-only changes.

projects/terminal/src/favicon.ico

14.7 KB
Binary file not shown.

projects/terminal/src/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Terminal</title>
6+
<base href="/">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<link rel="icon" type="image/x-icon" href="favicon.ico">
9+
</head>
10+
<body>
11+
<app-root></app-root>
12+
</body>
13+
</html>

projects/terminal/src/main.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { bootstrapApplication } from '@angular/platform-browser';
2+
import { appConfig } from './app/app.config';
3+
import { AppComponent } from './app/app.component';
4+
5+
bootstrapApplication(AppComponent, appConfig)
6+
.catch((err) => console.error(err));

projects/terminal/src/styles.scss

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

projects/terminal/tsconfig.app.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
2+
{
3+
"extends": "../../tsconfig.json",
4+
"compilerOptions": {
5+
"outDir": "../../out-tsc/app",
6+
"types": ["w3c-web-serial"]
7+
},
8+
"files": [
9+
"src/main.ts"
10+
],
11+
"include": [
12+
"src/**/*.d.ts"
13+
]
14+
}

projects/terminal/tsconfig.spec.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
2+
{
3+
"extends": "../../tsconfig.json",
4+
"compilerOptions": {
5+
"outDir": "../../out-tsc/spec",
6+
"types": [
7+
"jasmine"
8+
]
9+
},
10+
"include": [
11+
"src/**/*.spec.ts",
12+
"src/**/*.d.ts"
13+
]
14+
}

0 commit comments

Comments
 (0)