diff --git a/apps/testing-forms/.eslintrc.json b/apps/testing-forms/.eslintrc.json new file mode 100644 index 0000000..c34c7dd --- /dev/null +++ b/apps/testing-forms/.eslintrc.json @@ -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:@nrwl/nx/angular", + "plugin:@angular-eslint/template/process-inline-templates" + ] + }, + { + "files": ["*.html"], + "extends": ["plugin:@nrwl/nx/angular-template"], + "rules": {} + } + ] +} diff --git a/apps/testing-forms/README.md b/apps/testing-forms/README.md new file mode 100644 index 0000000..d32c235 --- /dev/null +++ b/apps/testing-forms/README.md @@ -0,0 +1,38 @@ +

Forms testing

+ +> Author: Thomas Laforge + +### Statement: + +NOT IMPLEMENTED YET + + + +### Submitting your work + +1. Fork the project +2. clone it +3. npm install +4. `npx nx serve testing-forms` to play with the application +5. `npx nx test testing-forms` to test your application with Testing Library +6. `npx nx component-test testing-forms --watch` to test your application with Cypress +7. _...work on it_ +8. Commit your work +9. Submit a PR with a title beginning with **Answer:20** that I will review and other dev can review. + +forms testing +forms testing solution author + + + +_You can ask any question on_ twitter diff --git a/apps/testing-forms/cypress.config.ts b/apps/testing-forms/cypress.config.ts new file mode 100644 index 0000000..ade9ea3 --- /dev/null +++ b/apps/testing-forms/cypress.config.ts @@ -0,0 +1,6 @@ +import { defineConfig } from 'cypress'; +import { nxComponentTestingPreset } from '@nrwl/angular/plugins/component-testing'; + +export default defineConfig({ + component: nxComponentTestingPreset(__filename), +}); diff --git a/apps/testing-forms/cypress/fixtures/example.json b/apps/testing-forms/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /dev/null +++ b/apps/testing-forms/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/apps/testing-forms/cypress/support/commands.ts b/apps/testing-forms/cypress/support/commands.ts new file mode 100644 index 0000000..e6c8976 --- /dev/null +++ b/apps/testing-forms/cypress/support/commands.ts @@ -0,0 +1,42 @@ +/// +import { mount } from 'cypress/angular'; + +// *********************************************** +// This example commands.ts 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 +// *********************************************** + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface Chainable { + login(email: string, password: string): void; + mount: typeof mount; + } + } +} + +Cypress.Commands.add('mount', mount); + +// +// -- 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) => { ... }) diff --git a/apps/testing-forms/cypress/support/component-index.html b/apps/testing-forms/cypress/support/component-index.html new file mode 100644 index 0000000..1f591ac --- /dev/null +++ b/apps/testing-forms/cypress/support/component-index.html @@ -0,0 +1,13 @@ + + + + + + + testing-forms Components App + + + +
+ + diff --git a/apps/testing-forms/cypress/support/component.ts b/apps/testing-forms/cypress/support/component.ts new file mode 100644 index 0000000..e3684db --- /dev/null +++ b/apps/testing-forms/cypress/support/component.ts @@ -0,0 +1,17 @@ +// *********************************************************** +// This example support/component.ts 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.ts using ES2015 syntax: +import './commands'; diff --git a/apps/testing-forms/cypress/tsconfig.cy.json b/apps/testing-forms/cypress/tsconfig.cy.json new file mode 100644 index 0000000..9025c2a --- /dev/null +++ b/apps/testing-forms/cypress/tsconfig.cy.json @@ -0,0 +1,17 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["cypress", "node"] + }, + "include": [ + "support/**/*.ts", + "../cypress.config.ts", + "../**/*.cy.ts", + "../**/*.cy.tsx", + "../**/*.cy.js", + "../**/*.cy.jsx", + "../**/*.d.ts" + ] +} diff --git a/apps/testing-forms/jest.config.ts b/apps/testing-forms/jest.config.ts new file mode 100644 index 0000000..f32c26b --- /dev/null +++ b/apps/testing-forms/jest.config.ts @@ -0,0 +1,21 @@ +/* eslint-disable */ +export default { + displayName: 'testing-forms', + preset: '../../jest.preset.js', + setupFilesAfterEnv: ['/src/test-setup.ts'], + transform: { + '^.+\\.(ts|mjs|js|html)$': [ + 'jest-preset-angular', + { + tsconfig: '/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', + ], +}; diff --git a/apps/testing-forms/project.json b/apps/testing-forms/project.json new file mode 100644 index 0000000..0a9c57f --- /dev/null +++ b/apps/testing-forms/project.json @@ -0,0 +1,105 @@ +{ + "name": "testing-forms", + "$schema": "../node_modules/nx/schemas/project-schema.json", + "projectType": "application", + "sourceRoot": "apps/testing-forms/src", + "prefix": "app", + "targets": { + "build": { + "executor": "@angular-devkit/build-angular:browser", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/apps/testing-forms", + "index": "apps/testing-forms/src/index.html", + "main": "apps/testing-forms/src/main.ts", + "polyfills": ["zone.js"], + "tsConfig": "apps/testing-forms/tsconfig.app.json", + "inlineStyleLanguage": "scss", + "assets": [ + "apps/testing-forms/src/favicon.ico", + "apps/testing-forms/src/assets" + ], + "styles": ["apps/testing-forms/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": "testing-forms:build:production" + }, + "development": { + "browserTarget": "testing-forms:build:development" + } + }, + "defaultConfiguration": "development" + }, + "extract-i18n": { + "executor": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "testing-forms:build" + } + }, + "lint": { + "executor": "@nrwl/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": [ + "apps/testing-forms/**/*.ts", + "apps/testing-forms/**/*.html" + ] + } + }, + "test": { + "executor": "@nrwl/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "apps/testing-forms/jest.config.ts", + "passWithNoTests": true + }, + "configurations": { + "ci": { + "ci": true, + "codeCoverage": true + } + } + }, + "component-test": { + "executor": "@nrwl/cypress:cypress", + "options": { + "cypressConfig": "apps/testing-forms/cypress.config.ts", + "testingType": "component", + "skipServe": true, + "devServerTarget": "testing-forms:build" + } + } + }, + "tags": [] +} diff --git a/apps/testing-forms/src/app/app.component.spec.ts b/apps/testing-forms/src/app/app.component.spec.ts new file mode 100644 index 0000000..f0d4b8e --- /dev/null +++ b/apps/testing-forms/src/app/app.component.spec.ts @@ -0,0 +1,32 @@ +import { TestBed } from '@angular/core/testing'; +import { AppComponent } from './app.component'; +import { NxWelcomeComponent } from './nx-welcome.component'; + +describe('AppComponent', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [AppComponent, NxWelcomeComponent], + }).compileComponents(); + }); + + it('should create the app', () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app).toBeTruthy(); + }); + + it(`should have as title 'testing-forms'`, () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app.title).toEqual('testing-forms'); + }); + + it('should render title', () => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + const compiled = fixture.nativeElement as HTMLElement; + expect(compiled.querySelector('h1')?.textContent).toContain( + 'Welcome testing-forms' + ); + }); +}); diff --git a/apps/testing-forms/src/app/app.component.ts b/apps/testing-forms/src/app/app.component.ts new file mode 100644 index 0000000..4010c3c --- /dev/null +++ b/apps/testing-forms/src/app/app.component.ts @@ -0,0 +1,13 @@ +import { NxWelcomeComponent } from './nx-welcome.component'; +import { Component } from '@angular/core'; + +@Component({ + standalone: true, + imports: [NxWelcomeComponent], + selector: 'app-root', + template: ` `, + styles: [], +}) +export class AppComponent { + title = 'testing-forms'; +} diff --git a/apps/testing-forms/src/app/nx-welcome.component.ts b/apps/testing-forms/src/app/nx-welcome.component.ts new file mode 100644 index 0000000..b3bbd6d --- /dev/null +++ b/apps/testing-forms/src/app/nx-welcome.component.ts @@ -0,0 +1,801 @@ +import { Component, ViewEncapsulation } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +/* eslint-disable */ + +@Component({ + selector: 'app-nx-welcome', + standalone: true, + imports: [CommonModule], + template: ` + + +
+
+ +
+

