diff --git a/tests/acceptance/config/behat.yml b/tests/acceptance/config/behat.yml index 10e1d42502..3495769457 100644 --- a/tests/acceptance/config/behat.yml +++ b/tests/acceptance/config/behat.yml @@ -10,6 +10,7 @@ default: - NextcloudTestServerContext - AppNavigationContext + - CommentsAppContext - FeatureContext - FilesAppContext - FilesSharingAppContext diff --git a/tests/acceptance/features/app-comments.feature b/tests/acceptance/features/app-comments.feature new file mode 100644 index 0000000000..81fc6f89ad --- /dev/null +++ b/tests/acceptance/features/app-comments.feature @@ -0,0 +1,8 @@ +Feature: app-comments + + Scenario: Writing a comment + Given I am logged in + And I open the details view for "welcome.txt" + And I open the "Comments" tab in the details view + When I create a new comment with "Hello world" as message + Then I see that a comment was added diff --git a/tests/acceptance/features/bootstrap/CommentsAppContext.php b/tests/acceptance/features/bootstrap/CommentsAppContext.php new file mode 100644 index 0000000000..64d1dc69bc --- /dev/null +++ b/tests/acceptance/features/bootstrap/CommentsAppContext.php @@ -0,0 +1,82 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +use Behat\Behat\Context\Context; + +class CommentsAppContext implements Context, ActorAwareInterface { + use ActorAware; + + + /** + * @When /^I create a new comment with "([^"]*)" as message$/ + */ + public function iCreateANewCommentWithAsMessage($commentText) { + $this->actor->find(self::newCommentField(), 2)->setValue($commentText); + $this->actor->find(self::submitNewCommentButton(), 2)->click(); + } + + /** + * @Then /^I see that a comment was added$/ + */ + public function iSeeThatACommentWasAdded() { + $self = $this; + + $result = Utils::waitFor(function () use ($self) { + return $self->isCommentAdded(); + }, 5, 0.5); + + PHPUnit_Framework_Assert::assertTrue($result); + } + + public function isCommentAdded() { + try { + $locator = self::commentFields(); + $comments = $this->actor->getSession()->getPage()->findAll($locator->getSelector(), $locator->getLocator()); + PHPUnit_Framework_Assert::assertSame(1, count($comments)); + } catch (PHPUnit_Framework_ExpectationFailedException $e) { + return false; + } + return true; + } + + /** + * @return Locator + */ + public static function newCommentField() { + return Locator::forThe()->css("div.newCommentRow .message")->descendantOf(FilesAppContext::currentSectionDetailsView())-> + describedAs("New comment field in the details view in Files app"); + } + + public static function commentFields() { + return Locator::forThe()->css(".comments .comment .message")->descendantOf(FilesAppContext::currentSectionDetailsView())-> + describedAs("Comment fields in the details view in Files app"); + } + + /** + * @return Locator + */ + public static function submitNewCommentButton() { + return Locator::forThe()->css("div.newCommentRow .submit")->descendantOf(FilesAppContext::currentSectionDetailsView())-> + describedAs("Submit new comment button in the details view in Files app"); + } +}