Browse Source

Merge pull request #1834 from abpframework/feature/tests

test: fix tests
pull/1838/head
Yasin Aydın 7 years ago
committed by GitHub
parent
commit
09362c5bef
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      npm/ng-packs/.prettierrc
  2. 21
      npm/ng-packs/.vscode/settings.json
  3. 159
      npm/ng-packs/angular.json
  4. 12
      npm/ng-packs/apps/dev-app/browserslist
  5. 30
      npm/ng-packs/apps/dev-app/e2e/protractor.conf.js
  6. 28
      npm/ng-packs/apps/dev-app/e2e/src/app.e2e-spec.ts
  7. 11
      npm/ng-packs/apps/dev-app/e2e/src/app.po.ts
  8. 9
      npm/ng-packs/apps/dev-app/e2e/tsconfig.json
  9. 32
      npm/ng-packs/apps/dev-app/karma.conf.js
  10. 34
      npm/ng-packs/apps/dev-app/src/app/app-routing.module.ts
  11. 10
      npm/ng-packs/apps/dev-app/src/app/app.component.ts
  12. 43
      npm/ng-packs/apps/dev-app/src/app/app.module.ts
  13. 18
      npm/ng-packs/apps/dev-app/src/app/home/home-routing.module.ts
  14. 15
      npm/ng-packs/apps/dev-app/src/app/home/home.component.html
  15. 14
      npm/ng-packs/apps/dev-app/src/app/home/home.component.ts
  16. 10
      npm/ng-packs/apps/dev-app/src/app/home/home.module.ts
  17. 7
      npm/ng-packs/apps/dev-app/src/app/lazy-libs/account-wrapper.module.ts
  18. 7
      npm/ng-packs/apps/dev-app/src/app/lazy-libs/identity-wrapper.module.ts
  19. 7
      npm/ng-packs/apps/dev-app/src/app/lazy-libs/tenant-management-wrapper.module.ts
  20. 14
      npm/ng-packs/apps/dev-app/src/app/shared/shared.module.ts
  21. 0
      npm/ng-packs/apps/dev-app/src/assets/.gitkeep
  22. 25
      npm/ng-packs/apps/dev-app/src/environments/environment.prod.ts
  23. 25
      npm/ng-packs/apps/dev-app/src/environments/environment.ts
  24. BIN
      npm/ng-packs/apps/dev-app/src/favicon.ico
  25. 13
      npm/ng-packs/apps/dev-app/src/index.html
  26. 13
      npm/ng-packs/apps/dev-app/src/main.ts
  27. 62
      npm/ng-packs/apps/dev-app/src/polyfills.ts
  28. 1
      npm/ng-packs/apps/dev-app/src/styles.scss
  29. 14
      npm/ng-packs/apps/dev-app/src/test.ts
  30. 38
      npm/ng-packs/apps/dev-app/tsconfig.app.json
  31. 9
      npm/ng-packs/apps/dev-app/tsconfig.spec.json
  32. 7
      npm/ng-packs/apps/dev-app/tslint.json
  33. 18
      npm/ng-packs/package.json
  34. 13
      npm/ng-packs/packages/core/src/lib/plugins/config/config.plugin.ts
  35. 3
      npm/ng-packs/packages/core/src/lib/services/application-configuration.service.ts
  36. 13
      npm/ng-packs/packages/core/src/lib/services/localization.service.ts
  37. 7
      npm/ng-packs/packages/core/src/lib/services/rest.service.ts
  38. 35
      npm/ng-packs/packages/core/src/lib/states/config.state.ts
  39. 343
      npm/ng-packs/packages/core/src/lib/tests/config.plugin.spec.ts
  40. 57
      npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts
  41. 37
      npm/ng-packs/packages/core/src/lib/tests/locale.provider.spec.ts
  42. 2
      npm/ng-packs/packages/core/src/lib/tests/router-outlet.component.spec.ts
  43. 3
      npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts
  44. 18
      npm/ng-packs/packages/core/tsconfig.spec.json
  45. 3
      npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.html
  46. 6
      npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.ts
  47. 17
      npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts
  48. 9
      npm/ng-packs/packages/theme-shared/src/lib/tests/button.component.spec.ts
  49. 83
      npm/ng-packs/packages/theme-shared/src/lib/tests/error.handler.spec.ts
  50. 46
      npm/ng-packs/packages/theme-shared/src/lib/tests/state-overwrite.ts
  51. 3
      npm/ng-packs/scripts/package.json
  52. 15
      npm/ng-packs/scripts/push.js
  53. 9
      npm/ng-packs/tsconfig.json

3
npm/ng-packs/.prettierrc

@ -1,4 +1,5 @@
{
"printWidth": 120,
"singleQuote": true
"singleQuote": true,
"trailingComma": "all"
}

21
npm/ng-packs/.vscode/settings.json

@ -1,5 +1,22 @@
{
"search.exclude": {
"**/dist": true
}
}
},
"tslint.rulesDirectory": "../node_modules/codelyzer",
"typescript.tsdk": "../node_modules/typescript/lib",
"workbench.colorCustomizations": {
"activityBar.background": "#df7fa2",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#c7ecb3",
"activityBarBadge.foreground": "#15202b",
"titleBar.activeBackground": "#d55685",
"titleBar.inactiveBackground": "#d5568599",
"titleBar.activeForeground": "#15202b",
"titleBar.inactiveForeground": "#15202b99",
"statusBar.background": "#d55685",
"statusBarItem.hoverBackground": "#c73169",
"statusBar.foreground": "#15202b"
},
"peacock.color": "#d55685"
}

159
npm/ng-packs/angular.json

@ -27,10 +27,7 @@
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"packages/core/tsconfig.lib.json",
"packages/core/tsconfig.spec.json"
],
"tsConfig": ["packages/core/tsconfig.lib.json", "packages/core/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
@ -61,10 +58,7 @@
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"packages/theme-shared/tsconfig.lib.json",
"packages/theme-shared/tsconfig.spec.json"
],
"tsConfig": ["packages/theme-shared/tsconfig.lib.json", "packages/theme-shared/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
@ -95,10 +89,7 @@
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"packages/theme-basic/tsconfig.lib.json",
"packages/theme-basic/tsconfig.spec.json"
],
"tsConfig": ["packages/theme-basic/tsconfig.lib.json", "packages/theme-basic/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
@ -128,10 +119,7 @@
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"packages/account/tsconfig.lib.json",
"packages/account/tsconfig.spec.json"
],
"tsConfig": ["packages/account/tsconfig.lib.json", "packages/account/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
@ -194,10 +182,7 @@
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"packages/identity/tsconfig.lib.json",
"packages/identity/tsconfig.spec.json"
],
"tsConfig": ["packages/identity/tsconfig.lib.json", "packages/identity/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
@ -359,10 +344,7 @@
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"packages/identity-config/tsconfig.lib.json",
"packages/identity-config/tsconfig.spec.json"
],
"tsConfig": ["packages/identity-config/tsconfig.lib.json", "packages/identity-config/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
@ -392,10 +374,7 @@
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"packages/account-config/tsconfig.lib.json",
"packages/account-config/tsconfig.spec.json"
],
"tsConfig": ["packages/account-config/tsconfig.lib.json", "packages/account-config/tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
@ -433,6 +412,130 @@
}
}
}
},
"dev-app": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
},
"root": "apps/dev-app",
"sourceRoot": "apps/dev-app/src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/dev-app",
"index": "apps/dev-app/src/index.html",
"main": "apps/dev-app/src/main.ts",
"polyfills": "apps/dev-app/src/polyfills.ts",
"tsConfig": "apps/dev-app/tsconfig.app.json",
"aot": false,
"assets": ["apps/dev-app/src/favicon.ico", "apps/dev-app/src/assets"],
"styles": [
"apps/dev-app/src/styles.scss",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/font-awesome/css/font-awesome.min.css",
"node_modules/primeng/resources/themes/nova-light/theme.css",
"node_modules/primeicons/primeicons.css",
"node_modules/primeng/resources/primeng.min.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "apps/dev-app/src/environments/environment.ts",
"with": "apps/dev-app/src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "dev-app:build"
},
"configurations": {
"production": {
"browserTarget": "dev-app:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "dev-app:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "apps/dev-app/src/test.ts",
"polyfills": "apps/dev-app/src/polyfills.ts",
"tsConfig": "apps/dev-app/tsconfig.spec.json",
"karmaConfig": "apps/dev-app/karma.conf.js",
"assets": ["apps/dev-app/src/favicon.ico", "apps/dev-app/src/assets"],
"styles": [
"apps/dev-app/src/styles.scss",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/font-awesome/css/font-awesome.min.css",
"node_modules/primeng/resources/themes/nova-light/theme.css",
"node_modules/primeicons/primeicons.css",
"node_modules/primeng/resources/primeng.min.css"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"apps/dev-app/tsconfig.app.json",
"apps/dev-app/tsconfig.spec.json",
"apps/dev-app/e2e/tsconfig.json"
],
"exclude": ["**/node_modules/**"]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "apps/dev-app/e2e/protractor.conf.js",
"devServerTarget": "dev-app:serve"
},
"configurations": {
"production": {
"devServerTarget": "dev-app:serve:production"
}
}
}
}
}
},
"defaultProject": "core"

