import KnowledgeHierarchy from "@knowledge/components/hierarchy/hierarchy";
import { registry } from "@web/core/registry";
import { Component, xml } from "@odoo/owl";
import { standardWidgetProps } from "@web/views/widgets/standard_widget_props";
import { defineMailModels } from "@mail/../tests/mail_test_helpers";
import { after, before, expect, test } from "@odoo/hoot";
import { click, queryFirst } from "@odoo/hoot-dom";
import { animationFrame } from "@odoo/hoot-mock";
import {
defineModels,
fields,
MockServer,
models,
mountView,
onRpc,
} from "@web/../tests/web_test_helpers";
class Article extends models.Model {
name = fields.Char();
icon = fields.Char();
display_name = fields.Char();
parent_id = fields.Many2one({ relation: "article" });
root_article_id = fields.Many2one({ relation: "article" });
parent_path = fields.Char();
is_locked = fields.Boolean();
user_can_write = fields.Boolean();
user_has_access = fields.Boolean();
category = fields.Char();
_records = [
{
id: 1,
name: "Root Article",
icon: "🙂",
display_name: "🙂 Root Article",
parent_id: false,
root_article_id: 1,
parent_path: "1/",
is_locked: false,
user_can_write: true,
user_has_access: true,
category: "workspace",
},
{
id: 2,
name: "Article 2",
icon: "🙃",
display_name: "🙃 Article 2",
parent_id: 1,
root_article_id: 1,
parent_path: "1/2/",
is_locked: false,
user_can_write: true,
user_has_access: true,
category: "workspace",
},
{
id: 3,
name: "Article 3",
icon: false,
display_name: "Article 3",
parent_id: 2,
root_article_id: 1,
parent_path: "1/2/3/",
is_locked: false,
user_can_write: true,
user_has_access: true,
category: "workspace",
},
{
id: 4,
name: "Article 4",
icon: "😎",
display_name: "😎 Article 4",
parent_id: 3,
root_article_id: 1,
parent_path: "1/2/3/4/",
is_locked: false,
user_can_write: true,
user_has_access: true,
category: "workspace",
},
{
id: 5,
name: "Article 5",
icon: false,
display_name: "Article 5",
parent_id: false,
root_article_id: 5,
parent_path: "5/",
is_locked: false,
user_can_write: true,
user_has_access: true,
category: "workspace",
},
];
}
defineMailModels();
defineModels([Article]);
onRpc("get_sidebar_articles", function () {
return {
articles: this.env["article"]._filter(),
favorite_ids: [],
};
});
onRpc(
"get_article_hierarchy",
async function ({ args: [articleId], kwargs: { exclude_article_ids: excludeArticleIds } }) {
const Article = this.env["article"];
// returns ancestors of the current article (without the ones given in excludeArticleIds)
return Article.slice(0, Article.indexOf(Article.browse(articleId)[0]) - 1).filter(
(article) => !excludeArticleIds.includes(article.id)
);
}
);
onRpc("has_access", function () {
return true;
});
let openArticle;
before(() => {
// Create a component to test the breadcrumb and the hierarchy without the top bar component:
class KnowledgeNavigation extends Component {
static template = xml`