-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add SearchBar to tile, Create Search Page, Add API for search
Currently only included projects, tags and versions. Feat(web): Add Search for Versions to Search Page Now the search also returns project versions that use the correct link (to the version itself). The project still links to the newest version. fixes: #13 Feat: Add Search functionality for project, tags and versions
- Loading branch information
Showing
8 changed files
with
532 additions
and
66 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,176 @@ | ||
import io | ||
|
||
|
||
def test_search_finds_project_by_name(client_with_claimed_project): | ||
""" | ||
Search should find a project by name. (Partial match) | ||
""" | ||
create_project_response = client_with_claimed_project.post( | ||
"/api/some-project/1.0.0", | ||
files={"file": ("index.html", io.BytesIO(b"<h1>Hello World</h1>"), "plain/text")}, | ||
) | ||
assert create_project_response.status_code == 201 | ||
|
||
search_response = client_with_claimed_project.get("/api/search?query=some") | ||
assert search_response.status_code == 200 | ||
assert search_response.json() == {"projects": [{"name": "some-project"}], "versions": [], "files": []} | ||
|
||
|
||
def test_search_finds_project_by_name_full_match(client_with_claimed_project): | ||
""" | ||
Search should find a project by name. (Full match) | ||
""" | ||
create_project_response = client_with_claimed_project.post( | ||
"/api/some-project/1.0.0", | ||
files={"file": ("index.html", io.BytesIO(b"<h1>Hello World</h1>"), "plain/text")}, | ||
) | ||
assert create_project_response.status_code == 201 | ||
|
||
search_response = client_with_claimed_project.get("/api/search?query=some-project") | ||
assert search_response.status_code == 200 | ||
assert search_response.json() == {"projects": [{"name": "some-project"}], "versions": [], "files": []} | ||
|
||
|
||
def test_search_project_by_name_negative(client_with_claimed_project): | ||
""" | ||
Search should not find a project by an unrelated name. | ||
""" | ||
create_project_response = client_with_claimed_project.post( | ||
"/api/some-project/1.0.0", | ||
files={"file": ("index.html", io.BytesIO(b"<h1>Hello World</h1>"), "plain/text")}, | ||
) | ||
assert create_project_response.status_code == 201 | ||
|
||
search_response = client_with_claimed_project.get("/api/search?query=other") | ||
assert search_response.status_code == 200 | ||
assert search_response.json() == {"projects": [], "versions": [], "files": []} | ||
|
||
|
||
def test_search_finds_tag(client_with_claimed_project): | ||
""" | ||
Search should find a tag by name. (Partial match) | ||
""" | ||
create_project_response = client_with_claimed_project.post( | ||
"/api/some-project/1.0.0", | ||
files={"file": ("index.html", io.BytesIO(b"<h1>Hello World</h1>"), "plain/text")}, | ||
) | ||
assert create_project_response.status_code == 201 | ||
|
||
create_tag_response = client_with_claimed_project.put("/api/some-project/1.0.0/tags/latest") | ||
assert create_tag_response.status_code == 201 | ||
|
||
search_response = client_with_claimed_project.get("/api/search?query=lat") | ||
assert search_response.status_code == 200 | ||
assert search_response.json() == {"projects": [], "versions": [{"project": "some-project", "version": "latest"}], "files": []} | ||
|
||
|
||
def test_search_finds_tag_full_match(client_with_claimed_project): | ||
""" | ||
Search should find a tag by name. (Full match) | ||
""" | ||
create_project_response = client_with_claimed_project.post( | ||
"/api/some-project/1.0.0", | ||
files={"file": ("index.html", io.BytesIO(b"<h1>Hello World</h1>"), "plain/text")}, | ||
) | ||
assert create_project_response.status_code == 201 | ||
|
||
create_tag_response = client_with_claimed_project.put("/api/some-project/1.0.0/tags/latest") | ||
assert create_tag_response.status_code == 201 | ||
|
||
search_response = client_with_claimed_project.get("/api/search?query=latest") | ||
assert search_response.status_code == 200 | ||
assert search_response.json() == {"projects": [], "versions": [{"project": "some-project", "version": "latest"}], "files": []} | ||
|
||
|
||
def test_search_finds_tag_negative(client_with_claimed_project): | ||
""" | ||
Search should not find a tag by an unrelated name. | ||
""" | ||
create_project_response = client_with_claimed_project.post( | ||
"/api/some-project/1.0.0", | ||
files={"file": ("index.html", io.BytesIO(b"<h1>Hello World</h1>"), "plain/text")}, | ||
) | ||
assert create_project_response.status_code == 201 | ||
|
||
create_tag_response = client_with_claimed_project.put("/api/some-project/1.0.0/tags/latest") | ||
assert create_tag_response.status_code == 201 | ||
|
||
search_response = client_with_claimed_project.get("/api/search?query=other") | ||
assert search_response.status_code == 200 | ||
assert search_response.json() == {"projects": [], "versions": [], "files": []} | ||
|
||
|
||
def test_search_finds_version(client_with_claimed_project): | ||
""" | ||
Search should find a version by name. (Partial match) | ||
""" | ||
create_project_response = client_with_claimed_project.post( | ||
"/api/some-project/1.0.0", | ||
files={"file": ("index.html", io.BytesIO(b"<h1>Hello World</h1>"), "plain/text")}, | ||
) | ||
assert create_project_response.status_code == 201 | ||
|
||
search_response = client_with_claimed_project.get("/api/search?query=1.0") | ||
assert search_response.status_code == 200 | ||
assert search_response.json() == {"projects": [], "versions": [{"project": "some-project", "version": "1.0.0"}], "files": []} | ||
|
||
|
||
def test_search_finds_version_full_match(client_with_claimed_project): | ||
""" | ||
Search should find a version by name. (Full match) | ||
""" | ||
create_project_response = client_with_claimed_project.post( | ||
"/api/some-project/1.0.0", | ||
files={"file": ("index.html", io.BytesIO(b"<h1>Hello World</h1>"), "plain/text")}, | ||
) | ||
assert create_project_response.status_code == 201 | ||
|
||
search_response = client_with_claimed_project.get("/api/search?query=1.0.0") | ||
assert search_response.status_code == 200 | ||
assert search_response.json() == {"projects": [], "versions": [{"project": "some-project", "version": "1.0.0"}], "files": []} | ||
|
||
|
||
def test_search_finds_version_negative(client_with_claimed_project): | ||
""" | ||
Search should not find a version by an unrelated name. | ||
""" | ||
create_project_response = client_with_claimed_project.post( | ||
"/api/some-project/1.0.0", | ||
files={"file": ("index.html", io.BytesIO(b"<h1>Hello World</h1>"), "plain/text")}, | ||
) | ||
assert create_project_response.status_code == 201 | ||
|
||
search_response = client_with_claimed_project.get("/api/search?query=0.1.0") | ||
assert search_response.status_code == 200 | ||
assert search_response.json() == {"projects": [], "versions": [], "files": []} | ||
|
||
|
||
def test_search_finds_both_project_and_version(client_with_claimed_project): | ||
""" | ||
Search should find both the version and the project itself, if the names contain the query. | ||
""" | ||
create_project_response = client_with_claimed_project.post( | ||
"/api/test/test", | ||
files={"file": ("index.html", io.BytesIO(b"<h1>Hello World</h1>"), "plain/text")}, | ||
) | ||
assert create_project_response.status_code == 201 | ||
|
||
search_response = client_with_claimed_project.get("/api/search?query=test") | ||
assert search_response.status_code == 200 | ||
assert search_response.json() == {"projects": [{"name": "test"}], "versions": [{"project": "test", "version": "test"}], "files": []} | ||
|
||
|
||
def test_search_is_case_insensitive(client_with_claimed_project): | ||
""" | ||
Search should find the project even when the case doesn't match. | ||
""" | ||
|
||
create_project_response = client_with_claimed_project.post( | ||
"/api/test/1.0.0", | ||
files={"file": ("index.html", io.BytesIO(b"<h1>Hello World</h1>"), "plain/text")}, | ||
) | ||
assert create_project_response.status_code == 201 | ||
|
||
search_response = client_with_claimed_project.get("/api/search?query=Test") | ||
assert search_response.status_code == 200 | ||
assert search_response.json() == {"projects": [{"name": "test"}], "versions": [], "files": []} |
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,31 @@ | ||
<template> | ||
<input type="search" class="searchbar-small" placeholder="Search Projects" v-model="searchQuery" | ||
@change="initialSearch()" /> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'searchbar', | ||
data() { | ||
return { | ||
searchQuery: '' | ||
} | ||
}, | ||
methods: { | ||
initialSearch() { | ||
this.$router.push({ path: '/search', query: { searchQuery: this.searchQuery } }) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
.searchbar-small { | ||
padding: 10px; | ||
border: 1px solid #e8e8e8; | ||
border-radius: 7px; | ||
margin-top: 16px; | ||
float: right; | ||
} | ||
</style> |
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
Oops, something went wrong.