Skip to content

Commit

Permalink
Move back to debouncing background refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Richmond committed Feb 24, 2016
1 parent 6343eb2 commit 2fa1cfc
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 18 deletions.
4 changes: 2 additions & 2 deletions addon/mixins/advanced-search-routeable.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default Ember.Mixin.create({
}
},

_throttleRefresh() {
_debounceRefresh() {
this.send('refresh', false);
},

Expand All @@ -105,7 +105,7 @@ export default Ember.Mixin.create({
},

backgroundRefresh() {
Ember.run.throttle(this, this._throttleRefresh, 1000);
Ember.run.debounce(this, this._debounceRefresh, 1000);
},

queryParamsDidChange(changed, totalPresent, removed) {
Expand Down
6 changes: 3 additions & 3 deletions addon/transforms/advanced-search-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export default DS.Transform.extend({
id: v.id,
key: v.key,
text: v.text
}
};

if (v.user_query) {
serializedValue.user_query = v.user_query
serializedValue.user_query = v.user_query;
}

return serializedValue
return serializedValue;
});
return {
and: deserialized.and || false,
Expand Down
4 changes: 2 additions & 2 deletions mirage/factories/person.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Factory } from 'ember-cli-mirage';
import { Factory, faker } from 'ember-cli-mirage';

export default Factory.extend({
name() { return Faker.name.firstName() }
name() { return faker.name.firstName() }
});
32 changes: 32 additions & 0 deletions tests/acceptance/background-refresh-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
import page from '../pages/people-search';

moduleForAcceptance('Acceptance | background refresh', {
beforeEach() {
server.create('person');
server.omitDefaultConditions = true;
}
});

test('triggering background refresh', function(assert) {
page.visit();

andThen(function() {
assert.equal(page.results().count(), 1, 'show have correct initial results');
server.create('person');
server.timing = 100;
page.triggerBackgroundRefresh();

let done = assert.async();
setTimeout(() => {
assert.notOk(page.isLoading(), 'should not show loading indicator');
done();
}, 80);

andThen(function() {
assert.equal(page.results().count(), 2, 'show update the search results');
server.timing = 0;
});
});
});
1 change: 0 additions & 1 deletion tests/acceptance/location-history-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ test('loading indicator', function(assert) {
server.timing = 0;
});
});

});

// Ensures pushPayload resets record
Expand Down
6 changes: 6 additions & 0 deletions tests/dummy/app/people-search/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
{{input id='search_description' type='text' value=model.conditions.description}}
</div>

<!-- typically you'd call this through a service, maybe due to a websocket -->
<!-- this is just for testing -->
<div style='visibility: hidden'>
<a href='' id='bg_refresh' {{action 'backgroundRefresh'}}>bg refresh</a>
</div>

<div>
<a href='' id='reset' {{action 'reset'}}>Reset</a>
</div>
Expand Down
21 changes: 11 additions & 10 deletions tests/pages/people-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ let isChecked = customHelper(function(selector) {
});

export default PageObject.create({
visit: visitable('/'),
nameValue: value('#search_name'),
name: fillable('#search_name'),
description: fillable('#search_description'),
descriptionValue: value('#search_description'),
submit: clickable('#search_submit'),
reset: clickable('#reset'),
isLoading: hasClass('loading', '.loading-area'),
openNameAutocomplete: clickable('#name_autocomplete .select2-input'),
visit: visitable('/'),
nameValue: value('#search_name'),
name: fillable('#search_name'),
description: fillable('#search_description'),
descriptionValue: value('#search_description'),
submit: clickable('#search_submit'),
reset: clickable('#reset'),
triggerBackgroundRefresh: clickable('#bg_refresh'),
isLoading: hasClass('loading', '.loading-area'),
openNameAutocomplete: clickable('#name_autocomplete .select2-input'),

autocompleteOptions: collection({
itemScope: '.select2-results li',
Expand All @@ -48,7 +49,7 @@ export default PageObject.create({
currentPage: text('#current_page'),
pageTwo: clickable('#page_two'),

sortName: clickable('th:nth-child(2) a'),
sortName: clickable('th:nth-child(2) a'),
nameHasSortAscClass: hasClass('asc', 'th:nth-child(2) a'),
nameHasSortDescClass: hasClass('desc', 'th:nth-child(2) a'),

Expand Down

0 comments on commit 2fa1cfc

Please sign in to comment.