Skip to content

Commit

Permalink
Fixed rule for sides validation and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ishubin committed Feb 28, 2016
1 parent 18ec3b4 commit 143e6ce
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 14 deletions.
26 changes: 12 additions & 14 deletions galen-extras/galen-extras-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,65 +128,63 @@ rule("%{objectPattern} sides are inside %{containerObject} with %{margin} margin
});



rule("%{objectPattern} sides are vertically inside %{containerObject} with %{margin} margin", function (objectName, parameters) {
rule("%{objectPattern} sides are vertically inside %{containerObject}", function (objectName, parameters) {
var items = findAll(parameters.objectPattern);
if (items.length > 0) {
this.addObjectSpecs(items[0].name, [ "inside " + parameters.containerObject + " " + parameters.margin + " top" ]);
this.addObjectSpecs(items[0].name, [ "inside " + parameters.containerObject + " -1 to 1 px top" ]);

for (var i = 1; i < items.length - 1; i++) {
this.addObjectSpecs(items[i].name, [ "inside " + parameters.containerObject ]);
}

this.addObjectSpecs(items[items.length - 1].name, [ "inside " + parameters.containerObject + " " + parameters.margin + " bottom" ]);
this.addObjectSpecs(items[items.length - 1].name, [ "inside " + parameters.containerObject + " -1 to 1 px bottom" ]);
} else {
throw new Error("Couldn't find any items matching " + parameters.objectPattern);
}
});


rule("%{objectPattern} sides are vertically inside %{containerObject}", function (objectName, parameters) {
rule("%{objectPattern} sides are vertically inside %{containerObject} with %{margin} margin", function (objectName, parameters) {
var items = findAll(parameters.objectPattern);
if (items.length > 0) {
this.addObjectSpecs(items[0].name, [ "inside " + parameters.containerObject + " 0 to 1 px top" ]);
this.addObjectSpecs(items[0].name, [ "inside " + parameters.containerObject + " " + parameters.margin + " top" ]);

for (var i = 1; i < items.length - 1; i++) {
this.addObjectSpecs(items[i].name, [ "inside " + parameters.containerObject ]);
}

this.addObjectSpecs(items[items.length - 1].name, [ "inside " + parameters.containerObject + " 0 to 1 px bottom" ]);
this.addObjectSpecs(items[items.length - 1].name, [ "inside " + parameters.containerObject + " " + parameters.margin + " bottom" ]);
} else {
throw new Error("Couldn't find any items matching " + parameters.objectPattern);
}
});


rule("%{objectPattern} sides are horizontally inside %{containerObject} with %{margin} margin", function (objectName, parameters) {
rule("%{objectPattern} sides are horizontally inside %{containerObject}", function (objectName, parameters) {
var items = findAll(parameters.objectPattern);
if (items.length > 0) {
this.addObjectSpecs(items[0].name, [ "inside " + parameters.containerObject + " " + parameters.margin + " left" ]);
this.addObjectSpecs(items[0].name, [ "inside " + parameters.containerObject + " -1 to 1 px left" ]);

for (var i = 1; i < items.length - 1; i++) {
this.addObjectSpecs(items[i].name, [ "inside " + parameters.containerObject ]);
}

this.addObjectSpecs(items[items.length - 1].name, [ "inside " + parameters.containerObject + " " + parameters.margin + " right" ]);
this.addObjectSpecs(items[items.length - 1].name, [ "inside " + parameters.containerObject + " -1 to 1 px right" ]);
} else {
throw new Error("Couldn't find any items matching " + parameters.objectPattern);
}
});


rule("%{objectPattern} sides are horizontally inside %{containerObject}", function (objectName, parameters) {
rule("%{objectPattern} sides are horizontally inside %{containerObject} with %{margin} margin", function (objectName, parameters) {
var items = findAll(parameters.objectPattern);
if (items.length > 0) {
this.addObjectSpecs(items[0].name, [ "inside " + parameters.containerObject + " 0 to 1 px left" ]);
this.addObjectSpecs(items[0].name, [ "inside " + parameters.containerObject + " " + parameters.margin + " left" ]);

for (var i = 1; i < items.length - 1; i++) {
this.addObjectSpecs(items[i].name, [ "inside " + parameters.containerObject ]);
}

this.addObjectSpecs(items[items.length - 1].name, [ "inside " + parameters.containerObject + " 0 to 1 px right" ]);
this.addObjectSpecs(items[items.length - 1].name, [ "inside " + parameters.containerObject + " " + parameters.margin + " right" ]);
} else {
throw new Error("Couldn't find any items matching " + parameters.objectPattern);
}
Expand Down
31 changes: 31 additions & 0 deletions rules-tests/sides.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("init.js");


testSpec("sides.gspec", [], function (spec) {
assertSpec(spec)
.hasRuleSection("box-* sides are inside main_container with 5px margin from top and bottom", {
"box-1": ["inside main_container 5px top"],
"box-2": ["inside main_container"],
"box-3": ["inside main_container 5px bottom"]
})
.hasRuleSection("box-* sides are vertically inside main_container with 4px margin", {
"box-1": ["inside main_container 4px top"],
"box-2": ["inside main_container"],
"box-3": ["inside main_container 4px bottom"]
})
.hasRuleSection("box-* sides are vertically inside main_container", {
"box-1": ["inside main_container -1 to 1 px top"],
"box-2": ["inside main_container"],
"box-3": ["inside main_container -1 to 1 px bottom"]
})
.hasRuleSection("box-* sides are horizontally inside main_container with 3px margin", {
"box-1": ["inside main_container 3px left"],
"box-2": ["inside main_container"],
"box-3": ["inside main_container 3px right"]
})
.hasRuleSection("box-* sides are horizontally inside main_container", {
"box-1": ["inside main_container -1 to 1 px left"],
"box-2": ["inside main_container"],
"box-3": ["inside main_container -1 to 1 px right"]
})
});
13 changes: 13 additions & 0 deletions rules-tests/specs/sides.gspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@import init.gspec
@script sides.mock.js

= Main =
| box-* sides are inside main_container with 5px margin from top and bottom

| box-* sides are vertically inside main_container with 4px margin

| box-* sides are vertically inside main_container

| box-* sides are horizontally inside main_container with 3px margin

| box-* sides are horizontally inside main_container
15 changes: 15 additions & 0 deletions rules-tests/specs/sides.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

var boxes = [
{name: "box-1"},
{name: "box-2"},
{name: "box-3"}
];

mockFunction("findAll")
.thenReturn(boxes)
.thenReturn(boxes)
.thenReturn(boxes)
.thenReturn(boxes)
.thenReturn(boxes)
.thenReturn(boxes)
.thenReturn(boxes)

0 comments on commit 143e6ce

Please sign in to comment.