mcgilman commented on code in PR #11112:
URL: https://github.com/apache/nifi/pull/11112#discussion_r3052893510


##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/state/shared/index.ts:
##########
@@ -413,11 +414,7 @@ export interface DocumentedType {
     deprecationReason?: string;
 }
 
-export interface Bundle {
-    artifact: string;
-    group: string;
-    version: string;
-}
+export type { Bundle } from '@nifi/shared';

Review Comment:
   Can we avoid re-exporting this type and update the imports to use `shared`?



##########
nifi-frontend/src/main/frontend/apps/nifi/src/app/pages/connectors/ui/connector-table/connector-table.component.spec.ts:
##########
@@ -0,0 +1,779 @@
+/*
+ * 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 { ConnectorTable } from './connector-table.component';
+import { ConnectorAction, ConnectorActionName, ConnectorEntity, NiFiCommon } 
from '@nifi/shared';
+import { NoopAnimationsModule } from '@angular/platform-browser/animations';
+import { By } from '@angular/platform-browser';
+import { FlowConfiguration } from '../../../../state/flow-configuration';
+import { CurrentUser } from '../../../../state/current-user';
+
+describe('ConnectorTable', () => {
+    function createMockAction(name: ConnectorActionName, allowed = true, 
reasonNotAllowed?: string): ConnectorAction {
+        const action: ConnectorAction = {
+            name,
+            description: `${name} action`,
+            allowed
+        };
+        if (reasonNotAllowed !== undefined) {
+            action.reasonNotAllowed = reasonNotAllowed;
+        }
+        return action;
+    }
+
+    function createMockConnector(
+        options: {
+            id?: string;
+            name?: string;
+            type?: string;
+            state?: string;
+            canRead?: boolean;
+            canWrite?: boolean;
+            canOperate?: boolean;
+            managedProcessGroupId?: string;
+            validationErrors?: string[];
+            validationStatus?: string;
+            availableActions?: ConnectorAction[];
+        } = {}
+    ): ConnectorEntity {
+        const defaultActions: ConnectorAction[] = options.availableActions ?? [
+            createMockAction('START', true),
+            createMockAction('STOP', true),
+            createMockAction('CONFIGURE', true),
+            createMockAction('DELETE', true)
+        ];
+
+        const connector: ConnectorEntity = {
+            id: options.id || 'connector-123',
+            uri: `http://localhost/nifi-api/connectors/${options.id || 
'connector-123'}`,
+            permissions: {
+                canRead: options.canRead ?? true,
+                canWrite: options.canWrite ?? true
+            },
+            revision: { version: 1, clientId: 'client-1' },
+            bulletins: [],
+            component: {
+                id: options.id || 'connector-123',
+                type: options.type || 
'org.apache.nifi.connector.TestConnector',
+                name: options.name || 'Test Connector',
+                bundle: {
+                    group: 'org.apache.nifi',
+                    artifact: 'nifi-test-nar',
+                    version: '1.0.0'
+                },
+                state: options.state || 'STOPPED',
+                managedProcessGroupId: options.managedProcessGroupId ?? 
'pg-root-default',
+                validationErrors: options.validationErrors,
+                validationStatus: options.validationStatus,
+                availableActions: defaultActions
+            },
+            status: {
+                runStatus: options.state || 'STOPPED'
+            }
+        };
+
+        if (options.canOperate !== undefined) {
+            connector.operatePermissions = {
+                canRead: true,
+                canWrite: options.canOperate
+            };
+        }
+
+        return connector;
+    }
+
+    function createMockConnectors(): ConnectorEntity[] {
+        return [
+            createMockConnector({ id: 'connector-1', name: 'Alpha Connector' 
}),
+            createMockConnector({ id: 'connector-2', name: 'Beta Connector' }),
+            createMockConnector({ id: 'connector-3', name: 'Charlie Connector' 
})
+        ];
+    }
+
+    function createMockFlowConfiguration(
+        options: {
+            supportsManagedAuthorizer?: boolean;
+        } = {}
+    ): FlowConfiguration {
+        return {
+            supportsManagedAuthorizer: options.supportsManagedAuthorizer ?? 
true,
+            supportsConfigurableAuthorizer: true,
+            supportsConfigurableUsersAndGroups: true,
+            currentTime: '2025-01-01T00:00:00.000Z',
+            timeOffset: 0,
+            defaultBackPressureDataSizeThreshold: 1073741824,
+            defaultBackPressureObjectThreshold: 10000
+        };
+    }
+
+    function createMockCurrentUser(
+        options: {
+            canReadTenants?: boolean;
+        } = {}
+    ): CurrentUser {
+        return {
+            identity: 'test-user',
+            anonymous: false,
+            logoutSupported: true,
+            canVersionFlows: false,
+            provenancePermissions: { canRead: true, canWrite: false },
+            countersPermissions: { canRead: true, canWrite: false },
+            tenantsPermissions: { canRead: options.canReadTenants ?? true, 
canWrite: false },
+            controllerPermissions: { canRead: true, canWrite: false },
+            policiesPermissions: { canRead: true, canWrite: false },
+            systemPermissions: { canRead: true, canWrite: false },
+            parameterContextPermissions: { canRead: true, canWrite: false },
+            restrictedComponentsPermissions: { canRead: true, canWrite: false 
},
+            connectorsPermissions: { canRead: true, canWrite: true },
+            componentRestrictionPermissions: []
+        };
+    }
+
+    interface SetupOptions {
+        connectors?: ConnectorEntity[];
+        selectedConnectorId?: string;
+        initialSortColumn?: 'name' | 'type' | 'bundle' | 'state';
+        initialSortDirection?: 'asc' | 'desc';
+        flowConfiguration?: FlowConfiguration;
+        currentUser?: CurrentUser;
+    }
+
+    async function setup(options: SetupOptions = {}) {
+        const mockNiFiCommon = {
+            formatType: vi.fn().mockReturnValue('TestConnector'),
+            formatBundle: vi.fn().mockReturnValue('nifi-test-nar - 1.0.0'),
+            compareString: vi.fn((a: string, b: string) => a.localeCompare(b)),
+            isEmpty: vi.fn((arr: unknown) => !arr || (Array.isArray(arr) && 
arr.length === 0))
+        };
+
+        await TestBed.configureTestingModule({
+            imports: [ConnectorTable, NoopAnimationsModule],
+            providers: [{ provide: NiFiCommon, useValue: mockNiFiCommon }]
+        }).compileComponents();
+
+        const fixture = TestBed.createComponent(ConnectorTable);
+        const component = fixture.componentInstance;
+
+        if (options.initialSortColumn) {
+            component.initialSortColumn = options.initialSortColumn;
+        }
+        if (options.initialSortDirection) {
+            component.initialSortDirection = options.initialSortDirection;
+        }
+        if (options.selectedConnectorId !== undefined) {
+            component.selectedConnectorId = options.selectedConnectorId;
+        }
+        if (options.connectors) {
+            component.connectors = options.connectors;
+        }
+        if (options.flowConfiguration) {
+            component.flowConfiguration = options.flowConfiguration;
+        }
+        if (options.currentUser) {
+            component.currentUser = options.currentUser;
+        }
+
+        fixture.detectChanges();
+
+        return { component, fixture, mockNiFiCommon };
+    }
+
+    beforeEach(() => {
+        vi.clearAllMocks();
+    });
+
+    describe('Component initialization', () => {
+        it('should create', async () => {
+            const { component } = await setup();
+            expect(component).toBeTruthy();
+        });
+
+        it('should initialize with default sort column and direction', async 
() => {
+            const { component } = await setup();
+            expect(component.initialSortColumn).toBe('name');
+            expect(component.initialSortDirection).toBe('asc');
+        });
+
+        it('should have correct displayed columns', async () => {
+            const { component } = await setup();
+            expect(component.displayedColumns).toEqual(['moreDetails', 'name', 
'type', 'bundle', 'state', 'actions']);
+        });
+    });
+
+    describe('Validation errors', () => {
+        it('should return true for hasErrors when connector has validation 
errors', async () => {
+            const { component } = await setup();
+            const connector = createMockConnector({ validationErrors: 
['Property X is required'] });
+            expect(component.hasErrors(connector)).toBe(true);
+        });
+
+        it('should return false for hasErrors when connector has no validation 
errors', async () => {
+            const { component } = await setup();
+            const connector = createMockConnector({ validationErrors: [] });
+            expect(component.hasErrors(connector)).toBe(false);
+        });
+
+        it('should return false for hasErrors when validationErrors is 
undefined', async () => {
+            const { component } = await setup();
+            const connector = createMockConnector();
+            expect(component.hasErrors(connector)).toBe(false);
+        });
+
+        it('should return isValidating true when status is VALIDATING', async 
() => {
+            const { component } = await setup();
+            const connector = createMockConnector({
+                validationErrors: ['Error 1'],
+                validationStatus: 'VALIDATING'
+            });
+            const tipData = component.getValidationErrorsTipData(connector);
+            expect(tipData.isValidating).toBe(true);
+            expect(tipData.validationErrors).toEqual(['Error 1']);
+        });
+
+        it('should return isValidating false when status is not VALIDATING', 
async () => {
+            const { component } = await setup();
+            const connector = createMockConnector({
+                validationErrors: ['Error 1', 'Error 2'],
+                validationStatus: 'INVALID'
+            });
+            const tipData = component.getValidationErrorsTipData(connector);
+            expect(tipData.isValidating).toBe(false);
+            expect(tipData.validationErrors).toEqual(['Error 1', 'Error 2']);
+        });
+
+        it('should return empty array for validationErrors when undefined', 
async () => {
+            const { component } = await setup();
+            const connector = createMockConnector();
+            const tipData = component.getValidationErrorsTipData(connector);
+            expect(tipData.validationErrors).toEqual([]);
+        });
+    });
+
+    describe('Permission checks', () => {
+        it('should check canRead permission', async () => {
+            const { component } = await setup();
+            expect(component.canRead(createMockConnector({ canRead: true 
}))).toBe(true);
+            expect(component.canRead(createMockConnector({ canRead: false 
}))).toBe(false);
+        });
+
+        it('should check canModify permission', async () => {
+            const { component } = await setup();
+            expect(component.canModify(createMockConnector({ canWrite: true 
}))).toBe(true);
+            expect(component.canModify(createMockConnector({ canWrite: false 
}))).toBe(false);
+        });
+
+        it('should check canOperate with write permission', async () => {
+            const { component } = await setup();
+            expect(component.canOperate(createMockConnector({ canWrite: true 
}))).toBe(true);
+        });
+
+        it('should check canOperate with operate permission', async () => {
+            const { component } = await setup();
+            expect(component.canOperate(createMockConnector({ canWrite: false, 
canOperate: true }))).toBe(true);
+        });
+
+        it('should check canOperate with neither permission', async () => {
+            const { component } = await setup();
+            expect(component.canOperate(createMockConnector({ canWrite: false, 
canOperate: false }))).toBe(false);
+        });
+
+        it('should check canOperate without operatePermissions', async () => {
+            const { component } = await setup();
+            expect(component.canOperate(createMockConnector({ canWrite: false 
}))).toBe(false);
+        });
+
+        it('should check canConfigure', async () => {
+            const { component } = await setup();
+            expect(
+                component.canConfigure(createMockConnector({ availableActions: 
[createMockAction('CONFIGURE', true)] }))
+            ).toBe(true);
+            expect(
+                component.canConfigure(
+                    createMockConnector({ availableActions: 
[createMockAction('CONFIGURE', false)] })
+                )
+            ).toBe(false);
+            expect(
+                component.canConfigure(createMockConnector({ availableActions: 
[createMockAction('START', true)] }))
+            ).toBe(false);
+        });
+
+        it('should check canDelete', async () => {
+            const { component } = await setup();
+            expect(
+                component.canDelete(createMockConnector({ availableActions: 
[createMockAction('DELETE', true)] }))
+            ).toBe(true);
+            expect(
+                component.canDelete(createMockConnector({ availableActions: 
[createMockAction('DELETE', false)] }))
+            ).toBe(false);
+            expect(
+                component.canDelete(createMockConnector({ availableActions: 
[createMockAction('START', true)] }))
+            ).toBe(false);
+        });
+
+        it('should check canStart', async () => {
+            const { component } = await setup();
+            expect(
+                component.canStart(createMockConnector({ availableActions: 
[createMockAction('START', true)] }))
+            ).toBe(true);
+            expect(
+                component.canStart(createMockConnector({ availableActions: 
[createMockAction('START', false)] }))
+            ).toBe(false);
+        });
+
+        it('should check canStop', async () => {
+            const { component } = await setup();
+            expect(component.canStop(createMockConnector({ availableActions: 
[createMockAction('STOP', true)] }))).toBe(
+                true
+            );
+            expect(
+                component.canStop(createMockConnector({ availableActions: 
[createMockAction('STOP', false)] }))
+            ).toBe(false);
+        });
+
+        it('should check canDiscardConfig', async () => {
+            const { component } = await setup();
+            expect(
+                component.canDiscardConfig(
+                    createMockConnector({
+                        availableActions: 
[createMockAction('DISCARD_WORKING_CONFIGURATION', true)]
+                    })
+                )
+            ).toBe(true);
+            expect(
+                component.canDiscardConfig(
+                    createMockConnector({
+                        availableActions: 
[createMockAction('DISCARD_WORKING_CONFIGURATION', false)]
+                    })
+                )
+            ).toBe(false);
+        });
+
+        it('should check canDrain', async () => {
+            const { component } = await setup();
+            expect(
+                component.canDrain(
+                    createMockConnector({ availableActions: 
[createMockAction('DRAIN_FLOWFILES', true)] })
+                )
+            ).toBe(true);
+            expect(
+                component.canDrain(
+                    createMockConnector({ availableActions: 
[createMockAction('DRAIN_FLOWFILES', false)] })
+                )
+            ).toBe(false);
+        });
+
+        it('should check canCancelDrain', async () => {
+            const { component } = await setup();
+            expect(
+                component.canCancelDrain(
+                    createMockConnector({ availableActions: 
[createMockAction('CANCEL_DRAIN_FLOWFILES', true)] })
+                )
+            ).toBe(true);
+            expect(
+                component.canCancelDrain(
+                    createMockConnector({ availableActions: 
[createMockAction('CANCEL_DRAIN_FLOWFILES', false)] })
+                )
+            ).toBe(false);
+        });
+
+        it('should check canPurge', async () => {
+            const { component } = await setup();
+            expect(
+                component.canPurge(
+                    createMockConnector({ availableActions: 
[createMockAction('PURGE_FLOWFILES', true)] })
+                )
+            ).toBe(true);
+            expect(
+                component.canPurge(
+                    createMockConnector({ availableActions: 
[createMockAction('PURGE_FLOWFILES', false)] })
+                )
+            ).toBe(false);
+        });
+    });
+
+    describe('Data formatting', () => {
+        it('should format name when readable', async () => {
+            const { component } = await setup();
+            expect(component.formatName(createMockConnector({ name: 'My 
Connector', canRead: true }))).toBe(
+                'My Connector'
+            );
+        });
+
+        it('should return ID when not readable', async () => {
+            const { component } = await setup();
+            expect(component.formatName(createMockConnector({ id: 
'connector-xyz', canRead: false }))).toBe(
+                'connector-xyz'
+            );
+        });
+
+        it('should format type when readable', async () => {
+            const { component, mockNiFiCommon } = await setup();
+            const connector = createMockConnector({ canRead: true });
+            component.formatType(connector);
+            
expect(mockNiFiCommon.formatType).toHaveBeenCalledWith(connector.component);
+        });
+
+        it('should return empty string for type when not readable', async () 
=> {
+            const { component } = await setup();
+            expect(component.formatType(createMockConnector({ canRead: false 
}))).toBe('');
+        });
+
+        it('should format bundle when readable', async () => {
+            const { component, mockNiFiCommon } = await setup();
+            const connector = createMockConnector({ canRead: true });
+            component.formatBundle(connector);
+            
expect(mockNiFiCommon.formatBundle).toHaveBeenCalledWith(connector.component.bundle);
+        });
+
+        it('should format state when readable', async () => {
+            const { component } = await setup();
+            expect(component.formatState(createMockConnector({ state: 
'RUNNING', canRead: true }))).toBe('RUNNING');
+        });
+
+        it('should return default STOPPED state', async () => {
+            const { component } = await setup();
+            expect(component.formatState(createMockConnector({ canRead: true 
}))).toBe('STOPPED');
+        });

Review Comment:
   This test appears to be assertig the default STOPPED state but it happens to 
work because `createMockConnector` falls back to a STOPPED state when not set.



-- 
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