Commit 78194c94 authored by Ryan Diehl's avatar Ryan Diehl

feat: add properties, logger and loading-events

imported from @psu/properties, @psu/logger and @psu/browser-utils
parent a8cd77a0
Pipeline #90220 passed with stages
in 4 minutes and 39 seconds
{
"typescript.tsdk": "node_modules/typescript/lib"
}
......@@ -280,6 +280,90 @@
}
}
}
},
"utils-properties": {
"projectType": "library",
"root": "libs/utils/properties",
"sourceRoot": "libs/utils/properties/src",
"prefix": "ut",
"architect": {
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["libs/utils/properties/tsconfig.lib.json", "libs/utils/properties/tsconfig.spec.json"],
"exclude": ["**/node_modules/**", "!libs/utils/properties/**"]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/utils/properties/jest.config.js",
"tsConfig": "libs/utils/properties/tsconfig.spec.json",
"setupFile": "libs/utils/properties/src/test-setup.ts"
}
}
},
"schematics": {
"@nrwl/angular:component": {
"styleext": "scss"
}
}
},
"utils-logger": {
"projectType": "library",
"root": "libs/utils/logger",
"sourceRoot": "libs/utils/logger/src",
"prefix": "ut",
"architect": {
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["libs/utils/logger/tsconfig.lib.json", "libs/utils/logger/tsconfig.spec.json"],
"exclude": ["**/node_modules/**", "!libs/utils/logger/**"]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/utils/logger/jest.config.js",
"tsConfig": "libs/utils/logger/tsconfig.spec.json",
"setupFile": "libs/utils/logger/src/test-setup.ts"
}
}
},
"schematics": {
"@nrwl/angular:component": {
"styleext": "scss"
}
}
},
"utils-loading-events": {
"projectType": "library",
"root": "libs/utils/loading-events",
"sourceRoot": "libs/utils/loading-events/src",
"prefix": "ut",
"architect": {
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["libs/utils/loading-events/tsconfig.lib.json", "libs/utils/loading-events/tsconfig.spec.json"],
"exclude": ["**/node_modules/**", "!libs/utils/loading-events/**"]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "libs/utils/loading-events/jest.config.js",
"tsConfig": "libs/utils/loading-events/tsconfig.spec.json",
"setupFile": "libs/utils/loading-events/src/test-setup.ts"
}
}
},
"schematics": {
"@nrwl/angular:component": {
"styleext": "scss"
}
}
}
},
"cli": {
......
# utils-loading-events
This library was generated with [Nx](https://nx.dev).
## Running unit tests
Run `nx test utils-loading-events` to execute the unit tests.
module.exports = {
name: 'utils-loading-events',
preset: '../../../jest.config.js',
coverageDirectory: '../../../coverage/libs/utils/loading-events',
snapshotSerializers: [
'jest-preset-angular/AngularSnapshotSerializer.js',
'jest-preset-angular/HTMLCommentSerializer.js'
]
};
{
"lib": {
"entryFile": "src/index.ts"
}
}
export * from './lib/loading-events';
export * from './lib/loading-events.module';
import { async, TestBed } from '@angular/core/testing';
import { LoadingEventsModule } from './loading-events.module';
describe('LoadingEventsModule', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [LoadingEventsModule]
}).compileComponents();
}));
it('should create', () => {
expect(LoadingEventsModule).toBeDefined();
});
});
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { LoggerModule } from '@psu/utils/logger';
import { LoadingEvents } from './loading-events';
@NgModule({
imports: [CommonModule, LoggerModule],
providers: [LoadingEvents]
})
export class LoadingEventsModule {}
import { DOCUMENT } from '@angular/common';
import { Inject, Injectable } from '@angular/core';
import { Logger } from '@psu/utils/logger';
@Injectable()
export class LoadingEvents {
private doc: Document;
private isAppReady: boolean;
constructor(@Inject(DOCUMENT) doc: any, private log: Logger) {
this.doc = doc;
this.isAppReady = false;
}
public triggerAppReady(): void {
if (this.isAppReady) {
return;
}
const bubbles = true;
const cancelable = false;
this.log.debug('appready event triggered');
this.doc.dispatchEvent(this.createEvent('appready', bubbles, cancelable));
this.isAppReady = true;
}
private createEvent(eventType: string, bubbles: boolean, cancelable: boolean): Event {
const customEvent: any = new CustomEvent(eventType, {
bubbles,
cancelable
});
return customEvent;
}
}
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"]
}
}
# utils-logger
This library was generated with [Nx](https://nx.dev).
## Running unit tests
Run `nx test utils-logger` to execute the unit tests.
module.exports = {
name: 'utils-logger',
preset: '../../../jest.config.js',
coverageDirectory: '../../../coverage/libs/utils/logger',
snapshotSerializers: [
'jest-preset-angular/AngularSnapshotSerializer.js',
'jest-preset-angular/HTMLCommentSerializer.js'
]
};
{
"lib": {
"entryFile": "src/index.ts"
}
}
export * from './lib/log-level.model';
export * from './lib/logger.module';
export * from './lib/logger.service';
/**
* The available options to set the Level of the Logger.
* See {@link Logger}.
*/
export enum Level {
OFF = 0,
ERROR = 1,
WARN = 2,
INFO = 3,
DEBUG = 4,
LOG = 5
}
import { async, TestBed } from '@angular/core/testing';
import { LoggerModule } from './logger.module';
describe('LoggerModule', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [LoggerModule]
}).compileComponents();
}));
it('should create', () => {
expect(LoggerModule).toBeDefined();
});
});
import { ModuleWithProviders, NgModule } from '@angular/core';
import { Logger, Options } from './logger.service';
@NgModule({})
export class LoggerModule {
public static forRoot(options: () => Options): ModuleWithProviders {
return {
ngModule: LoggerModule,
providers: [{ provide: Options, useFactory: options }, Logger]
};
}
}
import { Logger, Options } from './logger.service';
import { TestBed } from '@angular/core/testing';
describe('LoggerService', () => {
let service: Logger;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [Logger, { provide: Options, useValue: {} }]
});
service = TestBed.get(Logger);
});
it('should create', () => {
expect(service).toBeDefined();
});
});
import { Injectable } from '@angular/core';
import { Level } from './log-level.model';
/**
* Logger options.
* See {@link Logger}.
*
* level - How much detail you want to see in the logs, 0 being off, 1 being the less detailed, 5 being the most. Defaults to LOG.
*/
export class Options {
level: Level;
}
// For browsers that don't implement the debug method, log will be used instead. Fixes #62.
const CONSOLE_DEBUG_METHOD = console['debug'] ? 'debug' : 'log';
const DEFAULT_OPTIONS: Options = {
level: Level.LOG
};
@Injectable()
export class Logger {
private _level: Level;
public Level: any = Level;
constructor(options: Options) {
const { level } = Object.assign({}, DEFAULT_OPTIONS, options);
this._level = level;
}
public error(message?: any, ...optionalParams: any[]) {
if (this.isErrorEnabled()) {
console.error.apply(console, arguments);
}
}
public warn(message?: any, ...optionalParams: any[]) {
if (this.isWarnEnabled()) {
console.warn.apply(console, arguments);
}
}
public info(message?: any, ...optionalParams: any[]) {
if (this.isInfoEnabled()) {
// tslint:disable-next-line:no-console
console.info.apply(console, arguments);
}
}
public debug(message?: any, ...optionalParams: any[]) {
if (this.isDebugEnabled()) {
(<any>console)[CONSOLE_DEBUG_METHOD].apply(console, arguments);
}
}
public log(message?: any, ...optionalParams: any[]) {
if (this.isLogEnabled()) {
// tslint:disable-next-line: no-console
console.log.apply(console, arguments);
}
}
public isErrorEnabled = (): boolean => this.level >= Level.ERROR;
public isWarnEnabled = (): boolean => this.level >= Level.WARN;
public isInfoEnabled = (): boolean => this.level >= Level.INFO;
public isDebugEnabled = (): boolean => this.level >= Level.DEBUG;
public isLogEnabled = (): boolean => this.level >= Level.LOG;
public get level(): Level {
return this._level;
}
public set level(level: Level) {
this._level = level;
}
}
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,7 +5,9 @@
"@angular/common": "^8.0.0",
"@angular/core": "^8.0.0",
"@angular/cdk": "^8.2.3",
"ramda": "^0.27.0"
"ngx-cookie": ">=4.1.2",
"ramda": "^0.27.0",
"short-uuid": ">=3.1.1"
},
"private": false,
"repository": {
......
# utils-properties
This library was generated with [Nx](https://nx.dev).
## Running unit tests
Run `ng test utils-properties` to execute the unit tests.
module.exports = {
name: 'utils-properties',
preset: '../../../jest.config.js',
coverageDirectory: '../../../coverage/libs/utils/properties',
snapshotSerializers: [
'jest-preset-angular/AngularSnapshotSerializer.js',
'jest-preset-angular/HTMLCommentSerializer.js'
]
};
{
"lib": {
"entryFile": "src/index.ts"
}
}
export * from './lib/properties.config';
export * from './lib/properties.module';
export * from './lib/properties.service';
import { InjectionToken } from '@angular/core';
export interface PropertiesConfig {
propertiesBase: string;
}
export const PROPERTIES_CONFIG = new InjectionToken<PropertiesConfig>('properties.config');
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { LoadingEventsModule } from '@psu/utils/loading-events';
import { LoggerModule } from '@psu/utils/logger';
import { PropertiesService } from './properties.service';
@NgModule({
imports: [CommonModule, LoggerModule, LoadingEventsModule],
providers: [PropertiesService]
})
export class PropertiesModule {}
import { HttpRequest } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { async, TestBed } from '@angular/core/testing';
import { NO_CACHE_HEADER } from '@psu/utils/browser';
import { LoadingEvents } from '@psu/utils/loading-events';
import { Logger } from '@psu/utils/logger';
import * as mockdate from 'mockdate';
import { Mock } from 'ts-mocks';
import { PropertiesConfig, PROPERTIES_CONFIG } from './properties.config';
import { PropertiesService } from './properties.service';
interface MyAppProperties {
security: {};
endpoints: {};
}
let logger: Mock<Logger>;
let loadingEvents: Mock<LoadingEvents>;
let httpTestingController: HttpTestingController;
let service: PropertiesService<MyAppProperties>;
let now: Date;
let config: PropertiesConfig;
const testData: MyAppProperties = {
security: {
clientId: 'id1',
loginCheckURL: 'check',
bearerTokenBase: 'base',
protectedURLs: [],
redirectURI: 'red',
sessionCheckInterval: 200,
sessionWarnStart: 20,
stringTable: {}
},
endpoints: {
a: 'http://www.google.com',
'b-1': 'https://psu.edu/',
links: {
a: 'a link'
}
}
};
describe('PropertiesService', () => {
beforeEach(async(() => {
logger = new Mock<Logger>({
warn: () => {},
debug: () => {},
error: () => {}
});
loadingEvents =