mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat(challenge24): create test harness
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -39,3 +39,5 @@ testem.log
|
|||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
.angular
|
.angular
|
||||||
|
|
||||||
|
TODO.md
|
||||||
36
apps/create-harness/.eslintrc.json
Normal file
36
apps/create-harness/.eslintrc.json
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"extends": ["../../.eslintrc.json"],
|
||||||
|
"ignorePatterns": ["!**/*"],
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": ["*.ts"],
|
||||||
|
"rules": {
|
||||||
|
"@angular-eslint/directive-selector": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"type": "attribute",
|
||||||
|
"prefix": "app",
|
||||||
|
"style": "camelCase"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@angular-eslint/component-selector": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"type": "element",
|
||||||
|
"prefix": "app",
|
||||||
|
"style": "kebab-case"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"plugin:@nx/angular",
|
||||||
|
"plugin:@angular-eslint/template/process-inline-templates"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["*.html"],
|
||||||
|
"extends": ["plugin:@nx/angular-template"],
|
||||||
|
"rules": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
21
apps/create-harness/jest.config.ts
Normal file
21
apps/create-harness/jest.config.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
export default {
|
||||||
|
displayName: 'create-harness',
|
||||||
|
preset: '../../jest.preset.js',
|
||||||
|
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
||||||
|
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',
|
||||||
|
],
|
||||||
|
};
|
||||||
95
apps/create-harness/project.json
Normal file
95
apps/create-harness/project.json
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
{
|
||||||
|
"name": "create-harness",
|
||||||
|
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||||
|
"projectType": "application",
|
||||||
|
"prefix": "app",
|
||||||
|
"sourceRoot": "apps/create-harness/src",
|
||||||
|
"tags": [],
|
||||||
|
"targets": {
|
||||||
|
"build": {
|
||||||
|
"executor": "@angular-devkit/build-angular:browser",
|
||||||
|
"outputs": ["{options.outputPath}"],
|
||||||
|
"options": {
|
||||||
|
"outputPath": "dist/apps/create-harness",
|
||||||
|
"index": "apps/create-harness/src/index.html",
|
||||||
|
"main": "apps/create-harness/src/main.ts",
|
||||||
|
"polyfills": ["zone.js"],
|
||||||
|
"tsConfig": "apps/create-harness/tsconfig.app.json",
|
||||||
|
"assets": [
|
||||||
|
"apps/create-harness/src/favicon.ico",
|
||||||
|
"apps/create-harness/src/assets"
|
||||||
|
],
|
||||||
|
"styles": ["apps/create-harness/src/styles.scss"],
|
||||||
|
"scripts": []
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"production": {
|
||||||
|
"budgets": [
|
||||||
|
{
|
||||||
|
"type": "initial",
|
||||||
|
"maximumWarning": "500kb",
|
||||||
|
"maximumError": "1mb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "anyComponentStyle",
|
||||||
|
"maximumWarning": "2kb",
|
||||||
|
"maximumError": "4kb"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputHashing": "all"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"buildOptimizer": false,
|
||||||
|
"optimization": false,
|
||||||
|
"vendorChunk": true,
|
||||||
|
"extractLicenses": false,
|
||||||
|
"sourceMap": true,
|
||||||
|
"namedChunks": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "production"
|
||||||
|
},
|
||||||
|
"serve": {
|
||||||
|
"executor": "@angular-devkit/build-angular:dev-server",
|
||||||
|
"configurations": {
|
||||||
|
"production": {
|
||||||
|
"browserTarget": "create-harness:build:production"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"browserTarget": "create-harness:build:development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "development"
|
||||||
|
},
|
||||||
|
"extract-i18n": {
|
||||||
|
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||||
|
"options": {
|
||||||
|
"browserTarget": "create-harness:build"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"executor": "@nx/jest:jest",
|
||||||
|
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||||
|
"options": {
|
||||||
|
"jestConfig": "apps/create-harness/jest.config.ts",
|
||||||
|
"passWithNoTests": true
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"ci": {
|
||||||
|
"ci": true,
|
||||||
|
"codeCoverage": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lint": {
|
||||||
|
"executor": "@nx/linter:eslint",
|
||||||
|
"outputs": ["{options.outputFile}"],
|
||||||
|
"options": {
|
||||||
|
"lintFilePatterns": [
|
||||||
|
"apps/create-harness/**/*.ts",
|
||||||
|
"apps/create-harness/**/*.html"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
apps/create-harness/src/app/app.component.ts
Normal file
26
apps/create-harness/src/app/app.component.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Component, signal } from '@angular/core';
|
||||||
|
import { SliderComponent } from './slider.component';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
standalone: true,
|
||||||
|
imports: [SliderComponent],
|
||||||
|
selector: 'app-root',
|
||||||
|
template: `
|
||||||
|
<h2>Slider 1: {{ slider1Value() }}</h2>
|
||||||
|
<app-slider
|
||||||
|
[step]="3"
|
||||||
|
[minValue]="10"
|
||||||
|
[maxValue]="30"
|
||||||
|
(valueChange)="slider1Value.set($event)" />
|
||||||
|
<h2>Slider 2: {{ slider2Value() }}</h2>
|
||||||
|
<app-slider
|
||||||
|
[step]="10"
|
||||||
|
[maxValue]="1000"
|
||||||
|
(valueChange)="slider2Value.set($event)" />
|
||||||
|
`,
|
||||||
|
styles: [''],
|
||||||
|
})
|
||||||
|
export class AppComponent {
|
||||||
|
slider1Value = signal(0);
|
||||||
|
slider2Value = signal(0);
|
||||||
|
}
|
||||||
5
apps/create-harness/src/app/app.config.ts
Normal file
5
apps/create-harness/src/app/app.config.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { ApplicationConfig } from '@angular/core';
|
||||||
|
|
||||||
|
export const appConfig: ApplicationConfig = {
|
||||||
|
providers: [],
|
||||||
|
};
|
||||||
8
apps/create-harness/src/app/slider.component.spec.ts
Normal file
8
apps/create-harness/src/app/slider.component.spec.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { render } from '@testing-library/angular';
|
||||||
|
import { SliderComponent } from './slider.component';
|
||||||
|
|
||||||
|
describe('SliderComponent', () => {
|
||||||
|
test('should have 1 slider, 3 checkboxes, 4 inputs, 2 buttons', async () => {
|
||||||
|
await render(SliderComponent);
|
||||||
|
});
|
||||||
|
});
|
||||||
71
apps/create-harness/src/app/slider.component.ts
Normal file
71
apps/create-harness/src/app/slider.component.ts
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import { Component, Input, OnInit, Output, signal } from '@angular/core';
|
||||||
|
import { toObservable } from '@angular/core/rxjs-interop';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { MatCardModule } from '@angular/material/card';
|
||||||
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
|
import { MatSliderModule } from '@angular/material/slider';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-slider',
|
||||||
|
template: `
|
||||||
|
<mat-card class="flex">
|
||||||
|
<mat-card-content>
|
||||||
|
<div class="flex gap-10 items-center">
|
||||||
|
<button mat-mini-fab (click)="back()">
|
||||||
|
<mat-icon>arrow_back_ios</mat-icon>
|
||||||
|
</button>
|
||||||
|
{{ minValue }}
|
||||||
|
<mat-slider
|
||||||
|
class="m-4"
|
||||||
|
[max]="maxValue"
|
||||||
|
[min]="minValue"
|
||||||
|
[step]="step">
|
||||||
|
<input matSliderThumb [value]="value()" />
|
||||||
|
</mat-slider>
|
||||||
|
{{ maxValue }}
|
||||||
|
<button mat-mini-fab (click)="forward()">
|
||||||
|
<mat-icon>arrow_forward_ios</mat-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</mat-card-content>
|
||||||
|
</mat-card>
|
||||||
|
`,
|
||||||
|
styles: [
|
||||||
|
`
|
||||||
|
.mat-mdc-slider {
|
||||||
|
max-width: 300px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mat-mdc-card + .mat-mdc-card {
|
||||||
|
margin-top: 8px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
],
|
||||||
|
standalone: true,
|
||||||
|
imports: [MatCardModule, FormsModule, MatSliderModule, MatIconModule],
|
||||||
|
})
|
||||||
|
export class SliderComponent implements OnInit {
|
||||||
|
@Input() step = 1;
|
||||||
|
@Input() minValue = 0;
|
||||||
|
@Input() maxValue = 100;
|
||||||
|
|
||||||
|
value = signal(0);
|
||||||
|
@Output() valueChange = toObservable(this.value);
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.value.set(this.minValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
back() {
|
||||||
|
if (this.value() - this.step >= this.minValue) {
|
||||||
|
this.value.update((v) => v - this.step);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
forward() {
|
||||||
|
if (this.value() + this.step <= this.maxValue) {
|
||||||
|
this.value.update((v) => v + this.step);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
apps/create-harness/src/app/slider.harness.ts
Normal file
5
apps/create-harness/src/app/slider.harness.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { ComponentHarness } from '@angular/cdk/testing';
|
||||||
|
|
||||||
|
class MySliderHarness extends ComponentHarness {
|
||||||
|
static hostSelector = 'app-slider';
|
||||||
|
}
|
||||||
0
apps/create-harness/src/assets/.gitkeep
Normal file
0
apps/create-harness/src/assets/.gitkeep
Normal file
BIN
apps/create-harness/src/favicon.ico
Normal file
BIN
apps/create-harness/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
16
apps/create-harness/src/index.html
Normal file
16
apps/create-harness/src/index.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>create-harness</title>
|
||||||
|
<base href="/" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||||
|
<link
|
||||||
|
href="https://fonts.googleapis.com/icon?family=Material+Icons"
|
||||||
|
rel="stylesheet" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<app-root></app-root>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
7
apps/create-harness/src/main.ts
Normal file
7
apps/create-harness/src/main.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { bootstrapApplication } from '@angular/platform-browser';
|
||||||
|
import { appConfig } from './app/app.config';
|
||||||
|
import { AppComponent } from './app/app.component';
|
||||||
|
|
||||||
|
bootstrapApplication(AppComponent, appConfig).catch((err) =>
|
||||||
|
console.error(err)
|
||||||
|
);
|
||||||
29
apps/create-harness/src/styles.scss
Normal file
29
apps/create-harness/src/styles.scss
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/* You can add global styles to this file, and also import other style files */
|
||||||
|
@use '@angular/material' as mat;
|
||||||
|
|
||||||
|
@tailwind base;
|
||||||
|
@tailwind components;
|
||||||
|
@tailwind utilities;
|
||||||
|
|
||||||
|
/* You can add global styles to this file, and also import other style files */
|
||||||
|
|
||||||
|
@include mat.core();
|
||||||
|
|
||||||
|
$theme-primary: mat.define-palette(mat.$indigo-palette);
|
||||||
|
$theme-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
|
||||||
|
|
||||||
|
$theme-warn: mat.define-palette(mat.$red-palette);
|
||||||
|
|
||||||
|
$theme: mat.define-light-theme(
|
||||||
|
(
|
||||||
|
color: (
|
||||||
|
primary: $theme-primary,
|
||||||
|
accent: $theme-accent,
|
||||||
|
warn: $theme-warn,
|
||||||
|
),
|
||||||
|
typography: mat.define-typography-config(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
@include mat.dialog-theme($theme);
|
||||||
|
@include mat.all-component-themes($theme);
|
||||||
2
apps/create-harness/src/test-setup.ts
Normal file
2
apps/create-harness/src/test-setup.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import '@testing-library/jest-dom';
|
||||||
|
import 'jest-preset-angular/setup-jest';
|
||||||
14
apps/create-harness/tailwind.config.js
Normal file
14
apps/create-harness/tailwind.config.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind');
|
||||||
|
const { join } = require('path');
|
||||||
|
|
||||||
|
/** @type {import('tailwindcss').Config} */
|
||||||
|
module.exports = {
|
||||||
|
content: [
|
||||||
|
join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'),
|
||||||
|
...createGlobPatternsForDependencies(__dirname),
|
||||||
|
],
|
||||||
|
theme: {
|
||||||
|
extend: {},
|
||||||
|
},
|
||||||
|
plugins: [],
|
||||||
|
};
|
||||||
10
apps/create-harness/tsconfig.app.json
Normal file
10
apps/create-harness/tsconfig.app.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../../dist/out-tsc",
|
||||||
|
"types": []
|
||||||
|
},
|
||||||
|
"files": ["src/main.ts"],
|
||||||
|
"include": ["src/**/*.d.ts"],
|
||||||
|
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
|
||||||
|
}
|
||||||
7
apps/create-harness/tsconfig.editor.json
Normal file
7
apps/create-harness/tsconfig.editor.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"include": ["src/**/*.ts"],
|
||||||
|
"compilerOptions": {
|
||||||
|
"types": []
|
||||||
|
}
|
||||||
|
}
|
||||||
32
apps/create-harness/tsconfig.json
Normal file
32
apps/create-harness/tsconfig.json
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2022",
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"noImplicitOverride": true,
|
||||||
|
"noPropertyAccessFromIndexSignature": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
},
|
||||||
|
"files": [],
|
||||||
|
"include": [],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.app.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.editor.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.spec.json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extends": "../../tsconfig.base.json",
|
||||||
|
"angularCompilerOptions": {
|
||||||
|
"enableI18nLegacyMessageIdFormat": false,
|
||||||
|
"strictInjectionParameters": true,
|
||||||
|
"strictInputAccessModifiers": true,
|
||||||
|
"strictTemplates": true
|
||||||
|
}
|
||||||
|
}
|
||||||
16
apps/create-harness/tsconfig.spec.json
Normal file
16
apps/create-harness/tsconfig.spec.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../../dist/out-tsc",
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "es2016",
|
||||||
|
"types": ["jest", "node", "@testing-library/jest-dom"]
|
||||||
|
},
|
||||||
|
"files": ["src/test-setup.ts"],
|
||||||
|
"include": [
|
||||||
|
"jest.config.ts",
|
||||||
|
"src/**/*.test.ts",
|
||||||
|
"src/**/*.spec.ts",
|
||||||
|
"src/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user