From 395dadcd4b6dfd61238c05f8db55ef5da6f607d8 Mon Sep 17 00:00:00 2001 From: Wendell Date: Fri, 8 Nov 2019 10:08:46 +0800 Subject: [PATCH] chore(module:message,notification): remove old injection tokens BREAKING CHANGE: - `NZ_MESSAGE_CONFIG` is removed. Please use `NzGlobalConfigService` instead. - `NZ_NOTIFICATION_CONFIG` is removed. Please use `NzGlobalConfigService` instead. - `config` method of `NzMessageService` and `NzNotificationService` is removed. Please use `set` method of `NzGlobalConfigService` instead. --- components/message/nz-message-base.service.ts | 15 +--- components/message/nz-message-config.ts | 38 --------- .../message/nz-message-container.component.ts | 56 ++++++------- components/message/nz-message.module.ts | 2 - components/message/nz-message.service.ts | 7 +- components/message/nz-message.spec.ts | 28 +++---- components/message/public-api.ts | 1 - components/notification/demo/placement.ts | 5 +- .../notification/nz-notification-config.ts | 39 --------- .../nz-notification-container.component.ts | 80 ++++++++----------- .../notification/nz-notification.module.ts | 2 - .../notification/nz-notification.service.ts | 7 +- .../notification/nz-notification.spec.ts | 32 ++++---- components/notification/public-api.ts | 1 - 14 files changed, 92 insertions(+), 221 deletions(-) delete mode 100644 components/message/nz-message-config.ts delete mode 100644 components/notification/nz-notification-config.ts diff --git a/components/message/nz-message-base.service.ts b/components/message/nz-message-base.service.ts index 8cae65b7977..17a9351b6eb 100644 --- a/components/message/nz-message-base.service.ts +++ b/components/message/nz-message-base.service.ts @@ -8,19 +8,14 @@ import { Overlay } from '@angular/cdk/overlay'; import { ApplicationRef, ComponentFactoryResolver, EmbeddedViewRef, Injector, Type } from '@angular/core'; -import { warnDeprecation, NzSingletonService } from 'ng-zorro-antd/core'; +import { NzSingletonService } from 'ng-zorro-antd/core'; -import { NzMessageConfigLegacy } from './nz-message-config'; import { NzMessageContainerComponent } from './nz-message-container.component'; import { NzMessageData, NzMessageDataFilled, NzMessageDataOptions } from './nz-message.definitions'; let globalCounter = 0; -export class NzMessageBaseService< - ContainerClass extends NzMessageContainerComponent, - MessageData, - MessageConfig extends NzMessageConfigLegacy -> { +export class NzMessageBaseService { protected _container: ContainerClass; constructor( @@ -58,12 +53,6 @@ export class NzMessageBaseService< return resultMessage; } - config(config: MessageConfig): void { - warnDeprecation(`'config' of 'NzMessageService' and 'NzNotificationService' is deprecated and will be removed in 9.0.0. Please use 'set' of 'NzConfigService' instead.`); - - this._container.setConfig(config); - } - protected _generateMessageId(): string { return `${this.name}-${globalCounter++}`; } diff --git a/components/message/nz-message-config.ts b/components/message/nz-message-config.ts deleted file mode 100644 index b1e657e10c2..00000000000 --- a/components/message/nz-message-config.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @license - * Copyright Alibaba.com All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE - */ - -import { InjectionToken } from '@angular/core'; - -/** - * @deprecated This interface has been removed to `ng-zorro-antd/core`. Please migrate to that. - */ -export interface NzMessageConfigLegacy { - nzAnimate?: boolean; - nzDuration?: number; - nzMaxStack?: number; - nzPauseOnHover?: boolean; - nzTop?: number | string; -} - -export const NZ_MESSAGE_DEFAULT_CONFIG = new InjectionToken('NZ_MESSAGE_DEFAULT_CONFIG'); - -/** - * @deprecated 9.0.0 - Injection token 'NZ_MESSAGE_CONFIG' is deprecated and will be removed in 9.0.0. Please use 'NzConfigService' instead. - */ -export const NZ_MESSAGE_CONFIG = new InjectionToken('NZ_MESSAGE_CONFIG'); - -export const NZ_MESSAGE_DEFAULT_CONFIG_PROVIDER = { - provide: NZ_MESSAGE_DEFAULT_CONFIG, - useValue: { - nzAnimate: true, - nzDuration: 3000, - nzMaxStack: 7, - nzPauseOnHover: true, - nzTop: 24 - } -}; diff --git a/components/message/nz-message-container.component.ts b/components/message/nz-message-container.component.ts index 4dbc0b924ba..bd824225549 100644 --- a/components/message/nz-message-container.component.ts +++ b/components/message/nz-message-container.component.ts @@ -6,23 +6,21 @@ * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ -import { - ChangeDetectionStrategy, - ChangeDetectorRef, - Component, - Inject, - OnInit, - Optional, - ViewEncapsulation -} from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit, ViewEncapsulation } from '@angular/core'; import { Subject } from 'rxjs'; -import { toCssPixel, warnDeprecation, NzConfigService } from 'ng-zorro-antd/core'; +import { toCssPixel, MessageConfig, NzConfigService } from 'ng-zorro-antd/core'; -import { NzMessageConfigLegacy, NZ_MESSAGE_CONFIG, NZ_MESSAGE_DEFAULT_CONFIG } from './nz-message-config'; import { NzMessageDataFilled, NzMessageDataOptions } from './nz-message.definitions'; const NZ_CONFIG_COMPONENT_NAME = 'message'; +const NZ_MESSAGE_DEFAULT_CONFIG: Required = { + nzAnimate: true, + nzDuration: 3000, + nzMaxStack: 7, + nzPauseOnHover: true, + nzTop: 24 +}; @Component({ changeDetection: ChangeDetectionStrategy.OnPush, @@ -34,33 +32,17 @@ const NZ_CONFIG_COMPONENT_NAME = 'message'; }) export class NzMessageContainerComponent implements OnInit { messages: NzMessageDataFilled[] = []; - config: Required; + config: Required; top: string | null; - constructor( - protected cdr: ChangeDetectorRef, - protected nzConfigService: NzConfigService, - @Optional() @Inject(NZ_MESSAGE_DEFAULT_CONFIG) defaultConfig: NzMessageConfigLegacy, - @Optional() @Inject(NZ_MESSAGE_CONFIG) config: NzMessageConfigLegacy - ) { - if (!!config) { - warnDeprecation( - `Injection token 'NZ_MESSAGE_CONFIG' is deprecated and will be removed in 9.0.0. Please use 'NzConfigService' instead.` - ); - } - this.setConfig({ ...defaultConfig, ...config }); + constructor(protected cdr: ChangeDetectorRef, protected nzConfigService: NzConfigService) { + this.updateConfig(); } ngOnInit(): void { this.subscribeConfigChange(); } - setConfig(config?: NzMessageConfigLegacy): void { - this.config = this.mergeMessageConfig(config); - this.top = toCssPixel(this.config.nzTop); - this.cdr.markForCheck(); - } - /** * Create a new message. * @param message Parsed message configuration. @@ -101,14 +83,22 @@ export class NzMessageContainerComponent implements OnInit { this.cdr.detectChanges(); } + protected updateConfig(): void { + this.config = this.updateConfigFromConfigService(); + this.top = toCssPixel(this.config.nzTop); + this.cdr.markForCheck(); + } + protected subscribeConfigChange(): void { - this.nzConfigService.getConfigChangeEventForComponent(NZ_CONFIG_COMPONENT_NAME).subscribe(() => this.setConfig()); + this.nzConfigService + .getConfigChangeEventForComponent(NZ_CONFIG_COMPONENT_NAME) + .subscribe(() => this.updateConfig()); } - protected mergeMessageConfig(config?: NzMessageConfigLegacy): Required { + protected updateConfigFromConfigService(): Required { return { + ...NZ_MESSAGE_DEFAULT_CONFIG, ...this.config, - ...config, ...this.nzConfigService.getConfigForComponent(NZ_CONFIG_COMPONENT_NAME) }; } diff --git a/components/message/nz-message.module.ts b/components/message/nz-message.module.ts index e45ec13713d..6433331ed00 100644 --- a/components/message/nz-message.module.ts +++ b/components/message/nz-message.module.ts @@ -12,7 +12,6 @@ import { NgModule } from '@angular/core'; import { NzAddOnModule } from 'ng-zorro-antd/core'; import { NzIconModule } from 'ng-zorro-antd/icon'; -import { NZ_MESSAGE_DEFAULT_CONFIG_PROVIDER } from './nz-message-config'; import { NzMessageContainerComponent } from './nz-message-container.component'; import { NzMessageComponent } from './nz-message.component'; import { NzMessageServiceModule } from './nz-message.service.module'; @@ -20,7 +19,6 @@ import { NzMessageServiceModule } from './nz-message.service.module'; @NgModule({ imports: [CommonModule, OverlayModule, NzIconModule, NzAddOnModule, NzMessageServiceModule], declarations: [NzMessageContainerComponent, NzMessageComponent], - providers: [NZ_MESSAGE_DEFAULT_CONFIG_PROVIDER], entryComponents: [NzMessageContainerComponent] }) export class NzMessageModule {} diff --git a/components/message/nz-message.service.ts b/components/message/nz-message.service.ts index c777725ef3f..e5820ffe5be 100644 --- a/components/message/nz-message.service.ts +++ b/components/message/nz-message.service.ts @@ -11,7 +11,6 @@ import { ApplicationRef, ComponentFactoryResolver, Injectable, Injector, Templat import { NzSingletonService } from 'ng-zorro-antd/core'; import { NzMessageBaseService } from './nz-message-base.service'; -import { NzMessageConfigLegacy } from './nz-message-config'; import { NzMessageContainerComponent } from './nz-message-container.component'; import { NzMessageData, NzMessageDataFilled, NzMessageDataOptions } from './nz-message.definitions'; import { NzMessageServiceModule } from './nz-message.service.module'; @@ -19,11 +18,7 @@ import { NzMessageServiceModule } from './nz-message.service.module'; @Injectable({ providedIn: NzMessageServiceModule }) -export class NzMessageService extends NzMessageBaseService< - NzMessageContainerComponent, - NzMessageData, - NzMessageConfigLegacy -> { +export class NzMessageService extends NzMessageBaseService { constructor( nzSingletonService: NzSingletonService, overlay: Overlay, diff --git a/components/message/nz-message.spec.ts b/components/message/nz-message.spec.ts index e0eb664196d..1eb54e2e569 100644 --- a/components/message/nz-message.spec.ts +++ b/components/message/nz-message.spec.ts @@ -3,9 +3,8 @@ import { Component, TemplateRef, ViewChild } from '@angular/core'; import { fakeAsync, inject, tick, ComponentFixture, TestBed } from '@angular/core/testing'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { dispatchMouseEvent, NzConfigService } from 'ng-zorro-antd/core'; +import { dispatchMouseEvent, NzConfig, NzConfigService, NZ_CONFIG } from 'ng-zorro-antd/core'; -import { NZ_MESSAGE_CONFIG } from './nz-message-config'; import { NzMessageModule } from './nz-message.module'; import { NzMessageService } from './nz-message.service'; @@ -17,10 +16,15 @@ describe('NzMessage', () => { let nzConfigService: NzConfigService; beforeEach(fakeAsync(() => { + const MESSAGE_CONFIG: NzConfig['message'] = { + nzMaxStack: 2, + nzTop: 24 + }; + TestBed.configureTestingModule({ imports: [NzMessageModule, NoopAnimationsModule], declarations: [NzTestMessageBasicComponent], - providers: [{ provide: NZ_MESSAGE_CONFIG, useValue: { nzMaxStack: 2, nzTop: 24 } }] + providers: [{ provide: NZ_CONFIG, useValue: { message: MESSAGE_CONFIG } }] }); TestBed.compileComponents(); @@ -28,15 +32,13 @@ describe('NzMessage', () => { beforeEach(inject([NzMessageService, OverlayContainer], (m: NzMessageService, oc: OverlayContainer) => { messageService = m; + // @ts-ignore + nzConfigService = messageService._container.nzConfigService; if (!overlayContainerElement) { overlayContainerElement = oc.getContainerElement(); } })); - beforeEach(inject([NzConfigService], (c: NzConfigService) => { - nzConfigService = c; - })); - afterEach(() => { messageService.remove(); }); @@ -161,17 +163,6 @@ describe('NzMessage', () => { expect(overlayContainerElement.textContent).not.toContain('EXISTS'); })); - /** - * @deprecated This test is going to be removed in 9.0.0 - */ - it('should reset default config dynamically', fakeAsync(() => { - messageService.config({ nzDuration: 0 }); - messageService.create('loading', 'EXISTS'); - fixture.detectChanges(); - tick(10000); - expect(overlayContainerElement.textContent).toContain('EXISTS'); - })); - it('should reset default config from config service', fakeAsync(() => { nzConfigService.set('message', { nzDuration: 0 }); messageService.create('loading', 'EXISTS'); @@ -181,7 +172,6 @@ describe('NzMessage', () => { })); it('should emit event when message close', fakeAsync(() => { - messageService.config({ nzDuration: 2000 }); const closeSpy = jasmine.createSpy('message closed'); const msg = messageService.create('loading', 'CLOSE'); const messageId = msg.messageId; diff --git a/components/message/public-api.ts b/components/message/public-api.ts index 11f50179dc0..ae41208d993 100644 --- a/components/message/public-api.ts +++ b/components/message/public-api.ts @@ -13,4 +13,3 @@ export * from './nz-message.module'; export * from './nz-message.component'; export * from './nz-message.definitions'; export * from './nz-message-container.component'; -export * from './nz-message-config'; diff --git a/components/notification/demo/placement.ts b/components/notification/demo/placement.ts index c28345fe835..6694964b933 100644 --- a/components/notification/demo/placement.ts +++ b/components/notification/demo/placement.ts @@ -1,4 +1,5 @@ import { Component } from '@angular/core'; +import { NzConfigService } from 'ng-zorro-antd/core'; import { NzNotificationService } from 'ng-zorro-antd/notification'; @Component({ @@ -25,7 +26,7 @@ export class NzDemoNotificationPlacementComponent { } createBasicNotification(): void { - this.notification.config({ + this.configService.set('notification', { nzPlacement: this.placement }); this.notification.blank( @@ -34,5 +35,5 @@ export class NzDemoNotificationPlacementComponent { ); } - constructor(private notification: NzNotificationService) {} + constructor(private notification: NzNotificationService, private configService: NzConfigService) {} } diff --git a/components/notification/nz-notification-config.ts b/components/notification/nz-notification-config.ts deleted file mode 100644 index 22f08a5cd8f..00000000000 --- a/components/notification/nz-notification-config.ts +++ /dev/null @@ -1,39 +0,0 @@ -/** - * @license - * Copyright Alibaba.com All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE - */ - -import { InjectionToken } from '@angular/core'; - -import { NzMessageConfigLegacy } from 'ng-zorro-antd/message'; - -/** - * @deprecated This interface would has been moved to `ng-zorro-antd/core`. Please migrate to that. - */ -export interface NzNotificationConfigLegacy extends NzMessageConfigLegacy { - nzTop?: string | number; - nzBottom?: string | number; - nzPlacement?: 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | string; -} - -export const NZ_NOTIFICATION_DEFAULT_CONFIG = new InjectionToken( - 'NZ_NOTIFICATION_DEFAULT_CONFIG' -); - -export const NZ_NOTIFICATION_CONFIG = new InjectionToken('NZ_NOTIFICATION_CONFIG'); - -export const NZ_NOTIFICATION_DEFAULT_CONFIG_PROVIDER = { - provide: NZ_NOTIFICATION_DEFAULT_CONFIG, - useValue: { - nzTop: '24px', - nzBottom: '24px', - nzPlacement: 'topRight', - nzDuration: 4500, - nzMaxStack: 7, - nzPauseOnHover: true, - nzAnimate: true - } -}; diff --git a/components/notification/nz-notification-container.component.ts b/components/notification/nz-notification-container.component.ts index cf3311b366f..56501532d65 100644 --- a/components/notification/nz-notification-container.component.ts +++ b/components/notification/nz-notification-container.component.ts @@ -6,28 +6,26 @@ * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ -import { - ChangeDetectionStrategy, - ChangeDetectorRef, - Component, - Inject, - Optional, - ViewEncapsulation -} from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ViewEncapsulation } from '@angular/core'; import { Subject } from 'rxjs'; -import { toCssPixel, warnDeprecation, NzConfigService } from 'ng-zorro-antd/core'; +import { toCssPixel, NotificationConfig, NzConfigService } from 'ng-zorro-antd/core'; import { NzMessageContainerComponent } from 'ng-zorro-antd/message'; -import { - NzNotificationConfigLegacy, - NZ_NOTIFICATION_CONFIG, - NZ_NOTIFICATION_DEFAULT_CONFIG -} from './nz-notification-config'; import { NzNotificationDataFilled, NzNotificationDataOptions } from './nz-notification.definitions'; const NZ_CONFIG_COMPONENT_NAME = 'notification'; +const NZ_NOTIFICATION_DEFAULT_CONFIG: Required = { + nzTop: '24px', + nzBottom: '24px', + nzPlacement: 'topRight', + nzDuration: 4500, + nzMaxStack: 7, + nzPauseOnHover: true, + nzAnimate: true +}; + @Component({ changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, @@ -37,7 +35,7 @@ const NZ_CONFIG_COMPONENT_NAME = 'notification'; templateUrl: './nz-notification-container.component.html' }) export class NzNotificationContainerComponent extends NzMessageContainerComponent { - config: Required; + config: Required; bottom: string | null; /** @@ -45,35 +43,8 @@ export class NzNotificationContainerComponent extends NzMessageContainerComponen */ messages: Array> = []; - constructor( - cdr: ChangeDetectorRef, - nzConfigService: NzConfigService, - @Optional() @Inject(NZ_NOTIFICATION_DEFAULT_CONFIG) defaultConfig: NzNotificationConfigLegacy, - @Optional() @Inject(NZ_NOTIFICATION_CONFIG) config: NzNotificationConfigLegacy - ) { - super(cdr, nzConfigService, defaultConfig, config); - if (!!config) { - warnDeprecation( - `Injection token 'NZ_NOTIFICATION_CONFIG' is deprecated and will be removed in 9.0.0. Please use 'NzConfigService' instead.` - ); - } - } - - /** - * @override - */ - setConfig(config?: NzNotificationConfigLegacy): void { - const newConfig = (this.config = { - ...this.config, - ...config, - ...this.nzConfigService.getConfigForComponent(NZ_CONFIG_COMPONENT_NAME) - }); - const placement = this.config.nzPlacement; - - this.top = placement === 'topLeft' || placement === 'topRight' ? toCssPixel(newConfig.nzTop) : null; - this.bottom = placement === 'bottomLeft' || placement === 'bottomRight' ? toCssPixel(newConfig.nzBottom) : null; - - this.cdr.markForCheck(); + constructor(cdr: ChangeDetectorRef, nzConfigService: NzConfigService) { + super(cdr, nzConfigService); } /** @@ -102,11 +73,30 @@ export class NzNotificationContainerComponent extends NzMessageContainerComponen this.cdr.detectChanges(); } + /** + * @override + */ + protected updateConfig(): void { + const newConfig = (this.config = { + ...NZ_NOTIFICATION_DEFAULT_CONFIG, + ...this.config, + ...this.nzConfigService.getConfigForComponent(NZ_CONFIG_COMPONENT_NAME) + }); + const placement = this.config.nzPlacement; + + this.top = placement === 'topLeft' || placement === 'topRight' ? toCssPixel(newConfig.nzTop) : null; + this.bottom = placement === 'bottomLeft' || placement === 'bottomRight' ? toCssPixel(newConfig.nzBottom) : null; + + this.cdr.markForCheck(); + } + /** * @override */ protected subscribeConfigChange(): void { - this.nzConfigService.getConfigChangeEventForComponent(NZ_CONFIG_COMPONENT_NAME).subscribe(() => this.setConfig()); + this.nzConfigService + .getConfigChangeEventForComponent(NZ_CONFIG_COMPONENT_NAME) + .subscribe(() => this.updateConfig()); } private replaceNotification(old: NzNotificationDataFilled, _new: NzNotificationDataFilled): void { diff --git a/components/notification/nz-notification.module.ts b/components/notification/nz-notification.module.ts index f76ef58fc68..6892c17f98c 100644 --- a/components/notification/nz-notification.module.ts +++ b/components/notification/nz-notification.module.ts @@ -11,7 +11,6 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { NzIconModule } from 'ng-zorro-antd/icon'; -import { NZ_NOTIFICATION_DEFAULT_CONFIG_PROVIDER } from './nz-notification-config'; import { NzNotificationContainerComponent } from './nz-notification-container.component'; import { NzNotificationComponent } from './nz-notification.component'; import { NzNotificationServiceModule } from './nz-notification.service.module'; @@ -19,7 +18,6 @@ import { NzNotificationServiceModule } from './nz-notification.service.module'; @NgModule({ imports: [CommonModule, OverlayModule, NzIconModule, NzNotificationServiceModule], declarations: [NzNotificationComponent, NzNotificationContainerComponent], - providers: [NZ_NOTIFICATION_DEFAULT_CONFIG_PROVIDER], entryComponents: [NzNotificationContainerComponent] }) export class NzNotificationModule {} diff --git a/components/notification/nz-notification.service.ts b/components/notification/nz-notification.service.ts index 03abccadb48..3c1581f740e 100644 --- a/components/notification/nz-notification.service.ts +++ b/components/notification/nz-notification.service.ts @@ -12,7 +12,6 @@ import { ApplicationRef, ComponentFactoryResolver, Injectable, Injector, Templat import { NzSingletonService } from 'ng-zorro-antd/core'; import { NzMessageBaseService } from 'ng-zorro-antd/message'; -import { NzNotificationConfigLegacy } from './nz-notification-config'; import { NzNotificationContainerComponent } from './nz-notification-container.component'; import { NzNotificationData, NzNotificationDataFilled, NzNotificationDataOptions } from './nz-notification.definitions'; import { NzNotificationServiceModule } from './nz-notification.service.module'; @@ -20,11 +19,7 @@ import { NzNotificationServiceModule } from './nz-notification.service.module'; @Injectable({ providedIn: NzNotificationServiceModule }) -export class NzNotificationService extends NzMessageBaseService< - NzNotificationContainerComponent, - NzNotificationData, - NzNotificationConfigLegacy -> { +export class NzNotificationService extends NzMessageBaseService { constructor( nzSingletonService: NzSingletonService, overlay: Overlay, diff --git a/components/notification/nz-notification.spec.ts b/components/notification/nz-notification.spec.ts index 855f1ad621d..a69d96d99fa 100644 --- a/components/notification/nz-notification.spec.ts +++ b/components/notification/nz-notification.spec.ts @@ -3,9 +3,8 @@ import { Component, TemplateRef, ViewChild } from '@angular/core'; import { fakeAsync, inject, tick, ComponentFixture, TestBed } from '@angular/core/testing'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { dispatchMouseEvent } from 'ng-zorro-antd/core'; +import { dispatchMouseEvent, NzConfig, NzConfigService, NZ_CONFIG } from 'ng-zorro-antd/core'; -import { NZ_NOTIFICATION_CONFIG } from './nz-notification-config'; import { NzNotificationModule } from './nz-notification.module'; import { NzNotificationService } from './nz-notification.service'; @@ -22,12 +21,17 @@ describe('NzNotification', () => { let notificationService: NzNotificationService; let overlayContainerElement: HTMLElement; let fixture: ComponentFixture; + let nzConfigService: NzConfigService; beforeEach(fakeAsync(() => { + const NOTIFICATION_CONFIG: NzConfig['notification'] = { + nzMaxStack: 2 + }; + TestBed.configureTestingModule({ imports: [NzNotificationModule, NoopAnimationsModule], declarations: [DemoAppComponent], - providers: [{ provide: NZ_NOTIFICATION_CONFIG, useValue: { nzMaxStack: 2 } }] // Override default config + providers: [{ provide: NZ_CONFIG, useValue: { notification: NOTIFICATION_CONFIG } }] }); TestBed.compileComponents(); @@ -35,19 +39,21 @@ describe('NzNotification', () => { beforeEach(inject([NzNotificationService, OverlayContainer], (n: NzNotificationService, oc: OverlayContainer) => { notificationService = n; + // @ts-ignore + nzConfigService = notificationService._container.nzConfigService; if (!overlayContainerElement) { overlayContainerElement = oc.getContainerElement(); } })); - afterEach(() => { - notificationService.remove(); - }); - beforeEach(() => { fixture = TestBed.createComponent(DemoAppComponent); }); + afterEach(() => { + notificationService.remove(); + }); + it('should open a message box with success', () => { notificationService.success('test-title', 'SUCCESS'); fixture.detectChanges(); @@ -151,23 +157,21 @@ describe('NzNotification', () => { tick(1000 + 10); expect(overlayContainerElement.textContent).not.toContain('EXISTS'); })); - it('should reset default config dynamically', fakeAsync(() => { - notificationService.config({ nzDuration: 0 }); + nzConfigService.set('notification', { nzDuration: 0 }); notificationService.create('', 'loading', 'EXISTS'); fixture.detectChanges(); - tick(50000); + tick(10000); expect(overlayContainerElement.textContent).toContain('EXISTS'); })); it('should show with placement of topLeft', () => { - notificationService.config({ nzPlacement: 'topLeft' }); + nzConfigService.set('notification', { nzPlacement: 'topLeft' }); notificationService.create('', '', 'EXISTS'); fixture.detectChanges(); expect(overlayContainerElement.textContent).toContain('EXISTS'); expect(overlayContainerElement.querySelector('.ant-notification-topLeft')).not.toBeNull(); }); - // Should support nzData as context. it('should open a message box with template ref', () => { notificationService.template(fixture.componentInstance.demoTemplateRef, { nzData: 'data' }); @@ -205,14 +209,14 @@ describe('NzNotification', () => { })); it('should support configurable nzTop & nzBottom', fakeAsync(() => { - notificationService.config({ nzTop: 48 }); + nzConfigService.set('notification', { nzTop: 48 }); notificationService.create('', '', 'TEST TOP', { nzDuration: 3000 }); waitForNotificationToggling(fixture); const notificationContainer = overlayContainerElement.querySelector('.ant-notification') as HTMLElement; expect(notificationContainer.style.top).toBe('48px'); expect(notificationContainer.style.bottom).toBeFalsy(); - notificationService.config({ nzPlacement: 'bottomLeft', nzBottom: '48px' }); + nzConfigService.set('notification', { nzPlacement: 'bottomLeft', nzBottom: '48px' }); notificationService.create('', '', 'TEST BOTTOM'); waitForNotificationToggling(fixture); expect(notificationContainer.style.top).toBeFalsy(); diff --git a/components/notification/public-api.ts b/components/notification/public-api.ts index dbcfb67b6de..c00399e2766 100644 --- a/components/notification/public-api.ts +++ b/components/notification/public-api.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE */ -export * from './nz-notification-config'; export * from './nz-notification.component'; export * from './nz-notification.module'; export * from './nz-notification.definitions';