12
npm/ng-packs/apps/dev-app/browserslist

@ -0,0 +1,12 @@
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# You can see what browsers were selected by your queries by running:
# npx browserslist
> 0.5%
last 2 versions
Firefox ESR
not dead
not IE 9-11 # For IE 9-11 support, remove 'not'.

30
npm/ng-packs/apps/dev-app/e2e/protractor.conf.js

@ -0,0 +1,30 @@
// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require('jasmine-spec-reporter');
/**
* @type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 11000,
specs: ['./src/**/*.e2e-spec.ts'],
capabilities: {
browserName: 'chrome',
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {},
},
onPrepare() {
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json'),
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
},
};

28
npm/ng-packs/apps/dev-app/e2e/src/app.e2e-spec.ts

@ -0,0 +1,28 @@
import { AppPage } from './app.po';
import { browser, logging } from 'protractor';
describe('workspace-project App', () => {
let page: AppPage;
beforeEach(() => {
page = new AppPage();
});
it('should display welcome message', () => {
page.navigateTo();
expect(page.getTitleText()).toEqual('dev-app app is running!');
});
afterEach(async () => {
// Assert that there are no errors emitted from the browser
const logs = await browser
.manage()
.logs()
.get(logging.Type.BROWSER);
expect(logs).not.toContain(
jasmine.objectContaining({
level: logging.Level.SEVERE,
} as logging.Entry),
);
});
});

11
npm/ng-packs/apps/dev-app/e2e/src/app.po.ts

@ -0,0 +1,11 @@
import { browser, by, element } from 'protractor';
export class AppPage {
navigateTo() {
return browser.get(browser.baseUrl) as Promise<any>;
}
getTitleText() {
return element(by.css('app-root .content span')).getText() as Promise<string>;
}
}

9
npm/ng-packs/apps/dev-app/e2e/tsconfig.json

@ -0,0 +1,9 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../../../out-tsc/e2e",
"module": "commonjs",
"target": "es5",
"types": ["jasmine", "jasminewd2", "node"]
}
}

32
npm/ng-packs/apps/dev-app/karma.conf.js

@ -0,0 +1,32 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage/dev-app'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true,
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
});
};

34
npm/ng-packs/apps/dev-app/src/app/app-routing.module.ts

@ -0,0 +1,34 @@
import { ABP } from '@abp/ng.core';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{
path: '',
loadChildren: () => import('./home/home.module').then(m => m.HomeModule),
data: {
routes: {
name: '::Menu:Home',
} as ABP.Route,
},
},
{
path: 'account',
loadChildren: () => import('./lazy-libs/account-wrapper.module').then(m => m.AccountWrapperModule),
},
{
path: 'identity',
loadChildren: () => import('./lazy-libs/identity-wrapper.module').then(m => m.IdentityWrapperModule),
},
{
path: 'tenant-management',
loadChildren: () =>
import('./lazy-libs/tenant-management-wrapper.module').then(m => m.TenantManagementWrapperModule),
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}

10
npm/ng-packs/apps/dev-app/src/app/app.component.ts

@ -0,0 +1,10 @@
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `
<abp-loader-bar></abp-loader-bar>
<router-outlet></router-outlet>
`,
})
export class AppComponent {}

43
npm/ng-packs/apps/dev-app/src/app/app.module.ts

@ -0,0 +1,43 @@
import { CoreModule } from '@abp/ng.core';
import { LAYOUTS } from '@abp/ng.theme.basic';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgxsReduxDevtoolsPluginModule } from '@ngxs/devtools-plugin';
import { NgxsModule } from '@ngxs/store';
import { OAuthModule } from 'angular-oauth2-oidc';
import { environment } from '../environments/environment';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { SharedModule } from './shared/shared.module';
import { ThemeSharedModule } from '@abp/ng.theme.shared';
import { AccountConfigModule } from '@abp/ng.account.config';
import { IdentityConfigModule } from '@abp/ng.identity.config';
import { TenantManagementConfigModule } from '@abp/ng.tenant-management.config';
@NgModule({
declarations: [AppComponent],
imports: [
CoreModule.forRoot({
environment,
requirements: {
layouts: LAYOUTS,
},
}),
ThemeSharedModule.forRoot(),
AccountConfigModule.forRoot({ redirectUrl: '/' }),
IdentityConfigModule,
TenantManagementConfigModule,
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
SharedModule,
OAuthModule.forRoot(),
NgxsModule.forRoot([]),
NgxsReduxDevtoolsPluginModule.forRoot(),
],
bootstrap: [AppComponent],
})
export class AppModule {}

18
npm/ng-packs/apps/dev-app/src/app/home/home-routing.module.ts

@ -0,0 +1,18 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home.component';
import { ApplicationLayoutComponent } from '@abp/ng.theme.basic';
const routes: Routes = [
{
path: '',
component: ApplicationLayoutComponent,
children: [{ path: '', component: HomeComponent }],
},
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class HomeRoutingModule {}

15
npm/ng-packs/apps/dev-app/src/app/home/home.component.html

@ -0,0 +1,15 @@
<div class="card">
<div class="card-header">{{ '::Welcome' | abpLocalization }}</div>
<div class="card-body">
<p>
{{ '::LongWelcomeMessage' | abpLocalization }}
</p>
<p *ngIf="!hasLoggedIn">
<a routerLink="/account/login" [state]="{ redirectUrl: '/' }" class="btn btn-primary" role="button"
><i class="fa fa-sign-in"></i>{{ 'AbpIdentity::Login' | abpLocalization }}</a
>
</p>
<hr />
<p class="text-right"><a href="https://abp.io?ref=tmpl" target="_blank">abp.io</a></p>
</div>
</div>

14
npm/ng-packs/apps/dev-app/src/app/home/home.component.ts

@ -0,0 +1,14 @@
import { Component } from '@angular/core';
import { OAuthService } from 'angular-oauth2-oidc';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
})
export class HomeComponent {
get hasLoggedIn(): boolean {
return this.oAuthService.hasValidAccessToken();
}
constructor(private oAuthService: OAuthService) {}
}

