-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(forms): "0" value is display correctly (#2015)
fixes #2013 --------- Co-authored-by: Sebastian Leidig <sebastian@aam-digital.com>
- Loading branch information
1 parent
ec425c5
commit 63150d5
Showing
11 changed files
with
99 additions
and
9 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/app/core/config/dynamic-components/dynamic-component.directive.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { TestBed } from "@angular/core/testing"; | ||
import { ChangeDetectorRef, ViewContainerRef } from "@angular/core"; | ||
import { DynamicComponentDirective } from "./dynamic-component.directive"; | ||
import { ComponentRegistry } from "../../../dynamic-components"; | ||
|
||
describe("DynamicComponentDirective", () => { | ||
let directive: DynamicComponentDirective; | ||
let mockContainer: jasmine.SpyObj<ViewContainerRef>; | ||
let mockDetector: jasmine.SpyObj<ChangeDetectorRef>; | ||
let mockRegistry: jasmine.SpyObj<ComponentRegistry>; | ||
|
||
beforeEach(() => { | ||
mockContainer = jasmine.createSpyObj(["clear", "createComponent"]); | ||
mockDetector = jasmine.createSpyObj(["detectChanges"]); | ||
mockRegistry = jasmine.createSpyObj(["get"]); | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ provide: ViewContainerRef, useValue: mockContainer }, | ||
{ provide: ChangeDetectorRef, useValue: mockDetector }, | ||
{ provide: ComponentRegistry, useValue: mockRegistry }, | ||
DynamicComponentDirective, | ||
], | ||
}); | ||
directive = TestBed.inject(DynamicComponentDirective); | ||
}); | ||
|
||
it("should create the configured component", async () => { | ||
directive.appDynamicComponent = { component: "TestComp" }; | ||
const comp = {} as any; | ||
mockRegistry.get.and.returnValue(() => Promise.resolve(comp)); | ||
|
||
await directive.ngOnChanges(); | ||
|
||
expect(mockRegistry.get).toHaveBeenCalledWith("TestComp"); | ||
expect(mockContainer.createComponent).toHaveBeenCalledWith(comp); | ||
}); | ||
|
||
it("should assign the properties to the component", async () => { | ||
directive.appDynamicComponent = { | ||
component: "TestComp", | ||
config: { | ||
numberProp: 0, | ||
stringProp: "should exist", | ||
missingProp: "should not exist", | ||
}, | ||
}; | ||
const changesSpy = jasmine.createSpy(); | ||
const comp: any = { | ||
prototype: { | ||
constructor: { | ||
["ɵcmp"]: { | ||
inputs: { numberProp: {}, stringProp: {}, otherProp: {} }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
const compRef: any = { instance: { ngOnChanges: changesSpy } }; | ||
mockRegistry.get.and.returnValue(() => Promise.resolve(comp)); | ||
mockContainer.createComponent.and.returnValue(compRef); | ||
|
||
await directive.ngOnChanges(); | ||
|
||
expect(compRef.instance.numberProp).toBe(0); | ||
expect(compRef.instance.stringProp).toBe("should exist"); | ||
expect(compRef.instance.missingProp).toBeUndefined(); | ||
expect(compRef.instance.otherProp).toBeUndefined(); | ||
expect(compRef.instance.ngOnChanges).toHaveBeenCalledWith({ | ||
numberProp: jasmine.anything(), | ||
stringProp: jasmine.anything(), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters