Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading