Skip to content

Commit

Permalink
fix: add test cases for select fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Corbin Robb authored and Corbin Robb committed Dec 8, 2021
1 parent 4782473 commit 499ae7f
Showing 1 changed file with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { styledMount as mount } from 'spec/helpers/theming';
const defaultProps = {
choices: [
['1 year ago', '1 year ago'],
['1 week ago', '1 week ago'],
['today', 'today'],
],
name: 'row_limit',
Expand All @@ -37,7 +38,8 @@ const defaultProps = {

const options = [
{ value: '1 year ago', label: '1 year ago', order: 0 },
{ value: 'today', label: 'today', order: 1 },
{ value: '1 week ago', label: '1 week ago', order: 1 },
{ value: 'today', label: 'today', order: 2 },
];

describe('SelectControl', () => {
Expand Down Expand Up @@ -149,6 +151,37 @@ describe('SelectControl', () => {
expect(wrapper.html()).not.toContain('add something');
});
});

describe('when select has a sortComparator prop', () => {
it('does not add add order key and sorts by sortComparator', () => {
const sortComparator = (a, b) => a.label.localeCompare(b.label);
const optionsSortedByLabel = options
.map(opt => ({ label: opt.label, value: opt.value }))
.sort(sortComparator);
wrapper = mount(
<SelectControl
{...defaultProps}
sortComparator={sortComparator}
value={50}
placeholder="add something"
/>,
);
expect(wrapper.state().options).toEqual(optionsSortedByLabel);
});
});

describe('when select does not have a sortComparator prop', () => {
it('adds an order key and maintains its intial order', () => {
wrapper = mount(
<SelectControl
{...defaultProps}
value={50}
placeholder="add something"
/>,
);
expect(wrapper.state().options).toEqual(options);
});
});
});

describe('getOptions', () => {
Expand Down

0 comments on commit 499ae7f

Please sign in to comment.