@Test
public void testSimpleSearch()
{
ExtensionAdministrationPage adminPage = ExtensionAdministrationPage.gotoPage().clickCoreExtensionsSection();
int coreExtensionCount = adminPage.getSearchResults().getPagination().getResultsCount();
SimpleSearchPane searchBar = adminPage.getSearchBar();
// Check if the tip is displayed.
Assert.assertEquals("search extension...", searchBar.getSearchInput().getAttribute("placeholder"));
// Check that the input is empty
Assert.assertEquals("", searchBar.getSearchInput().getAttribute("value"));
SearchResultsPane searchResults = searchBar.search("XWiki Rendering");
Assert.assertTrue(searchResults.getPagination().getResultsCount() < coreExtensionCount);
// Make sure the search input is not cleared.
searchBar = new SimpleSearchPane();
Assert.assertEquals("XWiki Rendering", searchBar.getSearchInput().getAttribute("value"));
Assert.assertNull(searchResults.getNoResultsMessage());
// Check that the result matches the search query.
ExtensionPane extension = searchResults.getExtension(RandomUtils.nextInt(20));
Assert.assertTrue(extension.getName().toLowerCase().contains("rendering"));
Assert.assertEquals("core", extension.getStatus());
// Test search query with no results.
searchResults = new SimpleSearchPane().search("blahblah");
Assert.assertEquals(0, searchResults.getDisplayedResultsCount());
Assert.assertNull(searchResults.getPagination());
Assert.assertEquals("There were no extensions found matching 'blahblah'. Try different keywords. "
+ "Alternatively, if you know the identifier and the version of the extension you're "
+ "looking for, you can use the Advanced Search form above.", searchResults.getNoResultsMessage());
// Test a search query with only a few results (only one page).
searchResults = searchBar.search("restlet");
Assert.assertNull(searchResults.getNoResultsMessage());
Assert.assertNull(searchResults.getPagination());
Assert.assertTrue(searchResults.getDisplayedResultsCount() > 1);
extension = searchResults.getExtension(0);