SimonTestNet / SimonTest

Repository for SimonTest questions and issues https://simontest.net
16 stars 2 forks source link

Cannot read property 'text' of undefined #44

Closed AlexKirilov closed 3 years ago

AlexKirilov commented 3 years ago

I am using the SimonTest (Extension) for VS Code. For some of the services or components, when I use the extension, it throws me the error "Cannot read property 'text' of undefined" Tried to research it, but I could not find a solution or why it could throw me that issue. Is it possible for the next version to put some warnings which will be thrown and checked more easily for the specific issue or place!? image

Thank you!

ManuelDeLeon commented 3 years ago

Can you post a small service or component to reproduce the error? (remove everything not necessary to reproduce it)

Thanks

AlexKirilov commented 3 years ago

import { Component, Input } from '@angular/core'; import { FormGroup, FormControl } from '@angular/forms';

import { PortfolioEntry } from 'client/model/portfolioEntry'; import { IFileUpload } from '../../../shared/models/interfaces'; import { NoIdentifier, WrongFileFormate, NoRequiredHeaders, RequiredHeadersHelper } from '../../models/default-values';

export interface IsValid { passed: boolean; fileName?: string, errorMessage: string; }

@Component({ selector: 'csv-upload', templateUrl: './csv-upload.component.html', styleUrls: ['./csv-upload.component.scss'], }) export class CSVUploadComponent { @Input() title: string; @Input() sampleFileHref: string; @Input() requiredColumns: string[]; @Input() extraConstraint: string; @Input() checkParentValidation: (value: [string[], string[]]) => IsValid;

public files: IFileUpload[] = []; public cvsData: PortfolioEntry[] = []; public warningMessage: string; public fileName: string = '';

public form: FormGroup = new FormGroup({ file: new FormControl(), });

private uploadFiles: any; private supportedFileTypes: string[] = [ 'text/csv', 'text/x-csv', 'application/vnd.ms-excel', 'application/csv', 'application/x-csv', 'text/comma-separated-values', 'text/x-comma-separated-values', 'text/tab-separated-values', ];

private supportedExtensions: string[] = ['.csv'];

public fileBrowseHandler(files: any, input: any) { this.warningMessage = '';

if (this.checkFileType(files)) {
  this.convertFile(input);
  this.uploadFiles = files;
} else {
  this.warningMessage = WrongFileFormate;
  this.form.get('file').reset();
}

}

public deleteFile(index: number) { this.files.splice(index, 1); }

private checkFileType(files: Partial[]): boolean { for (let i = 0; i < files.length; i++) { const f = files[i] as Partial; this.fileName = f.name; if (f.type === '') { // If unable to determine MIME-type // Use the file extension to verify supported format const fileExtension = this.getFileExtension(f.name); if (!this.supportedExtensions.includes(fileExtension)) { return false; } } else { // Otherwise, use MIME-type if (!this.supportedFileTypes.includes(f.type)) { return false; } } } return true; }

private getFileExtension(fileName: string): string { const lastPeriod = fileName.lastIndexOf('.'); if (lastPeriod === -1) return ''; // No extension, returning an empty string will mean it won't get matched to supported list return fileName.substring(lastPeriod); // return rest of file name (should be extension) }

/**

export const IDENTIFERS: string[] = ['isin', 'sedol', 'tickercode', 'ticker'];

ManuelDeLeon commented 3 years ago

Please update your SimonTest extension (to v1.9.10).

Thanks