alphagov/finder-frontend — pull request #107 by alicebartlett (2014-11-03 18:42:09+00:00)
Title: Fix search auto-update bug

Because search calls are asyncronous, it is possible for the results on a page to be in-consistent with the search form. This happens as follows:

1. Checkbox1 is checked triggering a search
2. An asynchronous call to the server (via cache etc) is made (call1)
3. Checkbox1 is unchecked triggering another search
4. Another async call to server is made (call2)
5. Call2 returns before call1
6. Search results for call2 are displayed
7. Call1 returns
8. Search results for call1 are displayed
9. The search results are now out of step with the checkboxes :(

This PR updates displayResults to only update the results if the liveSearch.state now is the same as it was when the search was triggered. It does this by passing the value through the ajax request under the searchState parameter.

This PR also includes a test for the new updateResults() and updates existing tests.

Trello ticket is here: https://trello.com/c/bRhlYQCu/394-sometimes-the-clear-button-on-dropdowns-doesn-t-work-on-finder-frontend