mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 21:03:03 -05:00
fix(test): move all test apps
This commit is contained in:
10
apps/testing/nested/src/app/app.component.ts
Normal file
10
apps/testing/nested/src/app/app.component.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { ChildComponent } from './child.component';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [ChildComponent],
|
||||
selector: 'app-root',
|
||||
template: ` <app-child></app-child> `,
|
||||
})
|
||||
export class AppComponent {}
|
||||
18
apps/testing/nested/src/app/child.component.cy.ts
Normal file
18
apps/testing/nested/src/app/child.component.cy.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { ChildComponent } from './child.component';
|
||||
|
||||
describe('ChildComponent', () => {
|
||||
const setup = () => {
|
||||
cy.mount(ChildComponent);
|
||||
};
|
||||
describe('When typing nothing and clicking on Validate', () => {
|
||||
test('Then show "Title is required" error message and no http request has been sent', async () => {
|
||||
setup();
|
||||
});
|
||||
});
|
||||
|
||||
describe('When typing "Good" and clicking on Validate', () => {
|
||||
test('Then show "Title is Good" message, no error message and send a http request to the backend', async () => {
|
||||
setup();
|
||||
});
|
||||
});
|
||||
});
|
||||
16
apps/testing/nested/src/app/child.component.spec.ts
Normal file
16
apps/testing/nested/src/app/child.component.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { render } from '@testing-library/angular';
|
||||
import { ChildComponent } from './child.component';
|
||||
|
||||
describe('ChildComponent', () => {
|
||||
describe('When typing nothing and clicking on Validate', () => {
|
||||
test('Then show "Title is required" error message and no http request has been sent', async () => {
|
||||
await render(ChildComponent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When typing "Good" and clicking on Validate', () => {
|
||||
test('Then show "Title is Good" message, no error message and send a http request to the backend', async () => {
|
||||
await render(ChildComponent);
|
||||
});
|
||||
});
|
||||
});
|
||||
86
apps/testing/nested/src/app/child.component.ts
Normal file
86
apps/testing/nested/src/app/child.component.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { NgIf } from '@angular/common';
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
EventEmitter,
|
||||
Input,
|
||||
Output,
|
||||
inject,
|
||||
} from '@angular/core';
|
||||
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||
import { HttpService } from './http.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-input',
|
||||
standalone: true,
|
||||
imports: [ReactiveFormsModule],
|
||||
template: ` <input type="text" [formControl]="title" /> `,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class InputComponent {
|
||||
title = new FormControl('', { nonNullable: true });
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'result',
|
||||
standalone: true,
|
||||
template: ` <p>Title is {{ title }}</p> `,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class ResultComponent {
|
||||
@Input() title = '';
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-button',
|
||||
standalone: true,
|
||||
template: `<button (click)="validate.emit()">Validate</button>`,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class ButtonComponent {
|
||||
@Output() validate = new EventEmitter();
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-error',
|
||||
standalone: true,
|
||||
template: `<p>Title is required !!!</p>`,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class ErrorComponent {
|
||||
@Output() validate = new EventEmitter();
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-child',
|
||||
standalone: true,
|
||||
imports: [
|
||||
ResultComponent,
|
||||
ButtonComponent,
|
||||
InputComponent,
|
||||
ErrorComponent,
|
||||
NgIf,
|
||||
],
|
||||
template: `
|
||||
<app-input #input></app-input>
|
||||
<result [title]="input.title.value"></result>
|
||||
<app-button (validate)="submit(input.title.value)"></app-button>
|
||||
<app-error *ngIf="showError"></app-error>
|
||||
`,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class ChildComponent {
|
||||
http = inject(HttpService);
|
||||
|
||||
showError = false;
|
||||
|
||||
submit(title: string) {
|
||||
this.showError = false;
|
||||
if (title === '') {
|
||||
this.showError = true;
|
||||
return;
|
||||
}
|
||||
|
||||
this.http.sendTitle(title);
|
||||
}
|
||||
}
|
||||
8
apps/testing/nested/src/app/http.service.ts
Normal file
8
apps/testing/nested/src/app/http.service.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class HttpService {
|
||||
sendTitle(title: string) {
|
||||
console.log(`${title} has been sent !!!`);
|
||||
}
|
||||
}
|
||||
0
apps/testing/nested/src/assets/.gitkeep
Normal file
0
apps/testing/nested/src/assets/.gitkeep
Normal file
BIN
apps/testing/nested/src/favicon.ico
Normal file
BIN
apps/testing/nested/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
13
apps/testing/nested/src/index.html
Normal file
13
apps/testing/nested/src/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>TestingNested</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>
|
||||
4
apps/testing/nested/src/main.ts
Normal file
4
apps/testing/nested/src/main.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app/app.component';
|
||||
|
||||
bootstrapApplication(AppComponent).catch((err) => console.error(err));
|
||||
1
apps/testing/nested/src/styles.scss
Normal file
1
apps/testing/nested/src/styles.scss
Normal file
@@ -0,0 +1 @@
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
2
apps/testing/nested/src/test-setup.ts
Normal file
2
apps/testing/nested/src/test-setup.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import 'jest-preset-angular/setup-jest';
|
||||
Reference in New Issue
Block a user