mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-04 21:51:17 +08:00
Fix Select array values showing k
This commit is contained in:
parent
ca1cd1e2fc
commit
a39bec15cc
@ -5,24 +5,46 @@ import SelectType from '../types/Select';
|
||||
describe('Select', () => {
|
||||
let knob;
|
||||
|
||||
beforeEach(() => {
|
||||
knob = {
|
||||
name: 'Colors',
|
||||
value: '#00ff00',
|
||||
options: {
|
||||
Green: '#00ff00',
|
||||
Red: '#ff0000',
|
||||
},
|
||||
};
|
||||
describe('Object values', () => {
|
||||
beforeEach(() => {
|
||||
knob = {
|
||||
name: 'Colors',
|
||||
value: '#00ff00',
|
||||
options: {
|
||||
Green: '#00ff00',
|
||||
Red: '#ff0000',
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('displays value', () => {
|
||||
it('correctly maps option keys and values', () => {
|
||||
const wrapper = shallow(<SelectType knob={knob} />);
|
||||
|
||||
const green = wrapper.find('option').first();
|
||||
expect(green.text()).toEqual('Green');
|
||||
expect(green.prop('value')).toEqual('Green');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('displays value', () => {
|
||||
it('correctly maps option keys and values', () => {
|
||||
const wrapper = shallow(<SelectType knob={knob} />);
|
||||
describe('Array values', () => {
|
||||
beforeEach(() => {
|
||||
knob = {
|
||||
name: 'Colors',
|
||||
value: 'green',
|
||||
options: ['green', 'red'],
|
||||
};
|
||||
});
|
||||
|
||||
const green = wrapper.find('option').first();
|
||||
expect(green.text()).toEqual('Green');
|
||||
expect(green.prop('value')).toEqual('Green');
|
||||
describe('displays value', () => {
|
||||
it('correctly maps option keys and values', () => {
|
||||
const wrapper = shallow(<SelectType knob={knob} />);
|
||||
|
||||
const green = wrapper.find('option').first();
|
||||
expect(green.text()).toEqual('green');
|
||||
expect(green.prop('value')).toEqual('green');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,7 +6,7 @@ import { Select } from '@storybook/components';
|
||||
const SelectType = ({ knob, onChange }) => {
|
||||
const { options } = knob;
|
||||
const entries = Array.isArray(options)
|
||||
? options.reduce((acc, k) => Object.assign(acc, { k }), {})
|
||||
? options.reduce((acc, k) => Object.assign(acc, { [k]: k }), {})
|
||||
: options;
|
||||
|
||||
const selectedKey = Object.keys(entries).find(k => entries[k] === knob.value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user