Skip to content

Commit

Permalink
Code refactor, java doc and style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
artbez committed Mar 19, 2017
1 parent d2235ef commit b2250ac
Show file tree
Hide file tree
Showing 29 changed files with 148 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ script:

- cd ../ui-testing
- mvn test -P travis &
- sleep 900
- sleep 1000

notifications:
slack: qreal-web:sT5qgA4qZZ9eyLI0yy2Mp81E
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <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;
}
Expand Down Expand Up @@ -401,6 +384,28 @@ class SceneController {
});
}

private checkBorder(element: DiagramElement, cellView, event) : void {
var sceneWrapper: HTMLDivElement = <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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ 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;
this.direction = Direction.None;
}

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;
}

}
1 change: 1 addition & 0 deletions ui-testing/src/main/java/com/qreal/wmp/uitesting/Page.java
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public interface Pallete {

/**
* Chose element from Pallete.
* Chooses an element from Pallete.
*
* @param elementName name of block
* @return block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.codeborne.selenide.SelenideElement;


/** Describes pallete's items. */
public class PalleteElement {

private final SelenideElement inner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -18,7 +21,7 @@ public class Coordinate {
/** Returns coordinate of object on scene. */
@NotNull
public static Optional<Coordinate> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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")
Expand Down Expand Up @@ -114,15 +114,15 @@ 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 {
if (!blockProvider.isEmpty()) {
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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() {
Expand All @@ -27,4 +33,8 @@ public String getName() {
public SceneElement getPort() {
return port;
}

public void moveToCell(int cellX, int cellY) {
scene.moveToCell(this, cellX, cellY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit b2250ac

Please sign in to comment.