<commit_before>const EvinceDocument = imports.gi.EvinceDocument;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const WebKit2 = imports.gi.WebKit2;

const Utils = imports.tests.utils;
Utils.register_gresource();

const ArticleObjectModel = imports.search.articleObjectModel;
const KnowledgeDocumentCard = imports.app.modules.knowledgeDocumentCard;
const CssClassMatcher = imports.tests.CssClassMatcher;
const InstanceOfMatcher = imports.tests.InstanceOfMatcher;
const Minimal = imports.tests.minimal;
const MockWidgets = imports.tests.mockWidgets;
const StyleClasses = imports.app.styleClasses;
const TableOfContents = imports.app.widgets.tableOfContents;
const TreeNode = imports.search.treeNode;
const WidgetDescendantMatcher = imports.tests.WidgetDescendantMatcher;

Gtk.init(null);
EvinceDocument.init();

const TEST_CONTENT_DIR = Utils.get_test_content_srcdir();

describe('Document Card', function () {
    let card, model;

    beforeEach(function () {
        jasmine.addMatchers(CssClassMatcher.customMatchers);
        jasmine.addMatchers(InstanceOfMatcher.customMatchers);
        jasmine.addMatchers(WidgetDescendantMatcher.customMatchers);
        Gio.DBus.session.signal_subscribe = () => {};

        model = new ArticleObjectModel.ArticleObjectModel({
            ekn_id: 'ekn:///foo/bar',
            title: '!!!',
        });
        card = new KnowledgeDocumentCard.KnowledgeDocumentCard({
            model: model,
            show_toc: true,
        });
    });

    it('can be constructed', function () {
        expect(card).toBeDefined();
    });

    it('instantiates a table of contents widget', function () {
        expect(card.toc).toBeA(TableOfContents.TableOfContents);
    });

    it('has labels that understand Pango markup', function () {
        expect(Gtk.test_find_label(card, '*!!!*').use_markup).toBeTruthy();
        // FIXME: the above line will find either title_label or top_title_label
        // but not both
    });

    describe('Style class of document card', function () {
        it('has article card class', function () {
            expect(card).toHaveCssClass(StyleClasses.CARD);
        });
        it('has a descendant with title class', function () {
            expect(card).toHaveDescendantWithCssClass(StyleClasses.CARD_TITLE);
        });
        it('has a descendant with toolbar frame class', function () {
            expect(card).toHaveDescendantWithCssClass(StyleClasses.DOCUMENT_CARD_TOOLBAR_FRAME);
        });<commit_msg>testKnowledgeDocumentCard: mock Gio.DBus.session<commit_after>const EvinceDocument = imports.gi.EvinceDocument;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const WebKit2 = imports.gi.WebKit2;

const Utils = imports.tests.utils;
Utils.register_gresource();

const ArticleObjectModel = imports.search.articleObjectModel;
const KnowledgeDocumentCard = imports.app.modules.knowledgeDocumentCard;
const CssClassMatcher = imports.tests.CssClassMatcher;
const InstanceOfMatcher = imports.tests.InstanceOfMatcher;
const Minimal = imports.tests.minimal;
const MockWidgets = imports.tests.mockWidgets;
const StyleClasses = imports.app.styleClasses;
const TableOfContents = imports.app.widgets.tableOfContents;
const TreeNode = imports.search.treeNode;
const WidgetDescendantMatcher = imports.tests.WidgetDescendantMatcher;

Gtk.init(null);
EvinceDocument.init();

const TEST_CONTENT_DIR = Utils.get_test_content_srcdir();

describe('Document Card', function () {
    let card, model, real_session_descriptor;

    beforeEach(function () {
        jasmine.addMatchers(CssClassMatcher.customMatchers);
        jasmine.addMatchers(InstanceOfMatcher.customMatchers);
        jasmine.addMatchers(WidgetDescendantMatcher.customMatchers);
        // Mock out the entire session bus or we will error in an environment
        // without a session bus. Because session is a property with only a
        // getter, it can't be mocked with regular spyOn methods yet. See bug
        // https://github.com/jasmine/jasmine/issues/943
        real_session_descriptor = Object.getOwnPropertyDescriptor(Gio.DBus, 'session');
        let mock_session = jasmine.createSpyObj('session', ['signal_subscribe']);
        Object.defineProperty(Gio.DBus, 'session', {
            value: mock_session,
            configurable: true,
        });

        model = new ArticleObjectModel.ArticleObjectModel({
            ekn_id: 'ekn:///foo/bar',
            title: '!!!',
        });
        card = new KnowledgeDocumentCard.KnowledgeDocumentCard({
            model: model,
            show_toc: true,
        });
    });

    afterEach(function () {
        Object.defineProperty(Gio.DBus, 'session', real_session_descriptor);
    });

    it('can be constructed', function () {
        expect(card).toBeDefined();
    });

    it('instantiates a table of contents widget', function () {
        expect(card.toc).toBeA(TableOfContents.TableOfContents);
    });

    it('has labels that understand Pango markup', function () {
        expect(Gtk.test_find_label(card, '*!!!*').use_markup).toBeTruthy();
        // FIXME: the above line will find either title_label or top_title_label
        // but not both
    });

    describe('Style class of document card', function () {
        it('has article card class', function () {
            expect(card).toHaveCssClass(StyleClasses.CARD);
        });
        it('has a descendant with title class', function () {
            expect(card).toHaveDescendantWithCssClass(StyleClasses.CARD_TITLE);
        });
        it('has a descendant with toolbar frame class', function () {
            expect(card).toHaveDescendantWithCssClass(StyleClasses.DOCUMENT_CARD_TOOLBAR_FRAME);
        });
{'fraction_non_alphanumeric': 0.1105659716138076, 'fraction_numerical': 0.0012265638689328894, 'mean_word_length': 3.4768627450980394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7653444', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1590, 'n_words': 335}