Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respect angular guard checks and do not navigate if authGuard check returns false #114

Merged
merged 4 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ testem.log
# System Files
.DS_Store
Thumbs.db

.angular
2 changes: 2 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"got-demo-e2e": "apps/got-demo-e2e",
"simple-demo": "apps/simple-demo",
"simple-demo-e2e": "apps/simple-demo-e2e",
"with-gaurd-check": "apps/with-gaurd-check",
"with-gaurd-check-e2e": "apps/with-gaurd-check-e2e",
"xng-breadcrumb": "libs/xng-breadcrumb"
}
}
17 changes: 9 additions & 8 deletions apps/breadcrumb-demo/src/app/app.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

.route-container {
padding: 16px;
}

div {
display: flex;
flex-direction: row;
align-items: center;
label {
min-width: 240px;
}
}
.route-container div {
display: flex;
flex-direction: row;
align-items: center;
}

.route-container div label {
min-width: 240px;
}

@media (max-width: 960px) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
.connect {
display: flex;
justify-content: center;
button {
width: 200px;
}
}

.connect button {
width: 200px;
}
18 changes: 10 additions & 8 deletions apps/breadcrumb-demo/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ body {
margin-top: 16px;
justify-content: flex-end;
display: flex;
> *:not(:last-child) {
margin-right: 16px;
}
}

.button-row > *:not(:last-child) {
margin-right: 16px;
}

.label {
Expand Down Expand Up @@ -64,9 +65,10 @@ body {

.custom-breadcrumb.xng-breadcrumb-root {
background-color: #fff;
.xng-breadcrumb-item {
border-radius: 16px;
background-color: #f5f5f5;
padding: 4px 8px;
}
}

.custom-breadcrumb.xng-breadcrumb-root .xng-breadcrumb-item {
border-radius: 16px;
background-color: #f5f5f5;
padding: 4px 8px;
}
10 changes: 10 additions & 0 deletions apps/with-gaurd-check-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": ["plugin:cypress/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
}
]
}
12 changes: 12 additions & 0 deletions apps/with-gaurd-check-e2e/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"fileServerFolder": ".",
"fixturesFolder": "./src/fixtures",
"integrationFolder": "./src/integration",
"modifyObstructiveCode": false,
"supportFile": "./src/support/index.ts",
"pluginsFile": false,
"video": false,
"videosFolder": "../../dist/cypress/apps/with-gaurd-check-e2e/videos",
"screenshotsFolder": "../../dist/cypress/apps/with-gaurd-check-e2e/screenshots",
"chromeWebSecurity": false
}
28 changes: 28 additions & 0 deletions apps/with-gaurd-check-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"root": "apps/with-gaurd-check-e2e",
"sourceRoot": "apps/with-gaurd-check-e2e/src",
"projectType": "application",
"targets": {
"e2e": {
"executor": "@nrwl/cypress:cypress",
"options": {
"cypressConfig": "apps/with-gaurd-check-e2e/cypress.json",
"devServerTarget": "with-gaurd-check:serve:development"
},
"configurations": {
"production": {
"devServerTarget": "with-gaurd-check:serve:production"
}
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/with-gaurd-check-e2e/**/*.{js,ts}"]
}
}
},
"tags": [],
"implicitDependencies": ["with-gaurd-check"]
}
4 changes: 4 additions & 0 deletions apps/with-gaurd-check-e2e/src/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]"
}
36 changes: 36 additions & 0 deletions apps/with-gaurd-check-e2e/src/integration/app.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
describe('with-gaurd-check', () => {
it('should contain breadcrumbs for page1', () => {
cy.visit('/');
cy.get('.xng-breadcrumb-list').contains('Page 1');
cy.get('button').contains('To Page 2 Child').click();
cy.get('.xng-breadcrumb-list').contains('Page2 child');
});

it('Auth guard false should block navigation from breadcrumb', () => {
cy.get('button').contains('Back to Page 1').click();
cy.on('window:confirm', (text) => {
expect(text).to.contains(
'Are you sure you want to navigate away before saving changes?'
);
return false;
});
cy.get('.xng-breadcrumb-list').contains('Page2 child'); // navigation didn't happen
cy.location().should((loc) => {
expect(loc.pathname).to.eq('/page2/page2-child');
});
});

it('Auth guard true should allow navigation from breadcrumb', () => {
cy.get('button').contains('Back to Page 1').click();
cy.on('window:confirm', (text) => {
expect(text).to.contains(
'Are you sure you want to navigate away before saving changes?'
);
return true;
});
cy.get('.xng-breadcrumb-list').contains('Page2 child').should('not.exist'); // navigation happen
cy.location().should((loc) => {
expect(loc.pathname).to.eq('/page1');
});
});
});
1 change: 1 addition & 0 deletions apps/with-gaurd-check-e2e/src/support/app.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getGreeting = () => cy.get('h1');
33 changes: 33 additions & 0 deletions apps/with-gaurd-check-e2e/src/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************

// eslint-disable-next-line @typescript-eslint/no-namespace
declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
login(email: string, password: string): void;
}
}
//
// -- This is a parent command --
Cypress.Commands.add('login', (email, password) => {
console.log('Custom command example: Login', email, password);
});
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
17 changes: 17 additions & 0 deletions apps/with-gaurd-check-e2e/src/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';
19 changes: 19 additions & 0 deletions apps/with-gaurd-check-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc",
"allowJs": true,
"types": ["cypress", "node"],
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*.ts", "src/**/*.js"],
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
16 changes: 16 additions & 0 deletions apps/with-gaurd-check/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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

# For the full list of supported browsers by the Angular framework, please see:
# https://angular.io/guide/browser-support

# You can see what browsers were selected by your queries by running:
# npx browserslist

last 1 Chrome version
last 1 Firefox version
last 2 Edge major versions
last 2 Safari major versions
last 2 iOS major versions
Firefox ESR
36 changes: 36 additions & 0 deletions apps/with-gaurd-check/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "wgc",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "wgc",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nrwl/nx/angular-template"],
"rules": {}
}
]
}
21 changes: 21 additions & 0 deletions apps/with-gaurd-check/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
displayName: 'with-gaurd-check',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
},
coverageDirectory: '../../coverage/apps/with-gaurd-check',
transform: {
'^.+\\.(ts|mjs|js|html)$': 'jest-preset-angular',
},
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
snapshotSerializers: [
'jest-preset-angular/build/serializers/no-ng-attributes',
'jest-preset-angular/build/serializers/ng-snapshot',
'jest-preset-angular/build/serializers/html-comment',
],
};
Loading