Skip to content

Commit

Permalink
KOGITO-8949: Recreate TrySample test for Serverless Logic Web Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasdavidorg committed Nov 20, 2023
1 parent 7db52c5 commit 2908ccd
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 125 deletions.
183 changes: 183 additions & 0 deletions packages/serverless-logic-web-tools/e2e-tests/e2e/TrySample.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* 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.
*/

const ctrlOrCmd = Cypress.platform === "darwin" ? "Cmd" : "Ctrl";
const controlOrMeta = Cypress.platform === "darwin" ? "Meta" : "Control";

describe("Serverless Logic Web Tools - Try sample test", () => {
// CYPRESS_E2E_TEST_GITHUB_TOKEN env. variable
const E2E_TEST_GITHUB_TOKEN = Cypress.env("E2E_TEST_GITHUB_TOKEN");

if (E2E_TEST_GITHUB_TOKEN) {
beforeEach(() => {
cy.visit("/");

// allow clipboard permissions in browser
Cypress.automation("remote:debugger:protocol", {
command: "Browser.grantPermissions",
params: {
permissions: ["clipboardReadWrite", "clipboardSanitizedWrite"],
origin: window.location.origin,
},
});

// set GitHub token
cy.ouia({ ouiaId: "settings-button" }).click();
cy.ouia({ ouiaId: "add-access-token-button" }).click();
cy.window().then((win) => {
win.navigator.clipboard.writeText(E2E_TEST_GITHUB_TOKEN);

// Meta key does not work on Mac https://github.com/dmtrKovalenko/cypress-real-events/issues/292
cy.ouia({ ouiaId: "token-input" }).realPress([controlOrMeta, "v"]);
});
cy.ouia({ ouiaId: "signed-in-text" }).should("have.text", "You're signed in with GitHub.");
});

it("should check greeting sample", () => {
// open samples catalog
cy.ouia({ ouiaId: "app-title" }).click();
cy.goToSidebarLink({ ouiaId: "samples-catalog-nav" });

// open greeting example
cy.ouia({ ouiaId: "sample-category-dropdown" }).click();
cy.ouia({ ouiaId: "serverless-workflow-dropdown-item" }).click();
cy.ouia({ ouiaId: "samples-count-text" })
.should("contain.text", "Showing")
.should("contain.text", "sample")
.should("not.contain.text", "Showing 0");
cy.ouia({ ouiaId: "greeting-json-try-sample-button" }).click();

cy.loadEditor();

// check header type and name
cy.ouia({ ouiaId: "file-type-label" }).should("have.text", "Serverless Workflow");
cy.ouia({ ouiaId: "file-name-input" }).should("have.value", "greeting");

cy.getEditor().within(() => {
cy.iframe("#kogito-iframe[src='./serverless-workflow-text-editor-envelope.html']").within(() => {
// check text editor contains text
cy.get(".monaco-editor textarea")
.should("contain.value", '"id": "jsongreet"')
.should("contain.value", '"name": "Greeting workflow",');

// check shortcuts modal dialog
cy.ouia({ ouiaId: "keyboard-shortcuts-icon" }).click();
cy.get(".kie-tools--keyboard-shortcuts.pf-c-modal-box")
.should("contain.text", "Keyboard shortcuts")
.should("contain.text", `${ctrlOrCmd} + Z`)
.should("contain.text", "Undo last edit");
cy.get(".kie-tools--keyboard-shortcuts.pf-c-modal-box .pf-c-button").click();
});

cy.iframe("#kogito-iframe[src='./serverless-workflow-diagram-editor-envelope.html']")
.trigger("mouseover")
.within(() => {
// check canvas is present
cy.get("#canvasPanel").should("have.descendants", "canvas").should("be.visible");

// check zoom controls are present
cy.ouia({ ouiaId: "zoom-controls-panel" })
.should("be.visible")
.should("have.descendants", "button[data-ouia-component-id='reset-zoom-button']")
.should("have.descendants", "button[data-ouia-component-id='minus-zoom-button']")
.should("have.descendants", "button[data-ouia-component-id='plus-zoom-button']")
.should("have.descendants", "div[data-ouia-component-id='select-zoom-button']");

// check shortcuts modal dialog
cy.ouia({ ouiaId: "keyboard-shortcuts-icon" }).click();
cy.get(".kie-tools--keyboard-shortcuts.pf-c-modal-box")
.should("contain.text", "Keyboard shortcuts")
.should("contain.text", `${ctrlOrCmd} + Alt`)
.should("contain.text", "Hold to Preview");
cy.get(".kie-tools--keyboard-shortcuts.pf-c-modal-box .pf-c-button").click();
});
});

// check there are no problems in JSON file
cy.get("#total-notifications").should("have.text", 0);
});

it("should check serverless-workflow-report example of dashboard", () => {
// open samples catalog
cy.ouia({ ouiaId: "app-title" }).click();
cy.goToSidebarLink({ ouiaId: "samples-catalog-nav" });

// open serverless-workflow-report example
cy.ouia({ ouiaId: "sample-category-dropdown" }).click();
cy.ouia({ ouiaId: "dashbuilder-dropdown-item" }).click();
cy.ouia({ ouiaId: "samples-count-text" })
.should("contain.text", "Showing")
.should("contain.text", "sample")
.should("not.contain.text", "Showing 0");
cy.ouia({ ouiaId: "search-sample-input" }).click().type("Report");
cy.ouia({ ouiaId: "serverless-workflow-report-try-sample-button" }).click();

cy.loadEditor();

// check header type and name
cy.ouia({ ouiaId: "file-type-label" }).should("have.text", "Dashboard");
cy.ouia({ ouiaId: "file-name-input" }).should("have.value", "serverless-workflow-report");

cy.getEditor().within(() => {
// check text editor contains text
cy.get(".monaco-editor textarea")
.should("contain.value", "global:")
.should("contain.value", "mode: dark")
.should("contain.value", 'class="card-pf card-pf-aggregate-status"');

// check preview buttow hides text editor
cy.ouia({ ouiaId: "preview-button" }).click();
cy.get(".monaco-editor textarea").should("not.be.visible");
cy.ouia({ ouiaId: "preview-button" }).click();
cy.get(".monaco-editor textarea").should("be.visible");

// check shortcuts modal dialog
cy.ouia({ ouiaId: "keyboard-shortcuts-icon" }).click();
cy.get(".kie-tools--keyboard-shortcuts.pf-c-modal-box")
.should("contain.text", "Keyboard shortcuts")
.should("contain.text", `Shift + ${ctrlOrCmd} + Z`)
.should("contain.text", "Redo last edit");
cy.get(".kie-tools--keyboard-shortcuts.pf-c-modal-box .pf-c-button").click();

cy.iframe("[src='dashbuilder-client/index.html']").within(() => {
// check default values
cy.get("#mainContainer").should("contain.text", "Serverless Workflow Summary ");
cy.get(".card-pf-aggregate-status:contains('Total Workflows') > h2").should("contain.text", 464);
cy.get(".card-pf-aggregate-status:contains('Completed') > h2").should("contain.text", 458);
cy.get(".card-pf-aggregate-status:contains('Error') > h2").should("contain.text", 6);
cy.iframe("#externalComponentIFrame").within(() => {
cy.get(".pf-c-options-menu__toggle-text b").last().should("contain.text", 464);
});

// switch filter and check values
cy.get("select.form-control").select("yamlgreet");
cy.get(".card-pf-aggregate-status:contains('Total Workflows') > h2").should("contain.text", 177);
cy.get(".card-pf-aggregate-status:contains('Completed') > h2").should("contain.text", 173);
cy.get(".card-pf-aggregate-status:contains('Error') > h2").should("contain.text", 4);
cy.iframe("#externalComponentIFrame").within(() => {
cy.get(".pf-c-options-menu__toggle-text b").last().should("contain.text", 177);
});
});
});

// check there are no problems in dashbuilder file
cy.get("#total-notifications").should("have.text", 0);
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import "cypress-file-upload";
import "cypress-iframe";
import "./commands";
import "cypress-real-events";

// temporary workaround, will be removed with https://issues.redhat.com/browse/KOGITO-6355
Cypress.on("uncaught:exception", (err, runnable) => {
Expand Down
1 change: 1 addition & 0 deletions packages/serverless-logic-web-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"cypress-file-upload": "^5.0.8",
"cypress-iframe": "^1.0.1",
"cypress-log-to-output": "^1.1.2",
"cypress-real-events": "^1.10.3",
"html-replace-webpack-plugin": "^2.6.0",
"html-webpack-plugin": "^5.3.2",
"jest": "^26.6.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export function SamplesCatalog() {
<DropdownItem
key={`category-filter-${category}`}
onClick={() => onSearch({ searchValue: searchFilter, category })}
ouiaId={`${category}-dropdown-item`}
>
{LABEL_MAP[category]}
</DropdownItem>
Expand Down Expand Up @@ -248,6 +249,7 @@ export function SamplesCatalog() {
onClick={(e) => {
e.stopPropagation();
}}
data-ouia-component-id={"search-sample-input"}
/>
</ToolbarItem>
<ToolbarItem>
Expand All @@ -264,12 +266,13 @@ export function SamplesCatalog() {
</DropdownToggle>
}
isOpen={isCategoryFilterDropdownOpen}
ouiaId={"sample-category-dropdown"}
/>
</ToolbarItem>
<ToolbarItem>
{filterResultMessage && (
<TextContent>
<Text>{filterResultMessage}</Text>
<Text ouiaId={"samples-count-text"}>{filterResultMessage}</Text>
</TextContent>
)}
</ToolbarItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ export function SettingsButton() {

return (
<Link to={routes.settings.home.path({})}>
<Button variant={ButtonVariant.plain} aria-label="Settings" className={"kie-tools--masthead-hoverable-dark"}>
<Button
variant={ButtonVariant.plain}
aria-label="Settings"
className={"kie-tools--masthead-hoverable-dark"}
ouiaId={"settings-button"}
>
<CogIcon />
</Button>
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ export function GitHubSettings(props: SettingsPageProps) {
<EmptyState>
<EmptyStateIcon icon={CheckCircleIcon} color={"var(--pf-global--success-color--100)"} />
<TextContent>
<Text component={"h2"}>{"You're signed in with GitHub."}</Text>
<Text component={"h2"} ouiaId={"signed-in-text"}>
{"You're signed in with GitHub."}
</Text>
</TextContent>
<EmptyStateBody>
Gists are <b>{settings.github.scopes?.includes(GitHubTokenScope.GIST) ? "enabled" : "disabled"}.</b>
Expand Down Expand Up @@ -179,7 +181,7 @@ export function GitHubSettings(props: SettingsPageProps) {
You currently have no tokens to display. Access tokens allow you for creating repositories containing
models you design, and syncing changes with GitHub.
</EmptyStateBody>
<Button variant={ButtonVariant.primary} onClick={handleModalToggle}>
<Button variant={ButtonVariant.primary} onClick={handleModalToggle} ouiaId={"add-access-token-button"}>
Add access token
</Button>
</EmptyState>
Expand Down Expand Up @@ -223,6 +225,7 @@ export function GitHubSettings(props: SettingsPageProps) {
value={githubTokenToDisplay}
onPaste={onPasteGitHubToken}
tabIndex={1}
ouiaId={"token-input"}
/>
</InputGroup>
</FormGroup>
Expand Down
Loading

0 comments on commit 2908ccd

Please sign in to comment.