Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion core/src/main/java/hudson/search/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,18 @@
rsp.sendRedirect2(req.getContextPath() + target.getUrl());
return;
}

List<SuggestedItem> suggestions = suggest(index, query, smo);

if (suggestions.size() == 1) {

Check warning on line 135 in core/src/main/java/hudson/search/Search.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 135 is only partially covered, one branch is missing
rsp.sendRedirect2(req.getContextPath() + suggestions.get(0).getUrl());
return;

Check warning on line 137 in core/src/main/java/hudson/search/Search.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 136-137 are not covered by tests
Comment on lines +133 to +137
}
}
}
}

// no exact match. show the suggestions
// No exact match and no single suggestion.
rsp.setStatus(SC_NOT_FOUND);
req.getView(this, "search-failed.jelly").forward(req, rsp);
}
Expand Down
15 changes: 15 additions & 0 deletions test/src/test/java/hudson/search/SearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ void testSearchByProjectName() throws Exception {
assertTrue(contents.contains(String.format("<title>%s - Jenkins</title>", projectName)));
}

@Test
void shouldRedirectToSingleSuggestedItem() throws Exception {
FreeStyleProject project = j.createFreeStyleProject("job-config-scroll-test");

Page result = j.search("job-config-scroll");

assertNotNull(result);
j.assertGoodStatus(result);

assertEquals(
j.getURL().toString() + project.getUrl(),
result.getUrl().toString()
);
}

@Issue("JENKINS-24433")
@Test
void testSearchByProjectNameBehindAFolder() throws Exception {
Expand Down
Loading