mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat(doc): move race-condition
This commit is contained in:
36
apps/rxjs/race-condition/.eslintrc.json
Normal file
36
apps/rxjs/race-condition/.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/rxjs/race-condition/README.md
Normal file
13
apps/rxjs/race-condition/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Race Condition
|
||||
|
||||
> Author: Thomas Laforge
|
||||
|
||||
### Run Application
|
||||
|
||||
```bash
|
||||
npx nx serve rxjs-race-condition
|
||||
```
|
||||
|
||||
### Documentation and Instruction
|
||||
|
||||
Challenge documentation is [here](https://angular-challenges.vercel.app/challenges/rxjs/14-race-condition/).
|
||||
6
apps/rxjs/race-condition/cypress.config.ts
Normal file
6
apps/rxjs/race-condition/cypress.config.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { defineConfig } from 'cypress';
|
||||
import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing';
|
||||
|
||||
export default defineConfig({
|
||||
component: nxComponentTestingPreset(__filename),
|
||||
});
|
||||
5
apps/rxjs/race-condition/cypress/fixtures/example.json
Normal file
5
apps/rxjs/race-condition/cypress/fixtures/example.json
Normal file
@@ -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"
|
||||
}
|
||||
42
apps/rxjs/race-condition/cypress/support/commands.ts
Normal file
42
apps/rxjs/race-condition/cypress/support/commands.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/// <reference types="cypress" />
|
||||
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<Subject> {
|
||||
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) => { ... })
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||||
<title>rxjs-race-condition Components App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div data-cy-root></div>
|
||||
</body>
|
||||
</html>
|
||||
17
apps/rxjs/race-condition/cypress/support/component.ts
Normal file
17
apps/rxjs/race-condition/cypress/support/component.ts
Normal file
@@ -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';
|
||||
18
apps/rxjs/race-condition/cypress/tsconfig.json
Normal file
18
apps/rxjs/race-condition/cypress/tsconfig.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["cypress", "node"],
|
||||
"sourceMap": false
|
||||
},
|
||||
"include": [
|
||||
"support/**/*.ts",
|
||||
"../cypress.config.ts",
|
||||
"../**/*.cy.ts",
|
||||
"../**/*.cy.tsx",
|
||||
"../**/*.cy.js",
|
||||
"../**/*.cy.jsx",
|
||||
"../**/*.d.ts"
|
||||
]
|
||||
}
|
||||
23
apps/rxjs/race-condition/jest.config.ts
Normal file
23
apps/rxjs/race-condition/jest.config.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/* eslint-disable */
|
||||
export default {
|
||||
displayName: 'rxjs-race-condition',
|
||||
preset: '../../../jest.preset.js',
|
||||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
||||
globals: {},
|
||||
coverageDirectory: '../../../coverage/apps/rxjs/race-condition',
|
||||
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',
|
||||
],
|
||||
};
|
||||
99
apps/rxjs/race-condition/project.json
Normal file
99
apps/rxjs/race-condition/project.json
Normal file
@@ -0,0 +1,99 @@
|
||||
{
|
||||
"name": "rxjs-race-condition",
|
||||
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
||||
"projectType": "application",
|
||||
"sourceRoot": "apps/rxjs/race-condition/src",
|
||||
"prefix": "app",
|
||||
"targets": {
|
||||
"build": {
|
||||
"executor": "@angular-devkit/build-angular:browser",
|
||||
"outputs": ["{options.outputPath}"],
|
||||
"options": {
|
||||
"outputPath": "dist/apps/rxjs/race-condition",
|
||||
"index": "apps/rxjs/race-condition/src/index.html",
|
||||
"main": "apps/rxjs/race-condition/src/main.ts",
|
||||
"polyfills": ["zone.js"],
|
||||
"tsConfig": "apps/rxjs/race-condition/tsconfig.app.json",
|
||||
"inlineStyleLanguage": "scss",
|
||||
"assets": [
|
||||
"apps/rxjs/race-condition/src/favicon.ico",
|
||||
"apps/rxjs/race-condition/src/assets"
|
||||
],
|
||||
"styles": ["apps/rxjs/race-condition/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": "rxjs-race-condition:build:production"
|
||||
},
|
||||
"development": {
|
||||
"browserTarget": "rxjs-race-condition:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"executor": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"browserTarget": "rxjs-race-condition:build"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"executor": "@nx/linter:eslint",
|
||||
"outputs": ["{options.outputFile}"],
|
||||
"options": {
|
||||
"lintFilePatterns": [
|
||||
"apps/rxjs/race-condition/**/*.ts",
|
||||
"apps/rxjs/race-condition/**/*.html"
|
||||
]
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nx/jest:jest",
|
||||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
||||
"options": {
|
||||
"jestConfig": "apps/rxjs/race-condition/jest.config.ts",
|
||||
"passWithNoTests": true
|
||||
}
|
||||
},
|
||||
"component-test": {
|
||||
"executor": "@nx/cypress:cypress",
|
||||
"options": {
|
||||
"cypressConfig": "apps/rxjs/race-condition/cypress.config.ts",
|
||||
"testingType": "component",
|
||||
"skipServe": true,
|
||||
"devServerTarget": "rxjs-race-condition:build"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": []
|
||||
}
|
||||
21
apps/rxjs/race-condition/src/app/app.component.cy.ts
Normal file
21
apps/rxjs/race-condition/src/app/app.component.cy.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { MatDialogModule } from '@angular/material/dialog';
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
describe(AppComponent.name, () => {
|
||||
beforeEach(() => {
|
||||
TestBed.overrideComponent(AppComponent, {
|
||||
add: {
|
||||
imports: [MatDialogModule],
|
||||
providers: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('renders', () => {
|
||||
cy.mount(AppComponent);
|
||||
|
||||
cy.get('button').click();
|
||||
cy.get('ul li').should('have.length', '3');
|
||||
});
|
||||
});
|
||||
38
apps/rxjs/race-condition/src/app/app.component.ts
Normal file
38
apps/rxjs/race-condition/src/app/app.component.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
inject,
|
||||
OnInit,
|
||||
} from '@angular/core';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { take } from 'rxjs';
|
||||
import { TopicModalComponent } from './topic-dialog.component';
|
||||
import { TopicService, TopicType } from './topic.service';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
selector: 'app-root',
|
||||
template: ` <button (click)="openTopicModal()">Open Topic</button> `,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class AppComponent implements OnInit {
|
||||
title = 'rxjs-race-condition';
|
||||
dialog = inject(MatDialog);
|
||||
topicService = inject(TopicService);
|
||||
topics: TopicType[] = [];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.topicService
|
||||
.fakeGetHttpTopic()
|
||||
.pipe(take(1))
|
||||
.subscribe((topics) => (this.topics = topics));
|
||||
}
|
||||
|
||||
openTopicModal() {
|
||||
this.dialog.open(TopicModalComponent, {
|
||||
data: {
|
||||
topics: this.topics,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
6
apps/rxjs/race-condition/src/app/app.config.ts
Normal file
6
apps/rxjs/race-condition/src/app/app.config.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { ApplicationConfig } from '@angular/core';
|
||||
import { importProvidersFrom } from '@angular/core';
|
||||
import { MatDialogModule } from '@angular/material/dialog';
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [importProvidersFrom(MatDialogModule)],
|
||||
};
|
||||
24
apps/rxjs/race-condition/src/app/topic-dialog.component.ts
Normal file
24
apps/rxjs/race-condition/src/app/topic-dialog.component.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { NgFor } from '@angular/common';
|
||||
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatDialogModule, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
|
||||
@Component({
|
||||
template: ` <h1 mat-dialog-title>Show all Topics</h1>
|
||||
<div mat-dialog-content>
|
||||
<ul>
|
||||
<li *ngFor="let topic of data.topics">
|
||||
{{ topic }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div mat-dialog-actions>
|
||||
<button mat-button mat-dialog-close>Close</button>
|
||||
</div>`,
|
||||
imports: [MatDialogModule, MatButtonModule, NgFor],
|
||||
standalone: true,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class TopicModalComponent {
|
||||
data = inject(MAT_DIALOG_DATA);
|
||||
}
|
||||
10
apps/rxjs/race-condition/src/app/topic.service.ts
Normal file
10
apps/rxjs/race-condition/src/app/topic.service.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { map, timer } from 'rxjs';
|
||||
|
||||
export type TopicType = 'Politic' | 'Sport' | 'Culture' | 'Nature';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class TopicService {
|
||||
fakeGetHttpTopic = () =>
|
||||
timer(1000).pipe(map((): TopicType[] => ['Politic', 'Culture', 'Nature']));
|
||||
}
|
||||
0
apps/rxjs/race-condition/src/assets/.gitkeep
Normal file
0
apps/rxjs/race-condition/src/assets/.gitkeep
Normal file
BIN
apps/rxjs/race-condition/src/favicon.ico
Normal file
BIN
apps/rxjs/race-condition/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
13
apps/rxjs/race-condition/src/index.html
Normal file
13
apps/rxjs/race-condition/src/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>RxjsRaceCondition</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>
|
||||
8
apps/rxjs/race-condition/src/main.ts
Normal file
8
apps/rxjs/race-condition/src/main.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { appConfig } from './app/app.config';
|
||||
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app/app.component';
|
||||
|
||||
bootstrapApplication(AppComponent, appConfig).catch((err) =>
|
||||
console.error(err)
|
||||
);
|
||||
24
apps/rxjs/race-condition/src/styles.scss
Normal file
24
apps/rxjs/race-condition/src/styles.scss
Normal file
@@ -0,0 +1,24 @@
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
|
||||
@use '@angular/material' as mat;
|
||||
|
||||
@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.button-theme($theme);
|
||||
1
apps/rxjs/race-condition/src/test-setup.ts
Normal file
1
apps/rxjs/race-condition/src/test-setup.ts
Normal file
@@ -0,0 +1 @@
|
||||
import 'jest-preset-angular/setup-jest';
|
||||
20
apps/rxjs/race-condition/tsconfig.app.json
Normal file
20
apps/rxjs/race-condition/tsconfig.app.json
Normal file
@@ -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"
|
||||
]
|
||||
}
|
||||
7
apps/rxjs/race-condition/tsconfig.editor.json
Normal file
7
apps/rxjs/race-condition/tsconfig.editor.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src/**/*.ts"],
|
||||
"compilerOptions": {
|
||||
"types": ["jest", "node"]
|
||||
}
|
||||
}
|
||||
35
apps/rxjs/race-condition/tsconfig.json
Normal file
35
apps/rxjs/race-condition/tsconfig.json
Normal file
@@ -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.json"
|
||||
}
|
||||
],
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
||||
15
apps/rxjs/race-condition/tsconfig.spec.json
Normal file
15
apps/rxjs/race-condition/tsconfig.spec.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../../dist/out-tsc",
|
||||
"module": "commonjs",
|
||||
"types": ["jest", "node"]
|
||||
},
|
||||
"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