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:
parent
f75c9d5e32
commit
378f8d24f4
|
@ -33,33 +33,22 @@ Docs.reopenClass({
|
||||||
filters.push(`topic=${params.selectedTopic}`);
|
filters.push(`topic=${params.selectedTopic}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let promise = ajax(`/docs.json?${filters.join("&")}`);
|
return ajax(`/docs.json?${filters.join("&")}`).then((data) => {
|
||||||
|
|
||||||
promise = promise.then((data) => {
|
|
||||||
data.topics.topic_list.topics = data.topics.topic_list.topics.map(
|
data.topics.topic_list.topics = data.topics.topic_list.topics.map(
|
||||||
(topic) => {
|
(topic) => Topic.create(topic)
|
||||||
topic = Topic.create(topic);
|
|
||||||
return topic;
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
data.topic = Topic.create(data.topic);
|
data.topic = Topic.create(data.topic);
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
|
|
||||||
return promise;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
loadMore(loadMoreUrl) {
|
loadMore(loadMoreUrl) {
|
||||||
let promise = ajax(loadMoreUrl);
|
return ajax(loadMoreUrl).then((data) => {
|
||||||
|
|
||||||
promise = promise.then((data) => {
|
|
||||||
data.topics.topic_list.topics = data.topics.topic_list.topics.map(
|
data.topics.topic_list.topics = data.topics.topic_list.topics.map(
|
||||||
(topic) => Topic.create(topic)
|
(topic) => Topic.create(topic)
|
||||||
);
|
);
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
|
|
||||||
return promise;
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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}}
|
{{#unless category.active}}
|
||||||
{{d-icon "plus"}}
|
{{d-icon "plus"}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
|
@ -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}}
|
{{#unless tag.active}}
|
||||||
{{d-icon "plus"}}
|
{{d-icon "plus"}}
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
|
@ -30,8 +30,7 @@
|
||||||
{{#each categories as |category|}}
|
{{#each categories as |category|}}
|
||||||
{{docs-category
|
{{docs-category
|
||||||
category=category
|
category=category
|
||||||
selectCategory=(action "updateSelectedCategories"
|
selectCategory=(action "updateSelectedCategories" category)
|
||||||
tagName="")
|
|
||||||
}}
|
}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -43,7 +42,7 @@
|
||||||
{{#each tags as |tag|}}
|
{{#each tags as |tag|}}
|
||||||
{{docs-tag
|
{{docs-tag
|
||||||
tag=tag
|
tag=tag
|
||||||
selectTag=(action "updateSelectedTags")
|
selectTag=(action "updateSelectedTags" tag)
|
||||||
}}
|
}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { acceptance, queryAll } from "helpers/qunit-helpers";
|
import { acceptance, count, query } from "helpers/qunit-helpers";
|
||||||
import docsFixtures from "../fixtures/docs";
|
import docsFixtures from "../fixtures/docs";
|
||||||
|
|
||||||
acceptance("Docs", function (needs) {
|
acceptance("Docs", function (needs) {
|
||||||
|
@ -8,7 +8,25 @@ acceptance("Docs", function (needs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
needs.pretender((server, helper) => {
|
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) {
|
test("index page", async function (assert) {
|
||||||
|
@ -16,11 +34,19 @@ acceptance("Docs", function (needs) {
|
||||||
await click("#toggle-hamburger-menu");
|
await click("#toggle-hamburger-menu");
|
||||||
await click(".docs-link");
|
await click(".docs-link");
|
||||||
|
|
||||||
assert.equal(queryAll(".docs-category")[0].innerText.trim(), "bug 119");
|
assert.equal(query(".docs-category").innerText.trim(), "bug 119");
|
||||||
assert.equal(queryAll(".docs-tag")[0].innerText.trim(), "something 74");
|
assert.equal(query(".docs-tag").innerText.trim(), "something 74");
|
||||||
assert.equal(
|
assert.equal(
|
||||||
queryAll(".docs-topic-link")[0].innerText.trim(),
|
query(".docs-topic-link").innerText.trim(),
|
||||||
"Importing from Software X"
|
"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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue