markobean commented on code in PR #11582:
URL: https://github.com/apache/nifi/pull/11582#discussion_r4011721970


##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/flow-designer/ui/canvas/component-connections-dialog/component-connections-dialog.component.spec.ts:
##########
@@ -0,0 +1,337 @@
+/*
+ * 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 { ComponentFixture, TestBed } from '@angular/core/testing';
+import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
+import { provideMockStore, MockStore } from '@ngrx/store/testing';
+import { of } from 'rxjs';
+import { ComponentType } from '@nifi/shared';
+
+import { ComponentConnectionsDialog } from 
'./component-connections-dialog.component';
+import { ComponentConnectionsDialogRequest, ConnectionDirection, 
ConnectionEntity } from '../../../state/flow';
+import { navigateToComponent } from '../../../state/flow/flow.actions';
+import { CanvasUtils } from '../../../service/canvas-utils.service';
+
+const COMPONENT_ID = 'a1b2c3d4-0000-0000-0000-000000000000';
+const GROUP_ID = 'e5f6a7b8-0000-0000-0000-000000000000';
+const CHILD_GROUP_ID = 'c9d0e1f2-0000-0000-0000-000000000000';
+
+interface ConnectableStub {
+    id: string;
+    name: string;
+}
+
+/**
+ * Builds a readable connection between the two supplied endpoints. The 
endpoints are reported as
+ * living in the group being viewed, which is the common case; {@link 
connectionIntoChildGroup}
+ * covers an endpoint inside a child group.
+ */
+function connection(
+    id: string,
+    source: ConnectableStub,
+    destination: ConnectableStub,
+    component: { name?: string; selectedRelationships?: string[] } = {}
+): ConnectionEntity {
+    return {
+        id,
+        permissions: { canRead: true, canWrite: true },
+        position: { x: 0, y: 0 },
+        revision: { version: 0 },
+        sourceId: source.id,
+        sourceGroupId: GROUP_ID,
+        sourceType: 'PROCESSOR',
+        destinationId: destination.id,
+        destinationGroupId: GROUP_ID,
+        destinationType: 'INPUT_PORT',
+        component: {
+            id,
+            source,
+            destination,
+            ...component
+        }
+    };
+}
+
+/**
+ * Builds a connection the current user cannot read. The API omits the 
component entirely in that case
+ * but still reports the endpoints at the top level of the entity.
+ */
+function unreadableConnection(id: string, sourceId: string, destinationId: 
string): ConnectionEntity {
+    return {
+        id,
+        permissions: { canRead: false, canWrite: false },
+        position: { x: 0, y: 0 },
+        revision: { version: 0 },
+        sourceId,
+        sourceGroupId: GROUP_ID,
+        sourceType: 'PROCESSOR',
+        destinationId,
+        destinationGroupId: GROUP_ID,
+        destinationType: 'INPUT_PORT',
+        component: null
+    };
+}
+
+/**
+ * Builds a connection from a component in the viewed group to an Input Port 
inside a child group.
+ * The canvas draws this as terminating at the child group, but the entity 
names the port.
+ */
+function connectionIntoChildGroup(
+    id: string,
+    source: ConnectableStub,
+    innerPort: ConnectableStub,
+    name: string
+): ConnectionEntity {
+    return {
+        id,
+        permissions: { canRead: true, canWrite: true },
+        position: { x: 0, y: 0 },
+        revision: { version: 0 },
+        sourceId: source.id,
+        sourceGroupId: GROUP_ID,
+        sourceType: 'PROCESSOR',
+        destinationId: innerPort.id,
+        destinationGroupId: CHILD_GROUP_ID,
+        destinationType: 'INPUT_PORT',
+        component: {
+            id,
+            name,
+            source,
+            destination: innerPort
+        }
+    };
+}
+
+interface CreatedDialog {
+    component: ComponentConnectionsDialog;
+    fixture: ComponentFixture<ComponentConnectionsDialog>;
+    store: MockStore;
+    dialogRef: { close: ReturnType<typeof vi.fn>; keydownEvents: () => 
ReturnType<typeof of> };
+}
+
+function createDialog(
+    direction: ConnectionDirection,
+    connections: ConnectionEntity[],
+    componentName = 'In'
+): CreatedDialog {
+    const dialogRequest: ComponentConnectionsDialogRequest = {
+        componentName,
+        groupId: GROUP_ID,
+        direction,
+        connections
+    };
+    const dialogRef = { close: vi.fn(), keydownEvents: () => of() };
+
+    // only formatConnectionName is exercised; the real CanvasUtils subscribes 
to canvas state on
+    // construction, which this dialog has no need of
+    const canvasUtils = {
+        formatConnectionName: (component: any): string => {
+            if (component.name) {
+                return component.name;
+            }
+            if (component.selectedRelationships) {
+                return component.selectedRelationships.join(', ');
+            }
+            return '';
+        }
+    };
+
+    TestBed.resetTestingModule();
+    TestBed.configureTestingModule({
+        imports: [ComponentConnectionsDialog],
+        providers: [
+            { provide: MAT_DIALOG_DATA, useValue: dialogRequest },
+            { provide: MatDialogRef, useValue: dialogRef },
+            { provide: CanvasUtils, useValue: canvasUtils },
+            provideMockStore({})

Review Comment:
   Refactored `component-connections-dialog.component.spec.ts` completely to 
reflect the current state of `component-connections-dialog.component.ts` and 
`component-connections-dialog.component.html`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to