2019-06-06 04:47:10 -04:00
|
|
|
import selectKit from "helpers/select-kit-helper";
|
2019-06-14 08:54:20 -04:00
|
|
|
import { acceptance } from "helpers/qunit-helpers";
|
2018-08-20 03:46:02 -04:00
|
|
|
|
|
|
|
const emptySearchContextCallbacks = [];
|
|
|
|
|
2019-06-14 08:54:20 -04:00
|
|
|
let searchArgs = {
|
2018-08-20 04:25:59 -04:00
|
|
|
pretend(server) {
|
|
|
|
server.handledRequest = (verb, path, request) => {
|
2018-08-20 03:46:02 -04:00
|
|
|
if (request.queryParams["search_context[type]"] === undefined) {
|
|
|
|
emptySearchContextCallbacks.forEach(callback => {
|
|
|
|
callback.call();
|
|
|
|
});
|
|
|
|
}
|
2018-08-20 04:25:59 -04:00
|
|
|
};
|
2018-08-20 03:46:02 -04:00
|
|
|
}
|
2019-06-14 08:54:20 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
acceptance("Search", searchArgs);
|
2015-06-22 14:05:35 -04:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
QUnit.test("search", async assert => {
|
|
|
|
await visit("/");
|
|
|
|
|
|
|
|
await click("#search-button");
|
|
|
|
|
|
|
|
assert.ok(exists("#search-term"), "it shows the search bar");
|
|
|
|
assert.ok(!exists(".search-menu .results ul li"), "no results by default");
|
|
|
|
|
|
|
|
await fillIn("#search-term", "dev");
|
|
|
|
await keyEvent("#search-term", "keyup", 16);
|
|
|
|
assert.ok(exists(".search-menu .results ul li"), "it shows results");
|
2020-04-16 19:35:26 -04:00
|
|
|
assert.ok(
|
|
|
|
exists(".search-menu .results ul li .topic-title[data-topic-id]"),
|
|
|
|
"topic has data-topic-id"
|
|
|
|
);
|
2018-07-19 10:40:12 -04:00
|
|
|
|
|
|
|
await click(".show-help");
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
find(".full-page-search").val(),
|
|
|
|
"dev",
|
|
|
|
"it shows the search term"
|
|
|
|
);
|
|
|
|
assert.ok(exists(".search-advanced-options"), "advanced search is expanded");
|
2015-06-22 14:05:35 -04:00
|
|
|
});
|
2017-02-20 17:02:02 -05:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
QUnit.test("search for a tag", async assert => {
|
|
|
|
await visit("/");
|
2017-08-25 11:52:18 -04:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
await click("#search-button");
|
2017-08-25 11:52:18 -04:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
await fillIn("#search-term", "evil");
|
|
|
|
await keyEvent("#search-term", "keyup", 16);
|
|
|
|
assert.ok(exists(".search-menu .results ul li"), "it shows results");
|
2017-08-25 11:52:18 -04:00
|
|
|
});
|
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
QUnit.test("search scope checkbox", async assert => {
|
2020-01-21 12:23:08 -05:00
|
|
|
await visit("/tag/important");
|
2019-11-13 19:40:26 -05:00
|
|
|
await click("#search-button");
|
|
|
|
assert.ok(
|
|
|
|
exists(".search-context input:checked"),
|
|
|
|
"scope to tag checkbox is checked"
|
|
|
|
);
|
|
|
|
await click("#search-button");
|
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
await visit("/c/bug");
|
|
|
|
await click("#search-button");
|
|
|
|
assert.ok(
|
|
|
|
exists(".search-context input:checked"),
|
|
|
|
"scope to category checkbox is checked"
|
|
|
|
);
|
|
|
|
await click("#search-button");
|
|
|
|
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await click("#search-button");
|
|
|
|
assert.not(
|
|
|
|
exists(".search-context input:checked"),
|
|
|
|
"scope to topic checkbox is not checked"
|
|
|
|
);
|
|
|
|
await click("#search-button");
|
|
|
|
|
|
|
|
await visit("/u/eviltrout");
|
|
|
|
await click("#search-button");
|
|
|
|
assert.ok(
|
|
|
|
exists(".search-context input:checked"),
|
|
|
|
"scope to user checkbox is checked"
|
|
|
|
);
|
2017-02-20 17:02:02 -05:00
|
|
|
});
|
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
QUnit.test("Search with context", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280/1");
|
2017-02-02 22:28:54 -05:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
await click("#search-button");
|
2019-04-03 03:57:51 -04:00
|
|
|
await fillIn("#search-term", "a proper");
|
2018-07-19 10:40:12 -04:00
|
|
|
await click(".search-context input[type='checkbox']");
|
|
|
|
await keyEvent("#search-term", "keyup", 16);
|
2017-02-02 22:28:54 -05:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
assert.ok(exists(".search-menu .results ul li"), "it shows results");
|
2018-05-07 03:17:34 -04:00
|
|
|
|
2019-04-03 03:57:51 -04:00
|
|
|
const highlighted = [];
|
|
|
|
|
2020-04-15 01:41:00 -04:00
|
|
|
find("#post_7 span.highlighted").map((_, span) => {
|
2019-04-03 03:57:51 -04:00
|
|
|
highlighted.push(span.innerText);
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
highlighted,
|
2020-04-15 01:41:00 -04:00
|
|
|
["a proper"],
|
2019-04-03 03:57:51 -04:00
|
|
|
"it should highlight the post with the search terms correctly"
|
2018-07-19 10:40:12 -04:00
|
|
|
);
|
2017-02-02 22:28:54 -05:00
|
|
|
|
2018-08-20 03:46:02 -04:00
|
|
|
let callbackCalled = false;
|
|
|
|
|
|
|
|
emptySearchContextCallbacks.push(() => {
|
|
|
|
callbackCalled = true;
|
|
|
|
});
|
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
await visit("/");
|
|
|
|
await click("#search-button");
|
2017-02-02 22:28:54 -05:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
assert.ok(!exists(".search-context input[type='checkbox']"));
|
2018-08-20 03:46:02 -04:00
|
|
|
assert.ok(callbackCalled, "it triggers a new search");
|
2017-02-02 22:28:54 -05:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
await visit("/t/internationalization-localization/280/1");
|
|
|
|
await click("#search-button");
|
2017-02-02 22:28:54 -05:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
assert.ok(!$(".search-context input[type=checkbox]").is(":checked"));
|
2017-07-17 15:42:32 -04:00
|
|
|
});
|
2017-08-08 04:08:07 -04:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
QUnit.test("Right filters are shown to anonymous users", async assert => {
|
2017-12-22 07:08:12 -05:00
|
|
|
const inSelector = selectKit(".select-kit#in");
|
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
await visit("/search?expanded=true");
|
2017-08-08 04:08:07 -04:00
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
await inSelector.expand();
|
2017-10-19 15:51:08 -04:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
assert.ok(inSelector.rowByValue("first").exists());
|
|
|
|
assert.ok(inSelector.rowByValue("pinned").exists());
|
|
|
|
assert.ok(inSelector.rowByValue("wiki").exists());
|
|
|
|
assert.ok(inSelector.rowByValue("images").exists());
|
2018-06-15 11:03:24 -04:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
assert.notOk(inSelector.rowByValue("unseen").exists());
|
|
|
|
assert.notOk(inSelector.rowByValue("posted").exists());
|
|
|
|
assert.notOk(inSelector.rowByValue("watching").exists());
|
|
|
|
assert.notOk(inSelector.rowByValue("tracking").exists());
|
|
|
|
assert.notOk(inSelector.rowByValue("bookmarks").exists());
|
2018-06-15 11:03:24 -04:00
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
assert.notOk(exists(".search-advanced-options .in-likes"));
|
|
|
|
assert.notOk(exists(".search-advanced-options .in-private"));
|
|
|
|
assert.notOk(exists(".search-advanced-options .in-seen"));
|
2017-08-08 04:08:07 -04:00
|
|
|
});
|
|
|
|
|
2019-06-14 08:54:20 -04:00
|
|
|
acceptance("Search", Object.assign({ loggedIn: true, searchArgs }));
|
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
QUnit.test("Right filters are shown to logged-in users", async assert => {
|
2017-12-22 07:08:12 -05:00
|
|
|
const inSelector = selectKit(".select-kit#in");
|
|
|
|
|
2018-07-19 10:40:12 -04:00
|
|
|
await visit("/search?expanded=true");
|
|
|
|
|
2018-07-29 16:51:32 -04:00
|
|
|
await inSelector.expand();
|
2018-07-19 10:40:12 -04:00
|
|
|
|
|
|
|
assert.ok(inSelector.rowByValue("first").exists());
|
|
|
|
assert.ok(inSelector.rowByValue("pinned").exists());
|
|
|
|
assert.ok(inSelector.rowByValue("wiki").exists());
|
|
|
|
assert.ok(inSelector.rowByValue("images").exists());
|
|
|
|
|
|
|
|
assert.ok(inSelector.rowByValue("unseen").exists());
|
|
|
|
assert.ok(inSelector.rowByValue("posted").exists());
|
|
|
|
assert.ok(inSelector.rowByValue("watching").exists());
|
|
|
|
assert.ok(inSelector.rowByValue("tracking").exists());
|
|
|
|
assert.ok(inSelector.rowByValue("bookmarks").exists());
|
|
|
|
|
|
|
|
assert.ok(exists(".search-advanced-options .in-likes"));
|
|
|
|
assert.ok(exists(".search-advanced-options .in-private"));
|
|
|
|
assert.ok(exists(".search-advanced-options .in-seen"));
|
2017-08-08 04:08:07 -04:00
|
|
|
});
|
2019-06-27 13:26:14 -04:00
|
|
|
|
|
|
|
acceptance(
|
|
|
|
"Search - with tagging enabled",
|
|
|
|
Object.assign({
|
|
|
|
loggedIn: true,
|
|
|
|
searchArgs,
|
|
|
|
settings: { tagging_enabled: true }
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
QUnit.test("displays tags", async assert => {
|
|
|
|
await visit("/");
|
|
|
|
|
|
|
|
await click("#search-button");
|
|
|
|
|
|
|
|
await fillIn("#search-term", "dev");
|
|
|
|
await keyEvent("#search-term", "keyup", 16);
|
|
|
|
|
|
|
|
const tags = find(".search-menu .results ul li:eq(0) .discourse-tags")
|
|
|
|
.text()
|
|
|
|
.trim();
|
|
|
|
|
|
|
|
assert.equal(tags, "dev slow");
|
|
|
|
});
|