Skip to content

Commit

Permalink
Exercices sur les pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
yatho committed Jul 25, 2024
1 parent fd3e01a commit 1e40e94
Show file tree
Hide file tree
Showing 20 changed files with 337 additions and 7 deletions.
36 changes: 36 additions & 0 deletions apps/pipes/.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:@nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
}
]
}
22 changes: 22 additions & 0 deletions apps/pipes/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable */
export default {
displayName: 'pipes',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
coverageDirectory: '../../coverage/apps/pipes',
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',
],
};
80 changes: 80 additions & 0 deletions apps/pipes/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"name": "pipes",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"prefix": "app",
"sourceRoot": "apps/pipes/src",
"tags": [],
"targets": {
"build": {
"executor": "@angular-devkit/build-angular:application",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/pipes",
"index": "apps/pipes/src/index.html",
"browser": "apps/pipes/src/main.ts",
"polyfills": ["zone.js"],
"tsConfig": "apps/pipes/tsconfig.app.json",
"assets": [
{
"glob": "**/*",
"input": "apps/pipes/public"
}
],
"styles": ["apps/pipes/src/styles.css"],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"outputHashing": "all"
},
"development": {
"optimization": false,
"extractLicenses": false,
"sourceMap": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"executor": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"buildTarget": "pipes:build:production"
},
"development": {
"buildTarget": "pipes:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"buildTarget": "pipes:build"
}
},
"lint": {
"executor": "@nx/eslint:lint"
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "apps/pipes/jest.config.ts"
}
}
}
}
Binary file added apps/pipes/public/favicon.ico
Binary file not shown.
Empty file.
27 changes: 27 additions & 0 deletions apps/pipes/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h1>Pipe existant</h1>

<!-- TODO : Afficher le texte en majuscule -->
<!-- <p>Texte en majuscule: {{ 'angular is awesome' }}</p> -->
<!-- TODO : Afficher la date au format date dd/MM/yyyy -->
<!-- <p>Date actuelle: {{ today }}</p> -->
<!-- TODO : Afficher le montant au format EUR avec 2 chiffres après la virgule -->
<!-- <p>Montant: {{ 12345.6789 }}</p> -->
<!-- TODO : Afficher le texte tronqué à 10 caractères -->
<!-- <p>Texte tronqué: {{ 'angular is awesome' }}</p> -->

<h1>Vos pipes</h1>
<!-- TODO : Créer un pipe qui inverse une chaine de caractère exemple : hello -> olleh -->
<!-- <p>Texte inversé: {{ 'angular is awesome' | reverse }}</p> -->
<!-- TODO : Créer des tests unitaires sur le pipe reverse -->
<!-- TODO : Créer un pipe qui tronque une chaîne de caractères à une longueur définie et ajoute "..." si elle est plus longue. -->
<!-- <p>Texte tronqué: {{ 'angular is awesome' | truncate : 10 }}</p> -->
<!-- TODO : Créer un pipe qui filter une liste d'élément -->
<!-- <input [(ngModel)]="searchText" />
<ul>
@for (item of items | filter: searchText; track $index) {
<li>{{ item }}</li>
}
</ul> -->
<!-- TODO Bonus : Décommenter les 2 lignes ci dessous et résoudre le problème existant si vous le trouvez -->
<!-- <input #frontTechno placeholder="Ajout d'une nouvelle techno" />
<button (click)="addTechno(frontTechno.value)">Ajouter</button> -->
27 changes: 27 additions & 0 deletions apps/pipes/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { NxWelcomeComponent } from './nx-welcome.component';
import { RouterModule } from '@angular/router';

describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AppComponent, NxWelcomeComponent, RouterModule.forRoot([])],
}).compileComponents();
});

it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain(
'Welcome pipes'
);
});

it(`should have as title 'pipes'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('pipes');
});
});
31 changes: 31 additions & 0 deletions apps/pipes/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';

@Component({
standalone: true,
imports: [FormsModule],
selector: 'app-root',
templateUrl: './app.component.html',
styleUrl: './app.component.css',
})
export class AppComponent {
today = Date.now();
name = 'Angular';
value = 'pipes';

searchText = '';

items = [
'Angular',
'React',
'Vue',
'Svelte',
'Ember',
'Backbone',
'Knockout',
];

addTechno(techno: string) {
this.items.push(techno);
}
}
10 changes: 10 additions & 0 deletions apps/pipes/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import { appRoutes } from './app.routes';

export const appConfig: ApplicationConfig = {
providers: [
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(appRoutes),
],
};
3 changes: 3 additions & 0 deletions apps/pipes/src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Route } from '@angular/router';

export const appRoutes: Route[] = [];
13 changes: 13 additions & 0 deletions apps/pipes/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>pipes</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<app-root></app-root>
</body>
</html>
7 changes: 7 additions & 0 deletions apps/pipes/src/main.ts
Original file line number Diff line number Diff line change
@@ -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)
);
1 change: 1 addition & 0 deletions apps/pipes/src/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* You can add global styles to this file, and also import other style files */
8 changes: 8 additions & 0 deletions apps/pipes/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';
10 changes: 10 additions & 0 deletions apps/pipes/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -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"]
}
6 changes: 6 additions & 0 deletions apps/pipes/tsconfig.editor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts"],
"compilerOptions": {},
"exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"]
}
33 changes: 33 additions & 0 deletions apps/pipes/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"compilerOptions": {
"target": "es2022",
"useDefineForClassFields": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.editor.json"
},
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"extends": "../../tsconfig.base.json",
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
16 changes: 16 additions & 0 deletions apps/pipes/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"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"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@nx/eslint": "19.2.1",
"@nx/eslint-plugin": "19.2.1",
"@nx/jest": "19.2.1",
"@nx/js": "19.2.1",
"@nx/js": "19.5.0",
"@nx/workspace": "19.2.1",
"@schematics/angular": "~18.0.0",
"@swc-node/register": "~1.9.1",
Expand Down
Loading

0 comments on commit 1e40e94

Please sign in to comment.