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
To Be Corrected:
0. On product delete, delete trace results
1. On product delete, delete flamegraph result
2. Unit Test Add, Delete errors???
  • Loading branch information
juanfranciscocis committed Sep 6, 2024
1 parent 7887911 commit 5581dc5
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 20 deletions.
6 changes: 6 additions & 0 deletions src/app/interfaces/unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ export interface UnitTest {
state:boolean;
code:string;
title:string;
last_state_change:LastStateChange[];
}

export interface LastStateChange {
date: string;
state: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,64 @@ <H2>Choose a type of test.</H2>
</ion-col>
</ion-row>
</ion-grid>


<br>



<ion-grid>
<app-title [title]="'Unit Tests'"></app-title>
<ion-row class="lg:m-10 md:m-10">
<ion-col size="12" size-md="4" size-lg="4" class="">
<p>Created tests for product step: {{productStep}}</p>
</ion-col>
</ion-row>
<ion-row class="lg:m-10 md:m-10">
@for (unit of unitTests; track unit){
<ion-col size="12" size-md="3" size-lg="3" class="">
<ion-card>
<ion-card-header class="flex-row flex justify-between items-center">
<ion-card-title>{{unit.title}}</ion-card-title>
<ion-icon name="information-circle" class="text-xl" (click)="infoAutomateUnitState(unit.title)"></ion-icon>
</ion-card-header>
<ion-card-content class="flex flex-col justify-center items-center">
<p> Change the Test State: </p>
<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>
}
@if (!unit.state){
<ion-icon name="checkmark-circle" class="text-3xl" (click)="automateUnitState(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-card-content>
</ion-card>
</ion-col>
}
</ion-row>

<br>



<app-title [title]="'Integration Tests'"></app-title>
<ion-row class="lg:m-10 md:m-10">
<ion-col size="12" size-md="4" size-lg="4" class="">
<p>Created tests for product step: {{productStep}}</p>
</ion-col>
</ion-row>


<br>



<app-title [title]="'System Tests'"></app-title>
<ion-row class="lg:m-10 md:m-10">
<ion-col size="12" size-md="4" size-lg="4" class="">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Product} from "../../../interfaces/product";
import {SystemTestService} from "../../../services/system-test.service";
import {SystemTest} from "../../../interfaces/system-test";
import {User} from "../../../interfaces/user";
import {LoadingController} from "@ionic/angular";
import {AlertController, LoadingController} from "@ionic/angular";
import {EChartsOption} from "echarts";
import {UnitTestService} from "../../../services/unit-test.service";
import {UnitTest} from "../../../interfaces/unit-test";
Expand Down Expand Up @@ -65,7 +65,8 @@ export class SoftwareTestingChooserPage implements OnInit {
private router: Router,
private systemTestService: SystemTestService,
private loadingCtrl: LoadingController,
private unitTestService: UnitTestService
private unitTestService: UnitTestService,
private alertCtrl: AlertController
) { }

ngOnInit() {
Expand Down Expand Up @@ -252,12 +253,10 @@ export class SoftwareTestingChooserPage implements OnInit {
* Methods to show tests in each section.
*/
async getUnitTests() {
await this.showLoading()
// Get unit tests from the service
this.unitTestService.getUnitTests(this.orgName, this.productObjective, this.productStep).then(r => {
this.unitTests = r;
});
await this.hideLoading();
}
async getSystemTests() {
// Get system tests from the service
Expand All @@ -268,6 +267,33 @@ export class SoftwareTestingChooserPage implements OnInit {
}


/**
* Show Alert to tell the user a way to automate the unit test result.
*/
async infoAutomateUnitState(title: string) {
await this.showAlert('You can automate the result of this unit test (' + title + ') by sending a status update to the /unit_test_state API endpoint.', 'Automate Unit Test State');
}

/**
* Send a status update to the /unit_test_state API endpoint.
*/
async automateUnitState(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();
await this.hideLoading();
}else {
await this.hideLoading();
await this.showAlert('There was an error updating the unit test state.', 'Error');
}
});
await this.hideLoading();
}



