All files / src/app/test-controller/components/review-dialog review-dialog.component.ts

39.39% Statements 13/33
0% Branches 0/5
22.22% Functions 2/9
39.39% Lines 13/33

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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93                            1x 1x                     1x 1x 1x     1x 1x 1x       1x 1x                                         1x 1x 1x                                                              
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { Component, Inject, OnInit } from '@angular/core';
import { ReviewDialogData } from '../../interfaces/test-controller.interfaces';
import { KbDetectionService } from '../../../shared/services/kb-detection/kb-detection.service';
import { MainDataService } from '../../../shared/services/maindata/maindata.service';
 
@Component({
  templateUrl: './review-dialog.component.html',
  styles: [
    '.mat-mdc-radio-group {display: flex; flex-direction: column;}',
    'ul {list-style-type: none; padding: 0;}'
  ]
})
export class ReviewDialogComponent implements OnInit {
  reviewForm = new FormGroup({
    target: new FormControl('u', Validators.required),
    targetLabel: new FormControl(this.data.currentPageLabel),
    priority: new FormControl(''),
    tech: new FormControl(),
    content: new FormControl(),
    design: new FormControl(),
    entry: new FormControl('', Validators.required),
    sender: new FormControl(ReviewDialogComponent.savedName)
  });
 
  static savedName = '';
  showInputField: boolean = false;
  originalWindowHeight: number = 0;
 
  constructor(
    @Inject(MAT_DIALOG_DATA) public data: ReviewDialogData,
    private kbDetectionService: KbDetectionService,
    private mainDataService: MainDataService) {
  }
 
  ngOnInit(): void {
    this.originalWindowHeight = window.innerHeight;
    this.reviewForm.get('target')?.valueChanges.subscribe(value => {
      this.showInputField = value === 'p';
    });
  }
 
  getSelectedCategories(): string { // TODO wtf is this a string
    let selectedCategories = '';
    Iif (this.reviewForm.get('tech')?.value === true) {
      selectedCategories = ' tech';
    }
    Iif (this.reviewForm.get('design')?.value === true) {
      selectedCategories += ' design';
    }
    Iif (this.reviewForm.get('content')?.value === true) {
      selectedCategories += ' content';
    }
    return selectedCategories.trim();
  }
 
  // onKeydown and OnKeyup are needed to detect if the user is using an extended keyboard by measuring the keypress speed
  // it is assumed that keypresses on a physical keyboard are inherently slower on a virtual keyboard, thus the detection
  heightOuter: string = '';
  heightInner: string = '';
  keyPressStart: number = 0;
 
  onKeydown() {
    this.keyPressStart = new Date().getTime();
 
    Iif (this.mainDataService.isExtendedKbUsed === false) {
      this.downsizeTextarea();
    }
  }
 
  onKeyup() {
    this.kbDetectionService.pushKeyPressSpeeds(new Date().getTime() - this.keyPressStart);
  }
 
  onFocus() {
    Iif (this.mainDataService.isExtendedKbUsed === false) {
      this.downsizeTextarea();
    }
  }
 
  onBlur() {
    this.heightOuter = this.originalWindowHeight.toString();
    this.heightInner = (this.originalWindowHeight - 50).toString();
  }
 
  private downsizeTextarea() {
    const sum = this.originalWindowHeight * (1 / 5);
    this.heightOuter = sum.toString();
    this.heightInner = (sum - 30).toString();
  }
}