submitTCtoDB() {
console.log("The selected file list contains: " + this.selectedFileList)
this.readFile().then(() => {
alert("ReadFile has finished, now submitting TC");
this.submitTC()
});
}
readFile() {
return new Promise((resolve, reject) => {
for (let i = 0; i < this.selectedFileList.length; i++) {
let file = this.selectedFileList[i];
alert("File in readFile: " + file.name)
let fileReader = new FileReader();
fileReader.onload = () => {
this.fileContent = fileReader.result;
if (this.fileContent.indexOf("END DATA | BEGIN RESULTS") != -1) {
alert("Multiple test cases found in the file " + file.name + ". Please separate/save the test cases in Calc Builder and then reimport.");
const index: number = this.selectedFileList.indexOf(file);
if (index > -1) {
this.selectedFileList.splice(index, 1);
}
console.log(this.fileContent);
}
resolve(this.fileContent);
}
fileReader.readAsText(file);
}
});
}
I am encountering an issue where the submitTC() method is being invoked prematurely, before the readFile() method has completed. I suspect that the use of .then() inside the submitTCtoDB() method is causing this problem.
It seems like there may be an error in the way .then() or promises are being utilized in this context.
The desired functionality is to ensure that the submitTC method is only called once the readFile method has finished reading and processing all the files. Any assistance would be greatly appreciated.