Skip to content

Commit

Permalink
Feature/#250 wait style (#255)
Browse files Browse the repository at this point in the history
* Added support for parsed styles

* Added stdlib function.

* Added e2e tests

* Added e2e tests for STYLE_* functions
  • Loading branch information
ziflex authored Mar 13, 2019
1 parent 391836c commit 376ad77
Show file tree
Hide file tree
Showing 42 changed files with 1,223 additions and 215 deletions.
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
name = "github.com/PuerkitoBio/goquery"
version = "1.5.0"

[[constraint]]
name = "github.com/gorilla/css"
version = "v1.0.0"

[[constraint]]
name = "github.com/gofrs/uuid"
version = "3.1.2"
Expand Down
37 changes: 33 additions & 4 deletions e2e/pages/dynamic/components/pages/events/appearable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,52 @@ import random from "../../../utils/random.js";

const e = React.createElement;

function render(id) {
return e("span", { id: `${id}-content` }, ["Hello world"]);
function render(id, props = {}) {
return e("span", { id: `${id}-content`, ...props }, ["Hello world"]);
}

export default class AppearableComponent extends React.PureComponent {
constructor(props) {
super(props);

let element = null;

if (props.appear) {
if (props.useStyle) {
element = render(props.id, { style: {display: "none"}})
}
} else {
if (props.useStyle) {
element = render(props.id, { style: {display: "block" }})
} else {
element = render(props.id)
}
}

this.state = {
element: props.appear === true ? null : render(props.id)
element
};
}

handleClick() {
setTimeout(() => {
const props = this.props;
let element = null;

if (props.appear) {
if (props.useStyle) {
element = render(props.id, { style: {display: "block" }})
} else {
element = render(props.id)
}
} else {
if (props.useStyle) {
element = render(props.id, { style: {display: "none"}})
}
}

this.setState({
element: this.props.appear === true ? render(this.props.id) : null
element,
})
}, random())
}
Expand Down
20 changes: 19 additions & 1 deletion e2e/pages/dynamic/components/pages/events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,31 @@ export default class EventsPage extends React.Component {
title: "Appearable"
})
]),
]),
e("div", { className: "row" }, [
e("div", { className: "col-lg-4"}, [
e(Appearable, {
id: "wait-no-element",
appear: false,
title: "Disappearable"
})
])
]),
e("div", { className: "col-lg-4"}, [
e(Appearable, {
id: "wait-style",
appear: true,
title: "Appearable with style",
useStyle: true,
})
]),
e("div", { className: "col-lg-4"}, [
e(Appearable, {
id: "wait-no-style",
appear: false,
title: "Disappearable",
useStyle: true,
})
]),
])
])
}
Expand Down
11 changes: 11 additions & 0 deletions e2e/tests/el_attrs_get.d.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
LET url = @dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET pageSelector = "#page-events"
LET elemSelector = "#wait-no-style-content"

WAIT_ELEMENT(doc, pageSelector)

LET el = ELEMENT(doc, elemSelector)
LET attrs = ATTR_GET(el, "style")

RETURN EXPECT("display: block;", attrs.style)
17 changes: 17 additions & 0 deletions e2e/tests/el_attrs_remove.d.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LET url = @dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET pageSelector = "#page-events"
LET elemSelector = "#wait-no-style-content"

WAIT_ELEMENT(doc, pageSelector)
LET el = ELEMENT(doc, elemSelector)

LET prev = el.attributes.style

ATTR_REMOVE(el, "style")

WAIT(1000)

LET curr = el.attributes.style

RETURN prev == "display: block;" && curr == NONE ? "" : "expected attribute to be removed"
17 changes: 17 additions & 0 deletions e2e/tests/el_attrs_set.d.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LET url = @dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET pageSelector = "#page-events"
LET elemSelector = "#wait-no-style-content"

WAIT_ELEMENT(doc, pageSelector)

LET el = ELEMENT(doc, elemSelector)
LET prev = el.style

ATTR_SET(el, "style", "color: black;")

WAIT(1000)

LET curr = el.style

RETURN curr.color == "black" ? "" : "styles should be updated"
14 changes: 14 additions & 0 deletions e2e/tests/el_attrs_set_bulk.d.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
LET url = @dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET pageSelector = "#page-events"
LET elemSelector = "#wait-no-style-content"

WAIT_ELEMENT(doc, pageSelector)

LET el = ELEMENT(doc, elemSelector)

ATTR_SET(el, { style: "color: black;", "data-ferret-x": "test" })

WAIT(1000)

RETURN el.style.color == "black" && el.attributes["data-ferret-x"] == "test" ? "" : "styles should be updated"
11 changes: 11 additions & 0 deletions e2e/tests/el_style_get.d.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
LET url = @dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET pageSelector = "#page-events"
LET elemSelector = "#wait-no-style-content"

WAIT_ELEMENT(doc, pageSelector)

LET el = ELEMENT(doc, elemSelector)
LET val = STYLE_GET(el, "display")

RETURN val.display == "block" ? "" : "could not get style values"
17 changes: 17 additions & 0 deletions e2e/tests/el_style_remove.d.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LET url = @dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET pageSelector = "#page-events"
LET elemSelector = "#wait-no-style-content"

WAIT_ELEMENT(doc, pageSelector)
LET el = ELEMENT(doc, elemSelector)

LET prev = el.style

STYLE_REMOVE(el, "display")

WAIT(1000)

LET curr = el.style

RETURN prev.display == "block" && curr.display == NONE ? "" : "expected style to be removed"
17 changes: 17 additions & 0 deletions e2e/tests/el_style_set.d.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LET url = @dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET pageSelector = "#page-events"
LET elemSelector = "#wait-no-style-content"

WAIT_ELEMENT(doc, pageSelector)

LET el = ELEMENT(doc, elemSelector)
LET prev = el.style

STYLE_SET(el, "color", "black")

WAIT(1000)

LET curr = el.style

RETURN curr.color == "black" ? "" : "styles should be updated"
17 changes: 17 additions & 0 deletions e2e/tests/el_style_set_bulk.d.fql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LET url = @dynamic + "?redirect=/events"
LET doc = DOCUMENT(url, true)
LET pageSelector = "#page-events"
LET elemSelector = "#wait-no-style-content"

WAIT_ELEMENT(doc, pageSelector)

LET el = ELEMENT(doc, elemSelector)
LET prev = el.style

STYLE_SET(el, { color: "black", "min-width": "100px", "background-color": "#11111" })

WAIT(1000)

LET curr = el.style

RETURN curr.color == "black" && curr["min-width"] == "100px" && curr["background-color"] == "#11111" ? "" : "styles should be updated"
Loading

0 comments on commit 376ad77

Please sign in to comment.