Skip to content

Commit

Permalink
feat: create not-found page 🔍 (#72)
Browse files Browse the repository at this point in the history
## Description 📝

Add page to display when route is not found.
  • Loading branch information
peterjokumsen authored Oct 29, 2023
1 parent 1034039 commit afc1e74
Show file tree
Hide file tree
Showing 28 changed files with 301 additions and 12 deletions.
24 changes: 24 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,31 @@ coverage:
hpb-client:
flags:
- hpb-client
hpb-shared-styles:
flags:
- hpb-shared-styles
hpb-shared-ui:
flags:
- hpb-shared-ui
hpb-pages-landing:
flags:
- hpb-pages-landing
hpb-pages-not-found:
flags:
- hpb-pages-not-found
flags:
hpb-client:
paths:
- apps/hpb-client
hpb-shared-styles:
paths:
- libs/shared/styles
hpb-shared-ui:
paths:
- libs/shared/ui
hpb-pages-landing:
paths:
- libs/pages/landing
hpb-pages-not-found:
paths:
- libs/pages/not-found
5 changes: 5 additions & 0 deletions apps/hpb-client/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"glob": "**/*",
"input": "libs/pages/landing/src/assets",
"output": "/assets"
},
{
"glob": "**/*",
"input": "libs/pages/not-found/src/assets",
"output": "/assets"
}
],
"styles": ["libs/shared/styles/src/lib/theme.scss", "apps/hpb-client/src/styles.scss"],
Expand Down
4 changes: 4 additions & 0 deletions apps/hpb-client/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ export const appRoutes: Route[] = [
redirectTo: 'home',
pathMatch: 'full',
},
{
path: '**',
loadComponent: () => import('@helderberg-pirates-baseball/pages/not-found').then((m) => m.NotFoundComponent),
},
];
2 changes: 1 addition & 1 deletion libs/pages/landing/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './lib/lib.routes';

export * from './lib/pages-landing/pages-landing.component';
export * from './lib/landing.component';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h1>Discover the Excitement of Baseball</h1>
<h3>Are you ready to step up to the plate and dive into the thrilling world of baseball?</h3>
<section>
<img src="assets/landing-page/landing.png" alt="Home run!" />
<img src="/assets/landing-page-image.png" alt="Home run!" />
<div>
<p>At Helderberg Pirates, we live and breathe this fantastic sport.</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { PagesLandingComponent } from './pages-landing.component';
import { LandingComponent } from './landing.component';

describe('PagesLandingComponent', () => {
let component: PagesLandingComponent;
let fixture: ComponentFixture<PagesLandingComponent>;
let component: LandingComponent;
let fixture: ComponentFixture<LandingComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [PagesLandingComponent],
imports: [LandingComponent],
}).compileComponents();

