Skip to content

Commit

Permalink
Second iteration of UI tests for datamapper
Browse files Browse the repository at this point in the history
this part is enough to have non-regression tests for #747 when launched
on Windows

Signed-off-by: Aurélien Pupier <[email protected]>
  • Loading branch information
apupier committed Dec 24, 2024
1 parent a1ae844 commit 16c5ca0
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 15 deletions.
74 changes: 59 additions & 15 deletions 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 Down Expand Up @@ -114,7 +114,7 @@ describe('Kaoto basic development flow', function () {
});


it('Open empty file, add a datamapper step and save', async function () {
it.only('Open empty file, add a datamapper step and save', async function () {
let { kaotoWebview, kaotoEditor } = await openAndSwitchToKaotoFrame(
workspaceFolder,
'for_datamapper_test.camel.yaml',
Expand All @@ -127,6 +127,22 @@ describe('Kaoto basic development flow', function () {
await addDatamapperStep(driver);
await checkStepWithTestIdOrNodeLabelPresent(driver, 'custom-node__kaoto-datamapper', 'kaoto-datamapper');

await openDataMapperEditor(driver);

await addXsdForSource(driver, kaotoWebview);
await kaotoWebview.switchToFrame();

// 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(),
Expand All @@ -139,16 +155,6 @@ describe('Kaoto basic development flow', function () {

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

({ kaotoWebview, kaotoEditor } = await openAndSwitchToKaotoFrame(
workspaceFolder,
'for_datamapper_test.camel.yaml',
driver,
true
));
globalKaotoWebView = kaotoWebview;
await checkStepWithTestIdOrNodeLabelPresent(driver, 'custom-node__kaoto-datamapper', 'kaoto-datamapper');
await kaotoWebview.switchBack();
});

it('Open Camel file and check Kaoto UI is loading', async function () {
Expand Down Expand Up @@ -188,6 +194,47 @@ describe('Kaoto basic development flow', function () {

});

async function addXsdForSource(driver: WebDriver, kaotoWebview) {

Check failure on line 197 in it-tests/BasicFlow.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Parameter 'kaotoWebview' implicitly has an 'any' type.

Check failure on line 197 in it-tests/BasicFlow.test.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Parameter 'kaotoWebview' implicitly has an 'any' type.

Check failure on line 197 in it-tests/BasicFlow.test.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Parameter 'kaotoWebview' implicitly has an 'any' type.
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();
}

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 Down Expand Up @@ -234,9 +281,6 @@ async function addDatamapperStep(driver: WebDriver) {
));

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

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();
}

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

0 comments on commit 16c5ca0

Please sign in to comment.