Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion apps/vr-tests/src/stories/PeoplePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,56 @@ const people: (IPersonaProps & { key: string | number })[] = [
tertiaryText: 'In a meeting',
optionalText: 'Available at 4:00pm',
presence: PersonaPresence.offline
},
{
key: 5,
imageUrl: TestImages.personaMale,
imageInitials: 'RK',
primaryText: 'Alex Lundberg1',
secondaryText: 'Financial Analyst',
tertiaryText: 'In a meeting',
optionalText: 'Available at 4:00pm',
presence: PersonaPresence.offline
},
{
key: 6,
imageUrl: TestImages.personaMale,
imageInitials: 'RK',
primaryText: 'Alex Lundberg2',
secondaryText: 'Financial Analyst',
tertiaryText: 'In a meeting',
optionalText: 'Available at 4:00pm',
presence: PersonaPresence.offline
},
{
key: 7,
imageUrl: TestImages.personaMale,
imageInitials: 'RK',
primaryText: 'Alex Lundberg2',
secondaryText: 'Financial Analyst',
tertiaryText: 'In a meeting',
optionalText: 'Available at 4:00pm',
presence: PersonaPresence.offline
},
{
key: 8,
imageUrl: TestImages.personaMale,
imageInitials: 'RK',
primaryText: 'Alex Lundberg3',
secondaryText: 'Financial Analyst',
tertiaryText: 'In a meeting',
optionalText: 'Available at 4:00pm',
presence: PersonaPresence.offline
},
{
key: 9,
imageUrl: TestImages.personaMale,
imageInitials: 'RK',
primaryText: 'Alex Lundberg4',
secondaryText: 'Financial Analyst',
tertiaryText: 'In a meeting',
optionalText: 'Available at 4:00pm',
presence: PersonaPresence.offline
}
];

Expand Down Expand Up @@ -96,7 +146,22 @@ storiesOf('PeoplePicker', module)
pickerSuggestionsProps={ suggestionProps }
disabled
/>
))
)).add('Normal with text', () => (
<Screener
steps={ new Screener.Steps()
.snapshot('default', { cropTo: '.testWrapper' })
.click('.ms-BasePicker-input')
.setValue('.ms-BasePicker-input', 'a')
.snapshot('suggestiona')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe name the snapshot 'suggestion: "a"' so it's more clear what you're testing here

Normally we add hover() after click(). I forget the exact reasoning. Might be fine without it since you call setValue(), but when Screener finishes running, I'd check to make sure the snapshot looks as intended

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll rename it. The screenshot does look correct!

.end() }>
<NormalPeoplePicker
onResolveSuggestions={ getPeople }
onEmptyInputFocus={ getPeople }
getTextFromItem={ getTextFromItem }
className={ 'ms-PeoplePicker' }
pickerSuggestionsProps={ suggestionProps }
/>
</Screener>))
.addDecorator(story => (
<Screener
steps={ new Screener.Steps()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Pickers: fix bug where suggestions wouldn't have correct value selected",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "[email protected]"
}
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 === 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this supposed to be index === selectedIndex? selectedIndex isn't used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Catch

};
});

}

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();
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class Suggestions<T> extends BaseComponent<ISuggestionsProps<T>, ISuggest
>
{ suggestions.map((suggestion, index) =>
<div
ref={ this._selectedElement }
ref={ suggestion.selected ? this._selectedElement : '' }
// tslint:disable-next-line:no-string-literal
key={ (suggestion.item as any)['key'] ? (suggestion.item as any)['key'] : index }
id={ 'sug-' + index }
Expand Down
Loading