Skip to content

Commit

Permalink
New Features:
Browse files Browse the repository at this point in the history
New Pages:
Bugs Corrected:
1.Add, Delete, Update System Service
2. Unit Test Add, Delete errors
To Be Corrected:
0. On product delete, delete trace results
1. On product delete, delete flamegraph result
  • Loading branch information
juanfranciscocis committed Sep 6, 2024
1 parent 5581dc5 commit fe7e25a
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ <H2>Choose a type of test.</H2>
<div class="flex flex-row justify-center items-center">
@if (unit.state){
<ion-icon name="checkmark-circle" class="text-green-600 text-3xl"></ion-icon>
<ion-icon name="close-circle" class="text-3xl" (click)="automateUnitState(unit.title)"></ion-icon>
<ion-icon name="close-circle" class="text-3xl" (click)="updateUnitState(unit.title)"></ion-icon>
}
@if (!unit.state){
<ion-icon name="checkmark-circle" class="text-3xl" (click)="automateUnitState(unit.title)"></ion-icon>
<ion-icon name="checkmark-circle" class="text-3xl" (click)="updateUnitState(unit.title)"></ion-icon>
<ion-icon name="close-circle" class="text-red-800 text-3xl"></ion-icon>
}
</div>
</ion-card-content>
<ion-card-content>
<ion-button color="danger" expand="block" (click)="deleteTest(unit.title)">Delete Test</ion-button>
<ion-button color="danger" expand="block" (click)="deleteUnitTest(unit.title)">Delete Test</ion-button>
</ion-card-content>
</ion-card>
</ion-col>
Expand Down Expand Up @@ -154,7 +154,7 @@ <h1>{{ failedSystemTests }}</h1>
<ion-card-content>
<ion-button color="primary" expand="block" (click)="navigateToViewHistorySystemTest(test.title)">View Test Results</ion-button>
<ion-button color="success" expand="block" (click)="navigateToExecuteSystemTest(test.title)">Execute Test</ion-button>
<ion-button color="danger" expand="block" (click)="deleteTest(test.title)">Delete Test</ion-button>
<ion-button color="danger" expand="block" (click)="deleteSystemTest(test.title)">Delete Test</ion-button>
</ion-card-content>
</ion-card>
</ion-col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,10 @@ export class SoftwareTestingChooserPage implements OnInit {
}

/**
* Send a status update to the /unit_test_state API endpoint.
* Send a status update and save to the database.
*/
async automateUnitState(title: string) {
async updateUnitState(title: string) {
await this.showLoading();
// Send a status update to the /unit_test_state API endpoint
await this.unitTestService.updateUnitTestState(this.orgName, this.productObjective, this.productStep, title).then(async r => {
if (r) {
await this.getUnitTests();
Expand All @@ -292,6 +291,34 @@ export class SoftwareTestingChooserPage implements OnInit {
await this.hideLoading();
}

/**
* Methods to delete tests.
*/
async deleteUnitTest(title: string) {
await this.showLoading() ;
let unitTest = this.unitTests.find((unitTest: { title: string; }) => unitTest.title === title);
if (!unitTest) return;
await this.unitTestService.deleteUnitTest(this.orgName, this.productObjective, this.productStep,unitTest).then(async () => {
await this.getUnitTests();
});
await this.hideLoading();
}
async deleteSystemTest(title: string) {
await this.showLoading();
let systemTest = this.systemTests.find((systemTest: { title: string; }) => systemTest.title === title);
if (!systemTest) return;
await this.systemTestService.deleteSystemTest(this.orgName, this.productObjective, this.productStep,systemTest).then(async () => {
await this.getSystemTests();
});
await this.calculatePassedSystemTests();
await this.calculateGraphDataSystemTests();
await this.graphSystemTests();
await this.hideLoading();
}






/**
Expand All @@ -305,15 +332,6 @@ export class SoftwareTestingChooserPage implements OnInit {
}


async deleteTest(title: string) {
let systemTest = this.systemTests.find((systemTest: { title: string; }) => systemTest.title === title);
if (!systemTest) return;
await this.systemTestService.deleteSystemTest(this.orgName, this.productObjective, this.productStep,systemTest).then(async () => {
await this.getSystemTests();
});
await this.calculatePassedSystemTests();
await this.calculateGraphDataSystemTests();
}

/**
* Show a loading spinner.
Expand Down
53 changes: 39 additions & 14 deletions src/app/services/unit-test.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ export class UnitTestService {
console.log('Document created with ID: ', docRef.id);
return;
}

//if there is a unit test with the same title, return
for (let i = 0; i < data[productStep].length; i++){
if (data[productStep][i].title === unitTest.title){
return;
}
}

//add to the array
const arr = data[productStep] //get the array
console.log(arr);
arr.push(unitTest); //add the new system test
await setDoc(docRef, { [productStep]: arr }); //update the array key:productStep with the new array
data[productStep].push(unitTest); //add the new system test
await setDoc(docRef, data);
console.log('Document updated with ID: ', docSnap.id);
} else {
console.log('No such document!');
Expand All @@ -55,19 +61,38 @@ export class UnitTestService {
const docSnap = await getDoc(docRef);
if (docSnap.exists()){
const data = docSnap.data();
const arr = data[productStep];
for (let i = 0; i < arr.length; i++){
if (arr[i].title === title){
arr[i].state = !arr[i].state;
for (let i = 0; i < data[productStep].length; i++){
if (data[productStep][i].title === title){
data[productStep][i].state = !data[productStep][i].state;

const date = new Date();
const srtDate = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
let pushDate = date.getDate() + '/' + date.getMonth() + '/' + date.getFullYear() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
const last_state_change = {
date: pushDate,
state: data[productStep][i].state
}



data[productStep][i].last_state_change = [...data[productStep][i].last_state_change, last_state_change];
await setDoc(docRef, data);

return true;
}
}
}
return false;
}

arr[i]. last_state_change.push({
date: srtDate,
state: arr[i].state
});
await setDoc(docRef, { [productStep]: arr });
async deleteUnitTest(orgName: string, productObjective: string, productStep: string, unitTest: UnitTest) {
const docRef = doc(this.firestore, 'teams', orgName, 'products', productObjective, 'software_testing', 'unit_tests');
const docSnap = await getDoc(docRef);
if (docSnap.exists()) {
const data = docSnap.data();
for (let i = 0; i < data[productStep].length; i++) {
if (data[productStep][i].title === unitTest.title) {
data[productStep].splice(i, 1);
await setDoc(docRef, data);
return true;
}
}
Expand Down
Loading

0 comments on commit fe7e25a

Please sign in to comment.