-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into FCT-1186-data-table-manager-custom-configura…
…tions-story
- Loading branch information
Showing
14 changed files
with
1,047 additions
and
36 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
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
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
36 changes: 28 additions & 8 deletions
36
packages/components/filters/src/filter-menu/filter-menu.spec.tsx
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 |
---|---|---|
@@ -1,12 +1,32 @@ | ||
import { screen, render } from '../../../../../test/test-utils'; | ||
import FilterMenu from './filter-menu'; | ||
import FilterMenu, { type TFilterMenuProps } from './filter-menu'; | ||
|
||
/** | ||
* THIS IS A PLACEHOLDER, PLEASE UPDATE IT | ||
*/ | ||
describe('FilterMenu FilterMenu', () => { | ||
it('should render the filter-menu', async () => { | ||
await render(<FilterMenu label="filter menu" />); | ||
await screen.findByText('filter menu'); | ||
const mockRenderMenuBody = jest.fn(() => <div>im the body</div>); | ||
const mockOnRemoveRequest = jest.fn(); | ||
|
||
const getDefaultProps = (custom?: Partial<TFilterMenuProps>) => ({ | ||
filterKey: 'test', | ||
label: 'filter menu', | ||
renderMenuBody: mockRenderMenuBody, | ||
appliedFilterValues: [{ label: 'hello', value: 'hello' }], | ||
mockOnRemoveRequest: mockOnRemoveRequest, | ||
...custom, | ||
}); | ||
|
||
describe('FilterMenu component', () => { | ||
it('should render the FilterMenu label', async () => { | ||
const props = getDefaultProps(); | ||
await render(<FilterMenu {...props} />); | ||
await screen.findByText('filter menu:'); | ||
}); | ||
it('should open the menu body when defaultOpen is true', async () => { | ||
const props = getDefaultProps({ defaultOpen: true }); | ||
await render(<FilterMenu {...props} />); | ||
await screen.findByText('im the body'); | ||
}); | ||
it('should not open the menu body when isDisabled and defaultOpen are true', async () => { | ||
const props = getDefaultProps({ defaultOpen: true, isDisabled: true }); | ||
await render(<FilterMenu {...props} />); | ||
expect(screen.queryByText('im the body')).not.toBeInTheDocument(); | ||
}); | ||
}); |
100 changes: 93 additions & 7 deletions
100
packages/components/filters/src/filter-menu/filter-menu.tsx
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
96 changes: 88 additions & 8 deletions
96
packages/components/filters/src/filter-menu/trigger-button/trigger-button.spec.tsx
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 |
---|---|---|
@@ -1,12 +1,92 @@ | ||
import { screen, render } from '../../../../../../test/test-utils'; | ||
import TriggerButton from './trigger-button'; | ||
import { screen, render, fireEvent } from '../../../../../../test/test-utils'; | ||
import TriggerButton, { | ||
type TFilterMenuTriggerButtonProps, | ||
} from './trigger-button'; | ||
|
||
const mockOnRemoveRequest = jest.fn(); | ||
|
||
const getDefaultProps = (custom?: Partial<TFilterMenuTriggerButtonProps>) => ({ | ||
filterKey: 'test-key', | ||
label: 'test', | ||
appliedFilterValues: [{ label: 'cool test phrase', value: 'testPhrase' }], | ||
onRemoveRequest: mockOnRemoveRequest, | ||
...custom, | ||
}); | ||
|
||
/** | ||
* THIS IS A PLACEHOLDER, PLEASE UPDATE IT | ||
*/ | ||
describe('FilterMenu Trigger Button', () => { | ||
it('should render the trigger button', async () => { | ||
await render(<TriggerButton label="trigger button" />); | ||
await screen.findByText(/trigger button/i); | ||
it('should render the label', async () => { | ||
const props = getDefaultProps(); | ||
await render(<TriggerButton {...props} />); | ||
await screen.findByLabelText(/test:/i); | ||
}); | ||
|
||
describe('when there are no applied filter values', () => { | ||
it('should render the CaretDownIcon', async () => { | ||
const props = getDefaultProps({ appliedFilterValues: undefined }); | ||
await render(<TriggerButton {...props} />); | ||
await screen.findByLabelText('toggle filter menu icon'); | ||
}); | ||
it('should render the CaretDownIcon if isPersistent is true', async () => { | ||
const props = getDefaultProps({ | ||
appliedFilterValues: undefined, | ||
isPersistent: true, | ||
}); | ||
await render(<TriggerButton {...props} />); | ||
await screen.findByLabelText('toggle filter menu icon'); | ||
}); | ||
it('should not render a remove button', async () => { | ||
const props = getDefaultProps({ appliedFilterValues: undefined }); | ||
await render(<TriggerButton {...props} />); | ||
await screen.findByLabelText(/test:/i); | ||
expect( | ||
screen.queryByRole('button', { name: 'remove test filter' }) | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('when there are applied filter values', () => { | ||
it('should not render the CaretDownIcon', async () => { | ||
const props = getDefaultProps(); | ||
await render(<TriggerButton {...props} />); | ||
await screen.findByLabelText(/test:/i); | ||
expect( | ||
screen.queryByLabelText('toggle filter menu icon') | ||
).not.toBeInTheDocument(); | ||
}); | ||
it('should render a remove button', async () => { | ||
const props = getDefaultProps(); | ||
await render(<TriggerButton {...props} />); | ||
await screen.findByRole('button', { name: 'remove test filter' }); | ||
}); | ||
it('should call onRemoveRequest when remove button is clicked', async () => { | ||
const props = getDefaultProps(); | ||
await render(<TriggerButton {...props} />); | ||
const removeButton = await screen.findByRole('button', { | ||
name: 'remove test filter', | ||
}); | ||
fireEvent.click(removeButton); | ||
expect(mockOnRemoveRequest).toHaveBeenCalled(); | ||
}); | ||
it('should not render a remove button if isPersistent is true', async () => { | ||
const props = getDefaultProps({ isPersistent: true }); | ||
await render(<TriggerButton {...props} />); | ||
await screen.findByLabelText(/test:/i); | ||
expect( | ||
screen.queryByRole('button', { name: 'remove test filter' }) | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('when disabled', () => { | ||
it('should apply the proper attributes to the main action (overlay) button', async () => { | ||
const props = getDefaultProps({ isDisabled: true }); | ||
await render(<TriggerButton {...props} />); | ||
const overlayButton = await screen.findByRole('button', { | ||
name: 'test:', | ||
}); | ||
expect(overlayButton).toHaveAttribute('disabled'); | ||
expect(overlayButton).toHaveAttribute('readonly'); | ||
expect(overlayButton).toHaveAttribute('tabindex', '-1'); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.