10
npm/ng-packs/apps/dev-app/src/app/home/home.module.ts

@ -0,0 +1,10 @@
import { NgModule } from '@angular/core';
import { SharedModule } from '../shared/shared.module';
import { HomeRoutingModule } from './home-routing.module';
import { HomeComponent } from './home.component';
@NgModule({
declarations: [HomeComponent],
imports: [SharedModule, HomeRoutingModule],
})
export class HomeModule {}

7
npm/ng-packs/apps/dev-app/src/app/lazy-libs/account-wrapper.module.ts

@ -0,0 +1,7 @@
import { NgModule } from '@angular/core';
import { AccountModule } from '@abp/ng.account';
@NgModule({
imports: [AccountModule],
})
export class AccountWrapperModule {}

7
npm/ng-packs/apps/dev-app/src/app/lazy-libs/identity-wrapper.module.ts

@ -0,0 +1,7 @@
import { NgModule } from '@angular/core';
import { IdentityModule } from '@abp/ng.identity';
@NgModule({
imports: [IdentityModule],
})
export class IdentityWrapperModule {}

7
npm/ng-packs/apps/dev-app/src/app/lazy-libs/tenant-management-wrapper.module.ts

@ -0,0 +1,7 @@
import { NgModule } from '@angular/core';
import { TenantManagementModule } from '@abp/ng.tenant-management';
@NgModule({
imports: [TenantManagementModule],
})
export class TenantManagementWrapperModule {}

14
npm/ng-packs/apps/dev-app/src/app/shared/shared.module.ts

@ -0,0 +1,14 @@
import { CoreModule } from '@abp/ng.core';
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';
import { NgModule } from '@angular/core';
import { ThemeBasicModule } from '@abp/ng.theme.basic';
import { ThemeSharedModule } from '@abp/ng.theme.shared';
import { TableModule } from 'primeng/table';
@NgModule({
declarations: [],
imports: [CoreModule, ThemeSharedModule, ThemeBasicModule, TableModule, NgbDropdownModule],
exports: [CoreModule, ThemeSharedModule, ThemeBasicModule, TableModule, NgbDropdownModule],
providers: [],
})
export class SharedModule {}

0
npm/ng-packs/apps/dev-app/src/assets/.gitkeep

25
npm/ng-packs/apps/dev-app/src/environments/environment.prod.ts

@ -0,0 +1,25 @@
export const environment = {
production: true,
hmr: false,
application: {
name: 'MyProjectName',
logoUrl: '',
},
oAuthConfig: {
issuer: 'https://localhost:44305',
clientId: 'MyProjectName_App',
dummyClientSecret: '1q2w3e*',
scope: 'MyProjectName',
showDebugInformation: true,
oidc: false,
requireHttps: true,
},
apis: {
default: {
url: 'https://localhost:44305',
},
},
localization: {
defaultResourceName: 'MyProjectName',
},
};

25
npm/ng-packs/apps/dev-app/src/environments/environment.ts

@ -0,0 +1,25 @@
export const environment = {
production: false,
hmr: false,
application: {
name: 'MyProjectName',
logoUrl: '',
},
oAuthConfig: {
issuer: 'https://localhost:44305',
clientId: 'MyProjectName_App',
dummyClientSecret: '1q2w3e*',
scope: 'MyProjectName',
showDebugInformation: true,
oidc: false,
requireHttps: true,
},
apis: {
default: {
url: 'https://localhost:44305',
},
},
localization: {
defaultResourceName: 'MyProjectName',
},
};

BIN
npm/ng-packs/apps/dev-app/src/favicon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 948 B

13
npm/ng-packs/apps/dev-app/src/index.html

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>DevApp</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<app-root></app-root>
</body>
</html>

13
npm/ng-packs/apps/dev-app/src/main.ts

@ -0,0 +1,13 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch(err => console.error(err));

62
npm/ng-packs/apps/dev-app/src/polyfills.ts

@ -0,0 +1,62 @@
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
*/
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
* because those flags need to be set before `zone.js` being loaded, and webpack
* will put import in the top of bundle, so user need to create a separate file
* in this directory (for example: zone-flags.ts), and put the following flags
* into that file, and then add the following code before importing zone.js.
* import './zone-flags.ts';
*
* The flags allowed in zone-flags.ts are listed here.
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*
* (window as any).__Zone_enable_cross_context_check = true;
*
*/
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/

1
npm/ng-packs/apps/dev-app/src/styles.scss

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

14
npm/ng-packs/apps/dev-app/src/test.ts

@ -0,0 +1,14 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

38
npm/ng-packs/apps/dev-app/tsconfig.app.json

@ -0,0 +1,38 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": [],
"paths": {
"@abp/ng.core": ["packages/core/src/public-api.ts"],
"@abp/ng.core/*": ["packages/core/src/lib/*"],
// "@abp/ng.theme.shared": ["packages/theme-shared/src/public-api.ts"],
// "@abp/ng.theme.shared/*": ["packages/theme-shared/src/lib/*"],
"@abp/ng.theme.basic": ["packages/theme-basic/src/public-api.ts"],
"@abp/ng.theme.basic/*": ["packages/theme-basic/src/lib/*"],
"@abp/ng.account": ["packages/account/src/public-api.ts"],
"@abp/ng.account/*": ["packages/account/src/lib/*"],
"@abp/ng.account.config": ["packages/account-config/src/public-api.ts"],
"@abp/ng.account.config/*": ["packages/account-config/src/lib/*"],
"@abp/ng.identity": ["packages/identity/src/public-api.ts"],
"@abp/ng.identity/*": ["packages/identity/src/lib/*"],
"@abp/ng.identity.config": ["packages/identity-config/src/public-api.ts"],
"@abp/ng.identity.config/*": ["packages/identity-config/src/lib/*"],
"@abp/ng.tenant-management": ["packages/tenant-management/src/public-api.ts"],
"@abp/ng.tenant-management/*": ["packages/tenant-management/src/lib/*"],
"@abp/ng.tenant-management.config": ["packages/tenant-management-config/src/public-api.ts"],
"@abp/ng.tenant-management.config/*": ["packages/tenant-management-config/src/lib/*"],
"@abp/ng.setting-management": ["packages/setting-management/src/public-api.ts"],
"@abp/ng.setting-management/*": ["packages/setting-management/src/lib/*"],
"@abp/ng.setting-management.config": ["packages/setting-management-config/src/public-api.ts"],
"@abp/ng.setting-management.config/*": ["packages/setting-management-config/src/lib/*"],
"@abp/ng.permission-management": ["packages/permission-management/src/public-api.ts"],
"@abp/ng.permission-management/*": ["packages/permission-management/src/lib/*"],
"@abp/ng.feature-management": ["packages/feature-management/src/public-api.ts"],
"@abp/ng.feature-management/*": ["packages/feature-management/src/lib/*"]
}
},
"files": ["src/main.ts", "src/polyfills.ts"],
"include": ["src/**/*.ts"],
"exclude": ["src/test.ts", "src/**/*.spec.ts"]
}

