From 66d60a5c5819d0323a648f4c469b7c06bdcc9aa3 Mon Sep 17 00:00:00 2001 From: Raul Marquez <130402456+raul-marquez-csa@users.noreply.github.com> Date: Fri, 10 Nov 2023 09:32:26 -0800 Subject: [PATCH] Updates create and repeat test run execution to match backend changes (#13) --- .../test-details/test-details.component.ts | 10 ++-- .../test-execution-history.component.ts | 35 +++++++------ src/app/components/test/test.sandbox.ts | 45 ++++++++-------- src/app/shared/core_apis/test-run.ts | 51 ++++++++++--------- src/app/shared/test-run-utils.ts | 51 ++++++++++--------- 5 files changed, 101 insertions(+), 91 deletions(-) diff --git a/src/app/components/test/test-details/test-details.component.ts b/src/app/components/test/test-details/test-details.component.ts index ec89fc7..6284453 100644 --- a/src/app/components/test/test-details/test-details.component.ts +++ b/src/app/components/test/test-details/test-details.component.ts @@ -112,9 +112,13 @@ export class TestDetailsComponent { } } } - const testConfig: any = await this.testSandbox.createTestRunConfig(this.selectedDataFinal); - this.testSandbox.createTestRunExecution(this.callbackForStartTestExecution.bind(this), - testConfig.id, this.testName, this.testRunAPI.getSelectedOperator().id, this.description); + this.testSandbox.createTestRunExecution( + this.callbackForStartTestExecution.bind(this), + this.selectedDataFinal, + this.testName, + this.testRunAPI.getSelectedOperator().id, + this.description + ); } } } diff --git a/src/app/components/test/test-execution-history/test-execution-history.component.ts b/src/app/components/test/test-execution-history/test-execution-history.component.ts index 23e14ad..289b960 100644 --- a/src/app/components/test/test-execution-history/test-execution-history.component.ts +++ b/src/app/components/test/test-execution-history/test-execution-history.component.ts @@ -1,19 +1,19 @@ -/** - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/** + * + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import { Component, Injectable } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; import { DialogService } from 'primeng/dynamicdialog'; @@ -229,8 +229,7 @@ export class TestExecutionHistoryComponent { const title: any = executionData.title.slice(0, executionData.title.length - 20); this.sharedAPI.setAppState(APP_STATE[1]); this.sharedAPI.setWebSocketLoader(true); - this.testSandbox.createTestRunExecution(this.repeatExecution.bind(this), executionData.test_run_config_id, - title, executionData.operator.id, executionData.description); + this.testSandbox.repeatTestRunExecution(this.repeatExecution.bind(this), executionData.id); } } repeatExecution(execId: any) { diff --git a/src/app/components/test/test.sandbox.ts b/src/app/components/test/test.sandbox.ts index 7851353..77f5c04 100644 --- a/src/app/components/test/test.sandbox.ts +++ b/src/app/components/test/test.sandbox.ts @@ -1,19 +1,19 @@ -/** - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/** + * + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import { Injectable } from '@angular/core'; import { SharedAPI } from 'src/app/shared/core_apis/shared'; import { TestRunAPI } from 'src/app/shared/core_apis/test-run'; @@ -135,15 +135,14 @@ export class TestSandbox { setDefaultSelectedData(selectedData: any) { this.testRunStore.setSelectedTestCase(selectedData); } - // Trigger core_apis function to create new test-run-config - async createTestRunConfig(requestJson: any) { - const testConfigData = await this.testRunAPI.createTestRunConfig(requestJson); - return testConfigData; - } // Trigger core_apis function to create new test-run-executions - createTestRunExecution(callback: any, testConfigId: number, testName: string, operatorId: any, description: any) { + createTestRunExecution(callback: any, selectedDataFinal: any, testName: string, operatorId: any, description: any) { const selectedProjectId = this.sharedAPI.getSelectedProjectType().id; - this.testRunAPI.createTestRunExecution(callback, testConfigId, selectedProjectId, testName, operatorId, description); + this.testRunAPI.createTestRunExecution(callback, selectedDataFinal, selectedProjectId, testName, operatorId, description); + } + // Trigger core_apis function to repeat test-run-executions + repeatTestRunExecution(callback: any, testExecutionId: number) { + this.testRunAPI.repeatTestRunExecution(callback, testExecutionId); } // Start test execution and set initial running testcase data setRunningTestsDataOnStart(execId: any) { diff --git a/src/app/shared/core_apis/test-run.ts b/src/app/shared/core_apis/test-run.ts index a3a0c01..35caa07 100644 --- a/src/app/shared/core_apis/test-run.ts +++ b/src/app/shared/core_apis/test-run.ts @@ -1,19 +1,19 @@ -/** - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/** + * + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import { Injectable } from '@angular/core'; import { TestRunStore } from 'src/app/store/test-run-store'; import { TestRunService } from '../test-run-utils'; @@ -243,15 +243,20 @@ export class TestRunAPI { ); } - // Create new test run config - async createTestRunConfig(requestJson: any) { - const testConfigData = await this.testRunService.createTestRunConfig(requestJson); - return testConfigData; + // Create new test run execution + createTestRunExecution(callback: any, selectedDataFinal: any, selectedProjectId: number, testName: string, operatorId: any, description: any) { + return this.testRunService.createTestRunExecution(selectedDataFinal, selectedProjectId, testName, operatorId, description).subscribe( + (data) => { + callback(data.id); + return data; + }, err => { + this.sharedService.showPopUp(); + }); } - // Create new test run execution - createTestRunExecution(callback: any, testConfigId: number, selectedProjectId: number, testName: string, operatorId: any, description: any) { - return this.testRunService.createTestRunExecution(testConfigId, selectedProjectId, testName, operatorId, description).subscribe( + // Repeats a test run execution + repeatTestRunExecution(callback: any, testExecutionId: number) { + return this.testRunService.repeatTestRunExecution(testExecutionId).subscribe( (data) => { callback(data.id); return data; diff --git a/src/app/shared/test-run-utils.ts b/src/app/shared/test-run-utils.ts index c05aa22..cd2cf2b 100644 --- a/src/app/shared/test-run-utils.ts +++ b/src/app/shared/test-run-utils.ts @@ -1,19 +1,19 @@ -/** - * - * Copyright (c) 2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/** + * + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; @@ -37,23 +37,26 @@ export class TestRunService { getDefaultTestCases(): Observable { return this.http.get(getBaseUrl() + 'test_collections'); } - async createTestRunConfig(requestJson: any) { - const testConfigData = await this.http.post(getBaseUrl() + 'test_run_configs', requestJson).toPromise(); - return testConfigData; - } - createTestRunExecution(testConfigId: number, selectedProjectId: number, testName: string, operatorId: any, + createTestRunExecution(selectedDataFinal: any, selectedProjectId: number, testName: string, operatorId: any, description: any): Observable { /* eslint-disable @typescript-eslint/naming-convention */ + const selected_tests = selectedDataFinal.selected_tests; const requestJson = { 'test_run_execution_in': { - 'title': testName + '_' + getTimeStamp(), 'test_run_config_id': testConfigId, - 'project_id': selectedProjectId, 'description': description, 'operator_id': operatorId - } + 'title': testName + '_' + getTimeStamp(), + 'project_id': selectedProjectId, + 'description': description, + 'operator_id': operatorId + }, + selected_tests }; /* eslint-enable @typescript-eslint/naming-convention */ return this.http.post(getBaseUrl() + 'test_run_executions', requestJson); } + repeatTestRunExecution(testExecutionId: number): Observable { + return this.http.post(getBaseUrl() + `test_run_executions/${testExecutionId}/repeat`, {}); + } startTestRunExecution(id: number): Observable { return this.http.post(getBaseUrl() + 'test_run_executions/' + id + '/start', {}); }