Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI test for Datamapper #749

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 118 additions & 1 deletion it-tests/BasicFlow.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { By, EditorView, until, VSBrowser, WebDriver, WebView, logging } from 'vscode-extension-tester';
import { By, EditorView, until, VSBrowser, WebDriver, WebView, logging, InputBox } from 'vscode-extension-tester';
import { assert } from 'chai';
import * as path from 'path';
import { checkEmptyCanvasLoaded, checkTopologyLoaded, openAndSwitchToKaotoFrame } from './Util';
Expand All @@ -20,6 +20,10 @@ describe('Kaoto basic development flow', function () {
path.join(workspaceFolder, 'empty.camel.yaml'),
path.join(workspaceFolder, 'empty_copy.camel.yaml')
);
fs.copySync(
path.join(workspaceFolder, 'empty.camel.yaml'),
path.join(workspaceFolder, 'for_datamapper_test.camel.yaml')
);
fs.copySync(
path.join(workspaceFolder, 'emptyPipe.kaoto.yaml'),
path.join(workspaceFolder, 'emptyPipe.pipe.yaml')
Expand All @@ -34,6 +38,7 @@ describe('Kaoto basic development flow', function () {

after(function () {
fs.rmSync(path.join(workspaceFolder, 'empty_copy.camel.yaml'));
fs.rmSync(path.join(workspaceFolder, 'for_datamapper_test.camel.yaml'));
fs.rmSync(path.join(workspaceFolder, 'emptyPipe.pipe.yaml'));
fs.rmSync(path.join(workspaceFolder, 'emptyPipe-pipe.yaml'));
});
Expand Down Expand Up @@ -108,6 +113,49 @@ describe('Kaoto basic development flow', function () {
await kaotoWebview.switchBack();
});


it('Open empty file, add a datamapper step and save', async function () {
let { kaotoWebview, kaotoEditor } = await openAndSwitchToKaotoFrame(
workspaceFolder,
'for_datamapper_test.camel.yaml',
driver,
false
);
globalKaotoWebView = kaotoWebview;
await checkEmptyCanvasLoaded(driver);
await createNewRoute(driver);
await addDatamapperStep(driver);
await checkStepWithTestIdOrNodeLabelPresent(driver, 'custom-node__kaoto-datamapper', 'kaoto-datamapper');

await openDataMapperEditor(driver);

await addXsdForSource(driver, kaotoWebview);

// TODO: Add a target xsd
// TODO: Map an element

await (await driver.findElement(By.css('a[data-testid="design-tab"]'))).click();

const files = fs.readdirSync(workspaceFolder);
const xslFiles = files.filter(file => file.endsWith('.xsl'));
assert.isTrue(xslFiles.length === 1, `Expected one xsl file created, found ${xslFiles.length}`);

await deleteDataMapperStep(driver, workspaceFolder);

await kaotoWebview.switchBack();
assert.isTrue(
await kaotoEditor.isDirty(),
'The Kaoto editor should be dirty after adding a DataMapper step.'
);
await kaotoEditor.save();
await waitUntil(async () => {
return !(await kaotoEditor.isDirty());
});

const editorView = new EditorView();
await editorView.closeAllEditors();
});

it('Open Camel file and check Kaoto UI is loading', async function () {
const { kaotoWebview, kaotoEditor } = await openAndSwitchToKaotoFrame(
workspaceFolder,
Expand Down Expand Up @@ -145,6 +193,50 @@ describe('Kaoto basic development flow', function () {

});

async function addXsdForSource(driver: WebDriver, kaotoWebview: WebView) {
await driver.wait(
until.elementLocated(By.css('button[data-testid="attach-schema-sourceBody-Body-button"]')),
5000, 'Cannot find the button to attach the schema');
await (await driver.findElement(By.css('button[data-testid="attach-schema-sourceBody-Body-button"]'))).click();

await kaotoWebview.switchBack();
const xsdInputbox = await InputBox.create(10000);
await xsdInputbox.setText('shiporder.xsd');
await xsdInputbox.confirm();
await kaotoWebview.switchToFrame();

//TODO: check content is loaded
}

async function openDataMapperEditor(driver: WebDriver) {
const kaotoNode = await driver.findElement(By.css('g[data-testid^="custom-node__kaoto-datamapper"],g[data-testid="custom-node__route.from.steps.0.kaoto-datamapper"]'));
await kaotoNode.click();
await driver.wait(
until.elementLocated(By.css('button[title="Click to launch the Kaoto DataMapper editor"]')),
5000, 'Cannot find the button to open the datamapper');
await (await driver.findElement(By.css('button[title="Click to launch the Kaoto DataMapper editor"]'))).click();
}

async function deleteDataMapperStep(driver: WebDriver, workspaceFolder: string) {
await checkStepWithTestIdOrNodeLabelPresent(driver, 'custom-node__kaoto-datamapper', 'kaoto-datamapper');
const kaotoNodeConfigured = await driver.findElement(By.css('g[data-testid^="custom-node__kaoto-datamapper"],g[data-testid="custom-node__route.from.steps.0.kaoto-datamapper"]'));
await kaotoNodeConfigured.click();
await driver.wait(
until.elementLocated(By.css('button[data-testid="step-toolbar-button-delete"]'))
);
await (await driver.findElement(By.css('button[data-testid="step-toolbar-button-delete"]'))).click();
await driver.wait(
until.elementLocated(By.css('button[data-testid="action-confirmation-modal-btn-del-step-and-file"]'))
);
await (await driver.findElement(By.css('button[data-testid="action-confirmation-modal-btn-del-step-and-file"]'))).click();

await waitUntil(() => {
const filesAfterDeletion = fs.readdirSync(workspaceFolder);
const xslFilesAfterDeletion = filesAfterDeletion.filter(file => file.endsWith('.xsl'));
return xslFilesAfterDeletion.length === 0;
});
}

async function createNewRoute(driver: WebDriver) {
await (await driver.findElement(By.xpath("//button[@data-testid='dsl-list-btn']"))).click();
}
Expand All @@ -168,6 +260,31 @@ async function addActiveMQStep(driver: WebDriver) {
await (await driver.findElement(By.xpath("//div[@data-testid='tile-activemq']"))).click();
}

async function addDatamapperStep(driver: WebDriver) {
await driver.wait(
until.elementLocated(By.css('g[data-testid^="custom-node__log"],g[data-testid="custom-node__route.from.steps.0.log"]'))
, 5000, 'Cannot find the node for the log');

const canvasNode = await driver.findElement(By.css('g[data-testid^="custom-node__log"],g[data-testid="custom-node__route.from.steps.0.log"]'));
await driver.actions().contextClick(canvasNode).perform();

await driver.wait(
until.elementLocated(By.className('pf-v5-c-dropdown pf-m-expanded'))
);
await (await driver.findElement(By.xpath("//*[@data-testid='context-menu-item-replace']"))).click();

await driver.wait(
until.elementLocated(By.xpath("//input[@placeholder='Filter by name, description or tag']"))
);
const filterInput = await driver.findElement(By.xpath("//input[@placeholder='Filter by name, description or tag']"));
await filterInput.sendKeys('datamapper');
await driver.wait(
until.elementLocated(By.xpath("//div[@data-testid='tile-kaoto-datamapper']")
));

await (await driver.findElement(By.xpath("//div[@data-testid='tile-kaoto-datamapper']"))).click();
}

/**
*
* @param driver
Expand Down
1 change: 1 addition & 0 deletions test Fixture with speci@l chars/.kaoto
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
33 changes: 33 additions & 0 deletions test Fixture with speci@l chars/shiporder.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="shiporder">
<xs:complexType>
<xs:sequence>
<xs:element name="orderperson" type="xs:string" />
<xs:element name="shipto">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="address" type="xs:string" />
<xs:element name="city" type="xs:string" />
<xs:element name="country" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="note" type="xs:string" minOccurs="0" />
<xs:element name="quantity" type="xs:positiveInteger" />
<xs:element name="price" type="xs:decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="orderid" type="xs:string" use="required" />
</xs:complexType>
</xs:element>

</xs:schema>
Loading