9
npm/ng-packs/apps/dev-app/tsconfig.spec.json

@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": ["jasmine", "node"]
},
"files": ["src/test.ts", "src/polyfills.ts"],
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}

7
npm/ng-packs/apps/dev-app/tslint.json

@ -0,0 +1,7 @@
{
"extends": "../../tslint.json",
"rules": {
"directive-selector": [true, "attribute", "app", "camelCase"],
"component-selector": [true, "element", "app", "kebab-case"]
}
}

18
npm/ng-packs/package.json

@ -1,9 +1,10 @@
{
"scripts": {
"start": "ng serve dev-app",
"ng": "ng",
"symlink": "symlink",
"abpng": "abpng",
"commit": "git-cz",
"commit": "git-cz && node scripts/push.js",
"lint": "ng lint --fix"
},
"devDependencies": {
@ -17,20 +18,21 @@
"@angular/cdk": "^8.2.2",
"@angular/cli": "~8.3.6",
"@angular/common": "~8.2.8",
"@angular/compiler-cli": "~8.2.8",
"@angular/compiler": "~8.2.8",
"@angular/compiler-cli": "~8.2.8",
"@angular/core": "~8.2.8",
"@angular/forms": "~8.2.8",
"@angular/language-service": "~8.2.8",
"@angular/platform-browser-dynamic": "~8.2.8",
"@angular/platform-browser": "~8.2.8",
"@angular/platform-browser-dynamic": "~8.2.8",
"@angular/router": "~8.2.8",
"@ng-bootstrap/ng-bootstrap": "^5.1.0",
"@ngneat/spectator": "^4.3.2",
"@ngx-validate/core": "^0.0.5",
"@ngxs/router-plugin": "^3.5.0",
"@ngxs/storage-plugin": "^3.5.0",
"@ngxs/store": "^3.5.0",
"@ngxs/devtools-plugin": "^3.5.1",
"@ngxs/router-plugin": "^3.5.1",
"@ngxs/storage-plugin": "^3.5.1",
"@ngxs/store": "^3.5.1",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
@ -45,11 +47,11 @@
"jasmine-spec-reporter": "~4.2.1",
"just-clone": "3.1.0",
"just-compare": "^1.3.0",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"karma-jasmine": "~2.0.1",
"karma": "~4.1.0",
"karma-jasmine-html-reporter": "^1.4.0",
"lint-staged": "^9.4.0",
"ng-packagr": "^5.5.0",
"ngx-perfect-scrollbar": "^8.0.0",

13
npm/ng-packs/packages/core/src/lib/plugins/config/config.plugin.ts

@ -20,7 +20,6 @@ export class ConfigPlugin implements NgxsPlugin {
const matches = actionMatcher(event);
const isInitAction = matches(InitState) || matches(UpdateState);
// const layouts = snq(() => this.options.requirements.layouts.filter(layout => layout instanceof Type), []);
if (isInitAction && !this.initialized) {
const transformedRoutes = transformRoutes(this.router.config);
let { routes } = transformedRoutes;
@ -32,7 +31,7 @@ export class ConfigPlugin implements NgxsPlugin {
...(state.ConfigState && { ...state.ConfigState }),
...this.options,
routes,
flattedRoutes
flattedRoutes,
});
this.initialized = true;
@ -73,7 +72,7 @@ function transformRoutes(routes: Routes = [], wrappers: ABP.FullRoute[] = []): a
...route.data.routes,
path: route.path,
name: snq(() => route.data.routes.name, route.path),
children: route.data.routes.children || []
children: route.data.routes.children || [],
} as ABP.FullRoute);
}
});
@ -90,8 +89,8 @@ function setUrls(routes: ABP.FullRoute[], parentUrl?: string): ABP.FullRoute[] {
url: `${parentUrl}/${route.path}`,
...(route.children &&
route.children.length && {
children: setUrls(route.children, `${parentUrl}/${route.path}`)
})
children: setUrls(route.children, `${parentUrl}/${route.path}`),
}),
}));
}
@ -100,8 +99,8 @@ function setUrls(routes: ABP.FullRoute[], parentUrl?: string): ABP.FullRoute[] {
url: `/${route.path}`,
...(route.children &&
route.children.length && {
children: setUrls(route.children, `/${route.path}`)
})
children: setUrls(route.children, `/${route.path}`),
}),
}));
}

3
npm/ng-packs/packages/core/src/lib/services/application-configuration.service.ts

