Skip to content

Commit

Permalink
Merge main into renovate/rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
cultureamp-renovate[bot] authored Nov 29, 2024
2 parents 4b6f2a0 + 0d87b04 commit 667b09e
Show file tree
Hide file tree
Showing 22 changed files with 358 additions and 76 deletions.
6 changes: 6 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.68.4

### Patch Changes

- [#5322](https://github.com/cultureamp/kaizen-design-system/pull/5322) [`7903e38`](https://github.com/cultureamp/kaizen-design-system/commit/7903e38930fb442780f19285a9cc99e7aa167c55) - FilterBar: hide 'Clear all' button when there's nothing to clear

## 1.68.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kaizen/components",
"version": "1.68.3",
"version": "1.68.4",
"description": "Kaizen component library",
"author": "Geoffrey Chong <geoff.chong@cultureamp.com>",
"homepage": "https://cultureamp.design",
Expand Down
64 changes: 0 additions & 64 deletions packages/components/src/Filter/FilterBar/FilterBar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -722,70 +722,6 @@ describe("<FilterBar />", () => {
})
})

describe("Clear all", () => {
it("clears all the values of all the filters", async () => {
const { getByRole } = render(
<FilterBarWrapper<ValuesSimple>
filters={simpleFilters}
defaultValues={{
flavour: "jasmine-milk-tea",
sugarLevel: 50,
iceLevel: 100,
}}
/>
)
await waitForI18nContent()

const flavourButton = getByRole("button", {
name: "Flavour : Jasmine Milk Tea",
})
const sugarLevelButton = getByRole("button", {
name: "Sugar Level : 50%",
})
const iceLevelButton = getByRole("button", { name: "Ice Level : 100%" })

expect(flavourButton).toHaveAccessibleName("Flavour : Jasmine Milk Tea")
expect(sugarLevelButton).toHaveAccessibleName("Sugar Level : 50%")
expect(iceLevelButton).toHaveAccessibleName("Ice Level : 100%")

await user.click(getByRole("button", { name: "Clear all filters" }))

await waitFor(() => {
expect(flavourButton).toHaveAccessibleName("Flavour")
expect(sugarLevelButton).toHaveAccessibleName("Sugar Level")
expect(iceLevelButton).toHaveAccessibleName("Ice Level")
})
})

it("removes all removable filters", async () => {
const { getByRole } = render(
<FilterBarWrapper<ValuesRemovable>
filters={filtersRemovable}
defaultValues={{
flavour: "jasmine-milk-tea",
topping: "pearls",
}}
/>
)
await waitForI18nContent()

const flavourButton = getByRole("button", {
name: "Flavour : Jasmine Milk Tea",
})
const toppingButton = getByRole("button", { name: "Topping : Pearls" })

expect(flavourButton).toBeVisible()
expect(toppingButton).toBeVisible()

await user.click(getByRole("button", { name: "Clear all filters" }))

await waitFor(() => {
expect(flavourButton).not.toBeInTheDocument()
expect(toppingButton).not.toBeInTheDocument()
})
})
})

