This is an automated email from the ASF dual-hosted git repository. zehnder pushed a commit to branch 3298-add-cypress-e2e-tests-for-compact-adapter-feature-test-1 in repository https://gitbox.apache.org/repos/asf/streampipes.git
commit 7b25a07a18e5a9f2acb61fdeddc0a3e49dd15f00 Author: Philipp Zehnder <[email protected]> AuthorDate: Fri Oct 18 09:10:04 2024 +0200 feat(#3298): Add test to validate code editor for compact adapters in UI --- ui/cypress/support/utils/CompactUtils.ts | 27 +++++++++++ ui/cypress/support/utils/GeneralUtils.ts | 23 +++++++++ ui/cypress/support/utils/connect/ConnectBtns.ts | 4 ++ ui/cypress/support/utils/connect/ConnectUtils.ts | 8 ++-- .../tests/connect/compact/uiConfiguration.ts | 55 ++++++++++++++++++++++ .../basic-nav-tabs/basic-nav-tabs.component.html | 1 + .../start-adapter-configuration.component.html | 1 + .../configuration-code-panel.component.html | 2 + 8 files changed, 118 insertions(+), 3 deletions(-) diff --git a/ui/cypress/support/utils/CompactUtils.ts b/ui/cypress/support/utils/CompactUtils.ts new file mode 100644 index 0000000000..38df176d86 --- /dev/null +++ b/ui/cypress/support/utils/CompactUtils.ts @@ -0,0 +1,27 @@ +/* + * 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. + * + */ + +export class CompactUtils { + public static ymlConfiguration() { + return cy.dataCy('yaml-configuration', { timeout: 5000 }); + } + + public static jsonConfiguration() { + return cy.dataCy('json-configuration', { timeout: 5000 }); + } +} diff --git a/ui/cypress/support/utils/GeneralUtils.ts b/ui/cypress/support/utils/GeneralUtils.ts new file mode 100644 index 0000000000..8db505e32b --- /dev/null +++ b/ui/cypress/support/utils/GeneralUtils.ts @@ -0,0 +1,23 @@ +/* + * 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. + * + */ + +export class GeneralUtils { + public static tab(identifier: string) { + return cy.dataCy(`tab-${identifier}`).click(); + } +} diff --git a/ui/cypress/support/utils/connect/ConnectBtns.ts b/ui/cypress/support/utils/connect/ConnectBtns.ts index 20bfd696c5..722a5b0bf8 100644 --- a/ui/cypress/support/utils/connect/ConnectBtns.ts +++ b/ui/cypress/support/utils/connect/ConnectBtns.ts @@ -69,6 +69,10 @@ export class ConnectBtns { return cy.dataCy('stop-all-adapters-btn'); } + public static showCodeCheckbox() { + return cy.dataCy('show-code-checkbox'); + } + // ======================================================================== // ===================== Event Schema buttons ========================== diff --git a/ui/cypress/support/utils/connect/ConnectUtils.ts b/ui/cypress/support/utils/connect/ConnectUtils.ts index aaeccff82c..a63041a36c 100644 --- a/ui/cypress/support/utils/connect/ConnectUtils.ts +++ b/ui/cypress/support/utils/connect/ConnectUtils.ts @@ -76,9 +76,11 @@ export class ConnectUtils { ); } - ConnectEventSchemaUtils.markPropertyAsTimestamp( - adapterConfiguration.timestampProperty, - ); + if (adapterConfiguration.timestampProperty) { + ConnectEventSchemaUtils.markPropertyAsTimestamp( + adapterConfiguration.timestampProperty, + ); + } ConnectEventSchemaUtils.finishEventSchemaConfiguration(); } diff --git a/ui/cypress/tests/connect/compact/uiConfiguration.ts b/ui/cypress/tests/connect/compact/uiConfiguration.ts new file mode 100644 index 0000000000..798d8a8caf --- /dev/null +++ b/ui/cypress/tests/connect/compact/uiConfiguration.ts @@ -0,0 +1,55 @@ +/* + * 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 { AdapterBuilder } from '../../../support/builder/AdapterBuilder'; +import { ConnectBtns } from '../../../support/utils/connect/ConnectBtns'; +import { GeneralUtils } from '../../../support/utils/GeneralUtils'; +import { CompactUtils } from '../../../support/utils/CompactUtils'; + +describe('Test Compact Adapters', () => { + beforeEach('Setup Test', () => { + cy.initStreamPipesTest(); + }); + + it('Validate that code for existing adapter is displayed correctly', () => { + const adapterInput = AdapterBuilder.create('Machine_Data_Simulator') + .setName('Machine Data Simulator Test') + .addInput('input', 'wait-time-ms', '1000') + .build(); + + ConnectUtils.addAdapter(adapterInput); + + // Validate code editor in start dialog + ConnectBtns.showCodeCheckbox().parent().click(); + validateCodeEditor(); + + ConnectUtils.startAdapter(adapterInput); + + // Validate code editor in adapter details + ConnectBtns.detailsAdapter().click(); + GeneralUtils.tab('Code'); + validateCodeEditor(); + }); + + const validateCodeEditor = () => { + CompactUtils.ymlConfiguration().should('be.visible'); + cy.contains('span', 'JSON').click(); + CompactUtils.jsonConfiguration().should('be.visible'); + }; +}); diff --git a/ui/projects/streampipes/shared-ui/src/lib/components/basic-nav-tabs/basic-nav-tabs.component.html b/ui/projects/streampipes/shared-ui/src/lib/components/basic-nav-tabs/basic-nav-tabs.component.html index 68f9377e8f..c613d3cda3 100644 --- a/ui/projects/streampipes/shared-ui/src/lib/components/basic-nav-tabs/basic-nav-tabs.component.html +++ b/ui/projects/streampipes/shared-ui/src/lib/components/basic-nav-tabs/basic-nav-tabs.component.html @@ -42,6 +42,7 @@ *ngFor="let item of spNavigationItems" (click)="navigateTo(item)" [active]="activeLink === item.itemId" + [attr.data-cy]="'tab-' + item.itemTitle" > <span>{{ item.itemTitle }}</span> </a> diff --git a/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.html b/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.html index f7ff5b8c7b..d4eecdd6a7 100644 --- a/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.html +++ b/ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.html @@ -150,6 +150,7 @@ optionTitle="Show code" optionDescription="Show code to programmatically deploy this adapter over the API" optionIcon="code" + dataCy="show-code-checkbox" (optionSelectedEmitter)="showCode = $event" > @if (showCode) { diff --git a/ui/src/app/core-ui/configuration-code-panel/configuration-code-panel.component.html b/ui/src/app/core-ui/configuration-code-panel/configuration-code-panel.component.html index 083d9291c7..a6590ce049 100644 --- a/ui/src/app/core-ui/configuration-code-panel/configuration-code-panel.component.html +++ b/ui/src/app/core-ui/configuration-code-panel/configuration-code-panel.component.html @@ -22,6 +22,7 @@ [innerHTML]="configuration | yamlpretty" class="preview-text" [ngStyle]="{ maxHeight: maxHeight }" + data-cy="yaml-configuration" ></pre> </mat-tab> <mat-tab label="JSON"> @@ -29,6 +30,7 @@ [innerHTML]="configuration | jsonpretty" class="preview-text" [ngStyle]="{ maxHeight: maxHeight }" + data-cy="json-configuration" ></pre> </mat-tab> </mat-tab-group>
