Skip to content

Commit 9a84345

Browse files
committed
testing shared service between child WC and host ShellApp
1 parent 9d2b4bc commit 9a84345

File tree

15 files changed

+147
-4
lines changed

15 files changed

+147
-4
lines changed

angular.json

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
"assets": [
2626
"apps/webapp/src/favicon.ico",
2727
"apps/webapp/src/assets",
28-
{ "glob": "main.js", "input": "dist/apps/chat-app/", "output": "/assets/chat-app" }
28+
{
29+
"glob": "main.js",
30+
"input": "dist/apps/chat-app/",
31+
"output": "/assets/chat-app"
32+
}
2933
],
3034
"styles": [
3135
"apps/webapp/src/styles.scss"
@@ -317,6 +321,39 @@
317321
}
318322
}
319323
}
324+
},
325+
"core": {
326+
"root": "libs/core",
327+
"sourceRoot": "libs/core/src",
328+
"projectType": "library",
329+
"prefix": "ngx-starter-kit",
330+
"architect": {
331+
"lint": {
332+
"builder": "@angular-devkit/build-angular:tslint",
333+
"options": {
334+
"tsConfig": [
335+
"libs/core/tsconfig.lib.json",
336+
"libs/core/tsconfig.spec.json"
337+
],
338+
"exclude": [
339+
"**/node_modules/**"
340+
]
341+
}
342+
},
343+
"test": {
344+
"builder": "@nrwl/builders:jest",
345+
"options": {
346+
"jestConfig": "libs/core/jest.config.js",
347+
"tsConfig": "libs/core/tsconfig.spec.json",
348+
"setupFile": "libs/core/src/test-setup.ts"
349+
}
350+
}
351+
},
352+
"schematics": {
353+
"@nrwl/schematics:component": {
354+
"styleext": "scss"
355+
}
356+
}
320357
}
321358
},
322359
"cli": {

apps/chat-app/src/app/button/button.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, ViewEncapsulation } from '@angular/core';
2+
import { StateService } from '@ngx-starter-kit/core';
23

34
@Component({
45
selector: 'wc-button',
@@ -15,14 +16,18 @@ export class ButtonComponent implements OnChanges {
1516

1617
private numberOfClicks = 0;
1718

18-
constructor() { }
19+
constructor(private stateService: StateService) {
20+
stateService.ctx.name = 'ButtonComponent sumo'
21+
}
1922

2023
ngOnChanges(changes: SimpleChanges) {
2124
console.log(changes);
2225
}
2326

2427
handleClick(event) {
2528
this.numberOfClicks++;
29+
this.stateService.ctx.age = this.stateService.ctx.age + 2;
30+
console.log('in ButtonComponent WC', this.stateService.ctx);
2631
this.action.emit(this.numberOfClicks);
2732
}
2833
}

libs/core/jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
name: 'core',
3+
preset: '../../jest.config.js',
4+
coverageDirectory: '../../coverage/libs/core'
5+
};

libs/core/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './lib/core.module';
2+
export * from './lib/services/state.service';

libs/core/src/lib/core.module.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { async, TestBed } from '@angular/core/testing';
2+
import { CoreModule } from './core.module';
3+
4+
describe('CoreModule', () => {
5+
beforeEach(async(() => {
6+
TestBed.configureTestingModule({
7+
imports: [CoreModule]
8+
}).compileComponents();
9+
}));
10+
11+
it('should create', () => {
12+
expect(CoreModule).toBeDefined();
13+
});
14+
});

libs/core/src/lib/core.module.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { NgModule } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
4+
@NgModule({
5+
imports: [CommonModule]
6+
})
7+
export class CoreModule {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Injectable } from '@angular/core';
2+
3+
@Injectable({
4+
providedIn: 'root'
5+
})
6+
export class StateService {
7+
ctx = {
8+
name: 'sumo',
9+
age: 5
10+
};
11+
constructor() { }
12+
}

libs/core/src/test-setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'jest-preset-angular';

libs/core/tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"types": ["node", "jest"]
5+
},
6+
"include": ["**/*.ts"]
7+
}

libs/core/tsconfig.lib.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc/libs/core",
5+
"target": "es2015",
6+
"module": "es2015",
7+
"moduleResolution": "node",
8+
"declaration": true,
9+
"sourceMap": true,
10+
"inlineSources": true,
11+
"emitDecoratorMetadata": true,
12+
"experimentalDecorators": true,
13+
"importHelpers": true,
14+
"types": [],
15+
"lib": ["dom", "es2018"]
16+
},
17+
"angularCompilerOptions": {
18+
"annotateForClosureCompiler": true,
19+
"skipTemplateCodegen": true,
20+
"strictMetadataEmit": true,
21+
"fullTemplateTypeCheck": true,
22+
"strictInjectionParameters": true,
23+
"enableResourceInlining": true
24+
},
25+
"exclude": ["src/test.ts", "**/*.spec.ts"]
26+
}

0 commit comments

Comments
 (0)