From cea2a9fe53def516183747f8513e714af1f86a99 Mon Sep 17 00:00:00 2001 From: Kyle Zhao Date: Tue, 8 Aug 2017 04:08:07 -0400 Subject: [PATCH] UX: exclude irrelevant search filters for anonymous users On the advanced search page, filters like "I've read", "I'm watch -ing", etc, are irrelevant to anonymous users and should be hidden --- .../components/search-advanced-options.js.es6 | 7 ++- .../components/search-advanced-options.hbs | 12 +++-- .../acceptance/search-full-test.js.es6 | 1 + .../javascripts/acceptance/search-test.js.es6 | 52 ++++++++++++++++++- 4 files changed, 64 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/discourse/components/search-advanced-options.js.es6 b/app/assets/javascripts/discourse/components/search-advanced-options.js.es6 index 109182042c4..f29c6f95a39 100644 --- a/app/assets/javascripts/discourse/components/search-advanced-options.js.es6 +++ b/app/assets/javascripts/discourse/components/search-advanced-options.js.es6 @@ -30,12 +30,14 @@ const IN_OPTIONS_MAPPING = {'images': 'with'}; export default Em.Component.extend({ classNames: ['search-advanced-options'], - inOptions: [ + inOptionsForUsers: [ {name: I18n.t('search.advanced.filters.unseen'), value: "unseen"}, {name: I18n.t('search.advanced.filters.posted'), value: "posted"}, {name: I18n.t('search.advanced.filters.watching'), value: "watching"}, {name: I18n.t('search.advanced.filters.tracking'), value: "tracking"}, {name: I18n.t('search.advanced.filters.bookmarks'), value: "bookmarks"}, + ], + inOptionsForAll: [ {name: I18n.t('search.advanced.filters.first'), value: "first"}, {name: I18n.t('search.advanced.filters.pinned'), value: "pinned"}, {name: I18n.t('search.advanced.filters.unpinned'), value: "unpinned"}, @@ -91,7 +93,8 @@ export default Em.Component.extend({ when: 'before', days: '' } - } + }, + inOptions: this.currentUser ? this.inOptionsForUsers.concat(this.inOptionsForAll) : this.inOptionsForAll }); }, diff --git a/app/assets/javascripts/discourse/templates/components/search-advanced-options.hbs b/app/assets/javascripts/discourse/templates/components/search-advanced-options.hbs index e3ac643ec64..c1c1914b64a 100644 --- a/app/assets/javascripts/discourse/templates/components/search-advanced-options.hbs +++ b/app/assets/javascripts/discourse/templates/components/search-advanced-options.hbs @@ -53,11 +53,13 @@
-
- - - -
+ {{#if currentUser}} +
+ + + +
+ {{/if}} {{combo-box id="in" valueAttribute="value" content=inOptions value=searchedTerms.in none="user.locale.any"}}
diff --git a/test/javascripts/acceptance/search-full-test.js.es6 b/test/javascripts/acceptance/search-full-test.js.es6 index b978f8879d5..782d234adc5 100644 --- a/test/javascripts/acceptance/search-full-test.js.es6 +++ b/test/javascripts/acceptance/search-full-test.js.es6 @@ -1,6 +1,7 @@ import { acceptance, waitFor } from "helpers/qunit-helpers"; acceptance("Search - Full Page", { settings: {tagging_enabled: true}, + loggedIn: true, beforeEach() { const response = (object) => { return [ diff --git a/test/javascripts/acceptance/search-test.js.es6 b/test/javascripts/acceptance/search-test.js.es6 index c3d6f11e81b..4322ba1291a 100644 --- a/test/javascripts/acceptance/search-test.js.es6 +++ b/test/javascripts/acceptance/search-test.js.es6 @@ -1,4 +1,4 @@ -import { acceptance } from "helpers/qunit-helpers"; +import { acceptance, logIn } from "helpers/qunit-helpers"; acceptance("Search"); QUnit.test("search", (assert) => { @@ -73,3 +73,53 @@ QUnit.test("Search with context", assert => { assert.ok(!$('.search-context input[type=checkbox]').is(":checked")); }); }); + +QUnit.test("in:likes, in:private, and in:seen filters are hidden to anonymous users", assert => { + visit("/search?expanded=true"); + + andThen(() => { + assert.notOk(exists('.search-advanced-options .in-likes')); + assert.notOk(exists('.search-advanced-options .in-private')); + assert.notOk(exists('.search-advanced-options .in-seen')); + }); +}); + +QUnit.test("in:likes, in:private, and in:seen filters are available to logged in users", assert => { + logIn(); + Discourse.reset(); + visit("/search?expanded=true"); + + andThen(() => { + assert.ok(exists('.search-advanced-options .in-likes')); + assert.ok(exists('.search-advanced-options .in-private')); + assert.ok(exists('.search-advanced-options .in-seen')); + }); +}); + +QUnit.test(`"I've not read", "I posted in", "I'm watching", "I'm tracking", + "I've bookmarked" filters are hidden to anonymous users from the dropdown`, assert => { + visit("/search?expanded=true"); + + andThen(() => { + assert.notOk(exists('select#in option[value=unseen]')); + assert.notOk(exists('select#in option[value=posted]')); + assert.notOk(exists('select#in option[value=watching]')); + assert.notOk(exists('select#in option[value=tracking]')); + assert.notOk(exists('select#in option[value=bookmarks]')); + }); +}); + +QUnit.test(`"I've not read", "I posted in", "I'm watching", "I'm tracking", + "I've bookmarked" filters are available to logged in users in the dropdown`, assert => { + logIn(); + Discourse.reset(); + visit("/search?expanded=true"); + + andThen(() => { + assert.ok(exists('select#in option[value=unseen]')); + assert.ok(exists('select#in option[value=posted]')); + assert.ok(exists('select#in option[value=watching]')); + assert.ok(exists('select#in option[value=tracking]')); + assert.ok(exists('select#in option[value=bookmarks]')); + }); +});