Skip to content

Commit

Permalink
fix(#3388): Refactor asset link test
Browse files Browse the repository at this point in the history
  • Loading branch information
tenthe committed Dec 23, 2024
1 parent da66ce2 commit eb2ef73
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 67 deletions.
65 changes: 65 additions & 0 deletions ui/cypress/support/utils/asset/AssetBtns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 AssetBtns {
public static createAssetBtn() {
return cy.dataCy('create-new-asset-button', { timeout: 10000 });
}

public static assetNameInput() {
return cy.dataCy('asset-name', { timeout: 10000 });
}

public static saveAssetBtn() {
return cy.dataCy('save-asset', { timeout: 10000 });
}

public static basicTab() {
return cy.dataCy('basic-tab', { timeout: 10000 });
}

public static assetLinksTab() {
return cy.dataCy('asset-links-tab', { timeout: 10000 });
}

public static manageLinksBtn() {
return cy.dataCy('assets-manage-links-button', { timeout: 10000 });
}

public static adapterCheckbox(adapterName: string) {
return cy.dataCy('select-adapters-checkbox-' + adapterName, {
timeout: 10000,
});
}

public static dataStreamCheckbox(adapterName: string) {
return cy.dataCy('select-data-stream-checkbox-' + adapterName, {
timeout: 10000,
});
}

public static updateAssetLinksBtn() {
return cy.dataCy('assets-update-links-button', { timeout: 10000 });
}

public static goBackToOverviewBtn() {
return cy.dataCy('save-data-explorer-go-back-to-overview', {
timeout: 10000,
});
}
}
36 changes: 36 additions & 0 deletions ui/cypress/support/utils/asset/AssetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,44 @@
*
*/

import { AssetBtns } from './AssetBtns';

export class AssetUtils {
public static goToAssets() {
cy.visit('#/assets/overview');
}

public static goBackToOverview() {
AssetBtns.goBackToOverviewBtn().click();
}

public static addNewAsset(assetName: string) {
AssetBtns.createAssetBtn().click();
AssetBtns.assetNameInput().clear();
AssetBtns.assetNameInput().type(assetName);
AssetBtns.saveAssetBtn().click();
}

public static openManageAssetLinks() {
AssetBtns.manageLinksBtn().should('be.enabled');
AssetBtns.manageLinksBtn().click();
}

public static selectAdapterAssetLink(adapterName: string) {
AssetBtns.adapterCheckbox(adapterName).click();
}

public static selectDataStreamAssetLink(adapterName: string) {
AssetBtns.dataStreamCheckbox(adapterName).click();
}

public static checkAmountOfAssets(amount: number) {
cy.dataCy('assets-table').should('have.length', amount);
}

public static checkAmountOfLinkedResources(amount: number) {
cy.dataCy('linked-resources-list')
.children()
.should('have.length', amount);
}
}
62 changes: 0 additions & 62 deletions ui/cypress/tests/assetManagement/createAsset.spec.ts

This file was deleted.

54 changes: 54 additions & 0 deletions ui/cypress/tests/assetManagement/generalAssetTest.smoke.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 { AssetUtils } from '../../support/utils/asset/AssetUtils';
import { DashboardUtils } from '../../support/utils/DashboardUtils';
import { AssetBtns } from '../../support/utils/asset/AssetBtns';

describe('Creates a new adapter, add to assets', () => {
const adapterName = 'Machine_Data_Simulator';

beforeEach('Setup Test', () => {
cy.initStreamPipesTest();
ConnectUtils.addMachineDataSimulator(adapterName);
});

it('Perform Test', () => {
// Create new asset from adapters
AssetUtils.goToAssets();

AssetUtils.addNewAsset('Test Asset');

AssetBtns.assetLinksTab().click();
AssetUtils.openManageAssetLinks();

AssetUtils.selectAdapterAssetLink(adapterName);
AssetUtils.selectDataStreamAssetLink(adapterName);
AssetBtns.updateAssetLinksBtn().click();

AssetUtils.checkAmountOfLinkedResources(2);
AssetBtns.saveAssetBtn().click();
AssetUtils.goBackToOverview();

// // Leave and navigate back to Assets
DashboardUtils.goToDashboard();
AssetUtils.goToAssets();
AssetUtils.checkAmountOfAssets(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<button
mat-button
mat-raised-button
data-cy="save-asset-button"
data-cy="save-asset"
color="accent"
(click)="saveAsset()"
>
Expand All @@ -56,12 +56,14 @@
<nav mat-tab-nav-bar color="accent">
<a
mat-tab-link
data-cy="basic-tab"
[active]="activeTab === 'basic'"
(click)="activeTab = 'basic'"
>Basics</a
>
<a
mat-tab-link
data-cy="asset-links-tab"
[active]="activeTab === 'asset-links'"
(click)="activeTab = 'asset-links'"
>Asset Links</a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
<mat-checkbox
color="accent"
[checked]="linkSelected(element.elementId)"
data-cy="manage-assets-select-adapters-checkbox"
[attr.data-cy]="
'select-adapters-checkbox-' + element.name
"
(change)="
selectLink(
$event.checked,
Expand Down Expand Up @@ -228,7 +230,9 @@
<mat-checkbox
color="accent"
[checked]="linkSelected(source.elementId)"
data-cy="manage-assets-select-data-sources-checkbox"
[attr.data-cy]="
'select-data-stream-checkbox-' + source.name
"
(change)="
selectLink(
$event.checked,
Expand Down Expand Up @@ -394,8 +398,8 @@
'pipeline'
)
"
>{{ pipeline.name }}</mat-checkbox
>
>{{ pipeline.name }}
</mat-checkbox>
</div>
</div>
</div>
Expand Down

0 comments on commit eb2ef73

Please sign in to comment.