|
|
|
@ -3,6 +3,7 @@ import { Component } from '@angular/core'; |
|
|
|
import { RouterTestingModule } from '@angular/router/testing'; |
|
|
|
import { createComponentFactory, Spectator } from '@ngneat/spectator/jest'; |
|
|
|
import { NgxsModule } from '@ngxs/store'; |
|
|
|
import { MessageService } from 'primeng/components/common/messageservice'; |
|
|
|
import { ToasterService } from '../services/toaster.service'; |
|
|
|
import { ThemeSharedModule } from '../theme-shared.module'; |
|
|
|
import { OAuthService } from 'angular-oauth2-oidc'; |
|
|
|
@ -10,7 +11,7 @@ import { OAuthService } from 'angular-oauth2-oidc'; |
|
|
|
@Component({ |
|
|
|
selector: 'abp-dummy', |
|
|
|
template: ` |
|
|
|
<abp-toast></abp-toast> |
|
|
|
<abp-toast-container></abp-toast-container> |
|
|
|
`,
|
|
|
|
}) |
|
|
|
class DummyComponent { |
|
|
|
@ -23,6 +24,7 @@ describe('ToasterService', () => { |
|
|
|
const createComponent = createComponentFactory({ |
|
|
|
component: DummyComponent, |
|
|
|
imports: [CoreModule, ThemeSharedModule.forRoot(), NgxsModule.forRoot(), RouterTestingModule], |
|
|
|
providers: [MessageService], |
|
|
|
mocks: [OAuthService], |
|
|
|
}); |
|
|
|
|
|
|
|
@ -30,4 +32,58 @@ describe('ToasterService', () => { |
|
|
|
spectator = createComponent(); |
|
|
|
service = spectator.get(ToasterService); |
|
|
|
}); |
|
|
|
|
|
|
|
test('should display an error toast', () => { |
|
|
|
service.error('test', 'title'); |
|
|
|
|
|
|
|
spectator.detectChanges(); |
|
|
|
|
|
|
|
expect(spectator.query('div.toast')).toBeTruthy(); |
|
|
|
expect(spectator.query('.toast-icon i')).toHaveClass('fa-times-circle'); |
|
|
|
expect(spectator.query('div.toast-title')).toHaveText('title'); |
|
|
|
expect(spectator.query('div.toast-message')).toHaveText('test'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('should display a warning toast', () => { |
|
|
|
service.warn('test', 'title'); |
|
|
|
spectator.detectChanges(); |
|
|
|
expect(spectator.query('.toast-icon i')).toHaveClass('fa-exclamation-triangle'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('should display a success toast', () => { |
|
|
|
service.success('test', 'title'); |
|
|
|
spectator.detectChanges(); |
|
|
|
expect(spectator.query('.toast-icon i')).toHaveClass('fa-check-circle'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('should display an info toast', () => { |
|
|
|
service.info('test', 'title'); |
|
|
|
spectator.detectChanges(); |
|
|
|
expect(spectator.query('.toast-icon i')).toHaveClass('fa-info-circle'); |
|
|
|
}); |
|
|
|
|
|
|
|
test('should display multiple toasts', () => { |
|
|
|
service.info('detail1', 'summary1'); |
|
|
|
service.info('detail2', 'summary2'); |
|
|
|
|
|
|
|
spectator.detectChanges(); |
|
|
|
expect(spectator.queryAll('div.toast-title').map(node => node.textContent.trim())).toEqual([ |
|
|
|
'summary1', |
|
|
|
'summary2', |
|
|
|
]); |
|
|
|
expect(spectator.queryAll('div.toast-message').map(node => node.textContent.trim())).toEqual([ |
|
|
|
'detail1', |
|
|
|
'detail2', |
|
|
|
]); |
|
|
|
}); |
|
|
|
|
|
|
|
test('should remove the opened toasts', () => { |
|
|
|
service.info('test', 'title'); |
|
|
|
spectator.detectChanges(); |
|
|
|
expect(spectator.query('div.toast')).toBeTruthy(); |
|
|
|
|
|
|
|
service.clear(); |
|
|
|
spectator.detectChanges(); |
|
|
|
expect(spectator.query('p-div.toast')).toBeFalsy(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|