Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Commit

Permalink
Revert "keep placeholder on multiselect (apache#11289)"
Browse files Browse the repository at this point in the history
This reverts commit b277f19.
  • Loading branch information
ktmud committed Nov 17, 2020
1 parent 4cfcaeb commit 94abb29
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ describe('AdhocFilters', () => {

let numScripts = 0;

xit('Should load AceEditor scripts when needed', () => {
it('Should load AceEditor scripts when needed', () => {
cy.get('script').then(nodes => {
numScripts = nodes.length;
});

cy.get('[data-test=adhoc_filters]').within(() => {
cy.get('.Select__control').scrollIntoView().click();
cy.get('input[type=text]').focus().type('name{enter}');
cy.get("div[role='button']").first().click();
});

// antd tabs do lazy loading, so we need to click on tab with ace editor
Expand Down Expand Up @@ -75,7 +74,7 @@ describe('AdhocFilters', () => {
});
});

xit('Set custom adhoc filter', () => {
it('Set custom adhoc filter', () => {
const filterType = 'name';
const filterContent = "'Amy' OR name = 'Donald'";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/* eslint-disable no-unused-expressions */
import React from 'react';
import sinon from 'sinon';
import { shallow, mount } from 'enzyme';
import { shallow } from 'enzyme';
import { Select, CreatableSelect } from 'src/components/Select';
import OnPasteSelect from 'src/components/Select/OnPasteSelect';
import SelectControl from 'src/explore/components/controls/SelectControl';
Expand Down Expand Up @@ -47,6 +47,25 @@ describe('SelectControl', () => {
wrapper = shallow(<SelectControl {...defaultProps} />);
});

it('renders with Select by default', () => {
expect(wrapper.find(OnPasteSelect)).not.toExist();
expect(wrapper.findWhere(x => x.type() === Select)).toHaveLength(1);
});

it('renders with OnPasteSelect when multi', () => {
wrapper.setProps({ multi: true });
expect(wrapper.find(OnPasteSelect)).toExist();
expect(wrapper.findWhere(x => x.type() === Select)).toHaveLength(0);
});

it('renders with Creatable when freeForm', () => {
wrapper.setProps({ freeForm: true });
expect(wrapper.find(OnPasteSelect)).not.toExist();
expect(wrapper.findWhere(x => x.type() === CreatableSelect)).toHaveLength(
1,
);
});

it('uses Select in onPasteSelect when freeForm=false', () => {
wrapper = shallow(<SelectControl {...defaultProps} multi />);
const select = wrapper.find(OnPasteSelect);
Expand Down Expand Up @@ -81,141 +100,6 @@ describe('SelectControl', () => {
expect(selectAllProps.onChange.calledWith(expectedValues)).toBe(true);
});

describe('render', () => {
it('renders with Select by default', () => {
expect(wrapper.find(OnPasteSelect)).not.toExist();
expect(wrapper.findWhere(x => x.type() === Select)).toHaveLength(1);
});

it('renders with OnPasteSelect when multi', () => {
wrapper.setProps({ multi: true });
expect(wrapper.find(OnPasteSelect)).toExist();
expect(wrapper.findWhere(x => x.type() === Select)).toHaveLength(0);
});

it('renders with Creatable when freeForm', () => {
wrapper.setProps({ freeForm: true });
expect(wrapper.find(OnPasteSelect)).not.toExist();
expect(wrapper.findWhere(x => x.type() === CreatableSelect)).toHaveLength(
1,
);
});
describe('empty placeholder', () => {
describe('withMulti', () => {
it('does not show a placeholder if there are no choices', () => {
const withMulti = mount(
<SelectControl
{...defaultProps}
choices={[]}
multi
placeholder="add something"
/>,
);
expect(withMulti.html()).not.toContain('placeholder=');
});
});
describe('withSingleChoice', () => {
it('does not show a placeholder if there are no choices', () => {
const singleChoice = mount(
<SelectControl
{...defaultProps}
choices={[]}
multi
placeholder="add something"
/>,
);
expect(singleChoice.html()).not.toContain('placeholder=');
});
});
describe('default placeholder', () => {
it('does not show a placeholder if there are no options', () => {
const defaultPlaceholder = mount(
<SelectControl {...defaultProps} choices={[]} multi />,
);
expect(defaultPlaceholder.html()).not.toContain('placeholder=');
});
});
describe('all choices selected', () => {
it('does not show a placeholder', () => {
const allChoicesSelected = mount(
<SelectControl
{...defaultProps}
multi
value={['today', '1 year ago']}
/>,
);
expect(allChoicesSelected.html()).toContain('placeholder=""');
});
});
});
describe('when select is multi', () => {
it('renders the placeholder when a selection has been made', () => {
wrapper = mount(
<SelectControl
{...defaultProps}
multi
value={50}
placeholder="add something"
/>,
);
expect(wrapper.html()).toContain('add something');
});
it('shows numbers of options as a placeholder by default', () => {
wrapper = mount(<SelectControl {...defaultProps} multi />);
expect(wrapper.html()).toContain('2 option(s');
});
it('reduces the number of options in the placeholder by the value length', () => {
wrapper = mount(
<SelectControl {...defaultProps} multi value={['today']} />,
);
expect(wrapper.html()).toContain('1 option(s');
});
});
describe('when select is single', () => {
it('does not render the placeholder when a selection has been made', () => {
wrapper = mount(
<SelectControl
{...defaultProps}
value={50}
placeholder="add something"
/>,
);
expect(wrapper.html()).not.toContain('add something');
});
});
});

describe('optionsRemaining', () => {
describe('isMulti', () => {
it('returns the options minus selected values', () => {
const wrapper = mount(
<SelectControl {...defaultProps} multi value={['today']} />,
);
expect(wrapper.instance().optionsRemaining()).toEqual(1);
});
});
describe('is not multi', () => {
it('returns the length of all options', () => {
wrapper = mount(
<SelectControl
{...defaultProps}
value={50}
placeholder="add something"
/>,
);
expect(wrapper.instance().optionsRemaining()).toEqual(2);
});
});
describe('with Select All', () => {
it('does not count it', () => {
const props = { ...defaultProps, multi: true, allowAll: true };
const wrapper = mount(<SelectControl {...props} />);
expect(wrapper.instance().getOptions(props).length).toEqual(3);
expect(wrapper.instance().optionsRemaining()).toEqual(2);
});
});
});

describe('getOptions', () => {
it('returns the correct options', () => {
wrapper.setProps(defaultProps);
Expand Down
129 changes: 0 additions & 129 deletions superset-frontend/src/components/Select/Select.stories.tsx

This file was deleted.

Loading

0 comments on commit 94abb29

Please sign in to comment.