fixture = TestBed.createComponent(PagesLandingComponent);
fixture = TestBed.createComponent(LandingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { MatCardModule } from '@angular/material/card';
@Component({
standalone: true,
imports: [CommonModule, MatButtonModule, MatCardModule],
templateUrl: './pages-landing.component.html',
styleUrls: ['./pages-landing.component.scss'],
templateUrl: './landing.component.html',
styleUrls: ['./landing.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PagesLandingComponent {}
export class LandingComponent {}
4 changes: 2 additions & 2 deletions libs/pages/landing/src/lib/lib.routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Route } from '@angular/router';

import { PagesLandingComponent } from './pages-landing/pages-landing.component';
import { LandingComponent } from './landing.component';

export const pagesLandingRoutes: Route[] = [{ path: '', component: PagesLandingComponent }];
export const pagesLandingRoutes: Route[] = [{ path: '', component: LandingComponent }];
40 changes: 40 additions & 0 deletions libs/pages/not-found/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": ["plugin:@nx/angular", "plugin:@angular-eslint/template/process-inline-templates"],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "helderbergPiratesBaseball",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "helderberg-pirates-baseball",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
},
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": "error"
}
}
]
}
7 changes: 7 additions & 0 deletions libs/pages/not-found/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pages-not-found

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test pages-not-found` to execute the unit tests.
22 changes: 22 additions & 0 deletions libs/pages/not-found/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
export default {
displayName: 'pages-not-found',
preset: '../../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
coverageDirectory: '../../../coverage/libs/pages/not-found',
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
],
},
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',
],
};
7 changes: 7 additions & 0 deletions libs/pages/not-found/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../dist/libs/pages/not-found",
"lib": {
"entryFile": "src/index.ts"
}
}
12 changes: 12 additions & 0 deletions libs/pages/not-found/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@helderberg-pirates-baseball/pages/not-found",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^16.2.0",
"@angular/core": "^16.2.0",
"@angular/material": "16.2.9",
"@angular/router": "16.2.10"
},
"dependencies": {},
"sideEffects": false
}
51 changes: 51 additions & 0 deletions libs/pages/not-found/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "pages-not-found",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/pages/not-found/src",
"prefix": "helderberg-pirates-baseball",
"tags": [],
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/angular:ng-packagr-lite",
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
"options": {
"project": "libs/pages/not-found/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "libs/pages/not-found/tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "libs/pages/not-found/tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/pages/not-found/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"libs/pages/not-found/**/*.ts",
"libs/pages/not-found/**/*.html",
"libs/pages/not-found/package.json"
]
}
}
}
}
Binary file not shown.
1 change: 1 addition & 0 deletions libs/pages/not-found/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/not-found.component';
7 changes: 7 additions & 0 deletions libs/pages/not-found/src/lib/not-found.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>Oops! This Route is Out of Bounds</h1>
<h2>We're sorry, but it seems you've hit a foul ball.</h2>
<img fetchpriority="high" src="/assets/not-found-image.webp" alt="Page not found" />
<p>The route you are trying to access is not available at the moment.</p>
<p>Don't worry, we'll get you back in the game soon!</p>
<!-- maybe check if referrer is from current site, and include a back button? -->
<button mat-raised-button color="primary" routerLink="/">Go Home</button>
4 changes: 4 additions & 0 deletions libs/pages/not-found/src/lib/not-found.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
img {
display: block;
width: 100%;
}
23 changes: 23 additions & 0 deletions libs/pages/not-found/src/lib/not-found.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';

import { NotFoundComponent } from './not-found.component';

describe('NotFoundComponent', () => {
let component: NotFoundComponent;
let fixture: ComponentFixture<NotFoundComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [NotFoundComponent, RouterTestingModule],
}).compileComponents();

fixture = TestBed.createComponent(NotFoundComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
14 changes: 14 additions & 0 deletions libs/pages/not-found/src/lib/not-found.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { RouterLink } from '@angular/router';

@Component({
standalone: true,
imports: [CommonModule, MatCardModule, MatButtonModule, RouterLink],
templateUrl: `./not-found.component.html`,
styleUrls: [`./not-found.component.scss`],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NotFoundComponent {}
8 changes: 8 additions & 0 deletions libs/pages/not-found/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
globalThis.ngJest = {
testEnvironmentOptions: {
errorOnUnknownElements: true,
errorOnUnknownProperties: true,
},
};
import 'jest-preset-angular/setup-jest';
29 changes: 29 additions & 0 deletions libs/pages/not-found/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es2022",
"useDefineForClassFields": false,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../../../tsconfig.base.json",
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
12 changes: 12 additions & 0 deletions libs/pages/not-found/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": []
},
"exclude": ["src/**/*.spec.ts", "src/test-setup.ts", "jest.config.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
7 changes: 7 additions & 0 deletions libs/pages/not-found/tsconfig.lib.prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.lib.json",
"compilerOptions": {
"declarationMap": false
},
"angularCompilerOptions": {}
}
11 changes: 11 additions & 0 deletions libs/pages/not-found/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"target": "es2016",
"types": ["jest", "node"]
},
"files": ["src/test-setup.ts"],
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"baseUrl": ".",
"paths": {
"@helderberg-pirates-baseball/pages/landing": ["libs/pages/landing/src/index.ts"],
"@helderberg-pirates-baseball/pages/not-found": ["libs/pages/not-found/src/index.ts"],
"@helderberg-pirates-baseball/shared/styles": ["libs/shared/styles/src/index.ts"],
"@helderberg-pirates-baseball/shared/ui": ["libs/shared/ui/src/index.ts"]
},
Expand Down

0 comments on commit afc1e74

Please sign in to comment.