Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ class QueryBar extends Component {
skipString: PropTypes.string,
limitString: PropTypes.string,

filterPlaceholder: PropTypes.string,
projectPlaceholder: PropTypes.string,
collationPlaceholder: PropTypes.string,
sortPlaceholder: PropTypes.string,
skipPlaceholder: PropTypes.string,
limitPlaceholder: PropTypes.string,
maxTimeMSPlaceholder: PropTypes.string,

actions: PropTypes.object,
buttonLabel: PropTypes.string,
queryState: PropTypes.string,
Expand Down Expand Up @@ -219,6 +227,8 @@ class QueryBar extends Component {
this.props[option] : this.props[`${option}String`];

const label = OPTION_DEFINITION[option].label || option;
const placeholder = this.props[`${option}Placeholder`] || OPTION_DEFINITION[option].placeholder;


return (
<QueryOption
Expand All @@ -230,7 +240,7 @@ class QueryBar extends Component {
key={`query-option-${id}`}
value={value}
actions={this.props.actions}
placeholder={OPTION_DEFINITION[option].placeholder}
placeholder={placeholder}
link={OPTION_DEFINITION[option].link}
inputType={OPTION_DEFINITION[option].type}
onChange={this.onChange.bind(this, option)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { shallow } from 'enzyme';
import { shallow, mount } from 'enzyme';

import QueryBar from '../query-bar';
import QueryOption from '../query-option';
Expand Down Expand Up @@ -328,5 +328,60 @@ describe('QueryBar [Component]', function() {
expect(component.find('#query-bar-menu-actions')).to.not.exist;
});
});

describe('a user is able to provide custom placeholders for the input fields', function() {
const layout = ['filter', 'project', ['sort', 'maxTimeMS'], ['collation', 'skip', 'limit']];


it('the input fields have a placeholder by default', function() {
const component = mount(
<QueryBar
store={store}
actions={actions}
layout={layout}
expanded
serverVersion="3.4.0" />
);

expect(component.find('div[data-test-id="query-bar-options-toggle"]')).to.exist;
component.find('div[data-test-id="query-bar-options-toggle"]').simulate('click');
expect(component.find('OptionEditor[label="filter"]').prop('placeholder')).to.not.be.empty;
expect(component.find('OptionEditor[label="project"]').prop('placeholder')).to.not.be.empty;
expect(component.find('OptionEditor[label="collation"]').prop('placeholder')).to.not.be.empty;
expect(component.find('OptionEditor[label="sort"]').prop('placeholder')).to.not.be.empty;
expect(component.find('QueryOption[label="Max Time MS"]').prop('placeholder')).to.not.be.empty;
expect(component.find('QueryOption[label="skip"]').prop('placeholder')).to.not.be.empty;
expect(component.find('QueryOption[label="limit"]').prop('placeholder')).to.not.be.empty;
});

it('the input fields placeholders can be modified', function() {
const component = mount(
<QueryBar
store={store}
actions={actions}
layout={layout}
sortOptionPlaceholder="{ field: -1 }"
expanded
serverVersion="3.4.0"
filterPlaceholder="{field: 'matchValue'}"
projectPlaceholder="{field: 1}"
collationPlaceholder="{locale: 'fr' }"
sortPlaceholder="{field: 1}"
skipPlaceholder="10"
limitPlaceholder="20"
maxTimeMSPlaceholder="50000" />
);

expect(component.find('div[data-test-id="query-bar-options-toggle"]')).to.exist;
component.find('div[data-test-id="query-bar-options-toggle"]').simulate('click');
expect(component.find('OptionEditor[label="filter"]').prop('placeholder')).to.equal("{field: 'matchValue'}");
expect(component.find('OptionEditor[label="project"]').prop('placeholder')).to.equal('{field: 1}');
expect(component.find('OptionEditor[label="collation"]').prop('placeholder')).to.equal("{locale: 'fr' }");
expect(component.find('OptionEditor[label="sort"]').prop('placeholder')).to.equal('{field: 1}');
expect(component.find('QueryOption[label="Max Time MS"]').prop('placeholder')).to.equal('50000');
expect(component.find('QueryOption[label="skip"]').prop('placeholder')).to.equal('10');
expect(component.find('QueryOption[label="limit"]').prop('placeholder')).to.equal('20');
});
});
});
});
55 changes: 55 additions & 0 deletions packages/compass-query-bar/src/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,59 @@ describe('QueryBar [Plugin]', () => {
expect(component.find('#query-bar-menu-actions')).to.not.exist;
});
});

describe('a user is able to provide custom placeholders for the input fields', function() {
const layout = ['filter', 'project', ['sort', 'maxTimeMS'], ['collation', 'skip', 'limit']];


it('the input fields have a placeholder by default', function() {
component = mount(
<QueryBarPlugin
store={store}
actions={actions}
layout={layout}
expanded
serverVersion="3.4.0" />
);

expect(component.find('div[data-test-id="query-bar-options-toggle"]')).to.exist;
component.find('div[data-test-id="query-bar-options-toggle"]').simulate('click');
expect(component.find('OptionEditor[label="filter"]').prop('placeholder')).to.not.be.empty;
expect(component.find('OptionEditor[label="project"]').prop('placeholder')).to.not.be.empty;
expect(component.find('OptionEditor[label="collation"]').prop('placeholder')).to.not.be.empty;
expect(component.find('OptionEditor[label="sort"]').prop('placeholder')).to.not.be.empty;
expect(component.find('QueryOption[label="Max Time MS"]').prop('placeholder')).to.not.be.empty;
expect(component.find('QueryOption[label="skip"]').prop('placeholder')).to.not.be.empty;
expect(component.find('QueryOption[label="limit"]').prop('placeholder')).to.not.be.empty;
});

it('the input fields placeholders can be modified', function() {
component = mount(
<QueryBarPlugin
store={store}
actions={actions}
layout={layout}
sortOptionPlaceholder="{ field: -1 }"
expanded
serverVersion="3.4.0"
filterPlaceholder="{field: 'matchValue'}"
projectPlaceholder="{field: 1}"
collationPlaceholder="{locale: 'fr' }"
sortPlaceholder="{field: 1}"
skipPlaceholder="10"
limitPlaceholder="20"
maxTimeMSPlaceholder="50000" />
);

expect(component.find('div[data-test-id="query-bar-options-toggle"]')).to.exist;
component.find('div[data-test-id="query-bar-options-toggle"]').simulate('click');
expect(component.find('OptionEditor[label="filter"]').prop('placeholder')).to.equal("{field: 'matchValue'}");
expect(component.find('OptionEditor[label="project"]').prop('placeholder')).to.equal('{field: 1}');
expect(component.find('OptionEditor[label="collation"]').prop('placeholder')).to.equal("{locale: 'fr' }");
expect(component.find('OptionEditor[label="sort"]').prop('placeholder')).to.equal('{field: 1}');
expect(component.find('QueryOption[label="Max Time MS"]').prop('placeholder')).to.equal('50000');
expect(component.find('QueryOption[label="skip"]').prop('placeholder')).to.equal('10');
expect(component.find('QueryOption[label="limit"]').prop('placeholder')).to.equal('20');
});
});
});