-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement - collection do not render empty filter (#972)
* make 'others' a const * extract into consts * extract into getYearFilters * extract getCategoryFilters * add correct types * extract getTagFilters * rename to singular * move logic into each get*Filter function to improve readability * fix import * remove type renaming during import * refactor imports location * refactor: standardize code structure * only return filters with at least 2 items * add storybook * do not render "category" if there's no category filter * Update packages/components/src/templates/next/layouts/Collection/utils.ts Co-authored-by: Hsu Zhong Jun <27919917+dcshzj@users.noreply.github.com> * split methods in utils into utils folder * sort tag filters * undo: shouldShowCategory * should filter out any filters with no items * add tests * update storybook --------- Co-authored-by: Hsu Zhong Jun <27919917+dcshzj@users.noreply.github.com>
- Loading branch information
1 parent
15593f2
commit ec7e344
Showing
17 changed files
with
606 additions
and
257 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
256 changes: 0 additions & 256 deletions
256
packages/components/src/templates/next/layouts/Collection/utils.ts
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
...omponents/src/templates/next/layouts/Collection/utils/__tests__/getCategoryFilter.test.ts
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,56 @@ | ||
import { describe, expect, it } from "vitest" | ||
|
||
import type { ProcessedCollectionCardProps } from "~/interfaces" | ||
import { getCategoryFilter } from "../getCategoryFilter" | ||
|
||
describe("getCategoryFilter", () => { | ||
it("should return empty filter items when no items provided", () => { | ||
// Arrange | ||
const items: ProcessedCollectionCardProps[] = [] | ||
|
||
// Act | ||
const result = getCategoryFilter(items) | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
id: "category", | ||
label: "Category", | ||
items: [], | ||
}) | ||
}) | ||
|
||
it("should count and format categories correctly", () => { | ||
// Arrange | ||
const items: ProcessedCollectionCardProps[] = [ | ||
{ | ||
category: "guides", | ||
} as ProcessedCollectionCardProps, | ||
{ | ||
category: "guides", | ||
} as ProcessedCollectionCardProps, | ||
{ | ||
category: "articles", | ||
} as ProcessedCollectionCardProps, | ||
{ | ||
category: "tutorials", | ||
} as ProcessedCollectionCardProps, | ||
{ | ||
category: "tutorials", | ||
} as ProcessedCollectionCardProps, | ||
] | ||
|
||
// Act | ||
const result = getCategoryFilter(items) | ||
|
||
// Assert | ||
expect(result).toEqual({ | ||
id: "category", | ||
label: "Category", | ||
items: [ | ||
{ id: "articles", label: "Articles", count: 1 }, | ||
{ id: "guides", label: "Guides", count: 2 }, | ||
{ id: "tutorials", label: "Tutorials", count: 2 }, | ||
], | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.