describe("External events", () => {
it("allows updating the values via an external event", async () => {
const Wrapper = (): JSX.Element => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
import React, { useState } from "react"
import { Meta, StoryObj } from "@storybook/react"
import { expect, userEvent, waitFor, within, fn } from "@storybook/test"
import { FilterMultiSelect } from "~components/Filter/FilterMultiSelect"
import { DateRange } from "~components/index"
import { FilterBar, Filters } from "../index"

const meta = {
title: "Components/FilterBar/FilterBar Tests",
component: FilterBar,
argTypes: {
filters: { control: false },
values: { control: false },
onValuesChange: { control: false },
},
args: {
filters: [], // Defined in stories
values: {}, // Defined in stories
onValuesChange: fn(),
},
} satisfies Meta<typeof FilterBar>

export default meta

type Story = StoryObj<typeof meta>

type Values = {
flavour: string
deliveryDates: DateRange
toppings: string[]
drank: Date
}

const filters = [
{
id: "flavour",
name: "Flavour",
Component: (
<FilterBar.Select
items={[
{ value: "jasmine-milk-tea", label: "Jasmine Milk Tea" },
{ value: "honey-milk-tea", label: "Honey Milk Tea" },
{ value: "lychee-green-tea", label: "Lychee Green Tea" },
]}
/>
),
},
{
id: "deliveryDates",
name: "Delivery Dates",
Component: <FilterBar.DateRangePicker />,
},
{
id: "toppings",
name: "Toppings",
Component: (
<FilterBar.MultiSelect
items={[
{ value: "none", label: "None" },
{ value: "pearls", label: "Pearls" },
{ value: "fruit-jelly", label: "Fruit Jelly" },
{ value: "peanuts", label: "Peanuts" },
{ value: "coconut", label: "Coconut" },
{ value: "aloe", label: "Aloe Vera" },
{ value: "mochi", label: "Mini Mochi" },
{ value: "popping-pearls", label: "Popping Pearls" },
]}
>
{(): JSX.Element => (
<>
<FilterMultiSelect.SearchInput />
<FilterMultiSelect.ListBox>
{({ allItems }): JSX.Element | JSX.Element[] =>
allItems.map(item => (
<FilterMultiSelect.Option key={item.key} item={item} />
))
}
</FilterMultiSelect.ListBox>
<FilterMultiSelect.MenuFooter>
<FilterMultiSelect.SelectAllButton />
<FilterMultiSelect.ClearButton />
</FilterMultiSelect.MenuFooter>
</>
)}
</FilterBar.MultiSelect>
),
isRemovable: true,
},
{
id: "drank",
name: "Drank",
Component: <FilterBar.DatePicker />,
isRemovable: true,
},
] satisfies Filters<Values>

export const ClearAllFromValue: Story = {
render: args => {
const [activeValues, onActiveValuesChange] = useState<Partial<Values>>({})
return (
<FilterBar<Values>
{...args}
filters={filters}
values={activeValues}
onValuesChange={onActiveValuesChange}
/>
)
},
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement.parentElement!)

await step(
"Clear all button hidden by default given no values",
async () => {
expect(
canvas.queryByRole("button", {
name: "Clear all filters",
})
).not.toBeInTheDocument()
}
)

await step("filter value is added", async () => {
await userEvent.click(canvas.getByRole("button", { name: "Flavour" }))
await userEvent.click(
canvas.getByRole("option", { name: "Jasmine Milk Tea" })
)
expect(
canvas.getByRole("button", { name: "Flavour: Jasmine Milk Tea" })
).toBeInTheDocument()
})

await step(
"'Clear all' press removes the value and hides itself",
async () => {
const clearAllButton = canvas.getByRole("button", {
name: "Clear all filters",
})
userEvent.click(clearAllButton)

waitFor(() =>
expect(
canvas.getByRole("button", { name: "Flavour" })
).toBeInTheDocument()
)

waitFor(() =>
expect(
canvas.queryByRole("button", {
name: "Clear all filters",
})
).not.toBeInTheDocument()
)
}
)
},
}

export const ClearAllFromRemovable: Story = {
render: args => {
const [activeValues, onActiveValuesChange] = useState<Partial<Values>>({})
return (
<FilterBar<Values>
{...args}
filters={filters}
values={activeValues}
onValuesChange={onActiveValuesChange}
/>
)
},
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement.parentElement!)

await step("removable filter is added with no value", async () => {
await waitFor(() => {
userEvent.click(canvas.getByRole("button", { name: "Add Filters" }))
})

await waitFor(() => {
userEvent.click(canvas.getByRole("button", { name: "Toppings" }))
})
})

await step("'Clear all' press removes removable filter", async () => {
await waitFor(() => {
userEvent.click(
canvas.getByRole("button", {
name: "Clear all filters",
})
)
})

waitFor(() =>
expect(
canvas.queryByRole("button", { name: "Toppings" })
).not.toBeInTheDocument()
)

waitFor(() =>
expect(
canvas.queryByRole("button", {
name: "Clear all filters",
})
).not.toBeInTheDocument()
)
})
},
}

export const ClearAllRemovesItself: Story = {
render: args => {
const [activeValues, onActiveValuesChange] = useState<Partial<Values>>({})
return (
<FilterBar<Values>
{...args}
filters={filters}
values={activeValues}
onValuesChange={onActiveValuesChange}
/>
)
},
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement.parentElement!)

await step("removable filter is added with no value", async () => {
await waitFor(() =>
userEvent.click(canvas.getByRole("button", { name: "Add Filters" }))
)
await userEvent.click(canvas.getByRole("button", { name: "Drank" }))
})

await step(
"Clear all button hides by itself after removing filter",
async () => {
await userEvent.click(
canvas.getByRole("button", { name: "Remove filter - Drank" })
)
}
)

waitFor(() =>
expect(
canvas.queryByRole("button", {
name: "Clear all filters",
})
).not.toBeInTheDocument()
)
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { FilterBar, Filters } from "../index"

export default {
title: "Components/Filter Bar",
title: "Components/FilterBar",
parameters: {
chromatic: { disable: false },
controls: { disable: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { FilterBar, Filters, useFilterBarContext } from "../index"
import { FilterBarMultiSelectProps } from "../subcomponents"

const meta = {
title: "Components/Filter Bar",
title: "Components/FilterBar",
component: FilterBar,
argTypes: {
filters: { control: false },
Expand Down
Loading

0 comments on commit 667b09e

Please sign in to comment.