From b3ab3397a98c975fed7dd164341b3a046ee3a44c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 16 Apr 2021 10:06:23 +0200 Subject: [PATCH] Add test for unified comments search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- tests/integration/config/behat.yml | 1 + .../features/bootstrap/BoardContext.php | 4 ++ .../features/bootstrap/CommentContext.php | 31 ++++++++++++++ .../features/bootstrap/SearchContext.php | 42 +++++++++++++++++++ tests/integration/features/search.feature | 7 ++++ 5 files changed, 85 insertions(+) create mode 100644 tests/integration/features/bootstrap/CommentContext.php diff --git a/tests/integration/config/behat.yml b/tests/integration/config/behat.yml index 8a019df34..b8673a677 100644 --- a/tests/integration/config/behat.yml +++ b/tests/integration/config/behat.yml @@ -8,4 +8,5 @@ default: baseUrl: http://localhost:8080/ - RequestContext - BoardContext + - CommentContext - SearchContext diff --git a/tests/integration/features/bootstrap/BoardContext.php b/tests/integration/features/bootstrap/BoardContext.php index cd994151b..fb412063f 100644 --- a/tests/integration/features/bootstrap/BoardContext.php +++ b/tests/integration/features/bootstrap/BoardContext.php @@ -27,6 +27,10 @@ class BoardContext implements Context { $this->serverContext = $environment->getContext('ServerContext'); } + public function getLastUsedCard() { + return $this->card; + } + /** * @Given /^creates a board named "([^"]*)" with color "([^"]*)"$/ */ diff --git a/tests/integration/features/bootstrap/CommentContext.php b/tests/integration/features/bootstrap/CommentContext.php new file mode 100644 index 000000000..40b6f4e45 --- /dev/null +++ b/tests/integration/features/bootstrap/CommentContext.php @@ -0,0 +1,31 @@ +getEnvironment(); + + $this->boardContext = $environment->getContext('BoardContext'); + } + + /** + * @Given /^post a comment with content "([^"]*)" on the card$/ + */ + public function postACommentWithContentOnTheCard($content) { + $card = $this->boardContext->getLastUsedCard(); + $this->requestContext->sendOCSRequest('POST', '/apps/deck/api/v1.0/cards/' . $card['id'] . '/comments', [ + 'message' => $content, + 'parentId' => null + ]); + } +} diff --git a/tests/integration/features/bootstrap/SearchContext.php b/tests/integration/features/bootstrap/SearchContext.php index c65ca6bc6..8ed46ff39 100644 --- a/tests/integration/features/bootstrap/SearchContext.php +++ b/tests/integration/features/bootstrap/SearchContext.php @@ -13,6 +13,7 @@ class SearchContext implements Context { protected $boardContext; private $searchResults; + private $unifiedSearchResult; /** @BeforeScenario */ public function gatherContexts(BeforeScenarioScope $scope) { @@ -32,6 +33,18 @@ class SearchContext implements Context { $this->searchResults = json_decode($data, true); } + /** + * @When /^searching for "([^"]*)" in comments in unified search$/ + * @param string $term + * https://cloud.nextcloud.com/ocs/v2.php/search/providers/talk-conversations/search?term=an&from=%2Fapps%2Fdashboard%2F + */ + public function searchingForComments(string $term) { + $this->requestContext->sendOCSRequest('GET', '/search/providers/deck-comment/search?term=' . urlencode($term), []); + $this->requestContext->getResponse()->getBody()->seek(0); + $data = (string)$this->getResponse()->getBody(); + $this->unifiedSearchResult = json_decode($data, true); + } + /** * @When /^searching for '([^']*)'$/ * @param string $term @@ -78,4 +91,33 @@ class SearchContext implements Context { public function theCardIsNotFound($arg1) { Assert::assertFalse($this->cardIsFound($arg1), 'Card can not be found'); } + + /** + * @Then /^the comment with "([^"]*)" is found$/ + */ + public function theCommentWithIsFound($arg1) { + $ocsData = $this->unifiedSearchResult['ocs']['data']['entries']; + $found = null; + foreach ($ocsData as $result) { + if ($result['subline'] === $arg1) { + $found = $result; + } + } + Assert::assertNotNull($found, 'Comment was expected but was not found'); + Assert::assertEquals('admin on Card with comment', $found['title']); + } + + /** + * @Then /^the comment with "([^"]*)" is not found$/ + */ + public function theCommentWithIsNotFound($arg1) { + $ocsData = $this->unifiedSearchResult['ocs']['data']['entries']; + $found = null; + foreach ($ocsData as $result) { + if ($result['subline'] === $arg1) { + $found = $result; + } + } + Assert::assertNull($found, 'Comment was found but not expected'); + } } diff --git a/tests/integration/features/search.feature b/tests/integration/features/search.feature index 179ffc277..9403c6072 100644 --- a/tests/integration/features/search.feature +++ b/tests/integration/features/search.feature @@ -257,3 +257,10 @@ Feature: Searching for cards Then the card "Example task 1" is not found And the card "Labeled card" is not found And the card "Multi labeled card" is found + + Scenario: Search for a card comment + Given create a card named "Card with comment" + And post a comment with content "My first comment" on the card + When searching for "My first comment" in comments in unified search + Then the comment with "My first comment" is found + Then the comment with "Any other" is not found