Commit faff2782 authored by Ryan Diehl's avatar Ryan Diehl

Merge branch 'feature/browser' into 'develop'

fix: add ngrx entrypoint for window actions/effects

See merge request !21
parents ee012779 1c4c310b
Pipeline #96423 passed with stages
in 4 minutes and 48 seconds
......@@ -364,6 +364,34 @@
"styleext": "scss"
}
}
},
"utils-ngrx": {
"projectType": "library",
"root": "libs/utils/ngrx",
"sourceRoot": "libs/utils/ngrx/src",
"prefix": "ut",
"architect": {
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["libs/utils/ngrx/tsconfig.lib.json", "libs/utils/ngrx/tsconfig.spec.json"],
"exclude": ["**/node_modules/**", "!libs/utils/ngrx/**"]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/utils/ngrx/jest.config.js",
"tsConfig": "libs/utils/ngrx/tsconfig.spec.json",
"setupFile": "libs/utils/ngrx/src/test-setup.ts"
}
}
},
"schematics": {
"@nrwl/angular:component": {
"styleext": "scss"
}
}
}
},
"cli": {
......
......@@ -5,7 +5,7 @@ export { FocusModule } from './lib/focus/focus.module';
export { HttpErrorService } from './lib/http-error/http-error.service';
export { LoadingEvents } from './lib/loading-screen/loading-events';
export { LocalStorageService } from './lib/local-storage/local-storage.service';
export { RequestTracingConfig } from './lib/tracing/request-tracing.config';
export { RequestTracingConfig, REQUEST_TRACING_CONFIG } from './lib/tracing/request-tracing.config';
export { RequestTracingInterceptor, TRACE_HEADER } from './lib/tracing/request-tracing.interceptor';
export { UrlBuilder } from './lib/url-builder/url-builder';
export { WindowService } from './lib/window/window.service';
# utils-ngrx
This library was generated with [Nx](https://nx.dev).
## Running unit tests
Run `nx test utils-ngrx` to execute the unit tests.
module.exports = {
name: 'utils-ngrx',
preset: '../../../jest.config.js',
coverageDirectory: '../../../coverage/libs/utils/ngrx',
snapshotSerializers: [
'jest-preset-angular/AngularSnapshotSerializer.js',
'jest-preset-angular/HTMLCommentSerializer.js'
]
};
{
"lib": {
"entryFile": "src/index.ts"
}
}
export * from './lib/ngrx.module';
export * from './lib/window';
import { async, TestBed } from '@angular/core/testing';
import { NgrxModule } from './ngrx.module';
describe('NgrxModule', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [NgrxModule]
}).compileComponents();
}));
it('should create', () => {
expect(NgrxModule).toBeDefined();
});
});
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { EffectsModule } from '@ngrx/effects';
import { WindowEffects } from './window/window.effects';
@NgModule({
imports: [CommonModule, EffectsModule.forFeature([WindowEffects])]
})
export class NgrxModule {}
export * from './window.actions';
import { createAction, props } from '@ngrx/store';
export const goToUrl = createAction('[Window] Go To URL', props<{ url: string; external?: boolean }>());
import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { Action } from '@ngrx/store';
import { WindowService } from '@psu/utils/browser';
import { ReplaySubject } from 'rxjs';
import { Mock } from 'ts-mocks';
import { goToUrl } from './window.actions';
import { WindowEffects } from './window.effects';
describe('WindowEffects', () => {
let effects: WindowEffects;
let actions$: ReplaySubject<Action>;
let service: Mock<WindowService>;
let result: Action;
beforeEach(() => {
result = undefined;
actions$ = new ReplaySubject(1);
service = new Mock<WindowService>({
load: () => {},
openExternal: () => {}
});
TestBed.configureTestingModule({
providers: [WindowEffects, provideMockActions(actions$), { provide: WindowService, useValue: service.Object }]
});
effects = TestBed.get(WindowEffects);
});
it('should create', () => {
expect(effects).toBeDefined();
});
describe('goToUrl effect', () => {
beforeEach(() => {
effects.goToUrl$.subscribe(r => (result = r));
});
describe('when external', () => {
beforeEach(() => {
actions$.next(
goToUrl({
url: 'my/url',
external: true
})
);
});
it('should return no action', () => {
expect(result).toEqual({ type: 'NO_ACTION' });
});
it('should open external window', () => {
expect(service.Object.openExternal).toHaveBeenCalledWith('my/url');
expect(service.Object.load).not.toHaveBeenCalled();
});
});
describe('when internal', () => {
beforeEach(() => {
actions$.next(
goToUrl({
url: 'my/url'
})
);
});
it('should return no action', () => {
expect(result).toEqual({ type: 'NO_ACTION' });
});
it('should load in current window', () => {
expect(service.Object.load).toHaveBeenCalledWith('my/url');
expect(service.Object.openExternal).not.toHaveBeenCalled();
});
});
});
});
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { WindowService } from '@psu/utils/browser';
import { map, tap } from 'rxjs/operators';
import { goToUrl } from './window.actions';
@Injectable({ providedIn: 'root' })
export class WindowEffects {
public goToUrl$ = createEffect(
() =>
this.actions$.pipe(
ofType(goToUrl),
tap(action => {
if (action.external) {
this.service.openExternal(action.url);
} else {
this.service.load(action.url);
}
}),
map(() => ({ type: 'NO_ACTION' }))
),
{ dispatch: false }
);
constructor(private actions$: Actions, private service: WindowService) {}
}
import 'jest-preset-angular';
import '../../../../jestGlobalMocks';
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": ["**/*.ts"]
}
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"target": "es2015",
"declaration": true,
"inlineSources": true,
"types": [],
"lib": ["dom", "es2018"]
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
},
"exclude": ["src/test-setup.ts", "**/*.spec.ts"]
}
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
{
"extends": "../../../tslint.json",
"rules": {
"directive-selector": [true, "attribute", "ut", "camelCase"],
"component-selector": [true, "element", "ut", "kebab-case"]
}
}
......@@ -5,6 +5,8 @@
"@angular/common": "^8.0.0",
"@angular/core": "^8.0.0",
"@angular/cdk": "^8.2.3",
"@ngrx/store": "^8.0.0",
"@ngrx/effects": "^8.0.0",
"ramda": "^0.27.0",
"short-uuid": "^3.1.1"
},
......
......@@ -43,6 +43,9 @@
},
"utils-loading-events": {
"tags": []
},
"utils-ngrx": {
"tags": []
}
}
}
......@@ -25,7 +25,8 @@
"@psu/utils/theming": ["libs/utils/theming/src/index.ts"],
"@psu/utils/properties": ["libs/utils/properties/src/index.ts"],
"@psu/utils/logger": ["libs/utils/logger/src/index.ts"],
"@psu/utils/loading-events": ["libs/utils/loading-events/src/index.ts"]
"@psu/utils/loading-events": ["libs/utils/loading-events/src/index.ts"],
"@psu/utils/ngrx": ["libs/utils/ngrx/src/index.ts"]
}
},
"exclude": ["node_modules", "tmp"]
......
......@@ -1255,6 +1255,16 @@
"@types/istanbul-reports" "^1.1.1"
"@types/yargs" "^13.0.0"
"@ngrx/effects@~8.3.0":
version "8.3.0"
resolved "https://nexus.ci.psu.edu/repository/npm-all/@ngrx/effects/-/effects-8.3.0.tgz#d99a777ab352d4efdf456a7dec307514187ba496"
integrity sha512-/DdBqCFpHOJZUAmIpefQ8EVwmJXXkcEdLhsV8aXncCNWkK61sy/MbZZfDAbee6Cd1is33bVXRUKD49Z+Upvw5A==
"@ngrx/store@~8.3.0":
version "8.3.0"
resolved "https://nexus.ci.psu.edu/repository/npm-all/@ngrx/store/-/store-8.3.0.tgz#f2eaf428ec9e8379801cc37e3f6bffe88c2af472"
integrity sha512-QtM5T6/wTYqAlqeW60ptqqrsBwYF7jvQHsh0yE3AnwZIQvSbLFM2t5S2kN+753v4rHiXVRrA5pLaLzjGhAKcSg==
"@ngtools/json-schema@^1.1.0":
version "1.1.0"
resolved "https://nexus.ci.psu.edu/repository/npm-all/@ngtools/json-schema/-/json-schema-1.1.0.tgz#c3a0c544d62392acc2813a42c8a0dc6f58f86922"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment