Skip to content

Commit e804d79

Browse files
committed
test: repair signal-migration spec failures + 2 component regressions
Спеки не компилировались после миграции компонентов на signal input()/model()/output(): присваивание read-only инпутов и обращение к удалённым EventEmitter (checkedChange/appValueChange). Перевёл на fixture.componentRef.setInput(...) и подписку на model()/output(). Специи вскрыли два реальных регресса миграции (правки в компонентах): - range-criterion-input: в шаблоне error/max использовались без вызова сигнала (функция всегда truthy → класс ошибки висел всегда, max не применялся) → error()/max(). - input: внешний [appValue] (two-way model) не отражался в значении поля — утрачен бывший @Input-сеттер appValue→value → добавлен effect-синк. Затронуты: button, checkbox, switch, input, search, course-module-card, write-task, range-criterion-input, chat-message, news-card (43/43 локально).
1 parent 3018845 commit e804d79

12 files changed

Lines changed: 32 additions & 23 deletions

File tree

projects/social_platform/src/app/ui/pages/courses/detail/info/course-module-card/course-module-card.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("CourseModuleCardComponent", () => {
3535

3636
fixture = TestBed.createComponent(CourseModuleCardComponent);
3737
component = fixture.componentInstance;
38-
component.courseModule = courseModule;
38+
fixture.componentRef.setInput("courseModule", courseModule);
3939
fixture.detectChanges();
4040
}
4141

projects/social_platform/src/app/ui/pages/courses/lesson/shared/write-task/write-task.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("WriteTaskComponent", () => {
2121

2222
fixture = TestBed.createComponent(WriteTaskComponent);
2323
component = fixture.componentInstance;
24-
component.data = { order: 1, bodyText: "test", videoUrl: "" } as any;
24+
fixture.componentRef.setInput("data", { order: 1, bodyText: "test", videoUrl: "" } as any);
2525
fixture.detectChanges();
2626
});
2727

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!-- @format -->
22

3-
<div class="field" [class.field--error]="error">
3+
<div class="field" [class.field--error]="error()">
44
<input
55
type="number"
66
[value]="value"
77
[min]="0"
8-
[max]="max"
8+
[max]="max()"
99
[step]="1"
1010
[disabled]="disabled"
1111
(input)="onInput($event)"
@@ -14,8 +14,8 @@
1414
(paste)="onPaste($event)"
1515
(focus)="moveCursorToEnd($event)"
1616
class="field__input text-body-10"
17-
[class.field__input--error]="error"
17+
[class.field__input--error]="error()"
1818
/>
1919
<span class="text-body-10">&nbsp;/</span>
20-
<span class="text-body-10">{{ max }}</span>
20+
<span class="text-body-10">{{ max() }}</span>
2121
</div>

projects/social_platform/src/app/ui/pages/program/detail/list/rating-card/project-rating/components/range-criterion-input/range-criterion-input.component.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ describe("RangeCriterionInputComponent", () => {
5555
it("should set the error class when error input is true", () => {
5656
const field = fixture.nativeElement.querySelector(".field");
5757
expect(field.classList).not.toContain("field--error");
58-
component.error = true;
5958
fixture.componentRef.setInput("error", true);
6059
fixture.detectChanges();
6160
expect(field.classList).toContain("field--error");

projects/social_platform/src/app/ui/primitives/button/button.component.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ describe("ButtonComponent", () => {
2424
});
2525

2626
it("should set the button type", () => {
27-
component.type = "submit";
27+
fixture.componentRef.setInput("type", "submit");
2828
fixture.detectChanges();
2929

3030
const button = fixture.debugElement.query(By.css("button")).nativeElement;
3131
expect(button.type).toEqual("submit");
3232
});
3333

3434
it("should set the button color", () => {
35-
component.color = "red";
35+
fixture.componentRef.setInput("color", "red");
3636
fixture.detectChanges();
3737

3838
const button = fixture.debugElement.query(By.css("button")).nativeElement;
3939
expect(button.classList).toContain("button--red");
4040
});
4141

4242
it("should set the button appearance", () => {
43-
component.appearance = "outline";
43+
fixture.componentRef.setInput("appearance", "outline");
4444
fixture.detectChanges();
4545

4646
const button = fixture.debugElement.query(By.css("button")).nativeElement;
4747
expect(button.classList).toContain("button--outline");
4848
});
4949

5050
it("should show the loader when loader input is true", () => {
51-
component.loader = true;
51+
fixture.componentRef.setInput("loader", true);
5252
fixture.detectChanges();
5353

5454
const loader = fixture.debugElement.query(By.css("app-loader"));

projects/social_platform/src/app/ui/primitives/checkbox/checkbox.component.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ describe("CheckboxComponent", () => {
2525
});
2626

2727
it("should emit the checked value when the field is clicked", () => {
28-
spyOn(component.checkedChange, "emit");
28+
const emitSpy = jasmine.createSpy("checkedChange");
29+
component.checked.subscribe(emitSpy);
2930

3031
const field = fixture.debugElement.query(By.css(".field"));
3132
field.triggerEventHandler("click", null);
3233

33-
expect(component.checkedChange.emit).toHaveBeenCalledWith(true);
34+
expect(emitSpy).toHaveBeenCalledWith(true);
3435
});
3536

3637
it('should add the "field--checked" class when checked is true', () => {

projects/social_platform/src/app/ui/primitives/input/input.component.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ describe("InputComponent", () => {
6060
});
6161

6262
it("should emit the input value on input", () => {
63-
spyOn(component.appValueChange, "emit");
63+
const emitSpy = jasmine.createSpy("appValueChange");
64+
component.appValue.subscribe(emitSpy);
6465
const testValue = "test";
6566
const input = fixture.nativeElement.querySelector("input");
6667
input.value = testValue;
6768
input.dispatchEvent(new Event("input"));
68-
expect(component.appValueChange.emit).toHaveBeenCalledWith(testValue);
69+
expect(emitSpy).toHaveBeenCalledWith(testValue);
6970
});
7071

7172
it("should emit enter event on enter keydown", () => {

projects/social_platform/src/app/ui/primitives/input/input.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ChangeDetectionStrategy,
66
ChangeDetectorRef,
77
Component,
8+
effect,
89
ElementRef,
910
forwardRef,
1011
input,
@@ -46,7 +47,12 @@ import { IconComponent } from "../icon/icon.component";
4647
changeDetection: ChangeDetectionStrategy.OnPush,
4748
})
4849
export class InputComponent implements ControlValueAccessor {
49-
constructor(private readonly cdr: ChangeDetectorRef) {}
50+
constructor(private readonly cdr: ChangeDetectorRef) {
51+
effect(() => {
52+
this.value = this.appValue();
53+
this.cdr.markForCheck();
54+
});
55+
}
5056

5157
placeholder = input("");
5258
type = input<"text" | "password" | "email" | "tel" | "date" | "radio">("text");

projects/social_platform/src/app/ui/primitives/search/search.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("SearchComponent", () => {
2727
});
2828

2929
it("should not call onSwitchSearch when clicked and openable is false", () => {
30-
component.openable = false;
30+
fixture.componentRef.setInput("openable", false);
3131
const searchDiv = fixture.nativeElement.querySelector(".search__other");
3232
searchDiv.dispatchEvent(new Event("click"));
3333
fixture.detectChanges();

projects/social_platform/src/app/ui/primitives/switch/switch.component.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ describe("SwitchComponent", () => {
2323
expect(component).toBeTruthy();
2424
});
2525

26-
it("should emit checkedChange when clicked", async () => {
27-
spyOn(component.checkedChange, "emit");
26+
it("should emit checkedChange when clicked", () => {
27+
const emitSpy = jasmine.createSpy("checkedChange");
28+
component.checked.subscribe(emitSpy);
2829
const switchElement = fixture.nativeElement.querySelector(".switch");
2930
switchElement.click();
30-
expect(component.checkedChange.emit).toHaveBeenCalledWith(true);
31+
expect(emitSpy).toHaveBeenCalledWith(true);
3132
});
3233

3334
it('should apply the "switch--active" class when checked is true', () => {

0 commit comments

Comments
 (0)