FEATURE: Register docs link under sidebar topics section. (#95)
This commit is contained in:
parent
0276cca4ab
commit
2b6a1f468d
|
@ -4,10 +4,6 @@ import I18n from "I18n";
|
||||||
function initialize(api, container) {
|
function initialize(api, container) {
|
||||||
const siteSettings = container.lookup("site-settings:main");
|
const siteSettings = container.lookup("site-settings:main");
|
||||||
|
|
||||||
if (!siteSettings.docs_enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
api.decorateWidget("hamburger-menu:generalLinks", () => {
|
api.decorateWidget("hamburger-menu:generalLinks", () => {
|
||||||
return {
|
return {
|
||||||
route: "docs",
|
route: "docs",
|
||||||
|
@ -31,13 +27,14 @@ export default {
|
||||||
name: "setup-docs",
|
name: "setup-docs",
|
||||||
|
|
||||||
initialize(container) {
|
initialize(container) {
|
||||||
|
const siteSettings = container.lookup("site-settings:main");
|
||||||
|
|
||||||
|
if (!siteSettings.docs_enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
withPluginApi("0.8", (api) => initialize(api, container));
|
withPluginApi("0.8", (api) => initialize(api, container));
|
||||||
withPluginApi("0.12.6", (api) => {
|
withPluginApi("0.12.6", (api) => {
|
||||||
const siteSettings = container.lookup("site-settings:main");
|
|
||||||
if (!siteSettings.docs_enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
api.addSearchSuggestion("in:docs");
|
api.addSearchSuggestion("in:docs");
|
||||||
|
|
||||||
const tip = {
|
const tip = {
|
||||||
|
@ -48,5 +45,18 @@ export default {
|
||||||
};
|
};
|
||||||
api.addQuickSearchRandomTip(tip);
|
api.addQuickSearchRandomTip(tip);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
withPluginApi("1.2.0", (api) => {
|
||||||
|
const currentUser = container.lookup("current-user:main");
|
||||||
|
|
||||||
|
if (currentUser?.experimental_sidebar_enabled) {
|
||||||
|
api.addTopicsSectionLink({
|
||||||
|
name: "docs",
|
||||||
|
route: "docs.index",
|
||||||
|
title: I18n.t("sidebar.docs_link_title"),
|
||||||
|
text: I18n.t("sidebar.docs_link_text"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,3 +29,6 @@ en:
|
||||||
navigate_to_topic: "View the discussion on this topic"
|
navigate_to_topic: "View the discussion on this topic"
|
||||||
filter_button: "Filters"
|
filter_button: "Filters"
|
||||||
filter_solved: "Topic Solved?"
|
filter_solved: "Topic Solved?"
|
||||||
|
sidebar:
|
||||||
|
docs_link_title: "Explore documentation topics"
|
||||||
|
docs_link_text: "Docs"
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
import I18n from "I18n";
|
||||||
|
|
||||||
|
import { click, currentURL, visit } from "@ember/test-helpers";
|
||||||
|
|
||||||
|
import {
|
||||||
|
acceptance,
|
||||||
|
conditionalTest,
|
||||||
|
exists,
|
||||||
|
query,
|
||||||
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import { isLegacyEmber } from "discourse-common/config/environment";
|
||||||
|
import docsFixtures from "../fixtures/docs";
|
||||||
|
import { cloneJSON } from "discourse-common/lib/object";
|
||||||
|
|
||||||
|
acceptance("Docs - Sidebar with docs disabled", function (needs) {
|
||||||
|
needs.user({ experimental_sidebar_enabled: true });
|
||||||
|
|
||||||
|
needs.settings({
|
||||||
|
docs_enabled: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
conditionalTest(
|
||||||
|
"docs sidebar link is hidden",
|
||||||
|
!isLegacyEmber(),
|
||||||
|
async function (assert) {
|
||||||
|
await visit("/");
|
||||||
|
|
||||||
|
assert.ok(
|
||||||
|
!exists(".sidebar-section-link-docs"),
|
||||||
|
"it does not display the docs link in sidebar"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
acceptance("Docs - Sidebar with docs enabled", function (needs) {
|
||||||
|
needs.user({ experimental_sidebar_enabled: true });
|
||||||
|
needs.settings({
|
||||||
|
docs_enabled: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
needs.pretender((server, helper) => {
|
||||||
|
server.get("/docs.json", () => helper.response(cloneJSON(docsFixtures)));
|
||||||
|
});
|
||||||
|
|
||||||
|
conditionalTest(
|
||||||
|
"clicking on docs link",
|
||||||
|
!isLegacyEmber(),
|
||||||
|
async function (assert) {
|
||||||
|
await visit("/");
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
query(".sidebar-section-link-docs").textContent.trim(),
|
||||||
|
I18n.t("sidebar.docs_link_text"),
|
||||||
|
"displays the right text for the link"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
query(".sidebar-section-link-docs").title,
|
||||||
|
I18n.t("sidebar.docs_link_title"),
|
||||||
|
"displays the right title for the link"
|
||||||
|
);
|
||||||
|
|
||||||
|
await click(".sidebar-section-link-docs");
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
currentURL(),
|
||||||
|
"/docs",
|
||||||
|
"it navigates to the right page"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
Loading…
Reference in New Issue