This is an automated email from the ASF dual-hosted git repository. zehnder pushed a commit to branch 4139-allow-manual-upload-of-sample-event-for-adapter-schema-inference in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 6148bfb30ce2deb3c48be857d8951d6cd49c469a Author: Philipp Zehnder <[email protected]> AuthorDate: Fri Jan 30 21:55:31 2026 +0100 fix(#4139): Add cypress test for upload sample --- ui/cypress/support/utils/connect/ConnectBtns.ts | 18 +++ ui/cypress/support/utils/connect/ConnectUtils.ts | 11 ++ ui/cypress/tests/connect/uploadSampleEvent.spec.ts | 131 +++++++++++++++++++++ .../adapter-configuration-state.service.ts | 3 +- .../adapter-configuration.component.ts | 8 +- .../upload-sample-event-dialog.component.html | 1 + 6 files changed, 168 insertions(+), 4 deletions(-) diff --git a/ui/cypress/support/utils/connect/ConnectBtns.ts b/ui/cypress/support/utils/connect/ConnectBtns.ts index 9caf3610e6..a036502496 100644 --- a/ui/cypress/support/utils/connect/ConnectBtns.ts +++ b/ui/cypress/support/utils/connect/ConnectBtns.ts @@ -272,6 +272,24 @@ export class ConnectBtns { }); } + public static uploadSampleBtn() { + return cy.dataCy('connect-upload-sample-button', { + timeout: 10000, + }); + } + + public static uploadSampleDialogTextarea() { + return cy.dataCy('upload-sample-event-textarea', { + timeout: 10000, + }); + } + + public static uploadSampleDialogSubmitBtn() { + return cy.dataCy('upload-sample-event-submit', { + timeout: 10000, + }); + } + public static configureFieldsEventPreviewResult() { return cy.dataCy('configure-fields-event-preview-result', { timeout: 10000, diff --git a/ui/cypress/support/utils/connect/ConnectUtils.ts b/ui/cypress/support/utils/connect/ConnectUtils.ts index 97f0e0635e..4e635d8758 100644 --- a/ui/cypress/support/utils/connect/ConnectUtils.ts +++ b/ui/cypress/support/utils/connect/ConnectUtils.ts @@ -409,6 +409,17 @@ export class ConnectUtils { .type(script); } + public static uploadSampleEvent(samplePayload: string) { + ConnectBtns.uploadSampleBtn().click(); + ConnectBtns.uploadSampleDialogTextarea() + .should('be.visible') + .clear() + .type(samplePayload, { parseSpecialCharSequences: false }); + ConnectBtns.uploadSampleDialogSubmitBtn() + .should('not.be.disabled') + .click(); + } + public static addScriptAsScriptTemplate( templateName: string, script: string, diff --git a/ui/cypress/tests/connect/uploadSampleEvent.spec.ts b/ui/cypress/tests/connect/uploadSampleEvent.spec.ts new file mode 100644 index 0000000000..06ccb5c6cd --- /dev/null +++ b/ui/cypress/tests/connect/uploadSampleEvent.spec.ts @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 { AdapterBuilder } from '../../support/builder/AdapterBuilder'; +import { ConnectUtils } from '../../support/utils/connect/ConnectUtils'; +import { ConnectBtns } from '../../support/utils/connect/ConnectBtns'; +import { SharedBtns } from '../../support/utils/shared/SharedBtns'; +import { SharedUtils } from '../../support/utils/shared/SharedUtils'; + +describe('Upload sample event during schema configuration', () => { + beforeEach('Setup Test', () => { + cy.initStreamPipesTest(); + + const adapterConfiguration = + buildMachineDataSimulator('Upload Sample Test'); + setupAdapter(adapterConfiguration); + }); + + it('Uses uploaded sample and refreshes fields on warning', () => { + ConnectBtns.configureSchemaNextBtn().click(); + ConnectUtils.eventSchemaWithFieldsShouldBeVisible(); + ConnectBtns.configureFieldsBackBtn().click(); + + uploadSample(); + + ConnectBtns.configureSchemaEventPreviewOriginal().should( + 'contain.text', + '"uploadedSample": true', + ); + + ConnectBtns.configureSchemaNextBtn().click(); + SharedUtils.confirmDialogVisible(); + SharedBtns.confirmDialogConfirmBtn().click(); + + ConnectUtils.eventSchemaWithFieldsShouldBeVisible(); + ConnectBtns.configureFieldsEventPreviewResult().should( + 'contain.text', + 'uploadedSample', + ); + }); + + it('Uses uploaded sample with script enabled after fields roundtrip', () => { + ConnectBtns.scriptActiveToggle().click(); + + ConnectBtns.configureSchemaNextBtn().click(); + ConnectUtils.eventSchemaWithFieldsShouldBeVisible(); + ConnectBtns.configureFieldsBackBtn().click(); + + uploadSample(); + + ConnectBtns.configureSchemaEventPreviewOriginal().should( + 'contain.text', + 'uploadedSample', + ); + ConnectBtns.configureSchemaEventPreviewResult().should( + 'contain.text', + 'uploadedSample', + ); + + ConnectBtns.configureSchemaNextBtn().click(); + SharedUtils.confirmDialogVisible(); + SharedBtns.confirmDialogConfirmBtn().click(); + + ConnectUtils.eventSchemaWithFieldsShouldBeVisible(); + ConnectBtns.configureFieldsEventPreviewResult().should( + 'contain.text', + 'uploadedSample', + ); + }); + + it('Uses uploaded sample with script enabled without fields roundtrip', () => { + ConnectBtns.scriptActiveToggle().click(); + + uploadSample(); + + ConnectBtns.configureSchemaEventPreviewOriginal().should( + 'contain.text', + 'uploadedSample', + ); + ConnectBtns.configureSchemaEventPreviewResult().should( + 'contain.text', + 'uploadedSample', + ); + + ConnectBtns.configureSchemaNextBtn().click(); + + ConnectUtils.eventSchemaWithFieldsShouldBeVisible(); + ConnectBtns.configureFieldsEventPreviewResult().should( + 'contain.text', + 'uploadedSample', + ); + }); + + const buildMachineDataSimulator = (name: string) => + AdapterBuilder.create('Machine_Data_Simulator') + .setName(name) + .setTimestampProperty('timestamp') + .addInput('input', 'wait-time-ms', '1000') + .build(); + + const setupAdapter = (adapterConfiguration: any) => { + ConnectUtils.goToConnect(); + ConnectUtils.goToNewAdapterPage(); + ConnectUtils.selectAdapter(adapterConfiguration.adapterType); + ConnectUtils.configureAdapter(adapterConfiguration); + ConnectBtns.configureSchemaEventPreviewOriginal().should('be.visible'); + }; + + const uploadSample = () => { + const uploadedSample = JSON.stringify({ + uploadedSample: true, + temperature: 42, + }); + ConnectUtils.uploadSampleEvent(uploadedSample); + }; +}); diff --git a/ui/src/app/connect/components/adapter-configuration/adapter-configuration-state-service/adapter-configuration-state.service.ts b/ui/src/app/connect/components/adapter-configuration/adapter-configuration-state-service/adapter-configuration-state.service.ts index b5fbc538f8..5468092725 100644 --- a/ui/src/app/connect/components/adapter-configuration/adapter-configuration-state-service/adapter-configuration-state.service.ts +++ b/ui/src/app/connect/components/adapter-configuration/adapter-configuration-state-service/adapter-configuration-state.service.ts @@ -454,8 +454,7 @@ export class AdapterConfigurationStateService { isGettingSample: false, adapterSettingsChanged: false, adapterSettingsString: JSON.stringify(updatedAdapter.config), - transformationConfigurationChanged: - transformationConfigurationChanged, + transformationConfigurationChanged, sampleFieldStatusInfos: null, sampleError: null, }); diff --git a/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.ts b/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.ts index 075f488a69..268ef7303a 100644 --- a/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.ts +++ b/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.ts @@ -101,10 +101,14 @@ export class AdapterConfigurationComponent implements OnInit, OnDestroy { } nextConfigureSchema() { + const adapter = + this.stateService.state().adapterDescription ?? + this.adapterDescription; + if (this.stateService.state().autoLoadSchema) { - this.stateService.getEventSchema(this.adapterDescription); + this.stateService.getEventSchema(adapter); } else { - this.stateService.updateEventPreview(this.adapterDescription); + this.stateService.updateEventPreview(adapter); } if (this.stateService.state().transformationConfigurationChanged) { diff --git a/ui/src/app/connect/dialog/upload-sample-event-dialog/upload-sample-event-dialog.component.html b/ui/src/app/connect/dialog/upload-sample-event-dialog/upload-sample-event-dialog.component.html index 152420c11a..21a2a981e5 100644 --- a/ui/src/app/connect/dialog/upload-sample-event-dialog/upload-sample-event-dialog.component.html +++ b/ui/src/app/connect/dialog/upload-sample-event-dialog/upload-sample-event-dialog.component.html @@ -26,6 +26,7 @@ (ngModelChange)="samplePayload.set($event)" class="code-input" rows="12" + data-cy="upload-sample-event-textarea" ></textarea> @if (isSampleInvalid()) { <sp-alert-banner
