FIX: Correctly trigger actions (#45)

Fixes a regression introduced in #32. Reported in https://meta.discourse.org/t/meta-discourse-org-docs-sidebar-filter-doesnt-work/188350/2

Included:
* DEV: Use `query` helper
* DEV: Simplify the Docs model
* DEV: Add a test
* FIX: Correctly trigger actions
* DEV: Use `count` instead of `queryAll`
This commit is contained in:
Jarek Radosz 2021-04-29 16:36:14 +02:00 committed by GitHub
parent f75c9d5e32
commit 378f8d24f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 24 deletions

View File

@ -33,33 +33,22 @@ Docs.reopenClass({
filters.push(`topic=${params.selectedTopic}`);
}
let promise = ajax(`/docs.json?${filters.join("&")}`);
promise = promise.then((data) => {
return ajax(`/docs.json?${filters.join("&")}`).then((data) => {
data.topics.topic_list.topics = data.topics.topic_list.topics.map(
(topic) => {
topic = Topic.create(topic);
return topic;
}
(topic) => Topic.create(topic)
);
data.topic = Topic.create(data.topic);
return data;
});
return promise;
},
loadMore(loadMoreUrl) {
let promise = ajax(loadMoreUrl);
promise = promise.then((data) => {
return ajax(loadMoreUrl).then((data) => {
data.topics.topic_list.topics = data.topics.topic_list.topics.map(
(topic) => Topic.create(topic)
);
return data;
});
return promise;
},
});

View File

@ -1,4 +1,4 @@
<a href {{action "selectCategory"}} class="docs-item docs-category {{if category.active "selected"}}">
<a href {{action this.selectCategory}} class="docs-item docs-category {{if category.active "selected"}}">
{{#unless category.active}}
{{d-icon "plus"}}
{{/unless}}

View File

@ -1,4 +1,4 @@
<a href {{action "selectTag"}} class="docs-item docs-tag {{if tag.active "selected"}} {{if subtag "subtag"}}">
<a href {{action this.selectTag}} class="docs-item docs-tag {{if tag.active "selected"}} {{if subtag "subtag"}}">
{{#unless tag.active}}
{{d-icon "plus"}}
{{/unless}}

View File

@ -30,8 +30,7 @@
{{#each categories as |category|}}
{{docs-category
category=category
selectCategory=(action "updateSelectedCategories"
tagName="")
selectCategory=(action "updateSelectedCategories" category)
}}
{{/each}}
</div>
@ -43,7 +42,7 @@
{{#each tags as |tag|}}
{{docs-tag
tag=tag
selectTag=(action "updateSelectedTags")
selectTag=(action "updateSelectedTags" tag)
}}
{{/each}}
</div>

View File

@ -1,4 +1,4 @@
import { acceptance, queryAll } from "helpers/qunit-helpers";
import { acceptance, count, query } from "helpers/qunit-helpers";
import docsFixtures from "../fixtures/docs";
acceptance("Docs", function (needs) {
@ -8,7 +8,25 @@ acceptance("Docs", function (needs) {
});
needs.pretender((server, helper) => {
server.get("/docs.json", () => helper.response(docsFixtures));
server.get("/docs.json", (request) => {
if (request.queryParams.category === "1") {
const fixture = JSON.parse(JSON.stringify(docsFixtures));
return helper.response(
Object.assign(fixture, {
categories: [
{
id: 1,
count: 119,
active: true,
},
],
})
);
} else {
return helper.response(docsFixtures);
}
});
});
test("index page", async function (assert) {
@ -16,11 +34,19 @@ acceptance("Docs", function (needs) {
await click("#toggle-hamburger-menu");
await click(".docs-link");
assert.equal(queryAll(".docs-category")[0].innerText.trim(), "bug 119");
assert.equal(queryAll(".docs-tag")[0].innerText.trim(), "something 74");
assert.equal(query(".docs-category").innerText.trim(), "bug 119");
assert.equal(query(".docs-tag").innerText.trim(), "something 74");
assert.equal(
queryAll(".docs-topic-link")[0].innerText.trim(),
query(".docs-topic-link").innerText.trim(),
"Importing from Software X"
);
});
test("selecting a category", async function (assert) {
await visit("/docs");
assert.equal(count(".docs-category.selected"), 0);
await click(".docs-item.docs-category");
assert.equal(count(".docs-category.selected"), 1);
});
});