mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
refactor: move libs
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { render } from '@testing-library/angular';
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
describe('AppComponent', () => {
|
||||
describe('When clicking 2 times on plus button of first slider', () => {
|
||||
test('Then value is 16', async () => {
|
||||
await render(AppComponent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When clicking 1 time on plus button and two times on minus button of first slider', () => {
|
||||
test('Then value is still 10', async () => {
|
||||
await render(AppComponent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When clicking 4 times on plus button of slider 1', () => {
|
||||
test('Then slider 2 is enabled', async () => {
|
||||
await render(AppComponent);
|
||||
});
|
||||
});
|
||||
});
|
||||
28
apps/testing/24-harness-creation/src/app/app.component.ts
Normal file
28
apps/testing/24-harness-creation/src/app/app.component.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Component, signal } from '@angular/core';
|
||||
import { SliderComponent } from './slider.component';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [SliderComponent],
|
||||
selector: 'app-root',
|
||||
template: `
|
||||
<h2>Slider 1: {{ slider1Value() }}</h2>
|
||||
<app-slider
|
||||
[step]="3"
|
||||
[minValue]="10"
|
||||
[maxValue]="30"
|
||||
(valueChange)="slider1Value.set($event)" />
|
||||
<h2>Slider 2: {{ slider2Value() }}</h2>
|
||||
<p>Enabled only if Slider 1 > 20</p>
|
||||
<app-slider
|
||||
[step]="10"
|
||||
[maxValue]="1000"
|
||||
[disabled]="slider1Value() < 20"
|
||||
(valueChange)="slider2Value.set($event)" />
|
||||
`,
|
||||
styles: [''],
|
||||
})
|
||||
export class AppComponent {
|
||||
slider1Value = signal(10);
|
||||
slider2Value = signal(0);
|
||||
}
|
||||
6
apps/testing/24-harness-creation/src/app/app.config.ts
Normal file
6
apps/testing/24-harness-creation/src/app/app.config.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { ApplicationConfig } from '@angular/core';
|
||||
import { provideAnimations } from '@angular/platform-browser/animations';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [provideAnimations()],
|
||||
};
|
||||
78
apps/testing/24-harness-creation/src/app/slider.component.ts
Normal file
78
apps/testing/24-harness-creation/src/app/slider.component.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { Component, Input, OnInit, Output, signal } from '@angular/core';
|
||||
import { toObservable } from '@angular/core/rxjs-interop';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatSliderModule } from '@angular/material/slider';
|
||||
import { skip } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-slider',
|
||||
template: `
|
||||
<mat-card class="items-center">
|
||||
<mat-card-content>
|
||||
<div class="flex items-center gap-10">
|
||||
<button id="minusButton" mat-mini-fab (click)="back()">
|
||||
<mat-icon>arrow_back_ios</mat-icon>
|
||||
</button>
|
||||
{{ minValue }}
|
||||
<mat-slider
|
||||
class="m-4"
|
||||
[max]="maxValue"
|
||||
[min]="minValue"
|
||||
[disabled]="disabled"
|
||||
[step]="step">
|
||||
<input
|
||||
matSliderThumb
|
||||
[value]="value()"
|
||||
(valueChange)="value.set($event)" />
|
||||
</mat-slider>
|
||||
{{ maxValue }}
|
||||
<button id="plusButton" mat-mini-fab (click)="forward()">
|
||||
<mat-icon>arrow_forward_ios</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
`,
|
||||
styles: [
|
||||
`
|
||||
.mat-mdc-slider {
|
||||
max-width: 300px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mat-mdc-card {
|
||||
margin-top: 8px;
|
||||
flex-direction: row;
|
||||
}
|
||||
`,
|
||||
],
|
||||
standalone: true,
|
||||
imports: [MatCardModule, MatSliderModule, MatIconModule, FormsModule],
|
||||
})
|
||||
export class SliderComponent implements OnInit {
|
||||
@Input() step = 1;
|
||||
@Input() minValue = 0;
|
||||
@Input() maxValue = 100;
|
||||
@Input() disabled = false;
|
||||
|
||||
value = signal(0);
|
||||
@Output() valueChange = toObservable(this.value).pipe(skip(1));
|
||||
|
||||
ngOnInit(): void {
|
||||
this.value.set(this.minValue);
|
||||
}
|
||||
|
||||
back() {
|
||||
if (this.value() - this.step >= this.minValue) {
|
||||
this.value.update((v) => v - this.step);
|
||||
}
|
||||
}
|
||||
|
||||
forward() {
|
||||
if (this.value() + this.step <= this.maxValue) {
|
||||
this.value.update((v) => v + this.step);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { ComponentHarness } from '@angular/cdk/testing';
|
||||
|
||||
export class MySliderHarness extends ComponentHarness {
|
||||
static hostSelector = 'app-slider';
|
||||
}
|
||||
BIN
apps/testing/24-harness-creation/src/favicon.ico
Normal file
BIN
apps/testing/24-harness-creation/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
16
apps/testing/24-harness-creation/src/index.html
Normal file
16
apps/testing/24-harness-creation/src/index.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>create-harness</title>
|
||||
<base href="/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/icon?family=Material+Icons"
|
||||
rel="stylesheet" />
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
7
apps/testing/24-harness-creation/src/main.ts
Normal file
7
apps/testing/24-harness-creation/src/main.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app/app.component';
|
||||
import { appConfig } from './app/app.config';
|
||||
|
||||
bootstrapApplication(AppComponent, appConfig).catch((err) =>
|
||||
console.error(err),
|
||||
);
|
||||
29
apps/testing/24-harness-creation/src/styles.scss
Normal file
29
apps/testing/24-harness-creation/src/styles.scss
Normal file
@@ -0,0 +1,29 @@
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
@use '@angular/material' as mat;
|
||||
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
|
||||
@include mat.core();
|
||||
|
||||
$theme-primary: mat.define-palette(mat.$indigo-palette);
|
||||
$theme-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
|
||||
|
||||
$theme-warn: mat.define-palette(mat.$red-palette);
|
||||
|
||||
$theme: mat.define-light-theme(
|
||||
(
|
||||
color: (
|
||||
primary: $theme-primary,
|
||||
accent: $theme-accent,
|
||||
warn: $theme-warn,
|
||||
),
|
||||
typography: mat.define-typography-config(),
|
||||
)
|
||||
);
|
||||
|
||||
@include mat.dialog-theme($theme);
|
||||
@include mat.all-component-themes($theme);
|
||||
2
apps/testing/24-harness-creation/src/test-setup.ts
Normal file
2
apps/testing/24-harness-creation/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