From 09611d84b4d4cb9bf0926135ad9a18e052c0a17d Mon Sep 17 00:00:00 2001 From: Nikol Georgieva Date: Fri, 6 Jun 2025 10:34:38 +0300 Subject: [PATCH] add scheduled job test --- .../tests/framework/ide/Workbench.java | 36 ++++++++++- .../tests/ui/tests/CreateScheduledJobIT.java | 60 +++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 tests/tests-integrations/src/main/java/org/eclipse/dirigible/integration/tests/ui/tests/CreateScheduledJobIT.java diff --git a/tests/tests-framework/src/main/java/org/eclipse/dirigible/tests/framework/ide/Workbench.java b/tests/tests-framework/src/main/java/org/eclipse/dirigible/tests/framework/ide/Workbench.java index a23f8527a9f..a6b3cac9c6d 100644 --- a/tests/tests-framework/src/main/java/org/eclipse/dirigible/tests/framework/ide/Workbench.java +++ b/tests/tests-framework/src/main/java/org/eclipse/dirigible/tests/framework/ide/Workbench.java @@ -9,17 +9,20 @@ */ package org.eclipse.dirigible.tests.framework.ide; +import org.apache.commons.lang3.SystemUtils; import org.eclipse.dirigible.tests.framework.browser.Browser; import org.eclipse.dirigible.tests.framework.browser.HtmlAttribute; import org.eclipse.dirigible.tests.framework.browser.HtmlElementType; import org.eclipse.dirigible.tests.framework.util.SynchronizationUtil; +import org.openqa.selenium.Keys; public class Workbench { public static final String PROJECTS_VIEW_ID = "pvtree"; public static final String PROJECT_NAME_INPUT_ID = "pgfi1"; + public static final String FILE_NAME_INPUT_ID = "fdti1"; private static final String PROJECTS_CONTEXT_MENU_NEW_PROJECT = "New Project"; - private static final String CREATE_PROJECT_BUTTON_TEXT = "Create"; + private static final String CREATE_BUTTON_TEXT = "Create"; private final Browser browser; private final WelcomeViewFactory welcomeViewFactory; @@ -66,7 +69,7 @@ public void createNewProject(String projectName) { browser.enterTextInElementById(PROJECT_NAME_INPUT_ID, projectName); - browser.clickOnElementWithText(HtmlElementType.BUTTON, CREATE_PROJECT_BUTTON_TEXT); + browser.clickOnElementWithText(HtmlElementType.BUTTON, CREATE_BUTTON_TEXT); } public void createFileInProject(String projectName, String newFileType) { @@ -95,4 +98,33 @@ public Terminal openTerminal() { return terminalFactory.create(browser); } + public void createCustomElement(String fileName, String elementType) { + browser.clickOnElementByAttributePatternAndText(HtmlElementType.SPAN, HtmlAttribute.CLASS, "fd-menu__title", elementType); + + browser.enterTextInElementById(FILE_NAME_INPUT_ID, fileName); + browser.clickOnElementWithText(HtmlElementType.BUTTON, CREATE_BUTTON_TEXT); + } + + public void createCustomElementInProject(String projectName, String fileName, String elementType) { + browser.rightClickOnElementContainingText(HtmlElementType.ANCHOR, projectName); + createCustomElement(fileName, elementType); + } + + public void selectAll() { + if (SystemUtils.IS_OS_MAC) + browser.pressMultipleKeys(Keys.COMMAND, "a"); + else + browser.pressMultipleKeys(Keys.CONTROL, "a"); + } + + public void addContentToFile(String fileContent) { + browser.clickOnElementByAttributePattern(HtmlElementType.DIV, HtmlAttribute.CLASS, "view-lines monaco-mouse-cursor-text"); + selectAll(); + browser.type(fileContent); + } + + public void saveAll() { + browser.clickOnElementByAttributeValue(HtmlElementType.BUTTON, HtmlAttribute.GLYPH, "sap-icon--save"); + } + } diff --git a/tests/tests-integrations/src/main/java/org/eclipse/dirigible/integration/tests/ui/tests/CreateScheduledJobIT.java b/tests/tests-integrations/src/main/java/org/eclipse/dirigible/integration/tests/ui/tests/CreateScheduledJobIT.java new file mode 100644 index 00000000000..c7b9cea9289 --- /dev/null +++ b/tests/tests-integrations/src/main/java/org/eclipse/dirigible/integration/tests/ui/tests/CreateScheduledJobIT.java @@ -0,0 +1,60 @@ +package org.eclipse.dirigible.integration.tests.ui.tests; + +import org.eclipse.dirigible.tests.base.UserInterfaceIntegrationTest; +import org.eclipse.dirigible.tests.framework.ide.Workbench; +import org.eclipse.dirigible.tests.framework.browser.HtmlAttribute; +import org.eclipse.dirigible.tests.framework.browser.HtmlElementType; +import org.junit.jupiter.api.Test; + +public class CreateScheduledJobIT extends UserInterfaceIntegrationTest { + + private static final String PROJECT_NAME = "CreateScheduledJobIT"; + private static final String JS_FILE_NAME = "test1.mjs"; + private static final String JOB_FILE_NAME = "test1.job"; + private static final String JS_CONTENT = "console.log(\"Job executed\");"; + private static final String HANDLER_PATH = "CreateScheduledJobIT/test1.mjs"; + private static final String CONSOLE_ID = "console"; + + @Test + void test() { + Workbench workbench = ide.openWorkbench(); + workbench.createNewProject(this.getClass() + .getSimpleName()); + + workbench.createCustomElementInProject(PROJECT_NAME, JS_FILE_NAME, "JavaScript Service"); + workbench.openFile(JS_FILE_NAME); + + assertFileTabIsOpen(JS_FILE_NAME); + + workbench.addContentToFile(JS_CONTENT); + + workbench.createCustomElementInProject(PROJECT_NAME, JOB_FILE_NAME, "Scheduled Job"); + workbench.openFile(JOB_FILE_NAME); + + assertFileTabIsOpen(JOB_FILE_NAME); + + changeHandlerPath(workbench); + + workbench.saveAll(); + workbench.clickPublishAll(); + + assertLogIsPresent(); + } + + private void changeHandlerPath(Workbench workbench) { + browser.clickOnElementById("idHandler"); + workbench.selectAll(); + browser.type(HANDLER_PATH); + browser.clickOnElementByAttributePattern(HtmlElementType.BUTTON, HtmlAttribute.LABEL, "Save"); + } + + private void assertLogIsPresent() { + browser.clickOnElementById(CONSOLE_ID); + browser.assertElementExistsByTypeAndContainsText(HtmlElementType.DIV, "Job executed"); + } + + + private void assertFileTabIsOpen(String fileName) { + browser.assertElementExistByAttributePatternAndText(HtmlElementType.SPAN, HtmlAttribute.CLASS, "fd-icon-tab-bar__tag", fileName); + } +}