This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch 
3116-refactor-staticruntimeresolvabletreeinput-into-smaller-subcomponents
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to 
refs/heads/3116-refactor-staticruntimeresolvabletreeinput-into-smaller-subcomponents
 by this push:
     new fab0274a10 refactor(#3116): Add test to validate tree view of opc ua 
and buttons
fab0274a10 is described below

commit fab0274a10a36144c08f65fd8f7e913ec066c3fc
Author: Philipp Zehnder <[email protected]>
AuthorDate: Fri Aug 9 23:02:27 2024 +0200

    refactor(#3116): Add test to validate tree view of opc ua and buttons
---
 .../support/utils/userInput/StaticPropertyUtils.ts | 32 +-------
 .../utils/userInput/TreeStaticPropertyUtils.ts     | 78 +++++++++++++++++++
 .../tests/connect/opcAdapterConfiguration.spec.ts  | 90 ++++++++++++++++++++++
 .../static-tree-input.component.html               |  1 +
 4 files changed, 171 insertions(+), 30 deletions(-)

diff --git a/ui/cypress/support/utils/userInput/StaticPropertyUtils.ts 
b/ui/cypress/support/utils/userInput/StaticPropertyUtils.ts
index d29f1aaeb4..e3ecf69be1 100644
--- a/ui/cypress/support/utils/userInput/StaticPropertyUtils.ts
+++ b/ui/cypress/support/utils/userInput/StaticPropertyUtils.ts
@@ -1,21 +1,3 @@
-/*
- *  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.
- *
- */
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -35,7 +17,7 @@
  */
 
 import { UserInput } from '../../model/UserInput';
-import { TreeNode } from '../../model/TreeNode';
+import { TreeStaticPropertyUtils } from './TreeStaticPropertyUtils';
 
 export class StaticPropertyUtils {
     public static input(configs: UserInput[]) {
@@ -63,7 +45,7 @@ export class StaticPropertyUtils {
             } else if (config.type === 'slider') {
                 cy.dataCy(config.selector).type(config.value);
             } else if (config.type === 'tree') {
-                this.handleTreeNode(config.treeNode);
+                TreeStaticPropertyUtils.selectTreeNode(config.treeNode);
             } else {
                 cy.dataCy(config.selector).type(config.value);
             }
@@ -89,14 +71,4 @@ export class StaticPropertyUtils {
         });
     }
 
-    private static handleTreeNode(treeNode: TreeNode) {
-        if (treeNode.children && treeNode.children.length > 0) {
-            cy.dataCy('expand-' + treeNode.name).click();
-            treeNode.children.forEach(child => {
-                this.handleTreeNode(child);
-            });
-        } else {
-            cy.dataCy('select-' + treeNode.name).click();
-        }
-    }
 }
diff --git a/ui/cypress/support/utils/userInput/TreeStaticPropertyUtils.ts 
b/ui/cypress/support/utils/userInput/TreeStaticPropertyUtils.ts
new file mode 100644
index 0000000000..ad8f4422c5
--- /dev/null
+++ b/ui/cypress/support/utils/userInput/TreeStaticPropertyUtils.ts
@@ -0,0 +1,78 @@
+/*
+ *  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 { TreeNode } from '../../model/TreeNode';
+
+export class TreeStaticPropertyUtils {
+
+    /**
+     * Selects the @param treeNode in the tree view. If the tree node has
+     * children, it will expand the tree node and recursivly navigate through
+     * the selected node.
+     */
+    public static selectTreeNode(treeNode: TreeNode) {
+        if (treeNode.children && treeNode.children.length > 0) {
+            cy.dataCy('expand-' + treeNode.name).click();
+            treeNode.children.forEach(child => {
+                this.selectTreeNode(child);
+            });
+        } else {
+            cy.dataCy('select-' + treeNode.name).click();
+        }
+    }
+
+    /**
+     * Removes the selected node with the identifier @param nodeIdentifier.
+     * dataCy could not be used because often special characters are used in
+     * the nodeIdentifier.
+     */
+    public static removeSelectedNode(nodeIdentifier: string) {
+        cy.get('[data-cy="remove-' + nodeIdentifier + '"]').click();
+    }
+
+    /**
+     * Validates that the amount of nodes shown in the selected tab are equal
+     * to @param expectedAmount.
+     */
+    public static validateAmountOfSelectedNodes(expectedAmount: number) {
+        cy.dataCy('selected-node-', {}, true)
+            .should('have.length', expectedAmount);
+    };
+
+
+    /**
+     * Validates that the @param nodeName is marked as selected in the
+     * tree view.
+     */
+    public static checkThatNodeIsSelectedInTree(nodeName: string) {
+        cy.dataCy('tree-node-' + nodeName).within(() => {
+            cy.get('i.material-icons')
+                .contains('remove_circle')
+                .should('exist');
+        });
+    };
+
+
+    public static clickClearAndReloadButton() {
+        cy.dataCy('clear-tree-node-selection').click();
+    }
+
+}
+
+
diff --git a/ui/cypress/tests/connect/opcAdapterConfiguration.spec.ts 
b/ui/cypress/tests/connect/opcAdapterConfiguration.spec.ts
new file mode 100644
index 0000000000..08e46aeebb
--- /dev/null
+++ b/ui/cypress/tests/connect/opcAdapterConfiguration.spec.ts
@@ -0,0 +1,90 @@
+/*
+ * 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 { ConnectUtils } from '../../support/utils/connect/ConnectUtils';
+import { ParameterUtils } from '../../support/utils/ParameterUtils';
+import { AdapterBuilder } from '../../support/builder/AdapterBuilder';
+import { TreeNodeBuilder } from '../../support/builder/TreeNodeBuilder';
+import { StaticPropertyUtils } from 
'../../support/utils/userInput/StaticPropertyUtils';
+import { TreeStaticPropertyUtils } from 
'../../support/utils/userInput/TreeStaticPropertyUtils';
+
+describe('Test OPC-UA Adapter Pull Mode', () => {
+
+    beforeEach('Setup Test', () => {
+        cy.initStreamPipesTest();
+    });
+
+    it('Test OPC-UA Adapter Pull Mode', () => {
+        const adapterConfiguration = getAdapterBuilder();
+
+        // Set up initial configuration
+        ConnectUtils.goToConnect();
+        ConnectUtils.goToNewAdapterPage();
+        ConnectUtils.selectAdapter(adapterConfiguration.adapterType);
+        StaticPropertyUtils.input(adapterConfiguration.adapterConfiguration);
+
+        TreeStaticPropertyUtils.validateAmountOfSelectedNodes(2);
+
+        
TreeStaticPropertyUtils.checkThatNodeIsSelectedInTree('AlternatingBoolean');
+
+        // Test if delete node works
+        
TreeStaticPropertyUtils.removeSelectedNode('ns=3\\;s=AlternatingBoolean');
+        TreeStaticPropertyUtils.validateAmountOfSelectedNodes(1);
+
+        // Test clear selection and reload button
+        TreeStaticPropertyUtils.clickClearAndReloadButton();
+        TreeStaticPropertyUtils.validateAmountOfSelectedNodes(0);
+
+    });
+
+});
+
+const getAdapterBuilder = () => {
+    const host: string = ParameterUtils.get('localhost', 'opcua');
+
+    const builder = AdapterBuilder.create('OPC_UA').setName(
+        'OPC UA Configuration Test',
+    )
+        .addInput('radio', 'adapter_type-pull_mode', '')
+        .addInput('input', 'undefined-PULLING_INTERVAL-0', '1000')
+        .addInput('radio', 'access_mode-none', '')
+        .addInput('radio', 'opc_host_or_url-url', '')
+        .addInput(
+            'input',
+            'undefined-OPC_SERVER_URL-0',
+            'opc.tcp://' + host + ':50000',
+        )
+        .addTreeNode(
+            TreeNodeBuilder.create(
+                'Objects',
+                TreeNodeBuilder.create(
+                    'OpcPlc',
+                    TreeNodeBuilder.create(
+                        'Telemetry',
+                        TreeNodeBuilder.create('Basic').addChildren(
+                            TreeNodeBuilder.create('AlternatingBoolean'),
+                            TreeNodeBuilder.create('StepUp'),
+                        ),
+                    ),
+                ),
+            ),
+        ).setAutoAddTimestampPropery();
+
+    return builder.build();
+};
+
diff --git 
a/ui/src/app/core-ui/static-properties/static-runtime-resolvable-tree-input/static-tree-input.component.html
 
b/ui/src/app/core-ui/static-properties/static-runtime-resolvable-tree-input/static-tree-input.component.html
index ddfc2ba9d7..e66ece2672 100644
--- 
a/ui/src/app/core-ui/static-properties/static-runtime-resolvable-tree-input/static-tree-input.component.html
+++ 
b/ui/src/app/core-ui/static-properties/static-runtime-resolvable-tree-input/static-tree-input.component.html
@@ -27,6 +27,7 @@
                 (click)="resetOptionsAndReload()"
                 style="margin-right: 10px"
                 [disabled]="!showOptions"
+                data-cy='clear-tree-node-selection'
             >
                 <span>Clear selection & reload</span>
             </button>

Reply via email to