You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2026/10/01 10:36:01 UTC
(streampipes) branch dev updated: fix: Update state after adapter template import (#5051)
This is an automated email from the ASF dual-hosted git repository.
dominikriemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new 8db54a5639 fix: Update state after adapter template import (#5051)
8db54a5639 is described below
commit 8db54a56396cc57d088cbc85d71710809fcbddf5
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Thu Oct 1 12:35:54 2026 +0200
fix: Update state after adapter template import (#5051)
---
.../adapter-configuration.component.html | 2 +-
.../adapter-configuration.component.spec.ts | 121 +++++++++++++++++++++
.../adapter-configuration.component.ts | 5 +
.../adapter-settings/adapter-settings.component.ts | 2 +-
4 files changed, 128 insertions(+), 2 deletions(-)
diff --git a/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.html b/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.html
index eb48509770..613ff1d148 100644
--- a/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.html
+++ b/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.html
@@ -80,7 +80,7 @@
adapterConfigurationState.adapterDescription
"
(updateAdapterDescriptionEmitter)="
- adapterDescription = $event
+ updateAdapterDescription($event)
"
(nextEmitter)="nextAdapterSettings()"
(cancelEmitter)="navigateToAdapterCatalog()"
diff --git a/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.spec.ts b/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.spec.ts
new file mode 100644
index 0000000000..b932eff54e
--- /dev/null
+++ b/ui/src/app/connect/components/adapter-configuration/adapter-configuration.component.spec.ts
@@ -0,0 +1,121 @@
+/*
+ * 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 { TestBed } from '@angular/core/testing';
+import { MatDialog } from '@angular/material/dialog';
+import { Router } from '@angular/router';
+import { TranslateService } from '@ngx-translate/core';
+import {
+ AdapterDescription,
+ ConnectScriptLanguagesService,
+ FreeTextStaticProperty,
+ PipelineElementAssetService,
+ PipelineElementTemplateService,
+} from '@streampipes/platform-services';
+import { DialogService } from '@streampipes/shared-ui';
+import { NEVER, of } from 'rxjs';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { ShepherdService } from '../../../services/tour/shepherd.service';
+import { AdapterTemplateService } from '../../services/adapter-template.service';
+import { EventSchemaDiffService } from '../../services/event-schema-diff.service';
+import { RestService } from '../../services/rest.service';
+import { AdapterConfigurationComponent } from './adapter-configuration.component';
+import { AdapterConfigurationStateService } from './adapter-configuration-state-service/adapter-configuration-state.service';
+import { AdapterSettingsComponent } from './adapter-settings/adapter-settings.component';
+
+describe('Adapter template configuration', () => {
+ let component: AdapterConfigurationComponent;
+ let settings: AdapterSettingsComponent;
+ let state: AdapterConfigurationStateService;
+ let getSampleEvents: ReturnType<typeof vi.fn>;
+ let original: AdapterDescription;
+
+ function adapterWithInterval(value: string): AdapterDescription {
+ const interval = new FreeTextStaticProperty();
+ interval.internalName = 'PULLING_INTERVAL';
+ interval.value = value;
+ return {
+ config: [interval],
+ dataStream: { eventSchema: { eventProperties: [] } },
+ transformationConfig: { inputs: [], outputs: [] },
+ } as AdapterDescription;
+ }
+
+ beforeEach(() => {
+ getSampleEvents = vi.fn(() => NEVER);
+ TestBed.configureTestingModule({
+ providers: [
+ { provide: Router, useValue: {} },
+ { provide: ShepherdService, useValue: { trigger: vi.fn() } },
+ { provide: TranslateService, useValue: {} },
+ { provide: DialogService, useValue: {} },
+ { provide: MatDialog, useValue: {} },
+ { provide: PipelineElementAssetService, useValue: {} },
+ { provide: ConnectScriptLanguagesService, useValue: {} },
+ { provide: EventSchemaDiffService, useValue: {} },
+ { provide: RestService, useValue: { getSampleEvents } },
+ { provide: AdapterTemplateService, useValue: {} },
+ {
+ provide: PipelineElementTemplateService,
+ useValue: { getPipelineElementTemplates: () => of([]) },
+ },
+ ],
+ });
+ state = TestBed.inject(AdapterConfigurationStateService);
+ component = TestBed.runInInjectionContext(
+ () => new AdapterConfigurationComponent(),
+ );
+ settings = TestBed.runInInjectionContext(
+ () => new AdapterSettingsComponent(),
+ );
+ vi.spyOn(component, 'goForward').mockImplementation(() => {});
+ original = adapterWithInterval(null);
+ component.adapterDescription = original;
+ state.initializeCreateMode(original);
+ settings.adapterDescription = original;
+ settings.ngOnInit();
+ settings.updateAdapterDescriptionEmitter.subscribe(adapter =>
+ component.updateAdapterDescription(adapter),
+ );
+ });
+
+ it('requests sample data with the configuration restored from a template', () => {
+ settings.afterTemplateReceived(adapterWithInterval('1000'));
+
+ component.nextAdapterSettings();
+
+ expect(getSampleEvents).toHaveBeenCalledOnce();
+ const requested = getSampleEvents.mock.calls[0][0];
+ expect(requested.config[0].value).toBe('1000');
+ expect(state.state().adapterDescription.config).toEqual(
+ requested.config,
+ );
+ expect(original.config[0]).toHaveProperty('value', null);
+ });
+
+ it('synchronizes the restored configuration when clearing a template', () => {
+ (original.config[0] as FreeTextStaticProperty).value = '2000';
+ settings.afterTemplateReceived(adapterWithInterval('1000'));
+
+ settings.loadTemplate({ value: false });
+ component.nextAdapterSettings();
+
+ expect(getSampleEvents.mock.calls[0][0].config[0].value).toBe('2000');
+ expect(settings.selectedTemplate).toBe(false);
+ });
+});
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 5841a0670c..77cd1c0e8b 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
@@ -258,6 +258,11 @@ export class AdapterConfigurationComponent implements OnInit, OnDestroy {
this.stateService.reset();
}
+ updateAdapterDescription(adapter: AdapterDescription): void {
+ this.adapterDescription = adapter;
+ this.stateService.updateAdapter(adapter);
+ }
+
nextAdapterSettings() {
const adapter =
this.stateService.state().adapterDescription ??
diff --git a/ui/src/app/connect/components/adapter-configuration/adapter-settings/adapter-settings.component.ts b/ui/src/app/connect/components/adapter-configuration/adapter-settings/adapter-settings.component.ts
index fc21ca8bde..f5d312ea41 100644
--- a/ui/src/app/connect/components/adapter-configuration/adapter-settings/adapter-settings.component.ts
+++ b/ui/src/app/connect/components/adapter-configuration/adapter-settings/adapter-settings.component.ts
@@ -157,7 +157,7 @@ export class AdapterSettingsComponent implements OnInit {
loadTemplate(event: any) {
if (!event.value) {
- this.adapterDescription = { ...this.cachedAdapterDescription };
+ this.afterTemplateReceived({ ...this.cachedAdapterDescription });
this.selectedTemplate = false;
} else {
this.selectedTemplate = event.value;