+ Hello there, + Welcome testing-forms 👋 +

+
+ + +
+
+

+ + + + You're up and running +

+ What's next? +
+
+ + + +
+
+ + + + + +
+

Next steps

+

Here are some things you can do with Nx:

+
+ + + + + Add UI library + +
# Generate UI lib
+nx g @nrwl/angular:lib ui
+
+# Add a component
+nx g @nrwl/angular:component button --project ui
+
+
+ + + + + View interactive project graph + +
nx graph
+
+
+ + + + + Run affected commands + +
# see what's been affected by changes
+nx affected:graph
+
+# run tests for current changes
+nx affected:test
+
+# run e2e tests for current changes
+nx affected:e2e
+
+
+ +

+ Carefully crafted with + + + +

+
+
+ `, + styles: [], + encapsulation: ViewEncapsulation.None, +}) +export class NxWelcomeComponent {} diff --git a/apps/testing-forms/src/assets/.gitkeep b/apps/testing-forms/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/apps/testing-forms/src/favicon.ico b/apps/testing-forms/src/favicon.ico new file mode 100644 index 0000000..317ebcb Binary files /dev/null and b/apps/testing-forms/src/favicon.ico differ diff --git a/apps/testing-forms/src/index.html b/apps/testing-forms/src/index.html new file mode 100644 index 0000000..a27718f --- /dev/null +++ b/apps/testing-forms/src/index.html @@ -0,0 +1,13 @@ + + + + + TestingForms + + + + + + + + diff --git a/apps/testing-forms/src/main.ts b/apps/testing-forms/src/main.ts new file mode 100644 index 0000000..31c5da4 --- /dev/null +++ b/apps/testing-forms/src/main.ts @@ -0,0 +1,4 @@ +import { bootstrapApplication } from '@angular/platform-browser'; +import { AppComponent } from './app/app.component'; + +bootstrapApplication(AppComponent).catch((err) => console.error(err)); diff --git a/apps/testing-forms/src/styles.scss b/apps/testing-forms/src/styles.scss new file mode 100644 index 0000000..77e408a --- /dev/null +++ b/apps/testing-forms/src/styles.scss @@ -0,0 +1,5 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +/* You can add global styles to this file, and also import other style files */ diff --git a/apps/testing-forms/src/test-setup.ts b/apps/testing-forms/src/test-setup.ts new file mode 100644 index 0000000..15de72a --- /dev/null +++ b/apps/testing-forms/src/test-setup.ts @@ -0,0 +1,2 @@ +import '@testing-library/jest-dom'; +import 'jest-preset-angular/setup-jest'; diff --git a/apps/testing-forms/tailwind.config.js b/apps/testing-forms/tailwind.config.js new file mode 100644 index 0000000..f9b2a5e --- /dev/null +++ b/apps/testing-forms/tailwind.config.js @@ -0,0 +1,14 @@ +const { createGlobPatternsForDependencies } = require('@nrwl/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: [], +}; diff --git a/apps/testing-forms/tsconfig.app.json b/apps/testing-forms/tsconfig.app.json new file mode 100644 index 0000000..e46d4fc --- /dev/null +++ b/apps/testing-forms/tsconfig.app.json @@ -0,0 +1,20 @@ +{ + "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", + "cypress/**/*", + "cypress.config.ts", + "**/*.cy.ts", + "**/*.cy.js", + "**/*.cy.tsx", + "**/*.cy.jsx" + ] +} diff --git a/apps/testing-forms/tsconfig.editor.json b/apps/testing-forms/tsconfig.editor.json new file mode 100644 index 0000000..8ae117d --- /dev/null +++ b/apps/testing-forms/tsconfig.editor.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*.ts"], + "compilerOptions": { + "types": ["jest", "node"] + } +} diff --git a/apps/testing-forms/tsconfig.json b/apps/testing-forms/tsconfig.json new file mode 100644 index 0000000..bfbafa3 --- /dev/null +++ b/apps/testing-forms/tsconfig.json @@ -0,0 +1,35 @@ +{ + "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.spec.json" + }, + { + "path": "./tsconfig.editor.json" + }, + { + "path": "./cypress/tsconfig.cy.json" + } + ], + "extends": "../../tsconfig.base.json", + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +} diff --git a/apps/testing-forms/tsconfig.spec.json b/apps/testing-forms/tsconfig.spec.json new file mode 100644 index 0000000..1a4817a --- /dev/null +++ b/apps/testing-forms/tsconfig.spec.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "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" + ] +} diff --git a/apps/testing-modal/.eslintrc.json b/apps/testing-modal/.eslintrc.json new file mode 100644 index 0000000..c34c7dd --- /dev/null +++ b/apps/testing-modal/.eslintrc.json @@ -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:@nrwl/nx/angular", + "plugin:@angular-eslint/template/process-inline-templates" + ] + }, + { + "files": ["*.html"], + "extends": ["plugin:@nrwl/nx/angular-template"], + "rules": {} + } + ] +} diff --git a/apps/testing-modal/README.md b/apps/testing-modal/README.md new file mode 100644 index 0000000..494a0f0 --- /dev/null +++ b/apps/testing-modal/README.md @@ -0,0 +1,38 @@ +

Modal testing

+ +> Author: Thomas Laforge + +### Statement: + +NOT IMPLEMENTED YET + + + +### Submitting your work + +1. Fork the project +2. clone it +3. npm install +4. `npx nx serve testing-modal` to play with the application +5. `npx nx test testing-modal` to test your application with Testing Library +6. `npx nx component-test testing-modal --watch` to test your application with Cypress +7. _...work on it_ +8. Commit your work +9. Submit a PR with a title beginning with **Answer:21** that I will review and other dev can review. + +modal testing +modal testing solution author + + + +_You can ask any question on_ twitter diff --git a/apps/testing-modal/cypress.config.ts b/apps/testing-modal/cypress.config.ts new file mode 100644 index 0000000..ade9ea3 --- /dev/null +++ b/apps/testing-modal/cypress.config.ts @@ -0,0 +1,6 @@ +import { defineConfig } from 'cypress'; +import { nxComponentTestingPreset } from '@nrwl/angular/plugins/component-testing'; + +export default defineConfig({ + component: nxComponentTestingPreset(__filename), +}); diff --git a/apps/testing-modal/cypress/fixtures/example.json b/apps/testing-modal/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /dev/null +++ b/apps/testing-modal/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/apps/testing-modal/cypress/support/commands.ts b/apps/testing-modal/cypress/support/commands.ts new file mode 100644 index 0000000..e6c8976 --- /dev/null +++ b/apps/testing-modal/cypress/support/commands.ts @@ -0,0 +1,42 @@ +/// +import { mount } from 'cypress/angular'; + +// *********************************************** +// This example commands.ts 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 +// *********************************************** + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface Chainable { + login(email: string, password: string): void; + mount: typeof mount; + } + } +} + +Cypress.Commands.add('mount', mount); + +// +// -- 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) => { ... }) diff --git a/apps/testing-modal/cypress/support/component-index.html b/apps/testing-modal/cypress/support/component-index.html new file mode 100644 index 0000000..e8135e7 --- /dev/null +++ b/apps/testing-modal/cypress/support/component-index.html @@ -0,0 +1,13 @@ + + + + + + + testing-modal Components App + + + +
+ + diff --git a/apps/testing-modal/cypress/support/component.ts b/apps/testing-modal/cypress/support/component.ts new file mode 100644 index 0000000..e3684db --- /dev/null +++ b/apps/testing-modal/cypress/support/component.ts @@ -0,0 +1,17 @@ +// *********************************************************** +// This example support/component.ts 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.ts using ES2015 syntax: +import './commands'; diff --git a/apps/testing-modal/cypress/tsconfig.cy.json b/apps/testing-modal/cypress/tsconfig.cy.json new file mode 100644 index 0000000..9025c2a --- /dev/null +++ b/apps/testing-modal/cypress/tsconfig.cy.json @@ -0,0 +1,17 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["cypress", "node"] + }, + "include": [ + "support/**/*.ts", + "../cypress.config.ts", + "../**/*.cy.ts", + "../**/*.cy.tsx", + "../**/*.cy.js", + "../**/*.cy.jsx", + "../**/*.d.ts" + ] +} diff --git a/apps/testing-modal/jest.config.ts b/apps/testing-modal/jest.config.ts new file mode 100644 index 0000000..d895133 --- /dev/null +++ b/apps/testing-modal/jest.config.ts @@ -0,0 +1,21 @@ +/* eslint-disable */ +export default { + displayName: 'testing-modal', + preset: '../../jest.preset.js', + setupFilesAfterEnv: ['/src/test-setup.ts'], + transform: { + '^.+\\.(ts|mjs|js|html)$': [ + 'jest-preset-angular', + { + tsconfig: '/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', + ], +}; diff --git a/apps/testing-modal/project.json b/apps/testing-modal/project.json new file mode 100644 index 0000000..dc1c248 --- /dev/null +++ b/apps/testing-modal/project.json @@ -0,0 +1,105 @@ +{ + "name": "testing-modal", + "$schema": "../node_modules/nx/schemas/project-schema.json", + "projectType": "application", + "sourceRoot": "apps/testing-modal/src", + "prefix": "app", + "targets": { + "build": { + "executor": "@angular-devkit/build-angular:browser", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/apps/testing-modal", + "index": "apps/testing-modal/src/index.html", + "main": "apps/testing-modal/src/main.ts", + "polyfills": ["zone.js"], + "tsConfig": "apps/testing-modal/tsconfig.app.json", + "inlineStyleLanguage": "scss", + "assets": [ + "apps/testing-modal/src/favicon.ico", + "apps/testing-modal/src/assets" + ], + "styles": ["apps/testing-modal/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": "testing-modal:build:production" + }, + "development": { + "browserTarget": "testing-modal:build:development" + } + }, + "defaultConfiguration": "development" + }, + "extract-i18n": { + "executor": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "testing-modal:build" + } + }, + "lint": { + "executor": "@nrwl/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": [ + "apps/testing-modal/**/*.ts", + "apps/testing-modal/**/*.html" + ] + } + }, + "test": { + "executor": "@nrwl/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "apps/testing-modal/jest.config.ts", + "passWithNoTests": true + }, + "configurations": { + "ci": { + "ci": true, + "codeCoverage": true + } + } + }, + "component-test": { + "executor": "@nrwl/cypress:cypress", + "options": { + "cypressConfig": "apps/testing-modal/cypress.config.ts", + "testingType": "component", + "skipServe": true, + "devServerTarget": "testing-modal:build" + } + } + }, + "tags": [] +} diff --git a/apps/testing-modal/src/app/app.component.spec.ts b/apps/testing-modal/src/app/app.component.spec.ts new file mode 100644 index 0000000..579b471 --- /dev/null +++ b/apps/testing-modal/src/app/app.component.spec.ts @@ -0,0 +1,32 @@ +import { TestBed } from '@angular/core/testing'; +import { AppComponent } from './app.component'; +import { NxWelcomeComponent } from './nx-welcome.component'; + +describe('AppComponent', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [AppComponent, NxWelcomeComponent], + }).compileComponents(); + }); + + it('should create the app', () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app).toBeTruthy(); + }); + + it(`should have as title 'testing-modal'`, () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app.title).toEqual('testing-modal'); + }); + + it('should render title', () => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + const compiled = fixture.nativeElement as HTMLElement; + expect(compiled.querySelector('h1')?.textContent).toContain( + 'Welcome testing-modal' + ); + }); +}); diff --git a/apps/testing-modal/src/app/app.component.ts b/apps/testing-modal/src/app/app.component.ts new file mode 100644 index 0000000..75e5e65 --- /dev/null +++ b/apps/testing-modal/src/app/app.component.ts @@ -0,0 +1,13 @@ +import { NxWelcomeComponent } from './nx-welcome.component'; +import { Component } from '@angular/core'; + +@Component({ + standalone: true, + imports: [NxWelcomeComponent], + selector: 'app-root', + template: ` `, + styles: [], +}) +export class AppComponent { + title = 'testing-modal'; +} diff --git a/apps/testing-modal/src/app/nx-welcome.component.ts b/apps/testing-modal/src/app/nx-welcome.component.ts new file mode 100644 index 0000000..485b055 --- /dev/null +++ b/apps/testing-modal/src/app/nx-welcome.component.ts @@ -0,0 +1,801 @@ +import { Component, ViewEncapsulation } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +/* eslint-disable */ + +@Component({ + selector: 'app-nx-welcome', + standalone: true, + imports: [CommonModule], + template: ` + + +
+
+ +
+

