From b2250ac79fd32ea88f79c063752f60d70342fa21 Mon Sep 17 00:00:00 2001 From: ArtemiiBezguzikov Date: Sun, 19 Mar 2017 23:25:34 +0300 Subject: [PATCH] Code refactor, java doc and style guide --- .travis.yml | 2 +- .../editorCore/controller/SceneController.ts | 41 +++++++++++-------- .../app/core/editorCore/model/Scroller.ts | 18 ++++---- .../java/com/qreal/wmp/uitesting/Page.java | 1 + .../com/qreal/wmp/uitesting/PageFactory.java | 1 + .../com/qreal/wmp/uitesting/PageLoader.java | 4 ++ .../wmp/uitesting/dia/pallete/Pallete.java | 2 +- .../uitesting/dia/pallete/PalleteElement.java | 2 + .../uitesting/dia/pallete/PalleteImpl.java | 1 + .../dia/property/PropertyEditor.java | 3 +- .../dia/property/PropertyEditorImpl.java | 1 + .../wmp/uitesting/dia/scene/Coordinate.java | 5 ++- .../qreal/wmp/uitesting/dia/scene/Scene.java | 4 +- .../wmp/uitesting/dia/scene/SceneImpl.java | 14 +++---- .../uitesting/dia/scene/elements/Block.java | 16 ++++++-- .../uitesting/dia/scene/elements/Link.java | 9 ++-- .../dia/scene/elements/SceneElementImpl.java | 13 +++--- .../dia/scene/providers/BlockProvider.java | 25 ++++++----- .../dia/scene/providers/LinkProvider.java | 1 + .../dia/scene/window/SceneWindowImpl.java | 41 +++++++++++++------ .../ElementNotOnTheSceneException.java | 2 +- .../qreal/wmp/uitesting/pages/AuthPage.java | 1 + .../wmp/uitesting/pages/DashboardPage.java | 1 + .../qreal/wmp/uitesting/pages/EditorPage.java | 3 ++ .../uitesting/services/impl/AutherImpl.java | 1 + .../uitesting/services/impl/OpenerImpl.java | 1 + ...Test.java => ManipulatingDiagramTest.java} | 12 +++--- .../testspace/DiagramConstructingTest.java | 6 +-- ui-testing/ui-testing.iml | 1 + 29 files changed, 148 insertions(+), 84 deletions(-) rename ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/{DiaTest.java => ManipulatingDiagramTest.java} (94%) diff --git a/.travis.yml b/.travis.yml index c7cd3268..b60f5b0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,7 +69,7 @@ script: - cd ../ui-testing - mvn test -P travis & - - sleep 900 + - sleep 1000 notifications: slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E diff --git a/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts b/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts index 32f5707e..70ad237e 100644 --- a/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts +++ b/editor-core/src/main/webapp/app/core/editorCore/controller/SceneController.ts @@ -291,25 +291,8 @@ class SceneController { private cellPointermoveListener(cellView, event, x, y): void { var element: DiagramElement = this.scene.getNodeById(cellView.model.id) || this.scene.getLinkById(cellView.model.id); - var sceneWrapper: HTMLDivElement = $(".scene-wrapper")[0]; - var boundingBox: any = sceneWrapper.getBoundingClientRect(); if (element instanceof DefaultDiagramNode) { - var node = this.scene.getNodeById(cellView.model.id); - this.borderUnCrossed(); - if (event.pageX + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.right) { - this.scroller.direction = Direction.Right; - this.borderCrossed(node, event); - } else if (event.pageX - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.left) { - this.scroller.direction = Direction.Left; - this.borderCrossed(node, event); - } else if (event.pageY + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.bottom) { - this.scroller.direction = Direction.Down; - this.borderCrossed(node, event); - } else if (event.pageY - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.top) { - this.scroller.direction = Direction.Up; - this.borderCrossed(node, event); - } - this.updateLastCellScrollPosition(event); + this.checkBorder(element, cellView, event) } this.clickFlag = false; } @@ -401,6 +384,28 @@ class SceneController { }); } + private checkBorder(element: DiagramElement, cellView, event) : void { + var sceneWrapper: HTMLDivElement = $(".scene-wrapper")[0]; + var boundingBox: any = sceneWrapper.getBoundingClientRect(); + + var node = this.scene.getNodeById(cellView.model.id); + this.borderUnCrossed(); + if (event.pageX + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.right) { + this.scroller.direction = Direction.Right; + this.borderCrossed(node, event); + } else if (event.pageX - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.left) { + this.scroller.direction = Direction.Left; + this.borderCrossed(node, event); + } else if (event.pageY + this.scene.getGridSize() * this.scene.getZoom() >= boundingBox.bottom) { + this.scroller.direction = Direction.Down; + this.borderCrossed(node, event); + } else if (event.pageY - this.scene.getGridSize() * this.scene.getZoom() <= boundingBox.top) { + this.scroller.direction = Direction.Up; + this.borderCrossed(node, event); + } + this.updateLastCellScrollPosition(event); + } + private borderCrossed(node: DiagramNode, event): void { this.scroller.scroll = true; var that = this; diff --git a/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts b/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts index 43694f6f..153b5dce 100644 --- a/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts +++ b/editor-core/src/main/webapp/app/core/editorCore/model/Scroller.ts @@ -4,11 +4,11 @@ enum Direction { class Scroller { - private _scroll: boolean; + private scroll: boolean; - private _intervalId: number; + private intervalId: number; - private _direction: Direction; + private direction: Direction; constructor() { this.scroll = false; @@ -16,27 +16,27 @@ class Scroller { } get direction(): Direction { - return this._direction; + return this.direction; } set direction(value: Direction) { - this._direction = value; + this.direction = value; } get intervalId(): number { - return this._intervalId; + return this.intervalId; } set intervalId(value: number) { - this._intervalId = value; + this.intervalId = value; } get scroll(): boolean { - return this._scroll; + return this.scroll; } set scroll(value: boolean) { - this._scroll = value; + this.scroll = value; } } \ No newline at end of file diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java index 42165cae..ac6cbb79 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java @@ -1,5 +1,6 @@ package com.qreal.wmp.uitesting; +/** Describes WMP pages in browser. */ public enum Page { Auth("auth"), Dashboard("dashboard"), EditorRobots("robotsEditor"), EditorBPMN("bpmnEditor"); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java index 09525feb..2c2ef241 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageFactory.java @@ -10,6 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** Returns page instance for requested uri. */ public class PageFactory { private static final Logger logger = LoggerFactory.getLogger(PageFactory.class); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java index ca218ab9..cfdb53e7 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/PageLoader.java @@ -4,6 +4,10 @@ import com.qreal.wmp.uitesting.services.Auther; import com.qreal.wmp.uitesting.services.Opener; +/** Loads page. + * It means, firstly, it opens uri by Opener service. + * Secondly, it returns page by PageFactory. + * */ public class PageLoader { private final PageFactory pageFactory; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java index b3ce553e..52e1b1dd 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/Pallete.java @@ -9,7 +9,7 @@ public interface Pallete { /** - * Chose element from Pallete. + * Chooses an element from Pallete. * * @param elementName name of block * @return block diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java index 6c724a5c..d438b888 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteElement.java @@ -2,6 +2,8 @@ import com.codeborne.selenide.SelenideElement; + +/** Describes pallete's items. */ public class PalleteElement { private final SelenideElement inner; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java index 79cf26d5..f0846d64 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/pallete/PalleteImpl.java @@ -9,6 +9,7 @@ import static com.codeborne.selenide.Selectors.withText; import static com.codeborne.selenide.Selenide.$; +/** {@inheritDoc} */ public class PalleteImpl implements Pallete { private static final String SELECTOR = "#palette-tab-content"; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java index ab23dbae..3307b0ca 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditor.java @@ -3,7 +3,8 @@ import com.codeborne.selenide.SelenideElement; import org.openqa.selenium.NoSuchElementException; -/** Describe Property Editor. */ +/** Describe Property Editor. + * When block is clicked, it could be configured by Property Editor. */ public interface PropertyEditor { /** Set property of element which on the focus. */ void setProperty(SelenideElement element, String propertyName, String propertyValue) throws NoSuchElementException; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java index 5c70f9be..1200616e 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/property/PropertyEditorImpl.java @@ -13,6 +13,7 @@ import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.$$; +/** {@inheritDoc} */ public class PropertyEditorImpl implements PropertyEditor { private static final String SELECTOR = "#property_table"; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java index cf19d42a..dc6b8de9 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Coordinate.java @@ -5,6 +5,9 @@ import java.util.Optional; +/** Describes element's position on the Scene. + * Contains absolute coordinates of scene, which are written in 'transform' tag on the html representation. + * Also contains cell's position (the Scene is represented by a mesh of cells)*/ public class Coordinate { public static final String SELECTOR = "transform"; @@ -18,7 +21,7 @@ public class Coordinate { /** Returns coordinate of object on scene. */ @NotNull public static Optional getCoordinateFromSeleniumObject(SelenideElement element) { - final String position = element.attr("transform"); + final String position = element.attr(SELECTOR); final String[] pairStr = position.substring(position.indexOf('(') + 1, position.indexOf(')')).split(","); return Optional.of( new Coordinate( diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java index 1bbbd00a..bf5008fb 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/Scene.java @@ -13,10 +13,10 @@ public interface Scene { Block dragAndDrop(PalleteElement palleteElement); /** Drag element from scene or pallete and put it in cell of the scene. */ - Block dragAndDrop(PalleteElement element, int cell_x, int cell_y); + Block dragAndDrop(PalleteElement element, int cellX, int cellY); /** Move element from scene to the cell. */ - void moveToCell(Block block, int cell_x, int cell_y); + void moveToCell(Block block, int cellX, int cellY); /** Check if element exist on the scene. */ boolean exist(SceneElement element); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java index 70f7e4c2..03ceb95a 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/SceneImpl.java @@ -55,7 +55,7 @@ private SceneImpl(WebDriver webDriver) { ); } sceneWindow = SceneWindowImpl.getSceneWindow(webDriver); - blockProvider = BlockProvider.getBlockProvider(sceneWindow, SELECTOR); + blockProvider = BlockProvider.getBlockProvider(sceneWindow, SELECTOR, this); linkProvider = LinkProvider.getLinkProvider(SELECTOR, webDriver); } @@ -66,15 +66,15 @@ public Block dragAndDrop(final PalleteElement element) { } @Override - public Block dragAndDrop(final PalleteElement element, int cell_x, int cell_y) { + public Block dragAndDrop(final PalleteElement element, int cellX, int cellY) { Block newBlock = dragAndDrop(element); - blockProvider.moveToCell(newBlock, cell_x, cell_y); + blockProvider.moveToCell(newBlock, cellX, cellY); return newBlock; } @Override - public void moveToCell(Block block, final int cell_x, final int cell_y) { - blockProvider.moveToCell(block, cell_x, cell_y); + public void moveToCell(Block block, int cellX, int cellY) { + blockProvider.moveToCell(block, cellX, cellY); } @SuppressWarnings("SimplifiableIfStatement") @@ -114,7 +114,7 @@ public void clean() { try { remove(linkProvider.getLinks().get(0)); } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); + logger.error("It's impossible to remove link, because it is not on the Scene."); } clean(); } else { @@ -122,7 +122,7 @@ public void clean() { try { remove(blockProvider.getBlocks().get(0)); } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); + logger.error("It's impossible to remove block, because it is not on the scene."); } clean(); } else { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java index def9e525..a94ff39d 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Block.java @@ -1,9 +1,12 @@ package com.qreal.wmp.uitesting.dia.scene.elements; +import com.qreal.wmp.uitesting.dia.scene.Scene; import org.openqa.selenium.By; import static com.codeborne.selenide.Selenide.$; +/** Describes item, which is placed on the scene. + * Pallete have items. If we dragAndDrop these items to the Scene, we'll get Blocks. */ public class Block extends SceneElementImpl { public static final String CLASS_NAME = "element devs ImageWithPorts"; @@ -14,10 +17,13 @@ public class Block extends SceneElementImpl { private final SceneElement port; - public Block(String name, By by) { - super(by); + private final Scene scene; + + public Block(String name, By selector, Scene scene) { + super(selector); this.name = name; - this.port = new SceneElementImpl(By.id($(by).find(By.className(PORT_CLASS_NAME)).attr("id"))); + this.port = new SceneElementImpl(By.id($(selector).find(By.className(PORT_CLASS_NAME)).attr("id"))); + this.scene = scene; } public String getName() { @@ -27,4 +33,8 @@ public String getName() { public SceneElement getPort() { return port; } + + public void moveToCell(int cellX, int cellY) { + scene.moveToCell(this, cellX, cellY); + } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java index 6da6e550..6872a66d 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/Link.java @@ -7,6 +7,7 @@ import static com.codeborne.selenide.Selenide.$; +/** Link describes relations between blocks. */ public class Link extends SceneElementImpl { public static final String CLASS_NAME = "link"; @@ -20,12 +21,12 @@ public class Link extends SceneElementImpl { private final SceneElement target; /** Describes link between two blocks. */ - public Link(String name, By by) { - super(by); + public Link(String name, By selector) { + super(selector); this.name = name; - SelenideElement source = $(by).find(By.className(ARROWHEAD)).find(By.cssSelector(":nth-child(1)")); + SelenideElement source = $(selector).find(By.className(ARROWHEAD)).find(By.cssSelector(":nth-child(1)")); this.source = new SceneElementImpl(By.id(source.attr("id"))); - SelenideElement target = $(by).find(By.className(ARROWHEAD)).find(By.cssSelector(":nth-child(2)")); + SelenideElement target = $(selector).find(By.className(ARROWHEAD)).find(By.cssSelector(":nth-child(2)")); this.target = new SceneElementImpl(By.id(target.attr("id"))); } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java index fd0436cb..5203a26d 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/elements/SceneElementImpl.java @@ -7,21 +7,24 @@ import static com.codeborne.selenide.Selenide.$; +/** All Scene elements have selector by which we can clearly define their web instances. + * Also all scene elements have coordinates on the Scene. */ public class SceneElementImpl implements SceneElement { - private By by; + // Wrapper over an string selector. Used to search the element in HTML representation of current page. + private final By selector; - public SceneElementImpl(By by) { - this.by = by; + public SceneElementImpl(By selector) { + this.selector = selector; } /** Based on the Selenium element. */ public SelenideElement getInnerSeleniumElement() { - return $(by); + return $(selector); } public By getBy() { - return by; + return selector; } public Coordinate getCoordinateOnScene() throws ElementNotOnTheSceneException { diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java index e79e1b8a..d74ac86e 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/BlockProvider.java @@ -2,6 +2,7 @@ import com.codeborne.selenide.SelenideElement; import com.qreal.wmp.uitesting.dia.scene.Coordinate; +import com.qreal.wmp.uitesting.dia.scene.Scene; import com.qreal.wmp.uitesting.dia.scene.elements.Block; import com.qreal.wmp.uitesting.dia.scene.window.SceneWindow; import com.qreal.wmp.uitesting.exceptions.ElementNotOnTheSceneException; @@ -16,6 +17,7 @@ import static com.codeborne.selenide.Selenide.$$; +/** Encapsulates blocks operations. */ public class BlockProvider { private static final Logger logger = LoggerFactory.getLogger(BlockProvider.class); @@ -24,20 +26,23 @@ public class BlockProvider { private final String selector; + private final Scene scene; + private Set blocks = new HashSet<>(); - private BlockProvider(SceneWindow sceneWindow, String selector) { + private BlockProvider(SceneWindow sceneWindow, String selector, Scene scene) { this.sceneWindow = sceneWindow; this.selector = selector; + this.scene = scene; } /** Move element to cell with x and y coordinates. */ - public void moveToCell(final Block block, final int cell_x, final int cell_y) { - logger.info("Move element {} to cell ({}, {})", block, cell_x, cell_y); + public void moveToCell(final Block block, final int cellX, final int cellY) { + logger.info("Move element {} to cell ({}, {})", block, cellX, cellY); try { - sceneWindow.move(block, new Coordinate(cell_x * 25, cell_y * 25)); + sceneWindow.move(block, new Coordinate(cellX * 25, cellY * 25)); } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); + logger.error("It is impossible to move element, which is not on the Scene"); } } @@ -49,7 +54,7 @@ public List getBlocks() { public Block getNewBlock() { final SelenideElement newEl = updateBlocks().orElseThrow(NotFoundException::new); logger.info("Add element {} to scene", newEl); - Block block = new Block(newEl.attr("id"), By.id(newEl.attr("id"))); + Block block = new Block(newEl.attr("id"), By.id(newEl.attr("id")), scene); blocks.add(block); return block; } @@ -65,13 +70,13 @@ public boolean isEmpty() { public void recalculateBlocks() { blocks = $$(By.cssSelector(selector + " #v_7 > *")).stream() .filter(x -> x.attr("class").contains(Block.CLASS_NAME)) - .map(x -> new Block(x.attr("id"), By.id(x.attr("id")))) + .map(x -> new Block(x.attr("id"), By.id(x.attr("id")), scene)) .collect(Collectors.toSet()); } - @Contract("_, _ -> !null") - public static BlockProvider getBlockProvider(SceneWindow sceneWindow, String selector) { - return new BlockProvider(sceneWindow, selector); + @Contract("_, _, _ -> !null") + public static BlockProvider getBlockProvider(SceneWindow sceneWindow, String selector, Scene scene) { + return new BlockProvider(sceneWindow, selector, scene); } /** Return new element of the scene. */ diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java index e82240f4..8e193643 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/providers/LinkProvider.java @@ -16,6 +16,7 @@ import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.$$; +/** Encapsulates links operations. */ public class LinkProvider { private static final Logger logger = LoggerFactory.getLogger(LinkProvider.class); diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java index 76554a7e..3e8e79e7 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/dia/scene/window/SceneWindowImpl.java @@ -47,26 +47,32 @@ public void move(final Block element, final Coordinate dist) throws ElementNotOn Actions actions = new Actions(driver); actions.clickAndHold(element.getInnerSeleniumElement()); - if (Math.abs(dist.getXAbsolute() - element.getCoordinateOnScene().getXAbsolute()) < sizeHor / 2 - && Math.abs(dist.getYAbsolute() - element.getCoordinateOnScene().getYAbsolute()) < sizeVer / 2) { + if (isDistanceLessThenBarrier( + dist, + element.getCoordinateOnScene(), + new OffsetObject(sizeHor / 2, sizeVer / 2))) { + jump(actions, element, dist); } else { - Predicate condX = x -> Math.abs(x.getXAbsolute() - dist.getXAbsolute()) <= sizeHor / 3; + java.util.function.Predicate condX = x -> + isDistanceLessThenBarrier(x.getXAbsolute(), dist.getXAbsolute(), sizeHor / 3); + if (src.getXAbsolute() < dist.getXAbsolute()) { - movement(actions, element, new OffsetObject(sizeHor / 4, 0), condX); + innerMove(actions, element, new OffsetObject(sizeHor / 4, 0), condX); } else { - movement(actions, element, new OffsetObject(-sizeHor / 4, 0), condX); + innerMove(actions, element, new OffsetObject(-sizeHor / 4, 0), condX); } } if (Math.abs(dist.getXAbsolute() - element.getCoordinateOnScene().getXAbsolute()) < sizeHor / 2 && Math.abs(dist.getYAbsolute() - element.getCoordinateOnScene().getYAbsolute()) < sizeVer / 2) { jump(actions, element, dist); } else { - Predicate condY = x -> Math.abs(x.getYAbsolute() - dist.getYAbsolute()) <= sizeVer / 3; + java.util.function.Predicate condY = x -> + isDistanceLessThenBarrier(x.getYAbsolute(), dist.getYAbsolute(), sizeVer / 3); if (src.getYAbsolute() < dist.getYAbsolute()) { - movement(actions, element, new OffsetObject(0, sizeVer / 4), condY); + innerMove(actions, element, new OffsetObject(0, sizeVer / 4), condY); } else { - movement(actions, element, new OffsetObject(0, -sizeVer / 4), condY); + innerMove(actions, element, new OffsetObject(0, -sizeVer / 4), condY); } } @@ -77,7 +83,7 @@ public void move(final Block element, final Coordinate dist) throws ElementNotOn try { return element.getCoordinateOnScene().equals(dist); } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); + logger.error("It is impossible to move element, which is not on the Scene"); } return false; }); @@ -119,7 +125,9 @@ private void updateCanvasInfo() { } } - private void movement(Actions actions, SceneElement element, OffsetObject offset, Predicate cond) { + private void innerMove(Actions actions, SceneElement element, + OffsetObject offset, java.util.function.Predicate cond) { + (new WebDriverWait(driver, 40)) .until((Predicate) webDriver -> { try { @@ -139,9 +147,9 @@ private void movement(Actions actions, SceneElement element, OffsetObject offset offset.offsetY = signY * random.nextInt(Math.abs(offset.offsetY)); } } - return cond.apply(element.getCoordinateOnScene()); + return cond.test(element.getCoordinateOnScene()); } catch (ElementNotOnTheSceneException e) { - logger.error(e.getMessage()); + logger.error("It is impossible to move element, which is not on the Scene"); } return false; }); @@ -167,4 +175,13 @@ private class OffsetObject { this.offsetY = offsetY; } } + + private boolean isDistanceLessThenBarrier(double fst, double snd, double barrier) { + return Math.abs(fst - snd) <= barrier; + } + + private boolean isDistanceLessThenBarrier(Coordinate fst, Coordinate snd, OffsetObject barrier) { + return isDistanceLessThenBarrier(fst.getXAbsolute(), snd.getXAbsolute(), barrier.offsetX) && + isDistanceLessThenBarrier(fst.getYAbsolute(), snd.getYAbsolute(), barrier.offsetY); + } } \ No newline at end of file diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java index c264ebbc..53197584 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/exceptions/ElementNotOnTheSceneException.java @@ -3,7 +3,7 @@ public class ElementNotOnTheSceneException extends Exception { public ElementNotOnTheSceneException() { - super("It is impossible to get Coordinate of element, which is not on the Scene"); + super("It is impossible to get Coordinates of element, which is not on the Scene"); } } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java index f068daf9..656f42de 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/AuthPage.java @@ -1,4 +1,5 @@ package com.qreal.wmp.uitesting.pages; +/** Describes Authorization page of the WMP project. */ public class AuthPage { } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java index cd87621b..bc24f6f3 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/DashboardPage.java @@ -1,4 +1,5 @@ package com.qreal.wmp.uitesting.pages; +/** Describes Dashboard page of the WMP project. */ public class DashboardPage { } diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java index 680cd697..8af803b4 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/pages/EditorPage.java @@ -4,6 +4,9 @@ import com.qreal.wmp.uitesting.dia.property.PropertyEditor; import com.qreal.wmp.uitesting.dia.scene.Scene; +/** Describes Editor page of the WMP project. + * Includes such components as Scene, Pallete and PropertyEditor. + */ public class EditorPage { private final Scene scene; diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java index f1d3529f..382c52bf 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/AutherImpl.java @@ -11,6 +11,7 @@ import static com.codeborne.selenide.Selenide.$; import static com.codeborne.selenide.Selenide.open; +/** {@inheritDoc} */ public class AutherImpl implements Auther { /** Use properties from pages.properies file. */ diff --git a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java index f93fcd15..a5ebf771 100644 --- a/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java +++ b/ui-testing/src/main/java/com/qreal/wmp/uitesting/services/impl/OpenerImpl.java @@ -11,6 +11,7 @@ import static com.codeborne.selenide.Selectors.byText; import static com.codeborne.selenide.Selenide.$; +/** {@inheritDoc} */ public class OpenerImpl implements Opener { /** Uses properties from pages.properies file. */ diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/ManipulatingDiagramTest.java similarity index 94% rename from ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java rename to ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/ManipulatingDiagramTest.java index 295c31fa..bc651933 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/DiaTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/innertests/ManipulatingDiagramTest.java @@ -25,9 +25,9 @@ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = AppInit.class, loader = AnnotationConfigContextLoader.class) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -public class DiaTest { +public class ManipulatingDiagramTest { - private static final Logger logger = LoggerFactory.getLogger(DiaTest.class); + private static final Logger logger = LoggerFactory.getLogger(ManipulatingDiagramTest.class); @Autowired private PageLoader pageLoader; @@ -75,7 +75,7 @@ public void addLink() { final Block motor = scene.dragAndDrop(pallete.getElement("Motors Forward"), 4, 7); Link link = scene.addLink(initNode, motor); Link link2 = scene.addLink(motor, finalNode); - scene.moveToCell(motor, 72, 64); + motor.moveToCell(72, 64); assert scene.exist(link); assert scene.exist(link2); } @@ -93,11 +93,11 @@ public void propertyEditor() { public void moveElement() { final Block motor = scene.dragAndDrop(pallete.getElement("Motors Forward")); try { - scene.moveToCell(motor, 40, 40); + motor.moveToCell(40, 40); assert motor.getCoordinateOnScene().getXCell() == 40 && motor.getCoordinateOnScene().getYCell() == 40; - scene.moveToCell(motor, 72, 64); + motor.moveToCell(72, 64); assert motor.getCoordinateOnScene().getXCell() == 72 && motor.getCoordinateOnScene().getYCell() == 64; - scene.moveToCell(motor, 0, 0); + motor.moveToCell(0, 0); assert motor.getCoordinateOnScene().getXCell() == 0 && motor.getCoordinateOnScene().getYCell() == 0; } catch (ElementNotOnTheSceneException e) { logger.error(e.getMessage()); diff --git a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java index 49a4e318..2729a36e 100644 --- a/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java +++ b/ui-testing/src/test/java/com/qreal/wmp/uitesting/testspace/DiagramConstructingTest.java @@ -66,9 +66,9 @@ public void digramFiveNodes() { @Test public void moveSomeNodes() { - scene.moveToCell(elements.get(1), 20, 20); - scene.moveToCell(elements.get(0), 20, 10); - scene.moveToCell(elements.get(1), 0, 20); + elements.get(1).moveToCell(20, 20); + elements.get(0).moveToCell(20, 10); + elements.get(1).moveToCell(0, 20); assert allExist(); } diff --git a/ui-testing/ui-testing.iml b/ui-testing/ui-testing.iml index 9aa516a1..4c9c646c 100644 --- a/ui-testing/ui-testing.iml +++ b/ui-testing/ui-testing.iml @@ -21,6 +21,7 @@ +