-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't show matched fields if there is nothing to show
Datahub was returning a spurious 'tags: []' value, which doesn't require rendering anything. This meant we were showing an empty matched fields even when no search query was entered.
- Loading branch information
Showing
2 changed files
with
56 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import pytest | ||
from data_platform_catalogue.search_types import ResultType, SearchResult | ||
|
||
from tests.conftest import mock_search_response | ||
|
||
|
||
@pytest.mark.slow | ||
class TestSearchResultMetadata: | ||
""" | ||
Given I am on a search page | ||
When I look at the metadata underneath a search result | ||
Then "matched fields" should only be shown if I entered a search term | ||
""" | ||
|
||
@pytest.fixture(autouse=True) | ||
def setup(self, live_server, selenium): | ||
self.selenium = selenium | ||
self.live_server_url = live_server.url | ||
|
||
def test_matched_fields_hidden(self, mock_catalogue): | ||
result = SearchResult( | ||
urn="fake-urn", | ||
result_type=ResultType.DATABASE, | ||
name="abc", | ||
fully_qualified_name="abc", | ||
description="bla bla bla", | ||
matches={"tags": []}, | ||
) | ||
mock_search_response(mock_catalogue, total_results=1, page_results=[result]) | ||
|
||
self.selenium.get(f"{self.live_server_url}/search") | ||
|
||
assert "Matched fields:" not in self.selenium.page_source | ||
|
||
def test_matched_fields_shown(self, mock_catalogue): | ||
result = SearchResult( | ||
urn="fake-urn", | ||
result_type=ResultType.DATABASE, | ||
name="abc", | ||
fully_qualified_name="abc", | ||
description="bla bla bla", | ||
matches={"tags": [], "description": "abc"}, | ||
) | ||
mock_search_response(mock_catalogue, total_results=1, page_results=[result]) | ||
|
||
self.selenium.get(f"{self.live_server_url}/search?query=bla") | ||
|
||
assert "Matched fields:" in self.selenium.page_source |