+ Hello there, + Welcome testing-modal 👋 +

+
+ + +
+
+

+ + + + You're up and running +

+ What's next? +
+
+ + + +
+
+ + + + + +
+

Next steps

+

Here are some things you can do with Nx:

+
+ + + + + Add UI library + +
# Generate UI lib
+nx g @nrwl/angular:lib ui
+
+# Add a component
+nx g @nrwl/angular:component button --project ui
+
+
+ + + + + View interactive project graph + +
nx graph
+
+
+ + + + + Run affected commands + +
# see what's been affected by changes
+nx affected:graph
+
+# run tests for current changes
+nx affected:test
+
+# run e2e tests for current changes
+nx affected:e2e
+
+
+ +

+ Carefully crafted with + + + +

+
+
+ `, + styles: [], + encapsulation: ViewEncapsulation.None, +}) +export class NxWelcomeComponent {} diff --git a/apps/testing-modal/src/assets/.gitkeep b/apps/testing-modal/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/apps/testing-modal/src/favicon.ico b/apps/testing-modal/src/favicon.ico new file mode 100644 index 0000000..317ebcb Binary files /dev/null and b/apps/testing-modal/src/favicon.ico differ diff --git a/apps/testing-modal/src/index.html b/apps/testing-modal/src/index.html new file mode 100644 index 0000000..ce6d8d4 --- /dev/null +++ b/apps/testing-modal/src/index.html @@ -0,0 +1,13 @@ + + + + + TestingModal + + + + + + + + diff --git a/apps/testing-modal/src/main.ts b/apps/testing-modal/src/main.ts new file mode 100644 index 0000000..31c5da4 --- /dev/null +++ b/apps/testing-modal/src/main.ts @@ -0,0 +1,4 @@ +import { bootstrapApplication } from '@angular/platform-browser'; +import { AppComponent } from './app/app.component'; + +bootstrapApplication(AppComponent).catch((err) => console.error(err)); diff --git a/apps/testing-modal/src/styles.scss b/apps/testing-modal/src/styles.scss new file mode 100644 index 0000000..77e408a --- /dev/null +++ b/apps/testing-modal/src/styles.scss @@ -0,0 +1,5 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +/* You can add global styles to this file, and also import other style files */ diff --git a/apps/testing-modal/src/test-setup.ts b/apps/testing-modal/src/test-setup.ts new file mode 100644 index 0000000..15de72a --- /dev/null +++ b/apps/testing-modal/src/test-setup.ts @@ -0,0 +1,2 @@ +import '@testing-library/jest-dom'; +import 'jest-preset-angular/setup-jest'; diff --git a/apps/testing-modal/tailwind.config.js b/apps/testing-modal/tailwind.config.js new file mode 100644 index 0000000..f9b2a5e --- /dev/null +++ b/apps/testing-modal/tailwind.config.js @@ -0,0 +1,14 @@ +const { createGlobPatternsForDependencies } = require('@nrwl/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: [], +}; diff --git a/apps/testing-modal/tsconfig.app.json b/apps/testing-modal/tsconfig.app.json new file mode 100644 index 0000000..e46d4fc --- /dev/null +++ b/apps/testing-modal/tsconfig.app.json @@ -0,0 +1,20 @@ +{ + "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", + "cypress/**/*", + "cypress.config.ts", + "**/*.cy.ts", + "**/*.cy.js", + "**/*.cy.tsx", + "**/*.cy.jsx" + ] +} diff --git a/apps/testing-modal/tsconfig.editor.json b/apps/testing-modal/tsconfig.editor.json new file mode 100644 index 0000000..8ae117d --- /dev/null +++ b/apps/testing-modal/tsconfig.editor.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*.ts"], + "compilerOptions": { + "types": ["jest", "node"] + } +} diff --git a/apps/testing-modal/tsconfig.json b/apps/testing-modal/tsconfig.json new file mode 100644 index 0000000..bfbafa3 --- /dev/null +++ b/apps/testing-modal/tsconfig.json @@ -0,0 +1,35 @@ +{ + "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.spec.json" + }, + { + "path": "./tsconfig.editor.json" + }, + { + "path": "./cypress/tsconfig.cy.json" + } + ], + "extends": "../../tsconfig.base.json", + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +} diff --git a/apps/testing-modal/tsconfig.spec.json b/apps/testing-modal/tsconfig.spec.json new file mode 100644 index 0000000..1a4817a --- /dev/null +++ b/apps/testing-modal/tsconfig.spec.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "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" + ] +} diff --git a/apps/testing-nested/jest.config.ts b/apps/testing-nested/jest.config.ts index eedc4a1..d4e125d 100644 --- a/apps/testing-nested/jest.config.ts +++ b/apps/testing-nested/jest.config.ts @@ -3,7 +3,6 @@ export default { displayName: 'testing-nested', preset: '../../jest.preset.js', setupFilesAfterEnv: ['/src/test-setup.ts'], - coverageDirectory: '../../coverage/apps/testing-nested', transform: { '^.+\\.(ts|mjs|js|html)$': [ 'jest-preset-angular', diff --git a/apps/testing-table/.eslintrc.json b/apps/testing-table/.eslintrc.json new file mode 100644 index 0000000..c34c7dd --- /dev/null +++ b/apps/testing-table/.eslintrc.json @@ -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:@nrwl/nx/angular", + "plugin:@angular-eslint/template/process-inline-templates" + ] + }, + { + "files": ["*.html"], + "extends": ["plugin:@nrwl/nx/angular-template"], + "rules": {} + } + ] +} diff --git a/apps/testing-table/README.md b/apps/testing-table/README.md new file mode 100644 index 0000000..440a5f8 --- /dev/null +++ b/apps/testing-table/README.md @@ -0,0 +1,38 @@ +

Table testing

+ +> Author: Thomas Laforge + +### Statement: + +NOT IMPLEMENTED YET + + + +### Submitting your work + +1. Fork the project +2. clone it +3. npm install +4. `npx nx serve testing-table` to play with the application +5. `npx nx test testing-table` to test your application with Testing Library +6. `npx nx component-test testing-table --watch` to test your application with Cypress +7. _...work on it_ +8. Commit your work +9. Submit a PR with a title beginning with **Answer:22** that I will review and other dev can review. + +nested testing +nested testing solution author + + + +_You can ask any question on_ twitter diff --git a/apps/testing-table/cypress.config.ts b/apps/testing-table/cypress.config.ts new file mode 100644 index 0000000..ade9ea3 --- /dev/null +++ b/apps/testing-table/cypress.config.ts @@ -0,0 +1,6 @@ +import { defineConfig } from 'cypress'; +import { nxComponentTestingPreset } from '@nrwl/angular/plugins/component-testing'; + +export default defineConfig({ + component: nxComponentTestingPreset(__filename), +}); diff --git a/apps/testing-table/cypress/fixtures/example.json b/apps/testing-table/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /dev/null +++ b/apps/testing-table/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/apps/testing-table/cypress/support/commands.ts b/apps/testing-table/cypress/support/commands.ts new file mode 100644 index 0000000..e6c8976 --- /dev/null +++ b/apps/testing-table/cypress/support/commands.ts @@ -0,0 +1,42 @@ +/// +import { mount } from 'cypress/angular'; + +// *********************************************** +// This example commands.ts 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 +// *********************************************** + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface Chainable { + login(email: string, password: string): void; + mount: typeof mount; + } + } +} + +Cypress.Commands.add('mount', mount); + +// +// -- 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) => { ... }) diff --git a/apps/testing-table/cypress/support/component-index.html b/apps/testing-table/cypress/support/component-index.html new file mode 100644 index 0000000..bcae787 --- /dev/null +++ b/apps/testing-table/cypress/support/component-index.html @@ -0,0 +1,13 @@ + + + + + + + testing-table Components App + + + +
+ + diff --git a/apps/testing-table/cypress/support/component.ts b/apps/testing-table/cypress/support/component.ts new file mode 100644 index 0000000..e3684db --- /dev/null +++ b/apps/testing-table/cypress/support/component.ts @@ -0,0 +1,17 @@ +// *********************************************************** +// This example support/component.ts 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.ts using ES2015 syntax: +import './commands'; diff --git a/apps/testing-table/cypress/tsconfig.cy.json b/apps/testing-table/cypress/tsconfig.cy.json new file mode 100644 index 0000000..9025c2a --- /dev/null +++ b/apps/testing-table/cypress/tsconfig.cy.json @@ -0,0 +1,17 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["cypress", "node"] + }, + "include": [ + "support/**/*.ts", + "../cypress.config.ts", + "../**/*.cy.ts", + "../**/*.cy.tsx", + "../**/*.cy.js", + "../**/*.cy.jsx", + "../**/*.d.ts" + ] +} diff --git a/apps/testing-table/jest.config.ts b/apps/testing-table/jest.config.ts new file mode 100644 index 0000000..8a36e0f --- /dev/null +++ b/apps/testing-table/jest.config.ts @@ -0,0 +1,21 @@ +/* eslint-disable */ +export default { + displayName: 'testing-table', + preset: '../../jest.preset.js', + setupFilesAfterEnv: ['/src/test-setup.ts'], + transform: { + '^.+\\.(ts|mjs|js|html)$': [ + 'jest-preset-angular', + { + tsconfig: '/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', + ], +}; diff --git a/apps/testing-table/project.json b/apps/testing-table/project.json new file mode 100644 index 0000000..3def9f3 --- /dev/null +++ b/apps/testing-table/project.json @@ -0,0 +1,105 @@ +{ + "name": "testing-table", + "$schema": "../node_modules/nx/schemas/project-schema.json", + "projectType": "application", + "sourceRoot": "apps/testing-table/src", + "prefix": "app", + "targets": { + "build": { + "executor": "@angular-devkit/build-angular:browser", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/apps/testing-table", + "index": "apps/testing-table/src/index.html", + "main": "apps/testing-table/src/main.ts", + "polyfills": ["zone.js"], + "tsConfig": "apps/testing-table/tsconfig.app.json", + "inlineStyleLanguage": "scss", + "assets": [ + "apps/testing-table/src/favicon.ico", + "apps/testing-table/src/assets" + ], + "styles": ["apps/testing-table/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": "testing-table:build:production" + }, + "development": { + "browserTarget": "testing-table:build:development" + } + }, + "defaultConfiguration": "development" + }, + "extract-i18n": { + "executor": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "testing-table:build" + } + }, + "lint": { + "executor": "@nrwl/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": [ + "apps/testing-table/**/*.ts", + "apps/testing-table/**/*.html" + ] + } + }, + "test": { + "executor": "@nrwl/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "apps/testing-table/jest.config.ts", + "passWithNoTests": true + }, + "configurations": { + "ci": { + "ci": true, + "codeCoverage": true + } + } + }, + "component-test": { + "executor": "@nrwl/cypress:cypress", + "options": { + "cypressConfig": "apps/testing-table/cypress.config.ts", + "testingType": "component", + "skipServe": true, + "devServerTarget": "testing-table:build" + } + } + }, + "tags": [] +} diff --git a/apps/testing-table/src/app/app.component.spec.ts b/apps/testing-table/src/app/app.component.spec.ts new file mode 100644 index 0000000..5a87408 --- /dev/null +++ b/apps/testing-table/src/app/app.component.spec.ts @@ -0,0 +1,32 @@ +import { TestBed } from '@angular/core/testing'; +import { AppComponent } from './app.component'; +import { NxWelcomeComponent } from './nx-welcome.component'; + +describe('AppComponent', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [AppComponent, NxWelcomeComponent], + }).compileComponents(); + }); + + it('should create the app', () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app).toBeTruthy(); + }); + + it(`should have as title 'testing-table'`, () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app.title).toEqual('testing-table'); + }); + + it('should render title', () => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + const compiled = fixture.nativeElement as HTMLElement; + expect(compiled.querySelector('h1')?.textContent).toContain( + 'Welcome testing-table' + ); + }); +}); diff --git a/apps/testing-table/src/app/app.component.ts b/apps/testing-table/src/app/app.component.ts new file mode 100644 index 0000000..385bdd7 --- /dev/null +++ b/apps/testing-table/src/app/app.component.ts @@ -0,0 +1,13 @@ +import { NxWelcomeComponent } from './nx-welcome.component'; +import { Component } from '@angular/core'; + +@Component({ + standalone: true, + imports: [NxWelcomeComponent], + selector: 'app-root', + template: ` `, + styles: [], +}) +export class AppComponent { + title = 'testing-table'; +} diff --git a/apps/testing-table/src/app/nx-welcome.component.ts b/apps/testing-table/src/app/nx-welcome.component.ts new file mode 100644 index 0000000..3cca483 --- /dev/null +++ b/apps/testing-table/src/app/nx-welcome.component.ts @@ -0,0 +1,801 @@ +import { Component, ViewEncapsulation } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +/* eslint-disable */ + +@Component({ + selector: 'app-nx-welcome', + standalone: true, + imports: [CommonModule], + template: ` + + +
+
+ +
+

