All files / src/app/sys-check sys-check-data.service.ts

62.5% Statements 20/32
0% Branches 0/16
50% Functions 2/4
60% Lines 18/30

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 94 95 96 97 98 99 100 101 102                            1x 5x 5x 5x 5x 5x 5x                                             5x                         5x 5x 5x 5x 5x 5x             5x   5x 5x                                       4x                    
import { Injectable } from '@angular/core';
import {
  CheckConfig,
  NetworkCheckStatus,
  ReportEntry,
  SpeedParameters,
  StepDef,
  UnitAndPlayerContainer
} from './sys-check.interfaces';
import { KeyValuePairString } from '../test-controller/interfaces/test-controller.interfaces';
 
@Injectable({
  providedIn: 'root'
})
export class SysCheckDataService {
  private steps: string[] = [];
  stepLabels: string[] = [];
  private currentStep = 0;
  nextStep = '';
  prevStep = '';
  private stepDefs: StepDef[] = [
    {
      route: 'w',
      label: 'Ermitteln von Systemdaten (Betriebssystem, Browser)'
    },
    {
      route: 'n',
      label: 'Schätzung der Qualität der Internetverbindung'
    },
    {
      route: 'u',
      label: 'Prüfen von typischen Eingabe-Elementen'
    },
    {
      route: 'q',
      label: 'Beantworten einiger Fragen'
    },
    {
      route: 'r',
      label: 'Senden eines Berichtes'
    }
  ];
 
  checkConfig: CheckConfig = {
    canSave: false,
    customTexts: [],
    downloadSpeed: <SpeedParameters>{},
    hasUnit: false,
    label: '',
    name: '',
    questions: [],
    skipNetwork: true,
    uploadSpeed: <SpeedParameters>{},
    workspaceId: -1
  };
 
  loadConfigComplete = false;
  unitAndPlayerContainer: UnitAndPlayerContainer | null = null;
  environmentReports: ReportEntry[] = [];
  networkReports: ReportEntry[] = [];
  questionnaireReports: ReportEntry[] = [];
  networkCheckStatus: NetworkCheckStatus = {
    done: true,
    message: 'Messung noch nicht gestartet',
    avgUploadSpeedBytesPerSecond: -1,
    avgDownloadSpeedBytesPerSecond: -1
  };
 
  timeCheckDone = false;
 
  dataParts: KeyValuePairString = {};
  unitStateDataType: string = '';
 
  setSteps(): void {
    this.steps = [];
    this.stepLabels = [];
    this.stepDefs.forEach(step => {
      Iif (this.checkConfig) {
        Iif ((step.route === 'w') ||
          (step.route === 'n' && !this.checkConfig.skipNetwork) ||
          (step.route === 'u' && this.checkConfig.hasUnit) ||
          (step.route === 'q' && this.checkConfig.questions.length > 0) ||
          (step.route === 'r' && this.checkConfig.canSave)) {
          this.steps.push(step.route);
          this.stepLabels.push(step.label);
        }
      }
    });
  }
 
  setNewCurrentStep(newStep: string): void {
    for (let stepIndex = 0; stepIndex < this.steps.length; stepIndex++) {
      Iif (this.steps[stepIndex] === newStep) {
        this.currentStep = stepIndex;
        this.nextStep = stepIndex < this.steps.length - 1 ? this.steps[this.currentStep + 1] : '';
        this.prevStep = stepIndex > 0 ? this.steps[this.currentStep - 1] : '';
        break;
      }
    }
  }
}