Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
artbez committed May 7, 2017
1 parent 5d671a2 commit 6cbdeb5
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ export class DiagramEditorController {
return this.getNodeType(type);
};
this.diagramEditor = new DiagramEditor();
this.sceneController = new SceneController(this, this.diagramEditor.getScene(), selectorService.scene);
this.sceneController = new SceneController(
this,
this.diagramEditor.getScene(),
selectorService.scene,
selectorService.gestures);

this.elementsTypeLoader = new ElementsTypeLoader();

$scope.undo = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ export class SceneController {
private paperCommandFactory: SceneCommandFactory;
private contextMenuId;
private selectorService : any;
private gestures : any;

constructor(diagramEditorController: DiagramEditorController, paper: DiagramScene, selectorService: any) {
constructor(diagramEditorController: DiagramEditorController, paper: DiagramScene, selectorService: any, gestures: any) {
this.diagramEditorController = diagramEditorController;
this.undoRedoController = diagramEditorController.getUndoRedoController();
this.scene = paper;
Expand All @@ -44,6 +45,7 @@ export class SceneController {
this.lastCellScrollPosition = { x: 0, y: 0 };
this.contextMenuId = selectorService.contextMenu.id;
this.selectorService = selectorService;
this.gestures = gestures;

this.scene.on('cell:pointerdown', (cellView, event, x, y): void => {
this.cellPointerdownListener(cellView, event, x, y);
Expand Down Expand Up @@ -172,7 +174,7 @@ export class SceneController {

var contextMenu = new ContextMenu();
var menuDiv = document.createElement("div");
menuDiv.id = this.selectorService.gestures.gesturesMenu.id;
menuDiv.id = this.gestures.gesturesMenu.id;
menuDiv.className = "gestures-menu";
menuDiv.style.left = event.x + "px";
menuDiv.style.top = event.y + "px";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<%JSONObject headerPanelSelector = selectors.getJSONObject("editorHeaderPanel"); %>

<!-- Context menu in File->'Open diagram' window -->
<ul id="<%=headerPanelSelector.getJSONObject("contextMenu").getString("id")%>" class='custom-menu'>
<li id="<%=headerPanelSelector.getJSONObject("contextMenu").getJSONObject("deleteItem").getString("id")%>"
<%JSONObject contextMenuSelector = headerPanelSelector.getJSONObject("folderArea").getJSONObject("contextMenu"); %>
<ul id="<%=contextMenuSelector.getString("id")%>" class='custom-menu'>
<li id="<%=contextMenuSelector.getJSONObject("deleteItem").getString("id")%>"
data-action="delete">Delete</li>
<li data-action="share" >Share</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
Expand All @@ -18,27 +16,20 @@
@PropertySource("classpath:application.properties")
public class ConfigsMerger {

private static final Logger logger = LoggerFactory.getLogger(ConfigsMerger.class);

private final JsonParser parser = new JsonParser();

@Value("${selectorConfig}")
private String configFile;

/** Generates one config file from all which are used. */
public JsonObject generateCommonConfig() {
public JsonObject generateCommonConfig() throws FileNotFoundException {
String path = getClass().getClassLoader().getResource(configFile).getPath();
try {
JsonElement jsonElement = parser.parse(new FileReader(path));
JsonObject initialConfig = jsonElement.getAsJsonObject();
return merge(initialConfig, path);
} catch (FileNotFoundException e) {
logger.error(e.getMessage());
throw new RuntimeException("There are no files on path: " + path);
}
JsonElement jsonElement = parser.parse(new FileReader(path));
JsonObject initialConfig = jsonElement.getAsJsonObject();
return merge(initialConfig, path);
}

private JsonObject merge(JsonObject parent, String path) {
private JsonObject merge(JsonObject parent, String path) throws FileNotFoundException {
JsonObject result = new JsonObject();
for (Map.Entry<String, JsonElement> childEntry: parent.entrySet()) {
if (childEntry.getValue().isJsonPrimitive()) {
Expand All @@ -51,12 +42,7 @@ private JsonObject merge(JsonObject parent, String path) {
+ stringValue.substring(pathLink.length(), stringValue.length());

JsonObject parsedChild;
try {
parsedChild = parser.parse(new FileReader(newPath)).getAsJsonObject();
} catch (FileNotFoundException e) {
logger.error(e.getMessage());
throw new RuntimeException("There are no files on path: " + path);
}
parsedChild = parser.parse(new FileReader(newPath)).getAsJsonObject();
result.add(childEntry.getKey(), merge(parsedChild, newPath));
} else {
result.add(childEntry.getKey(), childEntry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.FileNotFoundException;

@Controller
public class RestController {

Expand All @@ -17,37 +19,37 @@ public RestController(ConfigsMerger merger) {

@GetMapping("/all")
@ResponseBody
public String getAllConfig() {
public String getAllConfig() throws FileNotFoundException {
return merger.generateCommonConfig().toString();
}

@GetMapping("/editor/robots")
@ResponseBody
public String getRobotEditor() {
public String getRobotEditor() throws FileNotFoundException {
return merger.generateCommonConfig().get("robotEditor").toString();
}

@GetMapping("/editor/bpmn")
@ResponseBody
public String getBPMNEditor() {
public String getBPMNEditor() throws FileNotFoundException {
return merger.generateCommonConfig().get("bpmnEditor").toString();
}

@GetMapping("/dashboard")
@ResponseBody
public String getDashboard() {
public String getDashboard() throws FileNotFoundException {
return merger.generateCommonConfig().get("dashboard").toString();
}

@GetMapping("/authform")
@ResponseBody
public String getAuthform() {
public String getAuthform() throws FileNotFoundException {
return merger.generateCommonConfig().get("authform").toString();
}

@GetMapping("/auth")
@ResponseBody
public String getAuth() {
public String getAuth() throws FileNotFoundException {
return merger.generateCommonConfig().get("authService").toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ public DiagramStoreService(EditorPageFacade facade, SelectorService selectorServ

/** Saves diagram. */
public void saveDiagram(String key) {
SelenideElement element =
$(By.id(selectorService.getId("savingMenu.savingInput")));
SelenideElement element = $(By.id(selectorService.getId("savingMenu.savingInput")));
element.setValue(getFilename(key));
diagrams.put(key, prepareElement(Jsoup.parseBodyFragment($(sceneSelector).innerHtml()).body()));
$(By.id(selectorService.getId("savingMenu.savingItem"))).click();
$(By.id(selectorService.getId("savingMenu.savingItem")))
.shouldBe(Condition.disappear);
$(By.id(selectorService.getId("savingMenu.savingItem"))).waitUntil(Condition.disappear, 5000);
lastKnownKey = key;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.qreal.wmp.uitesting.services.SelectorService;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -31,6 +32,8 @@ public class EditorHeaderPanelImpl implements EditorHeaderPanel {

private final SelectorService selectorService;

private final WebDriver webDriver;

private EditorHeaderPanelImpl(
PageFactory pageFactory,
WebDriver webDriver,
Expand All @@ -42,6 +45,7 @@ private EditorHeaderPanelImpl(
this.pageFactory = pageFactory;
this.editorPageFacade = editorPageFacade;
this.selectorService = selectorService;
this.webDriver = webDriver;
}

@Override
Expand Down Expand Up @@ -103,8 +107,8 @@ public static EditorHeaderPanel getEditorHeaderPanel(PageFactory pageFactory,
}

private FileItem clickFile() {
$(By.id(selectorService.getId("fileItem"))).waitUntil(Condition.visible, 5000);
$(By.id(selectorService.getId("fileItem"))).click();
$(By.id(selectorService.getId("fileItem"))).waitUntil(Condition.visible, 10000);
new Actions(webDriver).click($(By.id(selectorService.getId("fileItem")))).perform();
return fileItem;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.qreal.wmp.uitesting.headerpanel.folderwindow;

import com.codeborne.selenide.Condition;
import com.qreal.wmp.uitesting.services.SelectorService;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;

import static com.codeborne.selenide.Selenide.$;

Expand All @@ -24,28 +24,24 @@ public FileItem(WebDriver driver, SelectorService selectorService) {

/** Corresponds 'New' button. */
public void newDiagram() {
$(By.id(selectorService.getId("fileItem.newDiagramItem"))).click();
$(By.id(selectorService.getId("saveDiagramConfirmWindow")))
.waitUntil(Condition.visible, 10000);
new Actions(driver).click($(By.id(selectorService.getId("fileItem.newDiagramItem")))).perform();
SaveDiagramConfirm.getSaveDiagramConfirm(driver, selectorService.create("saveDiagramConfirmWindow")).notSave();
}

/** Returns folder window by clicking 'SaveAs'. */
public FolderArea getSaveItem() {
$(By.id(selectorService.getId("fileItem.saveAsItem"))).click();
$(By.id(selectorService.getId("folderArea"))).waitUntil(Condition.visible, 10000);
new Actions(driver).click($(By.id(selectorService.getId("fileItem.saveAsItem")))).perform();
return folderArea;
}

/** Returns folder window by clicking 'Open'. */
public FolderArea getOpenItem() {
$(By.id(selectorService.getId("fileItem.OpenItem"))).click();
$(By.id(selectorService.getId("folderArea"))).waitUntil(Condition.visible, 10000);
new Actions(driver).click($(By.id(selectorService.getId("fileItem.openItem")))).perform();
return folderArea;
}

/** Corresponds 'Save' button. */
public void saveDiagram() {
$(By.id(selectorService.getId("fileItem.SaveItem"))).click();
new Actions(driver).click($(By.id(selectorService.getId("fileItem.saveItem")))).perform();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.qreal.wmp.uitesting.services.SelectorService;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.Arrays;
Expand All @@ -30,9 +31,14 @@ public FolderAreaImpl(WebDriver driver, SelectorService selectorService) {

@Override
public FolderArea createFolder(String folderName) {
$(By.id(selectorService.getId("createItem"))).click();
$(By.id(selectorService.getId("folderMenu.folderNameInput"))).setValue(folderName);
$(By.id(selectorService.getId("folderMenu.confirmItem"))).click();
($(By.id(selectorService.getId("createItem")))).click();
(new WebDriverWait(driver, 10))
.until((Predicate<WebDriver>) webDriver ->
$(By.id(selectorService.getId("folderMenu.folderNameInput"))).exists());

new Actions(driver).sendKeys($(By.id(selectorService.getId("folderMenu.folderNameInput"))), folderName)
.click($(By.id(selectorService.getId("folderMenu.confirmItem")))).build().perform();

if ($(By.id(selectorService.getId("warningMessage"))).isDisplayed()) {
throw new IllegalArgumentException("The folder with this name already exists");
}
Expand All @@ -52,7 +58,9 @@ public FolderArea moveForward(String name) {
}
String oldPath = getCurrentPath();
oldPath = "".equals(oldPath) ? name : oldPath + "/" + name;
$(By.cssSelector(selectorService.getSelector("folders"))).find(byText(name)).click();
new Actions(driver)
.click($(By.cssSelector(selectorService.getSelector("folders"))).find(byText(name)))
.perform();
waitUntilEquals(oldPath, FolderArea::getCurrentPath);
return this;
}
Expand Down Expand Up @@ -96,18 +104,21 @@ public FolderArea deleteFolder(String name) {
if (!isFolderExist(name)) {
throw new IllegalArgumentException("Folder is not exist");
}
$(By.cssSelector(selectorService.getSelector("folders")))
.find(byText(name)).contextClick();
$(By.id(selectorService.getId("contextMenu"))).shouldBe(Condition.visible);
$(By.id(selectorService.getId("contextMenu.deleteItem"))).click();
new Actions(driver)
.contextClick($(By.cssSelector(selectorService.getSelector("folders"))).find(byText(name)))
.perform();
$(By.id(selectorService.getId("contextMenu"))).shouldBe(Condition.appear);
new Actions(driver)
.click($(By.id(selectorService.getId("contextMenu.deleteItem"))))
.perform();
return this;
}

@Override
public void close() {
SelenideElement closeButton = $(By.id(selectorService.getId("closeItem")));
if ($(By.id(selectorService.getId())).isDisplayed() && closeButton.isDisplayed()) {
closeButton.click();
new Actions(driver).moveToElement(closeButton).click().perform();
$(By.id(selectorService.getId())).shouldBe(Condition.disappear);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ private RobotCalibration(WebDriver driver) {
}

private Point calibrate() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
click(xPoint.begin, yPoint.begin);
// find left border
while (xPoint.begin < xPoint.end) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public void equalsFalseTest() {

@Test
public void saveAfterChangesTest() {
scene.clean();
addElements();
scene.moveToCell(elements.get(0), 10, 10);
headerPanel.saveDiagram();
assert headerPanel.equalsDiagrams(diagram);
Expand Down

0 comments on commit 6cbdeb5

Please sign in to comment.