+ Hello there, + Welcome testing-table 👋 +

+
+ + +
+
+

+ + + + You're up and running +

+ What's next? +
+
+ + + +
+
+ + + + + +
+

Next steps

+

Here are some things you can do with Nx:

+
+ + + + + Add UI library + +
# Generate UI lib
+nx g @nrwl/angular:lib ui
+
+# Add a component
+nx g @nrwl/angular:component button --project ui
+
+
+ + + + + View interactive project graph + +
nx graph
+
+
+ + + + + Run affected commands + +
# see what's been affected by changes
+nx affected:graph
+
+# run tests for current changes
+nx affected:test
+
+# run e2e tests for current changes
+nx affected:e2e
+
+
+ +

+ Carefully crafted with + + + +

+
+
+ `, + styles: [], + encapsulation: ViewEncapsulation.None, +}) +export class NxWelcomeComponent {} diff --git a/apps/testing-table/src/assets/.gitkeep b/apps/testing-table/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/apps/testing-table/src/favicon.ico b/apps/testing-table/src/favicon.ico new file mode 100644 index 0000000..317ebcb Binary files /dev/null and b/apps/testing-table/src/favicon.ico differ diff --git a/apps/testing-table/src/index.html b/apps/testing-table/src/index.html new file mode 100644 index 0000000..2eadaaa --- /dev/null +++ b/apps/testing-table/src/index.html @@ -0,0 +1,13 @@ + + + + + TestingTable + + + + + + + + diff --git a/apps/testing-table/src/main.ts b/apps/testing-table/src/main.ts new file mode 100644 index 0000000..31c5da4 --- /dev/null +++ b/apps/testing-table/src/main.ts @@ -0,0 +1,4 @@ +import { bootstrapApplication } from '@angular/platform-browser'; +import { AppComponent } from './app/app.component'; + +bootstrapApplication(AppComponent).catch((err) => console.error(err)); diff --git a/apps/testing-table/src/styles.scss b/apps/testing-table/src/styles.scss new file mode 100644 index 0000000..77e408a --- /dev/null +++ b/apps/testing-table/src/styles.scss @@ -0,0 +1,5 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +/* You can add global styles to this file, and also import other style files */ diff --git a/apps/testing-table/src/test-setup.ts b/apps/testing-table/src/test-setup.ts new file mode 100644 index 0000000..15de72a --- /dev/null +++ b/apps/testing-table/src/test-setup.ts @@ -0,0 +1,2 @@ +import '@testing-library/jest-dom'; +import 'jest-preset-angular/setup-jest'; diff --git a/apps/testing-table/tailwind.config.js b/apps/testing-table/tailwind.config.js new file mode 100644 index 0000000..f9b2a5e --- /dev/null +++ b/apps/testing-table/tailwind.config.js @@ -0,0 +1,14 @@ +const { createGlobPatternsForDependencies } = require('@nrwl/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: [], +}; diff --git a/apps/testing-table/tsconfig.app.json b/apps/testing-table/tsconfig.app.json new file mode 100644 index 0000000..e46d4fc --- /dev/null +++ b/apps/testing-table/tsconfig.app.json @@ -0,0 +1,20 @@ +{ + "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", + "cypress/**/*", + "cypress.config.ts", + "**/*.cy.ts", + "**/*.cy.js", + "**/*.cy.tsx", + "**/*.cy.jsx" + ] +} diff --git a/apps/testing-table/tsconfig.editor.json b/apps/testing-table/tsconfig.editor.json new file mode 100644 index 0000000..8ae117d --- /dev/null +++ b/apps/testing-table/tsconfig.editor.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*.ts"], + "compilerOptions": { + "types": ["jest", "node"] + } +} diff --git a/apps/testing-table/tsconfig.json b/apps/testing-table/tsconfig.json new file mode 100644 index 0000000..bfbafa3 --- /dev/null +++ b/apps/testing-table/tsconfig.json @@ -0,0 +1,35 @@ +{ + "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.spec.json" + }, + { + "path": "./tsconfig.editor.json" + }, + { + "path": "./cypress/tsconfig.cy.json" + } + ], + "extends": "../../tsconfig.base.json", + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +} diff --git a/apps/testing-table/tsconfig.spec.json b/apps/testing-table/tsconfig.spec.json new file mode 100644 index 0000000..1a4817a --- /dev/null +++ b/apps/testing-table/tsconfig.spec.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "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" + ] +} diff --git a/apps/testing-todos-list/.eslintrc.json b/apps/testing-todos-list/.eslintrc.json new file mode 100644 index 0000000..c34c7dd --- /dev/null +++ b/apps/testing-todos-list/.eslintrc.json @@ -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:@nrwl/nx/angular", + "plugin:@angular-eslint/template/process-inline-templates" + ] + }, + { + "files": ["*.html"], + "extends": ["plugin:@nrwl/nx/angular-template"], + "rules": {} + } + ] +} diff --git a/apps/testing-todos-list/README.md b/apps/testing-todos-list/README.md new file mode 100644 index 0000000..4968961 --- /dev/null +++ b/apps/testing-todos-list/README.md @@ -0,0 +1,38 @@ +

Todo list app testing

+ +> Author: Thomas Laforge + +### Statement: + +NOT IMPLEMENTED YET + + + +### Submitting your work + +1. Fork the project +2. clone it +3. npm install +4. `npx nx serve testing-todos-list` to play with the application +5. `npx nx test testing-todos-list` to test your application with Testing Library +6. `npx nx component-test testing-todos-list --watch` to test your application with Cypress +7. _...work on it_ +8. Commit your work +9. Submit a PR with a title beginning with **Answer:23** that I will review and other dev can review. + +todo list app testing +todo list app testing solution author + + + +_You can ask any question on_ twitter diff --git a/apps/testing-todos-list/cypress.config.ts b/apps/testing-todos-list/cypress.config.ts new file mode 100644 index 0000000..ade9ea3 --- /dev/null +++ b/apps/testing-todos-list/cypress.config.ts @@ -0,0 +1,6 @@ +import { defineConfig } from 'cypress'; +import { nxComponentTestingPreset } from '@nrwl/angular/plugins/component-testing'; + +export default defineConfig({ + component: nxComponentTestingPreset(__filename), +}); diff --git a/apps/testing-todos-list/cypress/fixtures/example.json b/apps/testing-todos-list/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /dev/null +++ b/apps/testing-todos-list/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/apps/testing-todos-list/cypress/support/commands.ts b/apps/testing-todos-list/cypress/support/commands.ts new file mode 100644 index 0000000..e6c8976 --- /dev/null +++ b/apps/testing-todos-list/cypress/support/commands.ts @@ -0,0 +1,42 @@ +/// +import { mount } from 'cypress/angular'; + +// *********************************************** +// This example commands.ts 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 +// *********************************************** + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Cypress { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface Chainable { + login(email: string, password: string): void; + mount: typeof mount; + } + } +} + +Cypress.Commands.add('mount', mount); + +// +// -- 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) => { ... }) diff --git a/apps/testing-todos-list/cypress/support/component-index.html b/apps/testing-todos-list/cypress/support/component-index.html new file mode 100644 index 0000000..4bcc08e --- /dev/null +++ b/apps/testing-todos-list/cypress/support/component-index.html @@ -0,0 +1,13 @@ + + + + + + + testing-todos-list Components App + + + +
+ + diff --git a/apps/testing-todos-list/cypress/support/component.ts b/apps/testing-todos-list/cypress/support/component.ts new file mode 100644 index 0000000..e3684db --- /dev/null +++ b/apps/testing-todos-list/cypress/support/component.ts @@ -0,0 +1,17 @@ +// *********************************************************** +// This example support/component.ts 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.ts using ES2015 syntax: +import './commands'; diff --git a/apps/testing-todos-list/cypress/tsconfig.cy.json b/apps/testing-todos-list/cypress/tsconfig.cy.json new file mode 100644 index 0000000..9025c2a --- /dev/null +++ b/apps/testing-todos-list/cypress/tsconfig.cy.json @@ -0,0 +1,17 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "../../../dist/out-tsc", + "module": "commonjs", + "types": ["cypress", "node"] + }, + "include": [ + "support/**/*.ts", + "../cypress.config.ts", + "../**/*.cy.ts", + "../**/*.cy.tsx", + "../**/*.cy.js", + "../**/*.cy.jsx", + "../**/*.d.ts" + ] +} diff --git a/apps/testing-todos-list/jest.config.ts b/apps/testing-todos-list/jest.config.ts new file mode 100644 index 0000000..d110948 --- /dev/null +++ b/apps/testing-todos-list/jest.config.ts @@ -0,0 +1,21 @@ +/* eslint-disable */ +export default { + displayName: 'testing-todos-list', + preset: '../../jest.preset.js', + setupFilesAfterEnv: ['/src/test-setup.ts'], + transform: { + '^.+\\.(ts|mjs|js|html)$': [ + 'jest-preset-angular', + { + tsconfig: '/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', + ], +}; diff --git a/apps/testing-todos-list/project.json b/apps/testing-todos-list/project.json new file mode 100644 index 0000000..a443848 --- /dev/null +++ b/apps/testing-todos-list/project.json @@ -0,0 +1,105 @@ +{ + "name": "testing-todos-list", + "$schema": "../node_modules/nx/schemas/project-schema.json", + "projectType": "application", + "sourceRoot": "apps/testing-todos-list/src", + "prefix": "app", + "targets": { + "build": { + "executor": "@angular-devkit/build-angular:browser", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/apps/testing-todos-list", + "index": "apps/testing-todos-list/src/index.html", + "main": "apps/testing-todos-list/src/main.ts", + "polyfills": ["zone.js"], + "tsConfig": "apps/testing-todos-list/tsconfig.app.json", + "inlineStyleLanguage": "scss", + "assets": [ + "apps/testing-todos-list/src/favicon.ico", + "apps/testing-todos-list/src/assets" + ], + "styles": ["apps/testing-todos-list/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": "testing-todos-list:build:production" + }, + "development": { + "browserTarget": "testing-todos-list:build:development" + } + }, + "defaultConfiguration": "development" + }, + "extract-i18n": { + "executor": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "testing-todos-list:build" + } + }, + "lint": { + "executor": "@nrwl/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": [ + "apps/testing-todos-list/**/*.ts", + "apps/testing-todos-list/**/*.html" + ] + } + }, + "test": { + "executor": "@nrwl/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "apps/testing-todos-list/jest.config.ts", + "passWithNoTests": true + }, + "configurations": { + "ci": { + "ci": true, + "codeCoverage": true + } + } + }, + "component-test": { + "executor": "@nrwl/cypress:cypress", + "options": { + "cypressConfig": "apps/testing-todos-list/cypress.config.ts", + "testingType": "component", + "skipServe": true, + "devServerTarget": "testing-todos-list:build" + } + } + }, + "tags": [] +} diff --git a/apps/testing-todos-list/src/app/app.component.spec.ts b/apps/testing-todos-list/src/app/app.component.spec.ts new file mode 100644 index 0000000..ceb7fb3 --- /dev/null +++ b/apps/testing-todos-list/src/app/app.component.spec.ts @@ -0,0 +1,32 @@ +import { TestBed } from '@angular/core/testing'; +import { AppComponent } from './app.component'; +import { NxWelcomeComponent } from './nx-welcome.component'; + +describe('AppComponent', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [AppComponent, NxWelcomeComponent], + }).compileComponents(); + }); + + it('should create the app', () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app).toBeTruthy(); + }); + + it(`should have as title 'testing-todos-list'`, () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app.title).toEqual('testing-todos-list'); + }); + + it('should render title', () => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + const compiled = fixture.nativeElement as HTMLElement; + expect(compiled.querySelector('h1')?.textContent).toContain( + 'Welcome testing-todos-list' + ); + }); +}); diff --git a/apps/testing-todos-list/src/app/app.component.ts b/apps/testing-todos-list/src/app/app.component.ts new file mode 100644 index 0000000..3ea12b3 --- /dev/null +++ b/apps/testing-todos-list/src/app/app.component.ts @@ -0,0 +1,13 @@ +import { NxWelcomeComponent } from './nx-welcome.component'; +import { Component } from '@angular/core'; + +@Component({ + standalone: true, + imports: [NxWelcomeComponent], + selector: 'app-root', + template: ` `, + styles: [], +}) +export class AppComponent { + title = 'testing-todos-list'; +} diff --git a/apps/testing-todos-list/src/app/nx-welcome.component.ts b/apps/testing-todos-list/src/app/nx-welcome.component.ts new file mode 100644 index 0000000..7e34caa --- /dev/null +++ b/apps/testing-todos-list/src/app/nx-welcome.component.ts @@ -0,0 +1,801 @@ +import { Component, ViewEncapsulation } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +/* eslint-disable */ + +@Component({ + selector: 'app-nx-welcome', + standalone: true, + imports: [CommonModule], + template: ` + + +
+
+ +
+