@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ApplicationConfiguration, Rest } from '../models';
import { Rest } from '../models/rest';
import { ApplicationConfiguration } from '../models/application-configuration';
import { RestService } from './rest.service';
@Injectable({

13
npm/ng-packs/packages/core/src/lib/services/localization.service.ts

@ -1,9 +1,7 @@
import { Injectable, Optional, SkipSelf, NgZone } from '@angular/core';
import { Injectable, NgZone, Optional, SkipSelf } from '@angular/core';
import { ActivatedRouteSnapshot, Router } from '@angular/router';
import { Actions, Store } from '@ngxs/store';
import { Store } from '@ngxs/store';
import { noop, Observable } from 'rxjs';
import { ConfigState } from '../states/config.state';
import { SessionState } from '../states/session.state';
import { registerLocale } from '../utils/initial-utils';
type ShouldReuseRoute = (future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot) => boolean;
@ -11,14 +9,13 @@ type ShouldReuseRoute = (future: ActivatedRouteSnapshot, curr: ActivatedRouteSna
@Injectable({ providedIn: 'root' })
export class LocalizationService {
get currentLang(): string {
return this.store.selectSnapshot(SessionState.getLanguage);
return this.store.selectSnapshot(state => state.SessionState.getLanguage);
}
constructor(
private store: Store,
private router: Router,
private ngZone: NgZone,
private actions: Actions,
@Optional()
@SkipSelf()
otherInstance: LocalizationService,
@ -45,10 +42,10 @@ export class LocalizationService {
}
get(keys: string, ...interpolateParams: string[]): Observable<string> {
return this.store.select(ConfigState.getCopy(keys, ...interpolateParams));
return this.store.select(state => state.ConfigState.getCopy(keys, ...interpolateParams));
}
instant(keys: string, ...interpolateParams: string[]): string {
return this.store.selectSnapshot(ConfigState.getCopy(keys, ...interpolateParams));
return this.store.selectSnapshot(state => state.ConfigState.getCopy(keys, ...interpolateParams));
}
}

7
npm/ng-packs/packages/core/src/lib/services/rest.service.ts

@ -1,11 +1,10 @@
import { HttpClient, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { NEVER, Observable, throwError } from 'rxjs';
import { Observable, throwError } from 'rxjs';
import { catchError, take } from 'rxjs/operators';
import { RestOccurError } from '../actions/rest.actions';
import { Rest } from '../models/rest';
import { ConfigState } from '../states';
import { RestOccurError } from '../actions';
@Injectable({
providedIn: 'root',
@ -21,7 +20,7 @@ export class RestService {
request<T, R>(request: HttpRequest<T> | Rest.Request<T>, config: Rest.Config = {}, api?: string): Observable<R> {
const { observe = Rest.Observe.Body, skipHandleError } = config;
const url = api || this.store.selectSnapshot(ConfigState.getApiUrl()) + request.url;
const url = api || this.store.selectSnapshot(state => state.ConfigState).environment.apis.default.url + request.url;
const { method, ...options } = request;
return this.http.request<T>(method, url, { observe, ...options } as any).pipe(
observe === Rest.Observe.Body ? take(1) : null,

35
npm/ng-packs/packages/core/src/lib/states/config.state.ts

@ -1,17 +1,18 @@
import { State, Selector, createSelector, Action, StateContext, Store } from '@ngxs/store';
import { Config, ABP } from '../models';
import { Config } from '../models/config';
import { ABP } from '../models/common';
import { GetAppConfiguration, PatchRouteByName } from '../actions/config.actions';
import { ApplicationConfigurationService } from '../services/application-configuration.service';
import { tap, switchMap } from 'rxjs/operators';
import snq from 'snq';
import { SetLanguage } from '../actions';
import { SetLanguage } from '../actions/session.actions';
import { SessionState } from './session.state';
import { of } from 'rxjs';
import { setChildRoute, sortRoutes, organizeRoutes } from '../utils/route-utils';
@State<Config.State>({
name: 'ConfigState',
defaults: {} as Config.State
defaults: {} as Config.State,
})
export class ConfigState {
@Selector()
@ -29,7 +30,7 @@ export class ConfigState {
[ConfigState],
(state: Config.State) => {
return state[key];
}
},
);
return selector;
@ -54,7 +55,7 @@ export class ConfigState {
return undefined;
}, state);
}
},
);
return selector;
@ -72,7 +73,7 @@ export class ConfigState {
return route;
}
});
}
},
);
return selector;
@ -83,7 +84,7 @@ export class ConfigState {
[ConfigState],
(state: Config.State): string => {
return state.environment.apis[key || 'default'].url;
}
},
);
return selector;
@ -94,7 +95,7 @@ export class ConfigState {
[ConfigState],
(state: Config.State) => {
return snq(() => state.setting.values[key]);
}
},
);
return selector;
@ -106,7 +107,7 @@ export class ConfigState {
(state: Config.State): boolean => {
if (!key) return true;
return snq(() => state.auth.grantedPolicies[key], false);
}
},
);
return selector;
@ -131,7 +132,7 @@ export class ConfigState {
localization: {
defaultResourceName: 'MyProjectName'
}
}`
}`,
);
}
@ -154,7 +155,7 @@ export class ConfigState {
}
return copy || key;
}
},
);
return selector;
@ -167,8 +168,8 @@ export class ConfigState {
return this.appConfigurationService.getConfiguration().pipe(
tap(configuration =>
patchState({
...configuration
})
...configuration,
}),
),
switchMap(configuration => {
let defaultLang: string = configuration.setting.values['Abp.Localization.DefaultLanguage'];
@ -178,7 +179,7 @@ export class ConfigState {
}
return this.store.selectSnapshot(SessionState.getLanguage) ? of(null) : dispatch(new SetLanguage(defaultLang));
})
}),
);
}
@ -191,7 +192,7 @@ export class ConfigState {
routes = patchRouteDeep(routes, name, newValue);
return patchState({
routes
routes,
});
}
}
@ -200,7 +201,7 @@ function patchRouteDeep(
routes: ABP.FullRoute[],
name: string,
newValue: Partial<ABP.FullRoute>,
parentUrl: string = null
parentUrl: string = null,
): ABP.FullRoute[] {
routes = routes.map(route => {
if (route.name === name) {
@ -211,7 +212,7 @@ function patchRouteDeep(
if (newValue.children && newValue.children.length) {
newValue.children = newValue.children.map(child => ({
...child,
url: `${parentUrl}/${route.path}/${child.path}`
url: `${parentUrl}/${route.path}/${child.path}`,
}));
}

343
npm/ng-packs/packages/core/src/lib/tests/config.plugin.spec.ts

@ -0,0 +1,343 @@
import { RouterTestingModule } from '@angular/router/testing';
import { createServiceFactory, SpectatorService } from '@ngneat/spectator';
import { NGXS_PLUGINS, NgxsModule, InitState, Store } from '@ngxs/store';
import { environment } from '../../../../../apps/dev-app/src/environments/environment';
import { LAYOUTS } from '../../../../theme-basic/src/public-api';
import { ABP } from '../models';
import { ConfigPlugin, NGXS_CONFIG_PLUGIN_OPTIONS, ABP_ROUTES } from '../plugins';
import { RouterOutletComponent } from '../components';
import { ConfigState } from '../states';
import { CoreModule } from '../core.module';
import { eLayoutType } from '../enums/common';
ABP_ROUTES.push(
{
name: 'AbpUiNavigation::Menu:Administration',
path: '',
order: 1,
wrapper: true,
},
{
name: 'AbpIdentity::Menu:IdentityManagement',
path: 'identity',
order: 1,
parentName: 'AbpUiNavigation::Menu:Administration',
layout: eLayoutType.application,
iconClass: 'fa fa-id-card-o',
children: [
{ path: 'roles', name: 'AbpIdentity::Roles', order: 2, requiredPolicy: 'AbpIdentity.Roles' },
{ path: 'users', name: 'AbpIdentity::Users', order: 1, requiredPolicy: 'AbpIdentity.Users' },
],
},
{
name: 'AbpAccount::Menu:Account',
path: 'account',
invisible: true,
layout: eLayoutType.application,
children: [
{ path: 'login', name: 'AbpAccount::Login', order: 1 },
{ path: 'register', name: 'AbpAccount::Register', order: 2 },
],
},
{
name: 'AbpTenantManagement::Menu:TenantManagement',
path: 'tenant-management',
parentName: 'AbpUiNavigation::Menu:Administration',
layout: eLayoutType.application,
iconClass: 'fa fa-users',
children: [
{
path: 'tenants',
name: 'AbpTenantManagement::Tenants',
order: 1,
requiredPolicy: 'AbpTenantManagement.Tenants',
},
],
},
);
const expectedState = {
environment,
requirements: {
layouts: LAYOUTS,
},
routes: [
{
name: '::Menu:Home',
path: '',
children: [],
url: '/',
},
{
name: 'AbpAccount::Menu:Account',
path: 'account',
invisible: true,
layout: 'application',
children: [
{
path: 'login',
name: 'AbpAccount::Login',
order: 1,
url: '/account/login',
},
{
path: 'register',
name: 'AbpAccount::Register',
order: 2,
url: '/account/register',
},
],
url: '/account',
},
{
name: 'AbpUiNavigation::Menu:Administration',
path: '',
order: 1,
wrapper: true,
children: [
{
name: 'AbpIdentity::Menu:IdentityManagement',
path: 'identity',
order: 1,
parentName: 'AbpUiNavigation::Menu:Administration',
layout: 'application',
iconClass: 'fa fa-id-card-o',
children: [
{
path: 'users',
name: 'AbpIdentity::Users',
order: 1,
requiredPolicy: 'AbpIdentity.Users',
url: '/identity/users',
},
{
path: 'roles',
name: 'AbpIdentity::Roles',
order: 2,
requiredPolicy: 'AbpIdentity.Roles',
url: '/identity/roles',
},
],
url: '/identity',
},
{
name: 'AbpTenantManagement::Menu:TenantManagement',
path: 'tenant-management',
parentName: 'AbpUiNavigation::Menu:Administration',
layout: 'application',
iconClass: 'fa fa-users',
children: [
{
path: 'tenants',
name: 'AbpTenantManagement::Tenants',
order: 1,
requiredPolicy: 'AbpTenantManagement.Tenants',
url: '/tenant-management/tenants',
},
],
url: '/tenant-management',
},
],
},
],
flattedRoutes: [
{
name: '::Menu:Home',
path: '',
children: [],
url: '/',
},
{
name: 'AbpAccount::Menu:Account',
path: 'account',
invisible: true,
layout: 'application',
children: [
{
path: 'login',
name: 'AbpAccount::Login',
order: 1,
url: '/account/login',
},
{
path: 'register',
name: 'AbpAccount::Register',
order: 2,
url: '/account/register',
},
],
url: '/account',
},
{
path: 'login',
name: 'AbpAccount::Login',
order: 1,
url: '/account/login',
},
{
path: 'register',
name: 'AbpAccount::Register',
order: 2,
url: '/account/register',
},
{
name: 'AbpUiNavigation::Menu:Administration',
path: '',
order: 1,
wrapper: true,
children: [
{
name: 'AbpIdentity::Menu:IdentityManagement',
path: 'identity',
order: 1,
parentName: 'AbpUiNavigation::Menu:Administration',
layout: 'application',
iconClass: 'fa fa-id-card-o',
children: [
{
path: 'users',
name: 'AbpIdentity::Users',
order: 1,
requiredPolicy: 'AbpIdentity.Users',
url: '/identity/users',
},
{
path: 'roles',
name: 'AbpIdentity::Roles',
order: 2,
requiredPolicy: 'AbpIdentity.Roles',
url: '/identity/roles',
},
],
url: '/identity',
},
{
name: 'AbpTenantManagement::Menu:TenantManagement',
path: 'tenant-management',
parentName: 'AbpUiNavigation::Menu:Administration',
layout: 'application',
iconClass: 'fa fa-users',
children: [
{
path: 'tenants',
name: 'AbpTenantManagement::Tenants',
order: 1,
requiredPolicy: 'AbpTenantManagement.Tenants',
url: '/tenant-management/tenants',
},
],
url: '/tenant-management',
},
],
},
{
name: 'AbpIdentity::Menu:IdentityManagement',
path: 'identity',
order: 1,
parentName: 'AbpUiNavigation::Menu:Administration',
layout: 'application',
iconClass: 'fa fa-id-card-o',
children: [
{
path: 'users',
name: 'AbpIdentity::Users',
order: 1,
requiredPolicy: 'AbpIdentity.Users',
url: '/identity/users',
},
{
path: 'roles',
name: 'AbpIdentity::Roles',
order: 2,
requiredPolicy: 'AbpIdentity.Roles',
url: '/identity/roles',
},
],
url: '/identity',
},
{
path: 'users',
name: 'AbpIdentity::Users',
order: 1,
requiredPolicy: 'AbpIdentity.Users',
url: '/identity/users',
},
{
path: 'roles',
name: 'AbpIdentity::Roles',
order: 2,
requiredPolicy: 'AbpIdentity.Roles',
url: '/identity/roles',
},
{
name: 'AbpTenantManagement::Menu:TenantManagement',
path: 'tenant-management',
parentName: 'AbpUiNavigation::Menu:Administration',
layout: 'application',
iconClass: 'fa fa-users',
children: [
{
path: 'tenants',
name: 'AbpTenantManagement::Tenants',
order: 1,
requiredPolicy: 'AbpTenantManagement.Tenants',
url: '/tenant-management/tenants',
},
],
url: '/tenant-management',
},
{
path: 'tenants',
name: 'AbpTenantManagement::Tenants',
order: 1,
requiredPolicy: 'AbpTenantManagement.Tenants',
url: '/tenant-management/tenants',
},
],
};
describe('ConfigPlugin', () => {
let spectator: SpectatorService<ConfigPlugin>;
const createService = createServiceFactory({
service: ConfigPlugin,
imports: [
CoreModule,
NgxsModule.forRoot([]),
RouterTestingModule.withRoutes([
{
path: '',
component: RouterOutletComponent,
data: {
routes: {
name: '::Menu:Home',
} as ABP.Route,
},
},
{ path: 'identity', component: RouterOutletComponent },
{ path: 'account', component: RouterOutletComponent },
{ path: 'tenant-management', component: RouterOutletComponent },
]),
],
providers: [
{
provide: NGXS_PLUGINS,
useClass: ConfigPlugin,
multi: true,
},
{
provide: NGXS_CONFIG_PLUGIN_OPTIONS,
useValue: { environment, requirements: { layouts: LAYOUTS } } as ABP.Root,
},
],
});
beforeEach(() => {
spectator = createService();
});
it('should ConfigState must be create with correct datas', () => {
const store = spectator.get(Store);
const state = store.selectSnapshot(ConfigState);
expect(state).toEqual(expectedState);
});
});

57
npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts

@ -1,17 +1,19 @@
import { ConfigState, CoreModule, DynamicLayoutComponent, eLayoutType, ABP, RouterOutletComponent } from '@abp/ng.core';
import { Location } from '@angular/common';
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { createRoutingFactory, SpectatorRouting, SpyObject } from '@ngneat/spectator';
import { NgxsModule, Store } from '@ngxs/store';
import { LAYOUTS, ThemeBasicModule } from '../../../../theme-basic/src/public-api';
import { OAuthService } from 'angular-oauth2-oidc';
import { NgxsResetPluginModule, StateOverwrite } from 'ngxs-reset-plugin';
import { LAYOUTS, ThemeBasicModule } from '../../../../theme-basic/src/public-api';
import { eLayoutType } from '../enums';
import { ABP } from '../models';
import { RouterOutletComponent, CoreModule, DynamicLayoutComponent, ConfigState } from '@abp/ng.core';
import { ThemeSharedModule } from '../../../../theme-shared/src/public-api';
import { ActivatedRoute } from '@angular/router';
import { MessageService } from 'primeng/components/common/messageservice';
@Component({
selector: 'abp-dummy',
template: '{{route.snapshot.data?.name}} works!'
template: '{{route.snapshot.data?.name}} works!',
})
class DummyComponent {
constructor(public route: ActivatedRoute) {}
@ -25,12 +27,13 @@ describe('DynamicLayoutComponent', () => {
CoreModule,
NgxsModule.forRoot([ConfigState]),
NgxsResetPluginModule.forRoot(),
ThemeSharedModule.forRoot(),
ThemeBasicModule
ThemeSharedModule,
ThemeBasicModule,
],
declarations: [DummyComponent],
entryComponents: [],
stubsEnabled: false,
providers: [{ provide: OAuthService, useValue: { getAccessToken: () => true } }],
providers: [MessageService, { provide: OAuthService, useValue: { getAccessToken: () => true } }],
routes: [
{ path: '', component: RouterOutletComponent },
{
@ -40,14 +43,14 @@ describe('DynamicLayoutComponent', () => {
{
path: 'childWithoutLayout',
component: DummyComponent,
data: { name: 'childWithoutLayout' }
data: { name: 'childWithoutLayout' },
},
{
path: 'childWithLayout',
component: DummyComponent,
data: { name: 'childWithLayout' }
}
]
data: { name: 'childWithLayout' },
},
],
},
{
path: 'withData',
@ -56,10 +59,10 @@ describe('DynamicLayoutComponent', () => {
{
path: '',
component: DummyComponent,
data: { name: 'withData' }
}
data: { name: 'withData' },
},
],
data: { layout: eLayoutType.empty }
data: { layout: eLayoutType.empty },
},
{
path: 'withoutLayout',
@ -68,12 +71,12 @@ describe('DynamicLayoutComponent', () => {
{
path: '',
component: DummyComponent,
data: { name: 'withoutLayout' }
}
data: { name: 'withoutLayout' },
},
],
data: { layout: null }
}
]
data: { layout: null },
},
],
});
let spectator: SpectatorRouting<RouterOutletComponent>;
@ -95,16 +98,16 @@ describe('DynamicLayoutComponent', () => {
{
path: 'parentWithLayout',
layout: eLayoutType.application,
children: [{ path: 'childWithoutLayout' }, { path: 'childWithLayout', layout: eLayoutType.account }]
}
]
children: [{ path: 'childWithoutLayout' }, { path: 'childWithLayout', layout: eLayoutType.account }],
},
],
},
{ path: 'withData', layout: eLayoutType.application },
,
] as ABP.FullRoute[],
environment: { application: {} }
}
])
environment: { application: {} },
},
]),
);
});
@ -139,7 +142,7 @@ describe('DynamicLayoutComponent', () => {
it('should not display any layout when layouts are empty', async () => {
store.dispatch(
new StateOverwrite([ConfigState, { ...store.selectSnapshot(ConfigState), requirements: { layouts: [] } }])
new StateOverwrite([ConfigState, { ...store.selectSnapshot(ConfigState), requirements: { layouts: [] } }]),
);
spectator.detectChanges();

37
npm/ng-packs/packages/core/src/lib/tests/locale.provider.spec.ts

@ -0,0 +1,37 @@
import { Component, LOCALE_ID } from '@angular/core';
import { createRoutingFactory, SpectatorHost, SpectatorRouting } from '@ngneat/spectator';
import { LocalizationService } from '../services';
import { LocaleProvider, LocaleId } from '../providers';
import localesMapping from '../constants/different-locales';
@Component({ selector: 'abp-dummy', template: '' })
export class DummyComponent {}
describe('LocaleProvider', () => {
let spectator: SpectatorRouting<DummyComponent>;
const createComponent = createRoutingFactory({
component: DummyComponent,
stubsEnabled: false,
providers: [
{ provide: LocalizationService, useValue: { currentLang: 'en-US' } },
{
provide: LOCALE_ID,
useClass: LocaleId,
deps: [LocalizationService],
},
],
});
describe('#LOCALE_ID', () => {
it('should equal to localizationService.currentLang', async () => {
spectator = createComponent();
const localizationService = spectator.get(LocalizationService);
expect(spectator.get(LOCALE_ID).valueOf()).toBe(localesMapping['en-US'] || 'en-US');
localizationService.currentLang = 'tr';
expect(spectator.get(LOCALE_ID).valueOf()).toBe(localesMapping['tr'] || 'tr');
});
});
});

2
npm/ng-packs/packages/core/src/lib/tests/router-outlet.component.spec.ts

@ -1,6 +1,6 @@
import { Spectator, createComponentFactory, createHostFactory } from '@ngneat/spectator';
import { RouterOutletComponent } from '@abp/ng.core';
import { RouterTestingModule } from '@angular/router/testing';
import { RouterOutletComponent } from '../components/router-outlet.component';
describe('RouterOutletComponent', () => {
let spectator: Spectator<RouterOutletComponent>;

3
npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts

@ -3,7 +3,6 @@ import { Injector } from '@angular/core';
import { Store } from '@ngxs/store';
import { GetAppConfiguration } from '../actions/config.actions';
import differentLocales from '../constants/different-locales';
import { SessionState } from '../states/session.state';
export function getInitialData(injector: Injector) {
const fn = () => {
@ -19,7 +18,7 @@ export function localeInitializer(injector: Injector) {
const fn = () => {
const store: Store = injector.get(Store);
const lang = store.selectSnapshot(SessionState.getLanguage) || 'en';
const lang = store.selectSnapshot(state => state.SessionState.getLanguage) || 'en';
return new Promise((resolve, reject) => {
registerLocale(lang).then(() => resolve(), reject);

18
npm/ng-packs/packages/core/tsconfig.spec.json

@ -2,16 +2,12 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
"types": ["jasmine", "node"],
"paths": {
"@abp/ng.core": ["packages/core/src/public-api.ts"],
"@abp/ng.core/*": ["packages/core/src/lib/*"]
}
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
"files": ["src/test.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}

3
npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.html

@ -13,9 +13,6 @@
<div id="SettingManagementWrapper">
<div class="card">
<div class="card-body">
<div *ngIf="!settings.length" class="text-center">
<i class="fa fa-spinner fa-spin"></i>
</div>
<div class="row">
<div class="col-3">
<ul class="nav flex-column nav-pills" id="nav-tab" role="tablist">

6
npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.ts

@ -18,10 +18,10 @@ export class SettingManagementComponent implements OnInit {
constructor(private router: Router, private store: Store) {}
ngOnInit() {
this.settings = SETTING_TABS.filter(setting =>
this.store.selectSnapshot(ConfigState.getGrantedPolicy(setting.requiredPolicy)),
).sort((a, b) => a.order - b.order);
if (this.settings.length) {
this.settings = SETTING_TABS.filter(setting =>
this.store.selectSnapshot(ConfigState.getGrantedPolicy(setting.requiredPolicy)),
).sort((a, b) => a.order - b.order);
this.selected = this.settings[0];
}
}

17
npm/ng-packs/packages/theme-shared/src/lib/handlers/error.handler.ts

@ -6,15 +6,16 @@ import {
EmbeddedViewRef,
Injectable,
Injector,
NgZone,
RendererFactory2,
} from '@angular/core';
import { Navigate, RouterState } from '@ngxs/router-plugin';
import { Router } from '@angular/router';
import { Actions, ofActionSuccessful, Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import snq from 'snq';
import { ErrorComponent } from '../components/error/error.component';
import { Toaster } from '../models/toaster';
import { ConfirmationService } from '../services/confirmation.service';
import snq from 'snq';
export const DEFAULT_ERROR_MESSAGES = {
defaultError: {
@ -47,6 +48,8 @@ export const DEFAULT_ERROR_MESSAGES = {
export class ErrorHandler {
constructor(
private actions: Actions,
private router: Router,
private ngZone: NgZone,
private store: Store,
private confirmationService: ConfirmationService,
private appRef: ApplicationRef,
@ -125,11 +128,11 @@ export class ErrorHandler {
}
private navigateToLogin() {
this.store.dispatch(
new Navigate(['/account/login'], null, {
state: { redirectUrl: this.store.selectSnapshot(RouterState).state.url },
}),
);
this.ngZone.run(() => {
this.router.navigate(['/account/login'], {
state: { redirectUrl: this.router.url },
});
});
}
createErrorComponent(instance: Partial<ErrorComponent>) {

9
npm/ng-packs/packages/theme-shared/src/lib/tests/button.component.spec.ts

@ -1,11 +1,4 @@
import { CoreModule } from '@abp/ng.core';
import {
createComponentFactory,
createHostFactory,
Spectator,
SpectatorHost,
createTestComponentFactory
} from '@ngneat/spectator';
import { createHostFactory, SpectatorHost } from '@ngneat/spectator';
import { ButtonComponent } from '../components';
describe('ButtonComponent', () => {

83
npm/ng-packs/packages/theme-shared/src/lib/tests/error.handler.spec.ts

@ -3,9 +3,7 @@ import { Location } from '@angular/common';
import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Component } from '@angular/core';
import { createRoutingFactory, SpectatorRouting } from '@ngneat/spectator';
import { RouterState } from '@ngxs/router-plugin';
import { NgxsModule, Store } from '@ngxs/store';
import { NgxsResetPluginModule, StateOverwrite } from 'ngxs-reset-plugin';
import { DEFAULT_ERROR_MESSAGES, ErrorHandler } from '../handlers';
import { ThemeSharedModule } from '../theme-shared.module';
@ -14,96 +12,97 @@ class DummyComponent {
constructor(public errorHandler: ErrorHandler, public store: Store) {}
}
describe('With Custom Host Component', () => {
let component: SpectatorRouting<DummyComponent>;
describe('ErrorHandler', () => {
let spectator: SpectatorRouting<DummyComponent>;
let store: Store;
const createComponent = createRoutingFactory({
component: DummyComponent,
imports: [CoreModule, ThemeSharedModule.forRoot(), NgxsModule.forRoot([]), NgxsResetPluginModule.forRoot()],
imports: [CoreModule, ThemeSharedModule.forRoot(), NgxsModule.forRoot([])],
stubsEnabled: false,
routes: [{ path: '', component: DummyComponent }, { path: 'account/login', component: RouterOutletComponent }]
routes: [{ path: '', component: DummyComponent }, { path: 'account/login', component: RouterOutletComponent }],
});
beforeEach(() => {
component = createComponent();
spectator = createComponent();
store = spectator.component.store;
const abpError = document.querySelector('abp-error');
if (abpError) document.body.removeChild(abpError);
});
it('should display the error component when server error occurs', () => {
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 500 })));
component.detectChanges();
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 500 })));
spectator.detectChanges();
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError500.title);
expect(document.querySelector('.error-details')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError500.details);
});
it('should display the error component when authorize error occurs', () => {
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 403 })));
component.detectChanges();
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 403 })));
spectator.detectChanges();
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError403.title);
expect(document.querySelector('.error-details')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError403.details);
});
it('should display the error component when unknown error occurs', () => {
component.component.store.dispatch(
new RestOccurError(new HttpErrorResponse({ status: 0, statusText: 'Unknown Error' }))
);
component.detectChanges();
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 0, statusText: 'Unknown Error' })));
spectator.detectChanges();
expect(document.querySelector('.error-template')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultErrorUnknown.title);
expect(document.querySelector('.error-details')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultErrorUnknown.details);
});
it('should display the confirmation when not found error occurs', () => {
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 404 })));
component.detectChanges();
expect(component.query('.abp-confirm-summary')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError404.title);
expect(component.query('.abp-confirm-body')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError404.details);
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 404 })));
spectator.detectChanges();
expect(spectator.query('.abp-confirm-summary')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError404.title);
expect(spectator.query('.abp-confirm-body')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError404.details);
});
it('should display the confirmation when default error occurs', () => {
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 412 })));
component.detectChanges();
expect(component.query('.abp-confirm-summary')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError.title);
expect(component.query('.abp-confirm-body')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError.details);
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 412 })));
spectator.detectChanges();
expect(spectator.query('.abp-confirm-summary')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError.title);
expect(spectator.query('.abp-confirm-body')).toHaveText(DEFAULT_ERROR_MESSAGES.defaultError.details);
});
it('should display the confirmation when authenticated error occurs', async () => {
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 401 })));
component.detectChanges();
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 401 })));
spectator.detectChanges();
component.component.store.dispatch(new StateOverwrite([RouterState, { state: { url: '/' } }]));
component.click('#confirm');
await component.fixture.whenStable();
expect(component.get(Location).path()).toBe('/account/login');
spectator.click('#confirm');
await spectator.fixture.whenStable();
expect(spectator.get(Location).path()).toBe('/account/login');
});
it('should display the confirmation when authenticated error occurs with _AbpErrorFormat header', async () => {
let headers: HttpHeaders = new HttpHeaders();
headers = headers.append('_AbpErrorFormat', '_AbpErrorFormat');
component.component.store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 401, headers })));
component.detectChanges();
component.component.store.dispatch(new StateOverwrite([RouterState, { state: { url: '/' } }]));
component.click('#confirm');
await component.fixture.whenStable();
expect(component.get(Location).path()).toBe('/account/login');
store.dispatch(new RestOccurError(new HttpErrorResponse({ status: 401, headers })));
spectator.detectChanges();
spectator.click('#confirm');
await spectator.fixture.whenStable();
expect(spectator.get(Location).path()).toBe('/account/login');
});
it('should display the confirmation when error occurs with _AbpErrorFormat header', () => {
let headers: HttpHeaders = new HttpHeaders();
headers = headers.append('_AbpErrorFormat', '_AbpErrorFormat');
component.component.store.dispatch(
store.dispatch(
new RestOccurError(
new HttpErrorResponse({
error: { error: { message: 'test message', details: 'test detail' } },
status: 412,
headers
})
)
headers,
}),
),
);
component.detectChanges();
spectator.detectChanges();
expect(component.query('.abp-confirm-summary')).toHaveText('test message');
expect(component.query('.abp-confirm-body')).toHaveText('test detail');
expect(spectator.query('.abp-confirm-summary')).toHaveText('test message');
expect(spectator.query('.abp-confirm-body')).toHaveText('test detail');
});
});

