Merge pull request #5032 from xrav3nz/ux-hide-options-in-adv-search

UX: exclude irrelevant search filters for anonymous users
This commit is contained in:
Guo Xiang Tan 2017-08-09 18:21:44 +09:00 committed by GitHub
commit 705f75dd8c
4 changed files with 60 additions and 8 deletions

View File

@ -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
});
},

View File

@ -53,11 +53,13 @@
<div class="control-group pull-left">
<label class="control-label" for="search-in-options">{{i18n "search.advanced.filters.label"}}</label>
<div class="controls">
{{#if currentUser}}
<section class='field'>
<label>{{input type="checkbox" class="in-likes" checked=searchedTerms.special.in.likes}} {{i18n "search.advanced.filters.likes"}}</label>
<label>{{input type="checkbox" class="in-private" checked=searchedTerms.special.in.private}} {{i18n "search.advanced.filters.private"}}</label>
<label>{{input type="checkbox" class="in-seen" checked=searchedTerms.special.in.seen}} {{i18n "search.advanced.filters.seen"}}</label>
</section>
{{/if}}
{{combo-box id="in" valueAttribute="value" content=inOptions value=searchedTerms.in none="user.locale.any"}}
</div>
</div>

View File

@ -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 [

View File

@ -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,49 @@ QUnit.test("Search with context", assert => {
assert.ok(!$('.search-context input[type=checkbox]').is(":checked"));
});
});
QUnit.test("Right filters are shown to anonymous users", assert => {
visit("/search?expanded=true");
andThen(() => {
assert.ok(exists('select#in option[value=first]'));
assert.ok(exists('select#in option[value=pinned]'));
assert.ok(exists('select#in option[value=unpinned]'));
assert.ok(exists('select#in option[value=wiki]'));
assert.ok(exists('select#in option[value=images]'));
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]'));
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("Right filters are shown to logged-in users", assert => {
logIn();
Discourse.reset();
visit("/search?expanded=true");
andThen(() => {
assert.ok(exists('select#in option[value=first]'));
assert.ok(exists('select#in option[value=pinned]'));
assert.ok(exists('select#in option[value=unpinned]'));
assert.ok(exists('select#in option[value=wiki]'));
assert.ok(exists('select#in option[value=images]'));
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]'));
assert.ok(exists('.search-advanced-options .in-likes'));
assert.ok(exists('.search-advanced-options .in-private'));
assert.ok(exists('.search-advanced-options .in-seen'));
});
});