All files / src/app/shared/directives iops.directive.ts

95.24% Statements 20/21
71.43% Branches 10/14
83.33% Functions 5/6
93.75% Lines 15/16

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 3298x 98x   98x         98x   98x   439x   98x 486x 486x     438x 438x 438x 438x         196x     98x  
import { Directive, EventEmitter, HostListener, Input, OnInit } from '@angular/core';
import { NgControl } from '@angular/forms';
 
import { FormatterService } from '../services/formatter.service';
 
@Directive({
  selector: '[cdIops]'
})
export class IopsDirective implements OnInit {
  @Input()
  ngDataReady: EventEmitter<any>;
 
  constructor(private formatter: FormatterService, private ngControl: NgControl) {}
 
  setValue(value: string): void {
    const iops = this.formatter.toIops(value);
    this.ngControl.control.setValue(`${iops} IOPS`);
  }
 
  ngOnInit(): void {
    this.setValue(this.ngControl.value);
    Eif (this.ngDataReady) {
      this.ngDataReady.subscribe(() => this.setValue(this.ngControl.value));
    }
  }
 
  @HostListener('blur', ['$event.target.value'])
  onUpdate(value) {
    this.setValue(value);
  }
}