Skip to content

Commit

Permalink
feat(stark-ui): refactor tests due to change in angular 16
Browse files Browse the repository at this point in the history
- The option `entryComponent` has been removed in `@NgModule`
- Fix issue with mutiple calls in input-mask-directives
  • Loading branch information
mhenkens committed Jun 3, 2024
1 parent c1b9881 commit 3ef970f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { MatIconModule } from "@angular/material/icon";
import { MatIconTestingModule } from "@angular/material/icon/testing";
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { BrowserDynamicTestingModule } from "@angular/platform-browser-dynamic/testing";
import { OverlayContainer } from "@angular/cdk/overlay";
import { ESCAPE } from "@angular/cdk/keycodes";
import { TranslateModule } from "@ngx-translate/core";
Expand Down Expand Up @@ -74,13 +73,7 @@ describe("AlertDialogComponent", () => {
declarations: [TestHostComponent, StarkAlertDialogComponent],
imports: [CommonModule, NoopAnimationsModule, MatDialogModule, MatIconModule, MatIconTestingModule, TranslateModule.forRoot()],
providers: []
})
.overrideModule(BrowserDynamicTestingModule, {
// FIXME review after https://github.com/angular/angular/issues/10760
// add entryComponent to TestingModule (suggested in https://github.com/angular/angular/issues/10760#issuecomment-250522300)
set: { entryComponents: [StarkAlertDialogComponent] }
})
.compileComponents()));
}).compileComponents()));

beforeEach(inject(
[MatDialog, OverlayContainer, ComponentFactoryResolver],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
MatLegacyDialogRef as MatDialogRef
} from "@angular/material/legacy-dialog";
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { BrowserDynamicTestingModule } from "@angular/platform-browser-dynamic/testing";
import { OverlayContainer } from "@angular/cdk/overlay";
import { ESCAPE } from "@angular/cdk/keycodes";
import { TranslateModule } from "@ngx-translate/core";
Expand Down Expand Up @@ -76,13 +75,7 @@ describe("ConfirmDialogComponent", () => {
declarations: [TestHostComponent, StarkConfirmDialogComponent],
imports: [CommonModule, NoopAnimationsModule, MatDialogModule, TranslateModule.forRoot()],
providers: []
})
.overrideModule(BrowserDynamicTestingModule, {
// FIXME review after https://github.com/angular/angular/issues/10760
// add entryComponent to TestingModule (suggested in https://github.com/angular/angular/issues/10760#issuecomment-250522300)
set: { entryComponents: [StarkConfirmDialogComponent] }
})
.compileComponents()));
}).compileComponents()));

beforeEach(inject(
[MatDialog, OverlayContainer, ComponentFactoryResolver],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from "@angular/material/legacy-dialog";
import { MatLegacyInputModule as MatInputModule } from "@angular/material/legacy-input";
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
import { BrowserDynamicTestingModule } from "@angular/platform-browser-dynamic/testing";
import { OverlayContainer } from "@angular/cdk/overlay";
import { ESCAPE } from "@angular/cdk/keycodes";
import { TranslateModule } from "@ngx-translate/core";
Expand Down Expand Up @@ -81,13 +80,7 @@ describe("PromptDialogComponent", () => {
declarations: [TestHostComponent, StarkPromptDialogComponent],
imports: [CommonModule, ReactiveFormsModule, NoopAnimationsModule, MatInputModule, MatDialogModule, TranslateModule.forRoot()],
providers: []
})
.overrideModule(BrowserDynamicTestingModule, {
// FIXME review after https://github.com/angular/angular/issues/10760
// add entryComponent to TestingModule (suggested in https://github.com/angular/angular/issues/10760#issuecomment-250522300)
set: { entryComponents: [StarkPromptDialogComponent] }
})
.compileComponents()));
}).compileComponents()));

