Skip to content

Commit

Permalink
docs: add standalone example
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Feb 4, 2023
1 parent 501d0fe commit 41e397d
Show file tree
Hide file tree
Showing 47 changed files with 837 additions and 0 deletions.
113 changes: 113 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,119 @@
}
}
},
"sample-code-flow-standalone": {
"projectType": "application",
"schematics": {},
"root": "projects/sample-code-flow-standalone",
"sourceRoot": "projects/sample-code-flow-standalone/src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/sample-code-flow-standalone",
"index": "projects/sample-code-flow-standalone/src/index.html",
"main": "projects/sample-code-flow-standalone/src/main.ts",
"polyfills": "projects/sample-code-flow-standalone/src/polyfills.ts",
"tsConfig": "projects/sample-code-flow-standalone/tsconfig.app.json",
"aot": true,
"assets": [
"projects/sample-code-flow-standalone/src/favicon.ico",
"projects/sample-code-flow-standalone/src/silent-renew.html",
"projects/sample-code-flow-standalone/src/assets"
],
"styles": ["projects/sample-code-flow-standalone/src/styles.css"],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "sample-code-flow-standalone:build",
"sslKey": "certs/dev_localhost.key",
"sslCert": "certs/dev_localhost.pem",
"port": 4204
},
"configurations": {
"production": {
"browserTarget": "sample-code-flow-standalone:build:production"
},
"development": {
"browserTarget": "sample-code-flow-standalone:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "sample-code-flow-standalone:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/sample-code-flow-standalone/src/test.ts",
"polyfills": "projects/sample-code-flow-standalone/src/polyfills.ts",
"tsConfig": "projects/sample-code-flow-standalone/tsconfig.spec.json",
"karmaConfig": "projects/sample-code-flow-standalone/karma.conf.js",
"assets": ["projects/sample-code-flow-standalone/src/favicon.ico", "projects/sample-code-flow-standalone/src/assets"],
"styles": ["projects/sample-code-flow-standalone/src/styles.css"],
"scripts": []
}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": ["projects/sample-code-flow-standalone/**/*.ts", "projects/sample-code-flow-standalone/**/*.html"]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "projects/sample-code-flow-standalone/e2e/protractor.conf.js",
"devServerTarget": "sample-code-flow-standalone:serve"
},
"configurations": {
"production": {
"devServerTarget": "sample-code-flow-standalone:serve:production"
}
}
}
}
},
"sample-code-flow-multi-Azure-B2C": {
"projectType": "application",
"schematics": {},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"start-sample-code-flow-multi-AAD": "ng serve sample-code-flow-multi-AAD --ssl -o",
"start-sample-code-flow-multi-Azure-B2C": "ng serve sample-code-flow-multi-Azure-B2C --ssl -o",
"start-sample-code-flow-multi-iframe": "ng serve sample-code-flow-multi-iframe --ssl -o",
"start-sample-code-standalone": "ng serve sample-code-flow-standalone --ssl -o",
"start-sample-implicit-flow-google": "ng serve sample-implicit-flow-google --ssl -o",
"start-sample-implicit-flow-silent-renew": "ng serve sample-implicit-flow-silent-renew --ssl -o",
"start-sample-code-flow-lazy-loaded": "ng serve sample-code-flow-lazy-loaded --ssl --port=4204 -o",
Expand Down
39 changes: 39 additions & 0 deletions projects/sample-code-flow-standalone/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"extends": "../../.eslintrc.json",
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"parserOptions": {
"project": [
"projects/sample-code-flow-standalone/tsconfig.app.json",
"projects/sample-code-flow-standalone/tsconfig.spec.json",
"projects/sample-code-flow-standalone/e2e/tsconfig.json"
],
"createDefaultProgram": true
},
"rules": {
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
],
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
]
}
},
{
"files": ["*.html"],
"rules": {}
}
]
}
37 changes: 37 additions & 0 deletions projects/sample-code-flow-standalone/e2e/protractor.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter');

/**
* @type { import("protractor").Config }
*/
exports.config = {
allScriptsTimeout: 11000,
specs: ['./src/**/*.e2e-spec.ts'],
capabilities: {
browserName: 'chrome',
},
directConnect: true,
SELENIUM_PROMISE_MANAGER: false,
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: StacktraceOption.PRETTY,
},
})
);
},
};
25 changes: 25 additions & 0 deletions projects/sample-code-flow-standalone/e2e/src/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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', async () => {
await page.navigateTo();
expect(await page.getTitleText()).toEqual('sample-code-flow-standalone 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 changes: 11 additions & 0 deletions projects/sample-code-flow-standalone/e2e/src/app.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { browser, by, element } from 'protractor';

export class AppPage {
async navigateTo(): Promise<unknown> {
return browser.get(browser.baseUrl);
}

async getTitleText(): Promise<string> {
return element(by.css('app-root .content span')).getText();
}
}
10 changes: 10 additions & 0 deletions projects/sample-code-flow-standalone/e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../../../out-tsc/e2e",
"module": "commonjs",
"target": "es2018",
"types": ["jasmine", "node"]
}
}
41 changes: 41 additions & 0 deletions projects/sample-code-flow-standalone/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true, // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, '../../coverage/sample-code-flow-standalone'),
subdir: '.',
reporters: [{ type: 'html' }, { type: 'text-summary' }],
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
});
};
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<app-navigation></app-navigation>

<div class="container-fluid">
<div class="row">
<div class="col-sm-12 body-content">
<router-outlet></router-outlet>
</div>
</div>
</div>
31 changes: 31 additions & 0 deletions projects/sample-code-flow-standalone/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { TestBed, waitForAsync } from '@angular/core/testing';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
}).compileComponents();
})
);

it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});

it(`should have as title 'sample-code-flow-standalone'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('sample-code-flow-standalone');
});

it('should render title in a h1 tag', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Welcome to sample-code-flow-standalone!');
});
});
40 changes: 40 additions & 0 deletions projects/sample-code-flow-standalone/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Component, OnInit } from '@angular/core';
import { OidcSecurityService } from 'angular-auth-oidc-client';
import {RouterOutlet} from "@angular/router";
import {NavigationComponent} from "./navigation/navigation.component";

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
standalone: true,
imports: [
RouterOutlet,
NavigationComponent
]
})
export class AppComponent implements OnInit {
constructor(private oidcSecurityService: OidcSecurityService) {}

ngOnInit() {
this.oidcSecurityService.checkAuth().subscribe(({ isAuthenticated, userData, accessToken }) => {
console.log('app authenticated', isAuthenticated);
console.log(`Current access token is '${accessToken}'`);
});
}

login() {
console.log('start login');
this.oidcSecurityService.authorize();
}

refreshSession() {
console.log('start refreshSession');
this.oidcSecurityService.authorize();
}

logout() {
console.log('start logoff');
this.oidcSecurityService.logoff().subscribe((result) => console.log(result));
}
}
Loading

0 comments on commit 41e397d

Please sign in to comment.