diff --git a/components/modal/demo/async.ts b/components/modal/demo/async.ts index 43eda653e3..e69bbf6d2c 100644 --- a/components/modal/demo/async.ts +++ b/components/modal/demo/async.ts @@ -1,7 +1,12 @@ import { Component } from '@angular/core'; +import { NzButtonModule } from 'ng-zorro-antd/button'; +import { NzModalModule } from 'ng-zorro-antd/modal'; + @Component({ selector: 'nz-demo-modal-async', + standalone: true, + imports: [NzButtonModule, NzModalModule], template: ` @@ -16,8 +21,6 @@ import { Component } from '@angular/core'; export class NzDemoModalBasicComponent { isVisible = false; - constructor() {} - showModal(): void { this.isVisible = true; } diff --git a/components/modal/demo/confirm-promise.ts b/components/modal/demo/confirm-promise.ts index 4e68d7f943..5f5db30d3e 100644 --- a/components/modal/demo/confirm-promise.ts +++ b/components/modal/demo/confirm-promise.ts @@ -1,10 +1,13 @@ import { Component } from '@angular/core'; -import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal'; +import { NzButtonModule } from 'ng-zorro-antd/button'; +import { NzModalModule, NzModalRef, NzModalService } from 'ng-zorro-antd/modal'; @Component({ selector: 'nz-demo-modal-confirm-promise', - template: ` ` + standalone: true, + imports: [NzButtonModule, NzModalModule], + template: `` }) export class NzDemoModalConfirmPromiseComponent { confirmModal?: NzModalRef; // For testing by now diff --git a/components/modal/demo/confirm.ts b/components/modal/demo/confirm.ts index 9dc6bf986b..e60653a6fc 100644 --- a/components/modal/demo/confirm.ts +++ b/components/modal/demo/confirm.ts @@ -1,9 +1,12 @@ import { Component } from '@angular/core'; -import { NzModalService } from 'ng-zorro-antd/modal'; +import { NzButtonModule } from 'ng-zorro-antd/button'; +import { NzModalModule, NzModalService } from 'ng-zorro-antd/modal'; @Component({ selector: 'nz-demo-modal-confirm', + standalone: true, + imports: [NzButtonModule, NzModalModule], template: ` diff --git a/components/modal/demo/draggable.ts b/components/modal/demo/draggable.ts index 0986353683..a8b898fc7e 100644 --- a/components/modal/demo/draggable.ts +++ b/components/modal/demo/draggable.ts @@ -1,7 +1,12 @@ import { Component } from '@angular/core'; +import { NzButtonModule } from 'ng-zorro-antd/button'; +import { NzModalModule } from 'ng-zorro-antd/modal'; + @Component({ selector: 'nz-demo-modal-draggable', + standalone: true, + imports: [NzButtonModule, NzModalModule], template: ` diff --git a/components/modal/demo/locale.ts b/components/modal/demo/locale.ts index 62209189eb..dd4cdac2b0 100644 --- a/components/modal/demo/locale.ts +++ b/components/modal/demo/locale.ts @@ -1,9 +1,12 @@ import { Component } from '@angular/core'; -import { NzModalService } from 'ng-zorro-antd/modal'; +import { NzButtonModule } from 'ng-zorro-antd/button'; +import { NzModalModule, NzModalService } from 'ng-zorro-antd/modal'; @Component({ selector: 'nz-demo-modal-locale', + standalone: true, + imports: [NzButtonModule, NzModalModule], template: `
diff --git a/components/modal/demo/manual.ts b/components/modal/demo/manual.ts index 613e1114ca..3197b113b2 100644 --- a/components/modal/demo/manual.ts +++ b/components/modal/demo/manual.ts @@ -1,10 +1,13 @@ import { Component } from '@angular/core'; -import { NzModalService } from 'ng-zorro-antd/modal'; +import { NzButtonModule } from 'ng-zorro-antd/button'; +import { NzModalModule, NzModalService } from 'ng-zorro-antd/modal'; @Component({ selector: 'nz-demo-modal-manual', - template: ` ` + standalone: true, + imports: [NzButtonModule, NzModalModule], + template: `` }) export class NzDemoModalManualComponent { constructor(private modalService: NzModalService) {} diff --git a/components/modal/demo/module b/components/modal/demo/module deleted file mode 100644 index 37bc21a166..0000000000 --- a/components/modal/demo/module +++ /dev/null @@ -1,5 +0,0 @@ -import { NzModalModule } from 'ng-zorro-antd/modal'; -import { NzButtonModule } from 'ng-zorro-antd/button'; -import { NzIconModule } from 'ng-zorro-antd/icon'; - -export const moduleList = [ NzModalModule, NzButtonModule, NzIconModule ]; diff --git a/components/modal/demo/position.ts b/components/modal/demo/position.ts index 46af116cce..faf6a33d0b 100644 --- a/components/modal/demo/position.ts +++ b/components/modal/demo/position.ts @@ -1,7 +1,12 @@ import { Component } from '@angular/core'; +import { NzButtonModule } from 'ng-zorro-antd/button'; +import { NzModalModule } from 'ng-zorro-antd/modal'; + @Component({ selector: 'nz-demo-modal-position', + standalone: true, + imports: [NzButtonModule, NzModalModule], template: ` String @@ -183,6 +186,8 @@ export class NzDemoModalServiceComponent { @Component({ selector: 'nz-modal-custom-component', + standalone: true, + imports: [NzButtonModule], template: `

{{ title }}

diff --git a/components/modal/modal.spec.ts b/components/modal/modal.spec.ts index 4d36810ac8..758a4de636 100644 --- a/components/modal/modal.spec.ts +++ b/components/modal/modal.spec.ts @@ -9,7 +9,6 @@ import { Directive, Injector, Input, - NgModule, TemplateRef, ViewChild, ViewContainerRef, @@ -24,8 +23,7 @@ import { inject as testingInject, tick } from '@angular/core/testing'; -import { FormsModule } from '@angular/forms'; -import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { provideAnimations, provideNoopAnimations } from '@angular/platform-browser/animations'; import { NzConfigService } from 'ng-zorro-antd/core/config'; import { @@ -49,10 +47,8 @@ describe('Animation', () => { beforeEach(fakeAsync(() => { TestBed.configureTestingModule({ - imports: [NzModalModule, TestModalModule, BrowserAnimationsModule] - }); - - TestBed.compileComponents(); + providers: [NzModalService, provideAnimations()] + }).compileComponents(); })); beforeEach( @@ -104,11 +100,8 @@ describe('NzModal', () => { beforeEach(fakeAsync(() => { TestBed.configureTestingModule({ - imports: [NzModalModule, TestModalModule, NoopAnimationsModule, FormsModule], - providers: [{ provide: Location, useClass: SpyLocation }] - }); - - TestBed.compileComponents(); + providers: [NzModalService, provideNoopAnimations(), { provide: Location, useClass: SpyLocation }] + }).compileComponents(); })); beforeEach( @@ -488,22 +481,22 @@ describe('NzModal', () => { fixture.detectChanges(); - expect(modalRef.getBackdropElement()?.classList).not.toContain('ant-modal-mask', 'should use global config'); + expect(modalRef.getBackdropElement()?.classList) + .withContext('should use global config') + .not.toContain('ant-modal-mask'); configService.set('modal', { nzMask: true }); fixture.detectChanges(); - expect(modalRef.getBackdropElement()?.classList).toContain( - 'ant-modal-mask', - 'should add class when global config changed' - ); + expect(modalRef.getBackdropElement()?.classList) + .withContext('should add class when global config changed') + .toContain('ant-modal-mask'); configService.set('modal', { nzMask: false }); fixture.detectChanges(); - expect(modalRef.getBackdropElement()?.classList).not.toContain( - 'ant-modal-mask', - 'should remove class when global config changed' - ); + expect(modalRef.getBackdropElement()?.classList) + .withContext('should remove class when global config changed') + .not.toContain('ant-modal-mask'); configService.set('modal', { nzMask: true }); // reset modalRef.close(); @@ -1084,7 +1077,7 @@ describe('NzModal', () => { }); describe('focus management', () => { - // When testing focus, all of the elements must be in the DOM. + // When testing focus, all the elements must be in the DOM. beforeEach(() => document.body.appendChild(overlayContainerElement)); afterEach(() => document.body.removeChild(overlayContainerElement)); @@ -1098,10 +1091,9 @@ describe('NzModal', () => { fixture.detectChanges(); flushMicrotasks(); - expect(document.activeElement!.tagName).toBe( - 'INPUT', - 'Expected first tabbable element (input) in the modal to be focused.' - ); + expect(document.activeElement!.tagName) + .withContext('Expected first tabbable element (input) in the modal to be focused.') + .toBe('INPUT'); })); it('should focus the first tabbable element when content is string type', fakeAsync(() => { @@ -1130,7 +1122,7 @@ describe('NzModal', () => { })); it('should re-focus trigger element when modal closes', fakeAsync(() => { - // Create a element that has focus before the modal is opened. + // Create an element that has focus before the modal is opened. const button = document.createElement('button'); button.id = 'modal-trigger'; document.body.appendChild(button); @@ -1144,25 +1136,22 @@ describe('NzModal', () => { fixture.detectChanges(); flushMicrotasks(); - expect(document.activeElement!.id).not.toBe( - 'modal-trigger', - 'Expected the focus to change when modal was opened.' - ); + expect(document.activeElement!.id) + .withContext('Expected the focus to change when modal was opened.') + .not.toBe('modal-trigger'); modalRef.close(); - expect(document.activeElement!.id).not.toBe( - 'modal-trigger', - 'Expcted the focus not to have changed before the animation finishes.' - ); + expect(document.activeElement!.id) + .withContext('Expected the focus not to have changed before the animation finishes.') + .not.toBe('modal-trigger'); flushMicrotasks(); fixture.detectChanges(); tick(500); - expect(document.activeElement!.id).toBe( - 'modal-trigger', - 'Expected that the trigger was refocused after the modal is closed.' - ); + expect(document.activeElement!.id) + .withContext('Expected that the trigger was refocused after the modal is closed.') + .toBe('modal-trigger'); document.body.removeChild(button); })); @@ -1177,7 +1166,9 @@ describe('NzModal', () => { fixture.detectChanges(); tick(16); - expect(document.activeElement!.tagName).toBe('NZ-MODAL-CONTAINER', 'Expected modal container to be focused.'); + expect(document.activeElement!.tagName) + .withContext('Expected modal container to be focused.') + .toBe('NZ-MODAL-CONTAINER'); })); }); @@ -1739,12 +1730,17 @@ describe('NzModal', () => { }); }); -@Directive({ selector: 'test-with-view-container' }) +@Directive({ + standalone: true, + selector: 'test-with-view-container' +}) class TestWithViewContainerDirective { constructor(public viewContainerRef: ViewContainerRef) {} } @Component({ + standalone: true, + imports: [TestWithViewContainerDirective], template: ` ` }) class TestWithChildViewContainerComponent { @@ -1756,6 +1752,7 @@ class TestWithChildViewContainerComponent { } @Component({ + standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, template: 'hello' }) @@ -1764,6 +1761,7 @@ class TestWithOnPushViewContainerComponent { } @Component({ + standalone: true, template: ` Hello {{ value }} @@ -1789,6 +1787,8 @@ class TestWithServiceComponent { } @Component({ + standalone: true, + imports: [NzModalModule], template: ` @@ -1799,11 +1799,8 @@ class TestWithServiceComponent { class TestWithModalContentComponent { @Input() value: string = inject(NZ_MODAL_DATA); nzModalData: string = inject(NZ_MODAL_DATA); - - constructor( - public modalRef: NzModalRef, - public modalInjector: Injector - ) {} + modalRef = inject(NzModalRef); + modalInjector = inject(Injector); destroyModal(): void { this.modalRef.destroy(); @@ -1811,6 +1808,8 @@ class TestWithModalContentComponent { } @Component({ + standalone: true, + imports: [NzModalModule], template: ` ; content: TemplateRef<{}> = this.templateRef; - constructor() {} - handleCancel(): void { this.isVisible = false; this.cancelSpy(); @@ -1847,22 +1844,8 @@ class TestModalComponent { } } -@Component({ template: '

Modal

' }) -class TestModalWithoutFocusableElementsComponent {} - -const TEST_DIRECTIVES = [ - TestWithServiceComponent, - TestWithModalContentComponent, - TestWithChildViewContainerComponent, - TestWithViewContainerDirective, - TestWithOnPushViewContainerComponent, - TestModalWithoutFocusableElementsComponent, - TestModalComponent -]; - -@NgModule({ - imports: [NzModalModule], - exports: TEST_DIRECTIVES, - declarations: TEST_DIRECTIVES +@Component({ + standalone: true, + template: '

Modal

' }) -class TestModalModule {} +class TestModalWithoutFocusableElementsComponent {}