mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #1888 from velesin/search_integration_tests
Adds JS integration tests for search
This commit is contained in:
commit
59253c937e
@ -20,6 +20,7 @@
|
|||||||
"blank",
|
"blank",
|
||||||
"present",
|
"present",
|
||||||
"visit",
|
"visit",
|
||||||
|
"andThen",
|
||||||
"click",
|
"click",
|
||||||
"currentPath",
|
"currentPath",
|
||||||
"currentRouteName",
|
"currentRouteName",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{{view Discourse.SearchTextField valueBinding="term" searchContextBinding="searchContext"}}
|
{{view Discourse.SearchTextField valueBinding="term" searchContextBinding="searchContext" id="search-term"}}
|
||||||
{{#unless loading}}
|
{{#unless loading}}
|
||||||
{{#unless noResults}}
|
{{#unless noResults}}
|
||||||
{{#each resultType in content}}
|
{{#each resultType in content}}
|
||||||
|
@ -11,6 +11,8 @@ integration("Header", {
|
|||||||
return scope;
|
return scope;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
sinon.stub(Ember.run, "debounce").callsArg(1);
|
||||||
|
|
||||||
var originalCategories = Discourse.Category.list();
|
var originalCategories = Discourse.Category.list();
|
||||||
sinon.stub(Discourse.Category, "list").returns(originalCategories);
|
sinon.stub(Discourse.Category, "list").returns(originalCategories);
|
||||||
|
|
||||||
@ -20,6 +22,7 @@ integration("Header", {
|
|||||||
|
|
||||||
teardown: function() {
|
teardown: function() {
|
||||||
I18n.t.restore();
|
I18n.t.restore();
|
||||||
|
Ember.run.debounce.restore();
|
||||||
Discourse.Category.list.restore();
|
Discourse.Category.list.restore();
|
||||||
Discourse.User.current.restore();
|
Discourse.User.current.restore();
|
||||||
}
|
}
|
||||||
@ -119,3 +122,52 @@ test("sitemap dropdown", function() {
|
|||||||
ok(exists($siteMapDropdown.find(".new-posts")), "has displaying category badges correctly bound");
|
ok(exists($siteMapDropdown.find(".new-posts")), "has displaying category badges correctly bound");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("search dropdown", function() {
|
||||||
|
Discourse.SiteSettings.min_search_term_length = 2;
|
||||||
|
Ember.run(function() {
|
||||||
|
Discourse.URL_FIXTURES["/search"] = [
|
||||||
|
{
|
||||||
|
type: "topic",
|
||||||
|
more: true,
|
||||||
|
results: [
|
||||||
|
{
|
||||||
|
url: "some-url"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
visit("/");
|
||||||
|
andThen(function() {
|
||||||
|
not(exists("#search-dropdown:visible"), "initially search box is closed");
|
||||||
|
});
|
||||||
|
click("#search-button");
|
||||||
|
andThen(function() {
|
||||||
|
ok(exists("#search-dropdown:visible"), "after clicking a button search box opens");
|
||||||
|
not(exists("#search-dropdown .heading"), "initially, immediately after opening, search box is empty");
|
||||||
|
});
|
||||||
|
fillIn("#search-term", "ab");
|
||||||
|
andThen(function() {
|
||||||
|
ok(exists("#search-dropdown .heading"), "when user completes a search, search box shows search results");
|
||||||
|
equal(find("#search-dropdown .selected a").attr("href"), "some-url", "the first search result is selected");
|
||||||
|
});
|
||||||
|
andThen(function() {
|
||||||
|
Discourse.URL_FIXTURES["/search"] = [
|
||||||
|
{
|
||||||
|
type: "topic",
|
||||||
|
more: true,
|
||||||
|
results: [
|
||||||
|
{
|
||||||
|
url: "another-url"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
});
|
||||||
|
click("#search-dropdown .filter");
|
||||||
|
andThen(function() {
|
||||||
|
equal(find("#search-dropdown .selected a").attr("href"), "another-url", "after clicking 'more of type' link, results are reloaded");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
var controller, oldSearchTextField, oldSearchResultsTypeView;
|
var controller, oldSearchTextField, oldSearchResultsTypeView, oldViews;
|
||||||
|
|
||||||
var SearchTextFieldStub = Ember.View.extend({
|
var SearchTextFieldStub = Ember.View.extend({
|
||||||
classNames: ["search-text-field-stub"],
|
classNames: ["search-text-field-stub"],
|
||||||
@ -18,7 +18,6 @@ var setUpController = function(properties) {
|
|||||||
|
|
||||||
var appendView = function() {
|
var appendView = function() {
|
||||||
Ember.run(function() {
|
Ember.run(function() {
|
||||||
Discourse.advanceReadiness();
|
|
||||||
Ember.View.create({
|
Ember.View.create({
|
||||||
container: Discourse.__container__,
|
container: Discourse.__container__,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
@ -42,6 +41,9 @@ module("Template: search", {
|
|||||||
oldSearchResultsTypeView = Discourse.SearchResultsTypeView;
|
oldSearchResultsTypeView = Discourse.SearchResultsTypeView;
|
||||||
Discourse.SearchResultsTypeView = SearchResultsTypeViewStub;
|
Discourse.SearchResultsTypeView = SearchResultsTypeViewStub;
|
||||||
|
|
||||||
|
oldViews = Ember.View.views;
|
||||||
|
Ember.View.views = {};
|
||||||
|
|
||||||
controller = Ember.ArrayController.create();
|
controller = Ember.ArrayController.create();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -50,6 +52,8 @@ module("Template: search", {
|
|||||||
|
|
||||||
Discourse.SearchTextField = oldSearchTextField;
|
Discourse.SearchTextField = oldSearchTextField;
|
||||||
Discourse.SearchResultsTypeView = oldSearchResultsTypeView;
|
Discourse.SearchResultsTypeView = oldSearchResultsTypeView;
|
||||||
|
|
||||||
|
Ember.View.views = oldViews;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user