Skip to content

Commit

Permalink
Do not match against the 'jar' in the maven coordinates string
Browse files Browse the repository at this point in the history
  • Loading branch information
holly-cummins committed Sep 11, 2024
1 parent ec640ac commit 95de644
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/components/filters/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ const filterExtensions = (
extensions,
{ regex, categoryFilter, keywordFilter, statusFilter, compatibilityFilter }
) => {
const regexObj = new RegExp(regex, "i")

return (
extensions
// Exclude unlisted and superseded extensions, unless they happen to match a non-trivial search filter
// We don't need to check if the searches matches, because we do that below
.filter(extension => (!extension.metadata.unlisted && !extension.isSuperseded) || regex.length > 2)
.filter(
extension =>
extension.name.toLowerCase().match(regex.toLowerCase()) ||
extension.artifact?.toLowerCase().match(regex.toLowerCase()) ||
extension.description?.toLowerCase().match(regex.toLowerCase())
regexObj.test(extension.name) ||
regexObj.test(extension.description) ||
regexObj.test(extension.artifact?.replace("::jar", ""))
)
.filter(
extension =>
Expand Down
25 changes: 21 additions & 4 deletions src/components/filters/filters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ describe("filters bar", () => {
const extensionsListener = jest.fn(extensions => (newExtensions = extensions))

const alice = {
name: "Alice",
name: "Alice Blaine",
description: "a nice person",
artifact: "some complex id",
artifact: "io.something:some-artifact-name::jar:3.10.2",
metadata: {
categories: ["lynx"],
status: "wonky",
Expand All @@ -36,6 +36,7 @@ describe("filters bar", () => {
}
const pascal = {
name: "Pascal",
artifact: "io.something:another-artifact-name::jar:3.10.2",
metadata: {
categories: ["skunks"],
keywords: ["cool"],
Expand Down Expand Up @@ -141,10 +142,10 @@ describe("filters bar", () => {
expect(newExtensions).not.toContain(pascal)
})

it("leaves in extensions whose id match the search filter", async () => {
it("leaves in extensions whose id matches the search filter", async () => {
const searchInput = screen.getByRole("textbox")
await user.click(searchInput)
await user.keyboard(alice.artifact)
await user.keyboard("some-artifact-name")
expect(extensionsListener).toHaveBeenCalled()
expect(newExtensions).toContain(alice)
expect(newExtensions).not.toContain(pascal)
Expand All @@ -156,6 +157,22 @@ describe("filters bar", () => {
await user.keyboard("alice")
expect(extensionsListener).toHaveBeenCalled()
expect(newExtensions).toContain(alice)
expect(newExtensions).not.toContain(pascal)

// select all and clear the search term
searchInput.setSelectionRange(0, searchInput.value.length)
await user.keyboard("pAScal")
expect(extensionsListener).toHaveBeenCalled()
expect(newExtensions).not.toContain(alice)
expect(newExtensions).toContain(pascal)
})

it("does not count the jar part in the maven artifact as a match", async () => {
const searchInput = screen.getByRole("textbox")
await user.click(searchInput)
await user.keyboard("jar")
expect(extensionsListener).toHaveBeenCalled()
expect(newExtensions).toHaveLength(0)
})

describe("for an unlisted extension", () => {
Expand Down

0 comments on commit 95de644

Please sign in to comment.