+ Hello there, + Welcome testing-todos-list 👋 +

+
+ + +
+
+

+ + + + You're up and running +

+ What's next? +
+
+ + + +
+
+ + + + + +
+

Next steps

+

Here are some things you can do with Nx:

+
+ + + + + Add UI library + +
# Generate UI lib
+nx g @nrwl/angular:lib ui
+
+# Add a component
+nx g @nrwl/angular:component button --project ui
+
+
+ + + + + View interactive project graph + +
nx graph
+
+
+ + + + + Run affected commands + +
# see what's been affected by changes
+nx affected:graph
+
+# run tests for current changes
+nx affected:test
+
+# run e2e tests for current changes
+nx affected:e2e
+
+
+ +

+ Carefully crafted with + + + +

+
+
+ `, + styles: [], + encapsulation: ViewEncapsulation.None, +}) +export class NxWelcomeComponent {} diff --git a/apps/testing-todos-list/src/assets/.gitkeep b/apps/testing-todos-list/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/apps/testing-todos-list/src/favicon.ico b/apps/testing-todos-list/src/favicon.ico new file mode 100644 index 0000000..317ebcb Binary files /dev/null and b/apps/testing-todos-list/src/favicon.ico differ diff --git a/apps/testing-todos-list/src/index.html b/apps/testing-todos-list/src/index.html new file mode 100644 index 0000000..269ff34 --- /dev/null +++ b/apps/testing-todos-list/src/index.html @@ -0,0 +1,13 @@ + + + + + TestingTodosList + + + + + + + + diff --git a/apps/testing-todos-list/src/main.ts b/apps/testing-todos-list/src/main.ts new file mode 100644 index 0000000..31c5da4 --- /dev/null +++ b/apps/testing-todos-list/src/main.ts @@ -0,0 +1,4 @@ +import { bootstrapApplication } from '@angular/platform-browser'; +import { AppComponent } from './app/app.component'; + +bootstrapApplication(AppComponent).catch((err) => console.error(err)); diff --git a/apps/testing-todos-list/src/styles.scss b/apps/testing-todos-list/src/styles.scss new file mode 100644 index 0000000..77e408a --- /dev/null +++ b/apps/testing-todos-list/src/styles.scss @@ -0,0 +1,5 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +/* You can add global styles to this file, and also import other style files */ diff --git a/apps/testing-todos-list/src/test-setup.ts b/apps/testing-todos-list/src/test-setup.ts new file mode 100644 index 0000000..15de72a --- /dev/null +++ b/apps/testing-todos-list/src/test-setup.ts @@ -0,0 +1,2 @@ +import '@testing-library/jest-dom'; +import 'jest-preset-angular/setup-jest'; diff --git a/apps/testing-todos-list/tailwind.config.js b/apps/testing-todos-list/tailwind.config.js new file mode 100644 index 0000000..f9b2a5e --- /dev/null +++ b/apps/testing-todos-list/tailwind.config.js @@ -0,0 +1,14 @@ +const { createGlobPatternsForDependencies } = require('@nrwl/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: [], +}; diff --git a/apps/testing-todos-list/tsconfig.app.json b/apps/testing-todos-list/tsconfig.app.json new file mode 100644 index 0000000..e46d4fc --- /dev/null +++ b/apps/testing-todos-list/tsconfig.app.json @@ -0,0 +1,20 @@ +{ + "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", + "cypress/**/*", + "cypress.config.ts", + "**/*.cy.ts", + "**/*.cy.js", + "**/*.cy.tsx", + "**/*.cy.jsx" + ] +} diff --git a/apps/testing-todos-list/tsconfig.editor.json b/apps/testing-todos-list/tsconfig.editor.json new file mode 100644 index 0000000..8ae117d --- /dev/null +++ b/apps/testing-todos-list/tsconfig.editor.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": ["src/**/*.ts"], + "compilerOptions": { + "types": ["jest", "node"] + } +} diff --git a/apps/testing-todos-list/tsconfig.json b/apps/testing-todos-list/tsconfig.json new file mode 100644 index 0000000..bfbafa3 --- /dev/null +++ b/apps/testing-todos-list/tsconfig.json @@ -0,0 +1,35 @@ +{ + "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.spec.json" + }, + { + "path": "./tsconfig.editor.json" + }, + { + "path": "./cypress/tsconfig.cy.json" + } + ], + "extends": "../../tsconfig.base.json", + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +} diff --git a/apps/testing-todos-list/tsconfig.spec.json b/apps/testing-todos-list/tsconfig.spec.json new file mode 100644 index 0000000..1a4817a --- /dev/null +++ b/apps/testing-todos-list/tsconfig.spec.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "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" + ] +}