Skip to content

Commit

Permalink
Merge pull request #93 from comicrelief/GP-909_school_error
Browse files Browse the repository at this point in the history
Gp 909 school error
  • Loading branch information
ayanozturk authored Nov 9, 2017
2 parents 967270b + 3ece284 commit 47cf681
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
10 changes: 3 additions & 7 deletions __tests__/components/SchoolsLookUp/SchoolsLookUp.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import React from 'react';
import { shallow, render } from 'enzyme';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import SchoolsLookUp from '../../../src/components/SchoolsLookUp/SchoolsLookUp';

Expand Down Expand Up @@ -130,14 +130,10 @@ test('search and recieve empty results', () => {
expect(component.find('[name="spinner"]').exists()).toBe(false);
// assert no results are recieved
expect(component.state('options')).toEqual([]);

// render menu list where no results found message is expected to be displayed
const instance = component.setState({ query: 'testquery' }).instance();
const emptyLabel = "Sorry, that postcode isn't in our database of schools and nurseries. Please manually fill in the address below.";
const menu = render(instance.renderMenu([], { emptyLabel, text: 'testquery' }));
const emptyLabel = "Sorry, we can't find this. Please check your school or postcode is correct and manually add the address below.";

// assert no results message is displayed
expect(menu.text()).toEqual(emptyLabel);
expect(component.text()).toContain(emptyLabel);
});
});

Expand Down
15 changes: 10 additions & 5 deletions src/components/SchoolsLookUp/SchoolsLookUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,9 @@ class SchoolsLookUp extends Component {
* @return {XML}
*/
renderMenu(results, menuProps) {
const { isSearching, isDefaultOptionHighlighted, query } = this.state;
const { isSearching, isDefaultOptionHighlighted } = this.state;
// do not show results until search is complete
if (menuProps.emptyLabel === 'Searching...' || isSearching === true ||
(results.length === 0 && query && query.toUpperCase() !== menuProps.text.toUpperCase())
if (menuProps.emptyLabel === 'Searching...' || isSearching === true || results.length === 0
) {
return <div />;
}
Expand Down Expand Up @@ -363,7 +362,7 @@ class SchoolsLookUp extends Component {
establishmentNameIdentifier, address1Identifier, address2Identifier, address3Identifier,
townIdentifier, postcodeIdentifier, min, selectedEstablishment, disabled,
} = this.props;
const { lookup, options, isSearching } = this.state;
const { lookup, options, isSearching, query } = this.state;
const orEnterManuallyCopy = 'Or enter details manually';

return (
Expand Down Expand Up @@ -394,7 +393,7 @@ class SchoolsLookUp extends Component {
type="text"
minLength={min}
bsSize="large"
emptyLabel="Sorry, that postcode isn't in our database of schools and nurseries. Please manually fill in the address below."
emptyLabel=""
onSearch={this.handleSearch}
onChange={this.handleChange}
onInputChange={this.handleInputChange}
Expand All @@ -411,6 +410,12 @@ class SchoolsLookUp extends Component {
<Icon name="spinner" spin />:
null
}
{!isSearching && query.length > min && options.length === 0 ?
<p className="font--red">
{"Sorry, we can't find this. Please check your school or postcode is correct and manually add the address below."}
</p>:
null
}
</div>
}
{lookup === SHOW_EDCO_LOOKUP ?
Expand Down

0 comments on commit 47cf681

Please sign in to comment.