Adds JS integration tests for search

This commit is contained in:
Wojciech Zawistowski
2014-01-31 01:53:08 -05:00
parent 51c06dea03
commit 73253ce32e
4 changed files with 60 additions and 3 deletions
@@ -11,6 +11,8 @@ integration("Header", {
return scope;
});
sinon.stub(Ember.run, "debounce").callsArg(1);
var originalCategories = Discourse.Category.list();
sinon.stub(Discourse.Category, "list").returns(originalCategories);
@@ -20,6 +22,7 @@ integration("Header", {
teardown: function() {
I18n.t.restore();
Ember.run.debounce.restore();
Discourse.Category.list.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");
});
});
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");
});
});