/**
* Methods to get the user.
*/
Expand Down Expand Up @@ -314,6 +340,20 @@ export class SoftwareTestingChooserPage implements OnInit {
$event.target.complete();
}

/**
* Show an alert with the given message.
*
* @param {string} message - The message to show in the alert.
*/
async showAlert(message:string, header:string) {
const alert = await this.alertCtrl.create({
header: header,
message:message,
buttons: ['OK']
});
await alert.present();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {AiMessage} from "../../../../interfaces/ai-message";
import {getGenerativeModel, VertexAI} from "@angular/fire/vertexai-preview";
import {UnitTestService} from "../../../../services/unit-test.service";
import {ActivatedRoute} from "@angular/router";
import {LastStateChange} from "../../../../interfaces/unit-test";

@Component({
selector: 'app-create-unit-test',
Expand Down Expand Up @@ -152,6 +153,14 @@ export class CreateUnitTestPage implements OnInit {
async saveUnitTest() {
await this.showLoading();

let date = new Date();
let srtDate = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();

const lastState:LastStateChange = {
date: srtDate,
state: false
}

const user = localStorage.getItem('user') ? JSON.parse(localStorage.getItem('user') || '{}') : null;
if (!user) {
return;
Expand All @@ -163,7 +172,8 @@ export class CreateUnitTestPage implements OnInit {
code: this.myUnitTest,
state: false,
type: 'unit-test',
title: this.title
title: this.title,
last_state_change: [lastState]
});
await this.hideLoading();
await this.showAlert('Your Unit Test saved', 'Unit Test Saved');
Expand All @@ -179,7 +189,8 @@ export class CreateUnitTestPage implements OnInit {
code: this.aiMessages[0].message,
state: false,
type: 'unit-test',
title: this.title
title: this.title,
last_state_change: [lastState]
});


Expand Down
22 changes: 14 additions & 8 deletions src/app/services/system-test.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ export class SystemTestService {
const docSnap = await getDoc(docRef);
if (docSnap.exists()) {
const data = docSnap.data();

if (!data[productStep]) {
data[productStep] = [systemTest];
await setDoc(docRef, data);
console.log('Document created with ID: ', docRef.id);
return;
}

//add to the array
const arr = data[productStep] //get the array
console.log(arr);
arr.push(systemTest); //add the new system test
await setDoc(docRef, { [productStep]: arr }); //update the array key:productStep with the new array
data[productStep].push(systemTest);
await setDoc(docRef, data);
console.log('Document updated with ID: ', docSnap.id);


} else {
console.log('No such document!');
//create the document
Expand Down Expand Up @@ -139,10 +147,8 @@ export class SystemTestService {
let docSnap = await getDoc(docRef);
if (docSnap.exists()) {
let data = docSnap.data();
let arr = data[productStep];
let index = arr.indexOf(systemTest);
arr.splice(index, 1);
await setDoc(docRef, {[productStep]: arr});
data[productStep] = data[productStep].filter((test: { title: string; }) => test.title !== systemTest.title);
await setDoc(docRef, data);
}

// Delete the system test from the system_tests_history collection
Expand Down
34 changes: 33 additions & 1 deletion src/app/services/unit-test.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ export class UnitTestService {
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();
let data = docSnap.data();
if (!data[productStep]) {
//there is data add a new key with the array
data[productStep] = [unitTest];
await setDoc(docRef, data);
console.log('Document created with ID: ', docRef.id);
return;
}
//add to the array
const arr = data[productStep] //get the array
console.log(arr);
Expand All @@ -42,4 +49,29 @@ export class UnitTestService {
}
return [];
}

async updateUnitTestState(orgName: string, productObjective: string, productStep: string, title: string) {
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();
const arr = data[productStep];
for (let i = 0; i < arr.length; i++){
if (arr[i].title === title){
arr[i].state = !arr[i].state;

const date = new Date();
const srtDate = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();

arr[i]. last_state_change.push({
date: srtDate,
state: arr[i].state
});
await setDoc(docRef, { [productStep]: arr });
return true;
}
}
}
return false;
}
}
Loading

0 comments on commit 5581dc5

Please sign in to comment.