Skip to content

Commit ab7035c

Browse files
committed
Tests
1 parent 17c6793 commit ab7035c

16 files changed

+374
-348
lines changed

angular.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
"options": {
8181
"runner": "karma",
8282
"runnerConfig": true,
83-
"coverage": true
83+
"coverage": true,
84+
"coverageExclude": ["src/app/*-toast/**"]
8485
}
8586
},
8687
"lint": {

karma.conf.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@ module.exports = function (config) {
1212
require('karma-jasmine'),
1313
require('karma-chrome-launcher'),
1414
require('karma-jasmine-html-reporter'),
15-
require('karma-coverage-istanbul-reporter'),
15+
require('karma-coverage'),
1616
],
17+
jasmineHtmlReporter: {
18+
suppressAll: true, // removes the duplicated traces
19+
},
1720
client: {
1821
clearContext: false, // leave Jasmine Spec Runner output visible in browser
1922
},
20-
coverageIstanbulReporter: {
21-
dir: require('path').join(__dirname, './coverage/zzz'),
22-
reports: ['html', 'lcovonly', 'text-summary'],
23-
fixWebpackSourcePaths: true,
23+
coverageReporter: {
24+
dir: require('path').join(__dirname, './coverage/ngx-toastr'),
25+
subdir: '.',
26+
includeAllSources: false,
27+
reporters: [{ type: 'html' }, { type: 'text-summary' }, { type: 'lcovonly' }],
2428
},
25-
reporters: ['coverage-istanbul', 'progress', 'kjhtml'],
29+
reporters: ['progress', 'kjhtml', 'coverage'],
2630
port: 9876,
2731
colors: true,
2832
logLevel: config.LOG_INFO,

projects/ngx-toastr/src/lib/toastr/toast/toast.component.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
}
55

66
&.toast-out {
7-
animation: toast-animation var(--animation-duration) var(--animation-easing) reverse;
7+
animation: toast-animation var(--animation-duration) var(--animation-easing) reverse forwards;
88
}
99
}
1010

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1-
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, ElementRef, inject } from '@angular/core';
22
import { ToastBase } from '../base-toast/base-toast.component';
33

44
@Component({
55
selector: '[toast-component]',
66
templateUrl: '../base-toast/base-toast.component.html',
77
styleUrl: './toast.component.scss',
88
host: {
9-
'[style.--animation-easing]': 'params().easing',
10-
'[style.--animation-duration]': 'params().easeTime + "ms"',
9+
'[style.--animation-easing]': 'params.easing',
10+
'[style.--animation-duration]': 'params.easeTime + "ms"',
1111
'animate.enter': 'toast-in',
12-
'animate.leave': 'toast-out',
1312
},
1413
standalone: true,
1514
changeDetection: ChangeDetectionStrategy.OnPush,
1615
})
1716
export class Toast<ConfigPayload = unknown> extends ToastBase<ConfigPayload> {
18-
readonly params = signal({ easeTime: this.toastPackage.config.easeTime, easing: 'ease-in' });
17+
readonly params = { easeTime: this.toastPackage.config.easeTime, easing: 'ease-in' };
18+
private elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
19+
20+
override remove(): void {
21+
if (this.state() === 'removed') return;
22+
23+
clearTimeout(this.timeout);
24+
this.state.set('removed');
25+
this.elementRef.nativeElement.classList.add('toast-out');
26+
this.timeout = this.timeoutsService.setTimeout(
27+
() => this.toastrService.remove(this.toastPackage.toastId),
28+
+this.params.easeTime,
29+
);
30+
}
1931
}

projects/ngx-toastr/src/lib/toastr/toastr-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export interface ToastrIconClasses {
118118
* Global Toast configuration
119119
* Includes all IndividualConfig
120120
*/
121-
export interface GlobalConfig extends IndividualConfig {
121+
export interface GlobalConfig<C = unknown> extends IndividualConfig<C> {
122122
/**
123123
* max toasts opened. Toasts will be queued
124124
* Zero is unlimited

projects/ngx-toastr/src/lib/toastr/toastr.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ToastToken,
1515
TOAST_CONFIG,
1616
} from './toastr-config';
17+
import type { ToastBase } from './base-toast/base-toast.component';
1718

1819
export interface ActiveToast<C> {
1920
/** Your Toast ID. Use this to close it individually */
@@ -65,13 +66,18 @@ export class ToastrService {
6566
}
6667
}
6768
/** show toast */
68-
show<ConfigPayload = unknown>(
69+
show<C extends ToastBase = ToastBase, ConfigPayload = unknown>(
6970
message?: string,
7071
title?: string,
7172
override: Partial<IndividualConfig<ConfigPayload>> = {},
7273
type = '',
7374
) {
74-
return this._preBuildNotification(type, message, title, this.applyConfig(override));
75+
return this._preBuildNotification(
76+
type,
77+
message,
78+
title,
79+
this.applyConfig(override),
80+
) as ActiveToast<C> | null;
7581
}
7682
/** show successful toast */
7783
success<ConfigPayload = unknown>(

src/app/app.component.spec.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/app/footer/footer.component.spec.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/app/header/header.component.spec.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/app/home/home.component.html

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,20 +502,24 @@
502502
<small>Toast Controls:</small>
503503
</p>
504504
<div class="d-flex justify-content-center">
505-
<button (click)="openToast()" type="button" class="btn btn-primary btn-block mx-1">
505+
<button
506+
(click)="toastManager.openToastAnimation(options, type, { message, title })"
507+
type="button"
508+
class="btn btn-primary btn-block mx-1"
509+
>
506510
Open Toast
507511
</button>
508512

509513
<button
510-
(click)="clearLastToast()"
514+
(click)="toastManager.clearLastToast()"
511515
type="button"
512516
class="btn btn-outline-primary btn-block mx-1"
513517
>
514518
Clear Last Toast
515519
</button>
516520

517521
<button
518-
(click)="clearToasts()"
522+
(click)="toastManager.clearToasts()"
519523
type="button"
520524
class="btn btn-outline-primary btn-block mx-1"
521525
>
@@ -530,23 +534,31 @@
530534
<small>Example Custom Toasts:</small>
531535
</p>
532536
<button
533-
(click)="openToastNoAnimation()"
537+
(click)="toastManager.openToastNoAnimation(options, type, { message, title })"
534538
type="button"
535539
class="btn btn-sm btn-light mx-1"
536540
>
537541
No Animations
538542
</button>
539543
<button
540-
(click)="openBootstrapToast()"
544+
(click)="toastManager.openBootstrapToast(options, { message, title })"
541545
type="button"
542546
class="btn btn-sm btn-light mx-1"
543547
>
544548
Bootstrap 5's Toast
545549
</button>
546-
<button (click)="openPinkToast()" type="button" class="btn btn-sm btn-pink mx-1">
550+
<button
551+
(click)="toastManager.openPinkToast(options, { message, title })"
552+
type="button"
553+
class="btn btn-sm btn-pink mx-1"
554+
>
547555
Pink
548556
</button>
549-
<button (click)="openNotyf()" type="button" class="btn btn-sm btn-dark mx-1">
557+
<button
558+
(click)="toastManager.openNotyf(options, { message, title })"
559+
type="button"
560+
class="btn btn-sm btn-dark mx-1"
561+
>
550562
Notyf
551563
</button>
552564
</div>

0 commit comments

Comments
 (0)