2016-10-06 15:18:05 -04:00
import { acceptance, waitFor } from "helpers/qunit-helpers";
acceptance("Search - Full Page", {
settings: {tagging_enabled: true},
2017-08-08 04:08:07 -04:00
loggedIn: true,
2017-06-14 13:57:58 -04:00
beforeEach() {
2016-10-06 15:18:05 -04:00
const response = (object) => {
return [
200,
{"Content-Type": "application/json"},
object
];
};
server.get('/tags/filter/search', () => { //eslint-disable-line
return response({results: [{text: 'monkey', count: 1}]});
});
2017-03-28 12:16:58 -04:00
server.get('/u/search/users', () => { //eslint-disable-line
2016-10-06 15:18:05 -04:00
return response({users: [{username: "admin", name: "admin",
2017-02-17 16:17:59 -05:00
avatar_template: "/images/avatar.png"}]});
2016-10-06 15:18:05 -04:00
});
server.get('/admin/groups.json', () => { //eslint-disable-line
return response([{id: 2, automatic: true, name: "moderators", user_count: 4, alias_level: 0,
visible: true, automatic_membership_email_domains: null, automatic_membership_retroactive: false,
primary_group: false, title: null, grant_trust_level: null, incoming_email: null,
notification_level: null, has_messages: true, is_member: true, mentionable: false,
flair_url: null, flair_bg_color: null, flair_color: null}]);
});
server.get('/badges.json', () => { //eslint-disable-line
return response({badge_types: [{id: 3, name: "Bronze", sort_order: 7}],
badge_groupings: [{id: 1, name: "Getting Started", description: null, position: 10, system: true}],
badges: [{id: 17, name: "Reader", description: "Read every reply in a topic with more than 100 replies",
grant_count: 0, allow_title: false, multiple_grant: false, icon: "fa-certificate", image: null,
listable: true, enabled: true, badge_grouping_id: 1, system: true,
long_description: "This badge is granted the first time you read a long topic with more than 100 replies. Reading a conversation closely helps you follow the discussion, understand different viewpoints, and leads to more interesting conversations. The more you read, the better the conversation gets. As we like to say, Reading is Fundamental! :slight_smile:\n",
slug: "reader", has_badge: false, badge_type_id: 3}]});
});
}
});
2015-07-15 11:16:49 -04:00
2017-06-14 13:57:58 -04:00
QUnit.test("perform various searches", assert => {
2016-08-09 12:16:29 -04:00
visit("/search");
andThen(() => {
2017-06-14 13:57:58 -04:00
assert.ok($('body.search-page').length, "has body class");
assert.ok(exists('.search-container'), "has container class");
2016-08-09 12:16:29 -04:00
assert.ok(find('input.search').length > 0);
2016-08-09 13:22:14 -04:00
assert.ok(find('.fps-topic').length === 0);
2016-08-09 12:16:29 -04:00
});
2016-10-06 15:18:05 -04:00
fillIn('.search input.full-page-search', 'none');
2016-08-09 12:16:29 -04:00
click('.search .btn-primary');
2017-08-14 18:07:49 -04:00
andThen(() => {
assert.ok(find('.fps-topic').length === 0, 'has no results');
assert.ok(find('.no-results-suggestion .google-search-form'));
});
2016-08-09 12:16:29 -04:00
2016-10-06 15:18:05 -04:00
fillIn('.search input.full-page-search', 'posts');
2016-08-09 12:16:29 -04:00
click('.search .btn-primary');
2016-08-09 13:22:14 -04:00
andThen(() => assert.ok(find('.fps-topic').length === 1, 'has one post'));
2016-08-09 12:16:29 -04:00
});
2016-10-06 15:18:05 -04:00
2017-06-14 13:57:58 -04:00
QUnit.test("open advanced search", assert => {
2016-10-06 15:18:05 -04:00
visit("/search");
andThen(() => assert.ok(exists('.search .search-advanced'), 'shows advanced search panel'));
fillIn('.search input.full-page-search', 'none');
2016-10-13 03:03:58 -04:00
click('.search-advanced-btn');
2016-10-06 15:18:05 -04:00
2016-10-13 03:03:58 -04:00
andThen(() => assert.ok(visible('.search-advanced .search-advanced-options'), '"search-advanced-options" is visible'));
2016-10-06 15:18:05 -04:00
});
2017-06-14 13:57:58 -04:00
QUnit.test("escape search term", (assert) => {
2016-12-12 15:22:26 -05:00
visit("/search");
fillIn('.search input.full-page-search', '@<script>prompt(1337)</script>gmail.com');
click('.search-advanced-btn');
andThen(() => {
assert.ok(exists('.search-advanced-options span:contains("<script>prompt(1337)</script>gmail.com")'), 'it escapes search term');
});
});
2017-06-14 13:57:58 -04:00
QUnit.test("update username through advanced search ui", assert => {
2016-10-06 15:18:05 -04:00
visit("/search");
fillIn('.search input.full-page-search', 'none');
2016-10-13 03:03:58 -04:00
click('.search-advanced-btn');
fillIn('.search-advanced-options .user-selector', 'admin');
click('.search-advanced-options .user-selector');
keyEvent('.search-advanced-options .user-selector', 'keydown', 8);
2016-10-06 15:18:05 -04:00
andThen(() => {
2017-06-14 13:57:58 -04:00
waitFor(assert, () => {
2016-10-13 03:03:58 -04:00
assert.ok(visible('.search-advanced-options .autocomplete'), '"autocomplete" popup is visible');
assert.ok(exists('.search-advanced-options .autocomplete ul li a span.username:contains("admin")'), '"autocomplete" popup has an entry for "admin"');
2016-10-06 15:18:05 -04:00
2016-10-13 03:03:58 -04:00
click('.search-advanced-options .autocomplete ul li a:first');
2016-10-06 15:18:05 -04:00
andThen(() => {
2016-10-13 03:03:58 -04:00
assert.ok(exists('.search-advanced-options span:contains("admin")'), 'has "admin" pre-populated');
2016-10-11 17:41:04 -04:00
assert.equal(find('.search input.full-page-search').val(), "none @admin", 'has updated search term to "none user:admin"');
2016-10-06 15:18:05 -04:00
});
});
});
});
2017-06-14 13:57:58 -04:00
QUnit.test("update category through advanced search ui", assert => {
2017-12-22 07:08:12 -05:00
const categoryChooser = selectKit('.search-advanced-options .category-chooser');
2016-10-06 15:18:05 -04:00
visit("/search");
2017-12-22 07:08:12 -05:00
2016-10-06 15:18:05 -04:00
fillIn('.search input.full-page-search', 'none');
2016-10-13 03:03:58 -04:00
click('.search-advanced-btn');
2017-12-22 07:08:12 -05:00
categoryChooser.expand().fillInFilter('faq').selectRowByValue(4);
2016-10-06 15:18:05 -04:00
andThen(() => {
2016-10-31 17:27:57 -04:00
assert.ok(exists('.search-advanced-options .badge-category:contains("faq")'), 'has "faq" populated');
2016-10-06 15:18:05 -04:00
assert.equal(find('.search input.full-page-search').val(), "none #faq", 'has updated search term to "none #faq"');
});
});
2016-10-11 17:50:16 -04:00
// test("update group through advanced search ui", assert => {
// visit("/search");
// fillIn('.search input.full-page-search', 'none');
2016-10-13 03:03:58 -04:00
// click('.search-advanced-btn');
// fillIn('.search-advanced-options .group-selector', 'moderators');
// click('.search-advanced-options .group-selector');
// keyEvent('.search-advanced-options .group-selector', 'keydown', 8);
2016-10-11 17:50:16 -04:00
//
// andThen(() => {
// waitFor(() => {
2016-10-13 03:03:58 -04:00
// assert.ok(visible('.search-advanced-options .autocomplete'), '"autocomplete" popup is visible');
// assert.ok(exists('.search-advanced-options .autocomplete ul li a:contains("moderators")'), '"autocomplete" popup has an entry for "moderators"');
2016-10-11 17:50:16 -04:00
//
2016-10-13 03:03:58 -04:00
// click('.search-advanced-options .autocomplete ul li a:first');
2016-10-11 17:50:16 -04:00
//
// andThen(() => {
2016-10-13 03:03:58 -04:00
// assert.ok(exists('.search-advanced-options span:contains("moderators")'), 'has "moderators" pre-populated');
2016-10-11 17:50:16 -04:00
// assert.equal(find('.search input.full-page-search').val(), "none group:moderators", 'has updated search term to "none group:moderators"');
// });
// });
// });
// });
// test("update badges through advanced search ui", assert => {
// visit("/search");
// fillIn('.search input.full-page-search', 'none');
2016-10-13 03:03:58 -04:00
// click('.search-advanced-btn');
// fillIn('.search-advanced-options .badge-names', 'Reader');
// click('.search-advanced-options .badge-names');
// keyEvent('.search-advanced-options .badge-names', 'keydown', 8);
2016-10-11 17:50:16 -04:00
//
// andThen(() => {
// waitFor(() => {
2016-10-13 03:03:58 -04:00
// assert.ok(visible('.search-advanced-options .autocomplete'), '"autocomplete" popup is visible');
// assert.ok(exists('.search-advanced-options .autocomplete ul li a:contains("Reader")'), '"autocomplete" popup has an entry for "Reader"');
2016-10-11 17:50:16 -04:00
//
2016-10-13 03:03:58 -04:00
// click('.search-advanced-options .autocomplete ul li a:first');
2016-10-11 17:50:16 -04:00
//
// andThen(() => {
2016-10-13 03:03:58 -04:00
// assert.ok(exists('.search-advanced-options span:contains("Reader")'), 'has "Reader" pre-populated');
2016-10-11 17:50:16 -04:00
// assert.equal(find('.search input.full-page-search').val(), "none badge:Reader", 'has updated search term to "none badge:Reader"');
// });
// });
// });
// });
2016-10-06 15:18:05 -04:00
// test("update tags through advanced search ui", assert => {
// visit("/search");
// fillIn('.search input.full-page-search', 'none');
2016-10-13 03:03:58 -04:00
// click('.search-advanced-btn');
2016-10-06 15:18:05 -04:00
//
2016-10-13 03:03:58 -04:00
// keyEvent('.search-advanced-options .tag-chooser input.select2-input', 'keydown', 110);
// fillIn('.search-advanced-options .tag-chooser input.select2-input', 'monkey');
// keyEvent('.search-advanced-options .tag-chooser input.select2-input', 'keyup', 110);
2016-10-06 15:18:05 -04:00
//
// andThen(() => {
// waitFor(() => {
// click('li.select2-result-selectable:first');
// andThen(() => {
2016-10-13 03:03:58 -04:00
// assert.ok(exists('.search-advanced-options .tag-chooser .tag-monkey'), 'has "monkey" pre-populated');
2016-10-06 15:18:05 -04:00
// assert.equal(find('.search input.full-page-search').val(), "none tags:monkey", 'has updated search term to "none tags:monkey"');
// });
// });
// });
// });
2017-06-14 13:57:58 -04:00
QUnit.test("update in:likes filter through advanced search ui", assert => {
2016-10-06 15:18:05 -04:00
visit("/search");
fillIn('.search input.full-page-search', 'none');
2016-10-13 03:03:58 -04:00
click('.search-advanced-btn');
2016-10-13 12:34:31 -04:00
click('.search-advanced-options .in-likes');
2016-10-06 15:18:05 -04:00
andThen(() => {
2016-10-13 12:34:31 -04:00
assert.ok(exists('.search-advanced-options .in-likes:checked'), 'has "I liked" populated');
2016-10-06 15:18:05 -04:00
assert.equal(find('.search input.full-page-search').val(), "none in:likes", 'has updated search term to "none in:likes"');
});
});
2017-06-14 13:57:58 -04:00
QUnit.test("update in:private filter through advanced search ui", assert => {
2016-10-13 12:34:31 -04:00
visit("/search");
fillIn('.search input.full-page-search', 'none');
click('.search-advanced-btn');
click('.search-advanced-options .in-private');
andThen(() => {
assert.ok(exists('.search-advanced-options .in-private:checked'), 'has "are in my messages" populated');
assert.equal(find('.search input.full-page-search').val(), "none in:private", 'has updated search term to "none in:private"');
});
});
2017-06-14 13:57:58 -04:00
QUnit.test("update in:seen filter through advanced search ui", assert => {
2016-10-13 12:34:31 -04:00
visit("/search");
fillIn('.search input.full-page-search', 'none');
click('.search-advanced-btn');
2017-03-08 21:45:43 -05:00
click('.search-advanced-options .in-seen');
2016-10-13 12:34:31 -04:00
andThen(() => {
2017-03-08 21:45:43 -05:00
assert.ok(exists('.search-advanced-options .in-seen:checked'), 'it should check the right checkbox');
assert.equal(find('.search input.full-page-search').val(), "none in:seen",
'it should update the search term'
);
2016-10-13 12:34:31 -04:00
});
});
2017-06-14 13:57:58 -04:00
QUnit.test("update in filter through advanced search ui", assert => {
2017-12-22 07:08:12 -05:00
const inSelector = selectKit('.search-advanced-options .select-kit#in');
2016-10-13 12:34:31 -04:00
visit("/search");
2017-12-22 07:08:12 -05:00
2016-10-13 12:34:31 -04:00
fillIn('.search input.full-page-search', 'none');
click('.search-advanced-btn');
2017-12-22 07:08:12 -05:00
inSelector.expand().selectRowByValue('bookmarks');
2016-10-13 12:34:31 -04:00
andThen(() => {
2017-12-22 07:08:12 -05:00
assert.ok(inSelector.rowByName("I bookmarked").exists(), 'has "I bookmarked" populated');
2016-10-13 12:34:31 -04:00
assert.equal(find('.search input.full-page-search').val(), "none in:bookmarks", 'has updated search term to "none in:bookmarks"');
});
});
2017-06-14 13:57:58 -04:00
QUnit.test("update status through advanced search ui", assert => {
2017-12-22 07:08:12 -05:00
const statusSelector = selectKit('.search-advanced-options .select-kit#status');
2016-10-06 15:18:05 -04:00
visit("/search");
2017-12-22 07:08:12 -05:00
2016-10-06 15:18:05 -04:00
fillIn('.search input.full-page-search', 'none');
2016-10-13 03:03:58 -04:00
click('.search-advanced-btn');
2017-12-22 07:08:12 -05:00
statusSelector.expand().selectRowByValue('closed');
2016-10-06 15:18:05 -04:00
andThen(() => {
2017-12-22 07:08:12 -05:00
assert.ok(statusSelector.rowByName("are closed").exists(), 'has "are closed" populated');
2016-10-06 15:18:05 -04:00
assert.equal(find('.search input.full-page-search').val(), "none status:closed", 'has updated search term to "none status:closed"');
});
});
2017-06-14 13:57:58 -04:00
QUnit.test("update post time through advanced search ui", assert => {
2017-12-22 07:08:12 -05:00
const postTimeSelector = selectKit('.search-advanced-options .select-kit#postTime');
2016-10-06 15:18:05 -04:00
visit("/search");
2017-12-22 07:08:12 -05:00
2016-10-06 15:18:05 -04:00
fillIn('.search input.full-page-search', 'none');
2016-10-13 03:03:58 -04:00
click('.search-advanced-btn');
2017-11-21 12:52:09 -05:00
fillIn('#search-post-date .date-picker', '2016-10-05');
2017-12-22 07:08:12 -05:00
postTimeSelector.expand().selectRowByValue('after');
2016-10-06 15:18:05 -04:00
andThen(() => {
2017-12-22 07:08:12 -05:00
assert.ok(postTimeSelector.rowByName("after").exists(), 'has "after" populated');
2016-10-13 12:34:31 -04:00
assert.equal(find('.search input.full-page-search').val(), "none after:2016-10-05", 'has updated search term to "none after:2016-10-05"');
2016-10-06 15:18:05 -04:00
});
});
2017-06-14 13:57:58 -04:00
QUnit.test("update min post count through advanced search ui", assert => {
2016-10-06 15:18:05 -04:00
visit("/search");
fillIn('.search input.full-page-search', 'none');
2016-10-13 03:03:58 -04:00
click('.search-advanced-btn');
2016-11-28 09:57:18 -05:00
fillIn('#search-min-post-count', '5');
2016-10-06 15:18:05 -04:00
andThen(() => {
2016-11-28 09:57:18 -05:00
assert.equal(find('.search-advanced-options #search-min-post-count').val(), "5", 'has "5" populated');
assert.equal(find('.search input.full-page-search').val(), "none min_post_count:5", 'has updated search term to "none min_post_count:5"');
2016-10-06 15:18:05 -04:00
});
});
2016-10-17 00:02:58 -04:00
2017-06-14 13:57:58 -04:00
QUnit.test("validate advanced search when initially empty", assert => {
2016-10-17 00:02:58 -04:00
visit("/search?expanded=true");
click('.search-advanced-options .in-likes');
andThen(() => {
assert.ok(exists('.search-advanced-options .in-likes:checked'), 'has "I liked" populated');
assert.equal(find('.search input.full-page-search').val(), "in:likes", 'has updated search term to "in:likes"');
});
});