mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
refactor: move libs
This commit is contained in:
36
apps/testing/23-harness/.eslintrc.json
Normal file
36
apps/testing/23-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": {}
|
||||
}
|
||||
]
|
||||
}
|
||||
13
apps/testing/23-harness/README.md
Normal file
13
apps/testing/23-harness/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Harness
|
||||
|
||||
> author: thomas-laforge
|
||||
|
||||
### Run Application
|
||||
|
||||
```bash
|
||||
npx nx serve testing-harness
|
||||
```
|
||||
|
||||
### Documentation and Instruction
|
||||
|
||||
Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/testing/23-harness/).
|
||||
21
apps/testing/23-harness/jest.config.ts
Normal file
21
apps/testing/23-harness/jest.config.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/* eslint-disable */
|
||||
export default {
|
||||
displayName: 'testing-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',
|
||||
],
|
||||
};
|
||||
81
apps/testing/23-harness/project.json
Normal file
81
apps/testing/23-harness/project.json
Normal file
@@ -0,0 +1,81 @@
|
||||
{
|
||||
"name": "testing-harness",
|
||||
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "application",
|
||||
"prefix": "app",
|
||||
"sourceRoot": "apps/testing/23-harness/src",
|
||||
"tags": [],
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@angular-devkit/build-angular:browser",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/apps/testing/23-harness",
|
||||
"index": "apps/testing/23-harness/src/index.html",
|
||||
"main": "apps/testing/23-harness/src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "apps/testing/23-harness/tsconfig.app.json",
|
||||
"assets": [
|
||||
"apps/testing/23-harness/src/favicon.ico",
|
||||
"apps/testing/23-harness/src/assets"
|
||||
],
|
||||
"styles": ["apps/testing/23-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": {
|
||||
"buildTarget": "testing-harness:build:production"
|
||||
},
|
||||
"development": {
|
||||
"buildTarget": "testing-harness:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"buildTarget": "testing-harness:build"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nx/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"options": {
|
||||
"jestConfig": "apps/testing/23-harness/jest.config.ts"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/eslint:lint"
|
||||
}
|
||||
}
|
||||
}
|
||||
13
apps/testing/23-harness/src/app/app.component.ts
Normal file
13
apps/testing/23-harness/src/app/app.component.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { ChildComponent } from './child.component';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [ChildComponent],
|
||||
selector: 'app-root',
|
||||
template: `
|
||||
<app-child />
|
||||
`,
|
||||
styles: [''],
|
||||
})
|
||||
export class AppComponent {}
|
||||
6
apps/testing/23-harness/src/app/app.config.ts
Normal file
6
apps/testing/23-harness/src/app/app.config.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { ApplicationConfig } from '@angular/core';
|
||||
import { provideAnimations } from '@angular/platform-browser/animations';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [provideAnimations()],
|
||||
};
|
||||
38
apps/testing/23-harness/src/app/child.component.spec.ts
Normal file
38
apps/testing/23-harness/src/app/child.component.spec.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { render } from '@testing-library/angular';
|
||||
import { ChildComponent } from './child.component';
|
||||
|
||||
describe('ChildComponent', () => {
|
||||
describe('When init', () => {
|
||||
test('Then show 1 slider, 3 checkboxes, 4 inputs, 2 buttons', async () => {
|
||||
await render(ChildComponent);
|
||||
});
|
||||
|
||||
test('Then initial value of slider thumb is 0', async () => {
|
||||
await render(ChildComponent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Given maxValue set to 109', () => {
|
||||
test('Then slider max value is 109', async () => {
|
||||
await render(ChildComponent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When disabled checkbox is toggled', () => {
|
||||
test('Then slider is disabled', async () => {
|
||||
await render(ChildComponent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Given step value set to 5, and When clicking on forward button two times', () => {
|
||||
test('Then thumb value is 10', async () => {
|
||||
await render(ChildComponent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Given slider value set to 5, and step value to 6 and When clicking on back button', () => {
|
||||
test('Then slider value is still 5', async () => {
|
||||
await render(ChildComponent);
|
||||
});
|
||||
});
|
||||
});
|
||||
120
apps/testing/23-harness/src/app/child.component.ts
Normal file
120
apps/testing/23-harness/src/app/child.component.ts
Normal file
@@ -0,0 +1,120 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatSliderModule } from '@angular/material/slider';
|
||||
|
||||
@Component({
|
||||
selector: 'app-child',
|
||||
template: `
|
||||
<mat-card>
|
||||
<mat-card-content>
|
||||
<h2 class="my-3">Slider configuration</h2>
|
||||
|
||||
<section class="flex items-center">
|
||||
<mat-form-field class="m-4 w-full max-w-[180px]">
|
||||
<mat-label>Value</mat-label>
|
||||
<input
|
||||
matInput
|
||||
type="number"
|
||||
[(ngModel)]="value"
|
||||
id="input-value" />
|
||||
</mat-form-field>
|
||||
<mat-form-field class="m-4 w-full max-w-[180px]">
|
||||
<mat-label>Min value</mat-label>
|
||||
<input matInput type="number" [(ngModel)]="min" id="input-min" />
|
||||
</mat-form-field>
|
||||
<mat-form-field class="m-4 w-full max-w-[180px]">
|
||||
<mat-label>Max value</mat-label>
|
||||
<input matInput type="number" [(ngModel)]="max" id="input-max" />
|
||||
</mat-form-field>
|
||||
<mat-form-field class="m-4 w-full max-w-[180px]">
|
||||
<mat-label>Step size</mat-label>
|
||||
<input matInput type="number" [(ngModel)]="step" id="input-step" />
|
||||
</mat-form-field>
|
||||
</section>
|
||||
|
||||
<section class="flex items-center">
|
||||
<mat-checkbox [(ngModel)]="showTicks">Show ticks</mat-checkbox>
|
||||
</section>
|
||||
|
||||
<section class="flex items-center">
|
||||
<mat-checkbox [(ngModel)]="thumbLabel">Show thumb label</mat-checkbox>
|
||||
</section>
|
||||
|
||||
<section class="flex items-center">
|
||||
<mat-checkbox [(ngModel)]="disabled">Disabled</mat-checkbox>
|
||||
</section>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
<mat-card class="flex">
|
||||
<mat-card-content>
|
||||
<div class="flex gap-10">
|
||||
<button mat-mini-fab (click)="back()">
|
||||
<mat-icon>arrow_back_ios</mat-icon>
|
||||
</button>
|
||||
<mat-slider
|
||||
class="m-4"
|
||||
[disabled]="disabled"
|
||||
[max]="max"
|
||||
[min]="min"
|
||||
[step]="step"
|
||||
[discrete]="thumbLabel"
|
||||
[showTickMarks]="showTicks">
|
||||
<input matSliderThumb [(ngModel)]="value" />
|
||||
</mat-slider>
|
||||
<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,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
FormsModule,
|
||||
MatCheckboxModule,
|
||||
MatSliderModule,
|
||||
MatIconModule,
|
||||
],
|
||||
})
|
||||
export class ChildComponent {
|
||||
disabled = false;
|
||||
max = 100;
|
||||
min = 0;
|
||||
showTicks = false;
|
||||
step = 1;
|
||||
thumbLabel = false;
|
||||
value = 0;
|
||||
|
||||
back() {
|
||||
if (this.value - this.step >= this.min) {
|
||||
this.value -= this.step;
|
||||
}
|
||||
}
|
||||
|
||||
forward() {
|
||||
if (this.value + this.step <= this.max) {
|
||||
this.value += this.step;
|
||||
}
|
||||
}
|
||||
}
|
||||
0
apps/testing/23-harness/src/assets/.gitkeep
Normal file
0
apps/testing/23-harness/src/assets/.gitkeep
Normal file
BIN
apps/testing/23-harness/src/favicon.ico
Normal file
BIN
apps/testing/23-harness/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
16
apps/testing/23-harness/src/index.html
Normal file
16
apps/testing/23-harness/src/index.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>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/testing/23-harness/src/main.ts
Normal file
7
apps/testing/23-harness/src/main.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app/app.component';
|
||||
import { appConfig } from './app/app.config';
|
||||
|
||||
bootstrapApplication(AppComponent, appConfig).catch((err) =>
|
||||
console.error(err),
|
||||
);
|
||||
28
apps/testing/23-harness/src/styles.scss
Normal file
28
apps/testing/23-harness/src/styles.scss
Normal file
@@ -0,0 +1,28 @@
|
||||
@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/testing/23-harness/src/test-setup.ts
Normal file
2
apps/testing/23-harness/src/test-setup.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import 'jest-preset-angular/setup-jest';
|
||||
14
apps/testing/23-harness/tailwind.config.js
Normal file
14
apps/testing/23-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/testing/23-harness/tsconfig.app.json
Normal file
10
apps/testing/23-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/testing/23-harness/tsconfig.editor.json
Normal file
7
apps/testing/23-harness/tsconfig.editor.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src/**/*.ts", "jest.config.ts"],
|
||||
"compilerOptions": {
|
||||
"types": []
|
||||
}
|
||||
}
|
||||
32
apps/testing/23-harness/tsconfig.json
Normal file
32
apps/testing/23-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/testing/23-harness/tsconfig.spec.json
Normal file
16
apps/testing/23-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