Fix randomly failing JS acceptance tests.

This commit is contained in:
Guo Xiang Tan 2017-12-20 11:04:23 +08:00
parent 7aa56fc9d9
commit 87c334c063
2 changed files with 15 additions and 9 deletions

View File

@ -3,14 +3,18 @@ import { createWidget } from 'discourse/widgets/widget';
import { h } from 'virtual-dom';
import DiscourseURL from 'discourse/lib/url';
const searchData = {
loading: false,
results: {},
noResults: false,
term: undefined,
typeFilter: null,
invalidTerm: false
};
const searchData = {};
export function initSearchData() {
searchData.loading = false;
searchData.results = {};
searchData.noResults = false;
searchData.term = undefined;
searchData.typeFilter = null;
searchData.invalidTerm = false;
}
initSearchData();
// Helps with debouncing and cancelling promises
const SearchHelper = {
@ -161,7 +165,7 @@ export default createWidget('search-menu', {
html(attrs) {
if (searchData.contextEnabled !== attrs.contextEnabled) {
searchData.contextEnabled = attrs.contextEnabled;
this.triggerSearch();
if (searchData.term) this.triggerSearch();
} else {
searchData.contextEnabled = attrs.contextEnabled;
}

View File

@ -8,6 +8,7 @@ import { clearCache as clearOutletCache, resetExtraClasses } from 'discourse/lib
import { clearHTMLCache } from 'discourse/helpers/custom-html';
import { flushMap } from 'discourse/models/store';
import { clearRewrites } from 'discourse/lib/url';
import { initSearchData } from 'discourse/widgets/search-menu';
export function currentUser() {
return Discourse.User.create(sessionFixtures['/session/current.json'].current_user);
@ -97,6 +98,7 @@ export function acceptance(name, options) {
clearHTMLCache();
resetPluginApi();
clearRewrites();
initSearchData();
Discourse.reset();
}
});