-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pickers: Add suggestions tests (#4409)
* Revert "FocusTrapZone does not correctly trap focus when last child is FocusZone (#4172)" This reverts commit 699fa69. * fix picker suggestions and add many tests * adding snap file * adding change file * improve test * fix tests and config * revert test changes * last test update * update test name and snapshot * undo suggestions change so it will merge properly * revert change to suggestions
- Loading branch information
Showing
3 changed files
with
3,252 additions
and
1 deletion.
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
91 changes: 91 additions & 0 deletions
91
packages/office-ui-fabric-react/src/components/pickers/Suggestions/Suggestions.test.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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
/* tslint:disable:no-unused-variable */ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import * as ReactTestUtils from 'react-dom/test-utils'; | ||
/* tslint:enable:no-unused-variable */ | ||
import * as renderer from 'react-test-renderer'; | ||
|
||
import { Suggestions } from './Suggestions'; | ||
import { ISuggestionItemProps } from './Suggestions.types'; | ||
import { ISuggestionModel } from './SuggestionsController'; | ||
|
||
const suggestions = [ | ||
'black', | ||
'blue', | ||
'brown', | ||
'cyan', | ||
'green', | ||
'magenta', | ||
'mauve', | ||
'orange', | ||
'pink', | ||
'purple', | ||
'red', | ||
'rose', | ||
'violet', | ||
'white', | ||
'yellow']; | ||
|
||
function generateSimpleSuggestions(selectedIndex: number = 0) { | ||
return suggestions.map<ISuggestionModel<ISimple>>((value, index) => { | ||
return { | ||
item: { | ||
key: value, | ||
name: value | ||
}, | ||
selected: index === selectedIndex | ||
}; | ||
}); | ||
|
||
} | ||
|
||
const basicSuggestionRenderer = (props: ISimple) => { | ||
return <div> { props.name } </div>; | ||
}; | ||
|
||
export interface ISimple { | ||
key: string; | ||
name: string; | ||
} | ||
|
||
function mockOnClick() { | ||
console.log('clicked'); | ||
} | ||
|
||
describe('Suggestions', () => { | ||
|
||
it('renders a list properly', () => { | ||
|
||
const component = renderer.create( | ||
<Suggestions | ||
onRenderSuggestion={ basicSuggestionRenderer } | ||
onSuggestionClick={ mockOnClick } | ||
suggestions={ generateSimpleSuggestions() } | ||
/> | ||
); | ||
const tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('scrolls to selected index properly', () => { | ||
const component = renderer.create( | ||
<Suggestions | ||
onRenderSuggestion={ basicSuggestionRenderer } | ||
onSuggestionClick={ mockOnClick } | ||
suggestions={ generateSimpleSuggestions() } | ||
/> | ||
); | ||
|
||
component.update( | ||
<Suggestions | ||
onRenderSuggestion={ basicSuggestionRenderer } | ||
onSuggestionClick={ mockOnClick } | ||
suggestions={ generateSimpleSuggestions(8) } | ||
/> | ||
); | ||
const tree = component.toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
}); |
Oops, something went wrong.