generated from discourse/discourse-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94e2986
commit f464c35
Showing
7 changed files
with
188 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
test/javascripts/acceptance/global-filter-preference-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { click, currentURL, visit } from "@ember/test-helpers"; | ||
import { acceptance } from "discourse/tests/helpers/qunit-helpers"; | ||
import { test } from "qunit"; | ||
|
||
acceptance("Discourse Global Filter - Filter Preference", function (needs) { | ||
needs.user({ custom_fields: { global_filter_preference: "support" } }); | ||
needs.settings({ | ||
discourse_global_filter_enabled: true, | ||
global_filters: "support|feature", | ||
}); | ||
|
||
needs.pretender((server, helper) => { | ||
server.get("/tag/support/notifications", () => | ||
helper.response({ | ||
tag_notification: { id: "support", notification_level: 2 }, | ||
}) | ||
); | ||
|
||
server.get("/tag/support/l/latest.json", () => { | ||
return helper.response({ | ||
users: [], | ||
primary_groups: [], | ||
topic_list: { | ||
can_create_topic: true, | ||
draft: null, | ||
draft_key: "new_topic", | ||
draft_sequence: 1, | ||
per_page: 30, | ||
tags: [], | ||
topics: [], | ||
}, | ||
}); | ||
}); | ||
|
||
server.get("/tag/support/l/top.json", () => { | ||
return helper.response({ | ||
users: [], | ||
primary_groups: [], | ||
topic_list: { | ||
can_create_topic: true, | ||
draft: null, | ||
draft_key: "new_topic", | ||
draft_sequence: 1, | ||
per_page: 30, | ||
tags: [], | ||
topics: [], | ||
}, | ||
}); | ||
}); | ||
|
||
server.put("/global_filter/filter_tags/support/assign.json", () => { | ||
return helper.response({ success: true }); | ||
}); | ||
}); | ||
|
||
test("redirects to tag when selected", async function (assert) { | ||
await visit("/"); | ||
await click(".global-filter-container .global-filter-item button"); | ||
|
||
assert.equal(currentURL(), "/tag/support", "it redirects to the right tag"); | ||
}); | ||
|
||
test("maintains tag filter when redirecting to a filtered topic view", async function (assert) { | ||
await visit("/"); | ||
await click("#navigation-bar .nav-item_top a"); | ||
|
||
assert.equal( | ||
currentURL(), | ||
"/tag/support/l/top", | ||
"it redirects to the user's global_filter_preference" | ||
); | ||
}); | ||
|
||
test("maintains tag filter when redirecting to root URL", async function (assert) { | ||
await visit("/"); | ||
|
||
assert.equal( | ||
currentURL(), | ||
"/tag/support/l/latest", | ||
"it redirects to the user's global_filter_preference" | ||
); | ||
}); | ||
|
||
test("maintains params when redirecting", async function (assert) { | ||
await visit("/latest?f=tracked"); | ||
|
||
assert.equal( | ||
currentURL(), | ||
"/tag/support/l/latest?f=tracked", | ||
"it redirects to the user's global_filter_preference" | ||
); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
test/javascripts/components/global-filter-container-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { visit } from "@ember/test-helpers"; | ||
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers"; | ||
import { test } from "qunit"; | ||
|
||
acceptance("Discourse Global Filter - Filter Container", function (needs) { | ||
needs.settings({ | ||
discourse_global_filter_enabled: true, | ||
global_filters: "support|feature", | ||
}); | ||
|
||
test("is present when a tag is included in global_filters", async function (assert) { | ||
await visit("/"); | ||
assert.ok(exists(".global-filter-container"), "container is present"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { click, visit } from "@ember/test-helpers"; | ||
import { | ||
acceptance, | ||
exists, | ||
queryAll, | ||
} from "discourse/tests/helpers/qunit-helpers"; | ||
import { test } from "qunit"; | ||
|
||
acceptance("Discourse Global Filter - Filter Item", function (needs) { | ||
needs.user(); | ||
needs.settings({ | ||
discourse_global_filter_enabled: true, | ||
global_filters: "support|feature", | ||
}); | ||
|
||
needs.pretender((server, helper) => { | ||
server.get("/tag/support/notifications", () => | ||
helper.response({ | ||
tag_notification: { id: "support", notification_level: 2 }, | ||
}) | ||
); | ||
|
||
server.get("/tag/support/l/latest.json", () => { | ||
return helper.response({ | ||
users: [], | ||
primary_groups: [], | ||
topic_list: { | ||
can_create_topic: true, | ||
draft: null, | ||
draft_key: "new_topic", | ||
draft_sequence: 1, | ||
per_page: 30, | ||
tags: [], | ||
topics: [], | ||
}, | ||
}); | ||
}); | ||
|
||
server.put("/global_filter/filter_tags/support/assign.json", () => { | ||
return helper.response({ success: true }); | ||
}); | ||
}); | ||
|
||
test("is present when included in global_filters", async function (assert) { | ||
await visit("/"); | ||
let tags = []; | ||
queryAll(".global-filter-container .global-filter-item").each((_, el) => | ||
tags.push(el.innerText.trim()) | ||
); | ||
assert.deepEqual(tags, this.siteSettings.global_filters.split("|")); | ||
}); | ||
|
||
test("adds active class to filter when selected", async function (assert) { | ||
await visit("/"); | ||
await click(".global-filter-container .global-filter-item button"); | ||
|
||
assert.ok( | ||
exists(".global-filter-container .global-filter-item button.active"), | ||
"button is active" | ||
); | ||
}); | ||
}); |