46
npm/ng-packs/packages/theme-shared/src/lib/tests/state-overwrite.ts

@ -0,0 +1,46 @@
import { Inject, Injectable, InjectionToken, Provider } from '@angular/core';
import { getActionTypeFromInstance, InitState, NgxsPlugin, NGXS_PLUGINS, setValue } from '@ngxs/store';
export const NGXS_OVERWRITE_PLUGIN_VALUE = new InjectionToken('NGXS_OVERWRITE_PLUGIN_VALUE');
export class StateOverwrite {
static readonly type = '[StateOverwrite] Patch';
constructor(public payload: { stateName: string; value: any }) {}
}
@Injectable()
export class OverwritePlugin implements NgxsPlugin {
initialized: boolean;
constructor(@Inject(NGXS_OVERWRITE_PLUGIN_VALUE) private options: any) {}
handle(state, action, next) {
const type = getActionTypeFromInstance(action);
if (action instanceof InitState && !this.initialized) {
state = { ...state, ...this.options };
console.log(state);
this.initialized = true;
}
if (action instanceof StateOverwrite) {
state = setValue(state, action.payload.stateName, action.payload.value);
}
return next(state, action);
}
}
export function stateOverwriteProviders(value = {}): Provider[] {
return [
{
provide: NGXS_PLUGINS,
useClass: OverwritePlugin,
multi: true,
},
{
provide: NGXS_OVERWRITE_PLUGIN_VALUE,
useValue: value,
},
];
}

3
npm/ng-packs/scripts/package.json

@ -15,6 +15,7 @@
"babel-preset-node6": "^11.0.0",
"esm": "^3.2.25",
"execa": "^2.0.3",
"fs-extra": "^8.1.0"
"fs-extra": "^8.1.0",
"prompt-confirm": "^2.0.4"
}
}

15
npm/ng-packs/scripts/push.js

@ -0,0 +1,15 @@
const Confirm = require('prompt-confirm');
const execa = require('execa');
(async () => {
const answer = await new Confirm('Would you like to push?').run().then(answer => answer);
if (answer) {
try {
await execa('git', ['push'], { stdout: 'inherit' });
console.log('Successfully!');
} catch (error) {
console.log('An error occured.' + error);
}
}
})();

9
npm/ng-packs/tsconfig.json

@ -11,13 +11,8 @@
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
],
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"],
"paths": {}
},
"angularCompilerOptions": {

Loading…
Cancel
Save