<commit_before>const Endless = imports.gi.Endless;
const EosKnowledge = imports.gi.EosKnowledge;
const EosKnowledgeSearch = imports.EosKnowledgeSearch;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;

// Load and register the GResource which has content for this app
let resource = Gio.Resource.load('tests/test-content/test-content.gresource');
resource._register();
let resource_path = Gio.File.new_for_uri('resource:///com/endlessm/thrones');

// Mock out the engine so that we aren't looking for an eos-thrones database
let mock_engine = new EosKnowledgeSearch.Engine();
mock_engine.get_object_by_id = function () {};
mock_engine.get_objects_by_query = function (query, callback) {
    const OBJECTS = [
        {
            title: 'Article One',
            authors: ['Plward11'],
            published: 'September 30, 2014',
            ekn_id: 'about:blank',
        },
        {
            title: 'Article Two',
            authors: ['Ffarfan'],
            ekn_id: 'about:blank',
        },
        {
            title: 'Article Three',
            published: 'September 30, 2014',
            ekn_id: 'about:blank',
        },
        {
            title: 'Article Four (Cheese)',
            published: 'February 13, 2015',
            synopsis: 'Cheese is really expensive in Canada...',
            authors: ['Ptomato'],
            ekn_id: 'about:blank',
        }
    ];
    callback(undefined, OBJECTS.slice(0, query.limit).map((props) => {
        let authors = props.authors;
        delete props.authors;
        let model = new EosKnowledgeSearch.ArticleObjectModel(props);
        if (authors)
            model.set_authors(authors);
        return model;
    }));
};
mock_engine.get_xapian_uri = function () {};

const TestApplication = new Lang.Class({
    Name: 'TestApplication',
    Extends: Endless.Application,

    _init: function (props) {
        this.parent(props);
    },

    vfunc_startup: function () {
        this.parent();

        let [success, app_json, len, etag] = resource_path.get_child('app.json')
            .load_contents(null);

        let presenter = new EosKnowledge.Reader.Presenter(JSON.parse(app_json), {
            engine: mock_engine,
            application: this,
        });
    },
});

let app = new TestApplication({
    application_id: 'com.endlessm.knowledge.readerPresenterSmokeTest',
    flags: Gio.ApplicationFlags.FLAGS_NONE,
});
app.run(ARGV);<commit_msg>Fix Reader presenter smoke test<commit_after>const Endless = imports.gi.Endless;
const EosKnowledge = imports.gi.EosKnowledge;
const EosKnowledgeSearch = imports.EosKnowledgeSearch;
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;

// Load and register the GResource which has content for this app
let resource = Gio.Resource.load('tests/test-content/test-content.gresource');
resource._register();
let resource_path = Gio.File.new_for_uri('resource:///com/endlessm/thrones');

// Mock out the engine so that we aren't looking for an eos-thrones database
let mock_engine = new EosKnowledgeSearch.Engine();
mock_engine.get_object_by_id = function () {};
mock_engine.get_objects_by_query = function (query, callback) {
    const OBJECTS = [
        {
            title: 'Article One',
            authors: ['Plward11'],
            published: 'September 30, 2014',
            ekn_id: 'about:blank',
        },
        {
            title: 'Article Two',
            authors: ['Ffarfan'],
            ekn_id: 'about:blank',
        },
        {
            title: 'Article Three',
            published: 'September 30, 2014',
            ekn_id: 'about:blank',
        },
        {
            title: 'Article Four (Cheese)',
            published: 'February 13, 2015',
            synopsis: 'Cheese is really expensive in Canada...',
            authors: ['Ptomato'],
            ekn_id: 'about:blank',
        }
    ];
    callback(undefined, OBJECTS.slice(0, query.limit).map((props) => {
        let authors = props.authors;
        delete props.authors;
        let model = new EosKnowledgeSearch.ArticleObjectModel(props);
        if (authors)
            model.set_authors(authors);
        return model;
    }));
};
mock_engine.get_xapian_uri = function () {};

const TestApplication = new Lang.Class({
    Name: 'TestApplication',
    Extends: Endless.Application,

    _init: function (props) {
        this.parent(props);
    },

    vfunc_startup: function () {
        this.parent();

        let [success, app_json, len, etag] = resource_path.get_child('app.json')
            .load_contents(null);

        let presenter = new EosKnowledge.Reader.Presenter(JSON.parse(app_json), {
            engine: mock_engine,
            application: this,
        });
        presenter.desktop_launch(0);
    },
});

let app = new TestApplication({
    application_id: 'com.endlessm.knowledge.readerPresenterSmokeTest',
    flags: Gio.ApplicationFlags.FLAGS_NONE,
});
app.run(ARGV);
{'fraction_non_alphanumeric': 0.12286689419795221, 'fraction_numerical': 0.008632804657699257, 'mean_word_length': 2.515878616796048, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '1780674', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1468, 'n_words': 334}