|
26 | 26 | class CommentsAppContext implements Context, ActorAwareInterface { |
27 | 27 | use ActorAware; |
28 | 28 |
|
29 | | - |
30 | 29 | /** |
31 | | - * @When /^I create a new comment with "([^"]*)" as message$/ |
| 30 | + * @return Locator |
32 | 31 | */ |
33 | | - public function iCreateANewCommentWithAsMessage($commentText) { |
34 | | - $this->actor->find(self::newCommentField(), 2)->setValue($commentText); |
35 | | - $this->actor->find(self::submitNewCommentButton(), 2)->click(); |
| 32 | + public static function newCommentField() { |
| 33 | + return Locator::forThe()->css("div.newCommentRow .message")-> |
| 34 | + descendantOf(FilesAppContext::currentSectionDetailsView())-> |
| 35 | + describedAs("New comment field in current section details view in Files app"); |
36 | 36 | } |
37 | 37 |
|
38 | 38 | /** |
39 | | - * @Then /^I see that a comment was added$/ |
| 39 | + * @return Locator |
40 | 40 | */ |
41 | | - public function iSeeThatACommentWasAdded() { |
42 | | - $self = $this; |
43 | | - |
44 | | - $result = Utils::waitFor(function () use ($self) { |
45 | | - return $self->isCommentAdded(); |
46 | | - }, 5, 0.5); |
47 | | - |
48 | | - PHPUnit_Framework_Assert::assertTrue($result); |
| 41 | + public static function submitNewCommentButton() { |
| 42 | + return Locator::forThe()->css("div.newCommentRow .submit")-> |
| 43 | + descendantOf(FilesAppContext::currentSectionDetailsView())-> |
| 44 | + describedAs("Submit new comment button in current section details view in Files app"); |
49 | 45 | } |
50 | 46 |
|
51 | | - public function isCommentAdded() { |
52 | | - try { |
53 | | - $locator = self::commentFields(); |
54 | | - $comments = $this->actor->getSession()->getPage()->findAll($locator->getSelector(), $locator->getLocator()); |
55 | | - PHPUnit_Framework_Assert::assertSame(1, count($comments)); |
56 | | - } catch (PHPUnit_Framework_ExpectationFailedException $e) { |
57 | | - return false; |
58 | | - } |
59 | | - return true; |
| 47 | + /** |
| 48 | + * @return Locator |
| 49 | + */ |
| 50 | + public static function commentList() { |
| 51 | + return Locator::forThe()->css("ul.comments")-> |
| 52 | + descendantOf(FilesAppContext::currentSectionDetailsView())-> |
| 53 | + describedAs("Comment list in current section details view in Files app"); |
60 | 54 | } |
61 | 55 |
|
62 | 56 | /** |
63 | 57 | * @return Locator |
64 | 58 | */ |
65 | | - public static function newCommentField() { |
66 | | - return Locator::forThe()->css("div.newCommentRow .message")->descendantOf(FilesAppContext::currentSectionDetailsView())-> |
67 | | - describedAs("New comment field in the details view in Files app"); |
| 59 | + public static function commentWithText($text) { |
| 60 | + return Locator::forThe()->xpath("//div[normalize-space() = '$text']/ancestor::li")-> |
| 61 | + descendantOf(self::commentList())-> |
| 62 | + describedAs("Comment with text \"$text\" in current section details view in Files app"); |
68 | 63 | } |
69 | 64 |
|
70 | | - public static function commentFields() { |
71 | | - return Locator::forThe()->css(".comments .comment .message")->descendantOf(FilesAppContext::currentSectionDetailsView())-> |
72 | | - describedAs("Comment fields in the details view in Files app"); |
| 65 | + /** |
| 66 | + * @When /^I create a new comment with "([^"]*)" as message$/ |
| 67 | + */ |
| 68 | + public function iCreateANewCommentWithAsMessage($commentText) { |
| 69 | + $this->actor->find(self::newCommentField(), 10)->setValue($commentText); |
| 70 | + $this->actor->find(self::submitNewCommentButton())->click(); |
73 | 71 | } |
74 | 72 |
|
75 | 73 | /** |
76 | | - * @return Locator |
| 74 | + * @Then /^I see a comment with "([^"]*)" as message$/ |
77 | 75 | */ |
78 | | - public static function submitNewCommentButton() { |
79 | | - return Locator::forThe()->css("div.newCommentRow .submit")->descendantOf(FilesAppContext::currentSectionDetailsView())-> |
80 | | - describedAs("Submit new comment button in the details view in Files app"); |
| 76 | + public function iSeeACommentWithAsMessage($commentText) { |
| 77 | + PHPUnit_Framework_Assert::assertTrue( |
| 78 | + $this->actor->find(self::commentWithText($commentText), 10)->isVisible()); |
81 | 79 | } |
82 | 80 | } |
0 commit comments