diff --git a/gradle/changelog/fix_file_search.yaml b/gradle/changelog/fix_file_search.yaml new file mode 100644 index 0000000000..53864c9a44 --- /dev/null +++ b/gradle/changelog/fix_file_search.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Repository file search ([#1867](https://github.com/scm-manager/scm-manager/pull/1867)) diff --git a/scm-ui/e2e-tests/cypress/integration/repository_code_filesearch.feature b/scm-ui/e2e-tests/cypress/integration/repository_code_filesearch.feature new file mode 100644 index 0000000000..5e42d94ec2 --- /dev/null +++ b/scm-ui/e2e-tests/cypress/integration/repository_code_filesearch.feature @@ -0,0 +1,35 @@ +# +# MIT License +# +# Copyright (c) 2020-present Cloudogu GmbH and Contributors +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +Feature: Repository File Search + + Background: + Given User is authenticated + And A git repository exists + + Scenario: Search file inside repository + Given User has permission to read and write repository + When User visits repository + And User performs file search inside repository + Then The search results are found diff --git a/scm-ui/e2e-tests/cypress/support/step_definitions/scm-manager.js b/scm-ui/e2e-tests/cypress/support/step_definitions/scm-manager.js new file mode 100644 index 0000000000..d57cc6938c --- /dev/null +++ b/scm-ui/e2e-tests/cypress/support/step_definitions/scm-manager.js @@ -0,0 +1,37 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +When("User visits repository", function() { + cy.visit(`/repo/${this.repository.namespace}/${this.repository.name}/code/sources`); +}); + +When("User performs file search inside repository", function() { + cy.byTestId("file_search_button").click(); + cy.url().should("include", `/repo/${this.repository.namespace}/${this.repository.name}/code/search/main?q=`); + cy.get("[data-testid=file_search_filter_input]").type("README"); +}); + +Then("The search results are found", function() { + cy.get("[data-testid=file_search_single_result]").contains("README.md"); +}); diff --git a/scm-ui/ui-components/src/forms/FilterInput.tsx b/scm-ui/ui-components/src/forms/FilterInput.tsx index 18c16ee36d..913d879c2f 100644 --- a/scm-ui/ui-components/src/forms/FilterInput.tsx +++ b/scm-ui/ui-components/src/forms/FilterInput.tsx @@ -67,20 +67,17 @@ const FilterInput: FC = ({ filter, value, testId, placeholder, autoFocus, }; return ( -
+
setStateValue(event.target.value)} + onChange={event => setStateValue(event.target.value)} autoFocus={autoFocus || false} aria-describedby={id} + {...createAttributesForTesting(testId)} /> diff --git a/scm-ui/ui-webapp/src/repos/codeSection/components/FileSearchButton.tsx b/scm-ui/ui-webapp/src/repos/codeSection/components/FileSearchButton.tsx index 8e567e4dea..53ade6fc2f 100644 --- a/scm-ui/ui-webapp/src/repos/codeSection/components/FileSearchButton.tsx +++ b/scm-ui/ui-webapp/src/repos/codeSection/components/FileSearchButton.tsx @@ -39,7 +39,11 @@ const SearchIcon = styled(Icon)` const FileSearchButton: FC = ({ baseUrl, revision }) => { const [t] = useTranslation("repos"); return ( - + ); diff --git a/scm-ui/ui-webapp/src/repos/codeSection/components/FileSearchResults.tsx b/scm-ui/ui-webapp/src/repos/codeSection/components/FileSearchResults.tsx index b0e884efc5..5a83cf2eb6 100644 --- a/scm-ui/ui-webapp/src/repos/codeSection/components/FileSearchResults.tsx +++ b/scm-ui/ui-webapp/src/repos/codeSection/components/FileSearchResults.tsx @@ -62,7 +62,7 @@ const PathResultRow: FC = ({ contentBaseUrl, path }) => { - + {path} @@ -78,7 +78,7 @@ type ResultTableProps = { const ResultTable: FC = ({ contentBaseUrl, paths }) => ( - {paths.map((path) => ( + {paths.map(path => ( ))} diff --git a/scm-ui/ui-webapp/src/repos/codeSection/containers/FileSearch.tsx b/scm-ui/ui-webapp/src/repos/codeSection/containers/FileSearch.tsx index 072ef0cbc2..e5c187cfe6 100644 --- a/scm-ui/ui-webapp/src/repos/codeSection/containers/FileSearch.tsx +++ b/scm-ui/ui-webapp/src/repos/codeSection/containers/FileSearch.tsx @@ -28,7 +28,7 @@ import classNames from "classnames"; import styled from "styled-components"; import { Branch, Repository } from "@scm-manager/ui-types"; import { urls, usePaths } from "@scm-manager/ui-api"; -import { ErrorNotification, FilterInput, Help, Icon, Loading } from "@scm-manager/ui-components"; +import { createA11yId, ErrorNotification, FilterInput, Help, Icon, Loading } from "@scm-manager/ui-components"; import CodeActionBar from "../components/CodeActionBar"; import FileSearchResults from "../components/FileSearchResults"; import { filepathSearch } from "../utils/filepathSearch"; @@ -91,7 +91,7 @@ const FileSearch: FC = ({ repository, baseUrl, branches, selectedBranch } }; const contentBaseUrl = `${baseUrl}/sources/${revision}/`; - const id = useA11yId("file-search"); + const id = createA11yId("file-search"); return ( <> @@ -123,6 +123,7 @@ const FileSearch: FC = ({ repository, baseUrl, branches, selectedBranch } filter={search} autoFocus={true} id={id} + testId="file_search_filter_input" />