All files / src/lib/common/toast toast.service.ts

100% Statements 20/20
100% Branches 2/2
100% Functions 8/8
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 371x     1x     1x 1x 1x 1x       9x     1x 1x     1x 2x     1x 2x     1x 2x     1x 2x   1x  
import {Injectable} from '@angular/core';
 
@Injectable({providedIn: 'root'})
export class ToastService {
    private controller: HTMLAnjToastControllerElement;
 
    public static createController(): HTMLAnjToastControllerElement {
        const controller = document.createElement('anj-toast-controller');
        document.body.appendChild(controller);
        return controller as HTMLAnjToastControllerElement;
    }
 
    constructor() {
        this.controller = document.querySelector('anj-toast-controller') || ToastService.createController();
    }
 
    public dismissAll(): void {
        this.controller.dismissAll();
    }
 
    public error(message: string, header?: string): Promise<HTMLAnjToastElement> {
        return this.controller.error(message, header);
    }
 
    public message(message: string, header?: string): Promise<HTMLAnjToastElement> {
        return this.controller.message(message, header);
    }
 
    public success(message: string, header?: string): Promise<HTMLAnjToastElement> {
        return this.controller.success(message, header);
    }
 
    public warn(message: string, header?: string): Promise<HTMLAnjToastElement> {
        return this.controller.warn(message, header);
    }
}