This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 144
Forward autocompleter
prop from CompareFilter
to Search
#6911
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
70 changes: 70 additions & 0 deletions
70
packages/components/src/compare-filter/test/compare-filter.js
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,70 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { render } from '@testing-library/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { Basic } from '../stories/index'; | ||
import { CompareFilter } from '../index'; | ||
import Search from '../../search'; | ||
import productAutocompleter from '../../search/autocompleters/product'; | ||
// Due to Jest implementation we cannot mock it only for specific tests. | ||
// If your test requires non-mocked Search, move them to another test file. | ||
jest.mock( '../../search' ); | ||
Search.mockName( 'Search' ); | ||
|
||
describe( 'CompareFilter', () => { | ||
let props; | ||
beforeEach( () => { | ||
props = { | ||
path: '/foo/bar', | ||
type: 'products', | ||
param: 'product', | ||
getLabels() { | ||
return Promise.resolve( [] ); | ||
}, | ||
labels: { | ||
helpText: 'Select at least two to compare', | ||
placeholder: 'Search for things to compare', | ||
title: 'Compare Things', | ||
update: 'Compare', | ||
}, | ||
}; | ||
} ); | ||
it( 'should render the example from the storybook', () => { | ||
const path = '/story/woocommerce-admin-components-comparefilter--basic'; | ||
|
||
expect( function () { | ||
render( <Basic path={ path } /> ); | ||
} ).not.toThrow(); | ||
} ); | ||
|
||
it( 'should forward the `type` prop the Search component', () => { | ||
props.type = 'custom'; | ||
|
||
render( <CompareFilter { ...props } /> ); | ||
|
||
// Check that Search component received the prop, without checking its behavior/internals/implementation details. | ||
expect( Search ).toHaveBeenLastCalledWith( | ||
expect.objectContaining( { | ||
type: 'custom', | ||
} ), | ||
expect.anything() | ||
); | ||
} ); | ||
it( 'should forward the `autocompleter` prop the Search component', () => { | ||
props.autocompleter = productAutocompleter; | ||
|
||
render( <CompareFilter { ...props } /> ); | ||
|
||
// Check that Search component received the prop, without checking its behavior/internals/implementation details. | ||
expect( Search ).toHaveBeenLastCalledWith( | ||
expect.objectContaining( { | ||
autocompleter: productAutocompleter, | ||
} ), | ||
expect.anything() | ||
); | ||
} ); | ||
} ); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about changing this to
searchAutocompleter
? That could make it more obvious that it is used by search.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then it would be inconsistent with
type
which is also kind ofsearchType
:and changing
type
would be a breaking change.As mentioned above I was thinking of doing it another way around and provide all props together like:
Or even accepting the entire component as a prop.
Personally, to keep the API and prop names consistent, I'd either:
WDYT?