beforeEach(inject(
[MatDialog, OverlayContainer, ComponentFactoryResolver],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,14 @@ describe("EmailMaskDirective", () => {
changeInputValue(inputElement, "");
fixture.detectChanges();
expect(hostComponent.formControl.value).toBe("");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
changeInputValue(inputElement, "my-email@", eventType);
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("my-email@ .");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
}
Expand All @@ -280,8 +278,7 @@ describe("EmailMaskDirective", () => {
changeInputValue(inputElement, "");
fixture.detectChanges();
expect(hostComponent.formControl.value).toBe("");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
changeInputValue(inputElement, "my-email@", eventType);
Expand All @@ -304,8 +301,7 @@ describe("EmailMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
}
Expand All @@ -316,8 +312,7 @@ describe("EmailMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("my-email@ .");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
hostComponent.emailMaskConfig = undefined;
Expand All @@ -329,8 +324,7 @@ describe("EmailMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("my-email@ ."); // the mask is enabled by default
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
hostComponent.emailMaskConfig = ""; // use case when the directive is used with no inputs: <input type='text' [formControl]='formControl' starkEmailMask>
Expand All @@ -342,8 +336,7 @@ describe("EmailMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("my-email@ ."); // the mask is enabled by default
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
hostComponent.emailMaskConfig = false;
Expand All @@ -355,8 +348,7 @@ describe("EmailMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("what@@.ever@."); // no mask at all
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,14 @@ describe("NumberMaskDirective", () => {
changeInputValue(inputElement, "");
fixture.detectChanges();
expect(hostComponent.formControl.value).toBe("");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
changeInputValue(inputElement, "12345", eventType);
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("12,345");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
}
Expand All @@ -296,8 +294,7 @@ describe("NumberMaskDirective", () => {
changeInputValue(inputElement, "");
fixture.detectChanges();
expect(hostComponent.formControl.value).toBe("");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
changeInputValue(inputElement, "12345", eventType);
Expand All @@ -320,8 +317,7 @@ describe("NumberMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
}
Expand All @@ -334,8 +330,7 @@ describe("NumberMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("12,345");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
}
Expand All @@ -346,16 +341,14 @@ describe("NumberMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("12,345");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
hostComponent.numberMaskConfig = { ...numberMaskConfig, prefix: "%", suffix: " percent", thousandsSeparatorSymbol: "-" };
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("%12-345 percent");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
});
Expand All @@ -365,8 +358,7 @@ describe("NumberMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("12,345");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
hostComponent.numberMaskConfig = <any>undefined;
Expand All @@ -378,8 +370,7 @@ describe("NumberMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("whatever+1*23-4/5"); // no mask at all
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,14 @@ describe("TextMaskDirective", () => {
changeInputValue(inputElement, "");
fixture.detectChanges();
expect(hostComponent.formControl.value).toBe("");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
changeInputValue(inputElement, "123", eventType);
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("12/3_");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
}
Expand All @@ -318,8 +316,7 @@ describe("TextMaskDirective", () => {
changeInputValue(inputElement, "");
fixture.detectChanges();
expect(hostComponent.formControl.value).toBe("");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
changeInputValue(inputElement, "123", eventType);
Expand All @@ -342,8 +339,7 @@ describe("TextMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
}
Expand All @@ -354,16 +350,14 @@ describe("TextMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("12/3_");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
hostComponent.textMaskConfig = { ...textMaskConfig, mask: [/\d/, "/", /\d/, "/", /\d/, /\d/], placeholderChar: "-" };
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("1/2/3-");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
});
Expand All @@ -373,16 +367,14 @@ describe("TextMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("12/3_");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
hostComponent.textMaskConfig = { ...textMaskConfig, guide: false };
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("12/3");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
});
Expand All @@ -392,8 +384,7 @@ describe("TextMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("12/3_");
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
hostComponent.textMaskConfig = <any>undefined;
Expand All @@ -405,8 +396,7 @@ describe("TextMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("whatever"); // no mask at all
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);

mockValueChangeObserver.next.calls.reset();
hostComponent.textMaskConfig = { mask: false };
Expand All @@ -418,8 +408,7 @@ describe("TextMaskDirective", () => {
fixture.detectChanges();

expect(hostComponent.formControl.value).toBe("123"); // no mask at all
// FIXME Check why it is called twice instead of once
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(2);
expect(mockValueChangeObserver.next).toHaveBeenCalledTimes(1);
expect(mockValueChangeObserver.error).not.toHaveBeenCalled();
expect(mockValueChangeObserver.complete).not.toHaveBeenCalled();
});
Expand Down
Loading

0 comments on commit 3ef970f

Please sign in to comment.