<commit_before>// Copyright 2015 Endless Mobile, Inc.

const Lang = imports.lang;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Mainloop = imports.mainloop;

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

const ArticleObjectModel = imports.search.articleObjectModel;
const CssClassMatcher = imports.tests.CssClassMatcher;
const Minimal = imports.tests.minimal;
const StyleClasses = imports.app.styleClasses;

Gtk.init(null);

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

    beforeEach(function () {
        jasmine.addMatchers(CssClassMatcher.customMatchers);

        model = new ArticleObjectModel.ArticleObjectModel({
            title: 'record title &',
            thumbnail_uri: 'about:blank',
            authors: ['record author &'],
            article_number: 0,
            tags: ['foo', 'bar'],
        });
        card = new Minimal.MinimalCard({
            model: model,
        });
    });

    // FIXME: the following two tests relied to much on exact timings and were
    // fragile on machines under high load or with slower processors. We should
    // rewrite in a way that does not rely on callback timings.
    xit('adds the "invisible" and "fade-in" style classes while fading', function (done) {
        card.FADE_IN_TIME_MS = 20;
        Mainloop.timeout_add(10, () => {
            expect(card).toHaveCssClass(StyleClasses.INVISIBLE);
            expect(card).toHaveCssClass(StyleClasses.FADE_IN);
            return GLib.SOURCE_REMOVE;
        });
        Mainloop.timeout_add(25, () => {
            expect(card).not.toHaveCssClass(StyleClasses.INVISIBLE);
            expect(card).not.toHaveCssClass(StyleClasses.FADE_IN);
            done();
            return GLib.SOURCE_REMOVE;
        });
        card.fade_in();
        Utils.update_gui();
    });

    xit('is insensitive while fading', function (done) {
        card.FADE_IN_TIME_MS = 20;
        Mainloop.timeout_add(10, () => {
            expect(card.sensitive).toBeFalsy();
            return GLib.SOURCE_REMOVE;
        });
        Mainloop.timeout_add(25, () => {
            expect(card.sensitive).toBeTruthy();
            done();
            return GLib.SOURCE_REMOVE;
        });
        card.fade_in();
        Utils.update_gui();
    });

    it('sets a title label visible if model has a title', function () {
        let label = new Gtk.Label();
        card.set_title_label_from_model(label);
        expect(label.visible).toBeTruthy();
    });

    it('sets a context label visible if model has tags', function () {
        let label = new Gtk.Label();
        card.set_context_label_from_model(label);
        expect(label.visible).toBeTruthy();
        expect(label.label).toBe('FOO | BAR');
    });

    it('markup-escapes the title', function () {
        let label = new Gtk.Label();
        card.set_title_label_from_model(label);
        expect(label.label).toContain('&amp;');
    });

    it('sets a author label visible if model has authors', function () {
        let label = new Gtk.Label();
        card.set_author_label_from_model(label);
        expect(label.visible).toBeTruthy();
    });

    it('markup-escapes the authors', function () {
        let label = new Gtk.Label();
        card.set_author_label_from_model(label);
        expect(label.label).toContain('&amp;');
    });

    it('highlights substring in title', function () {
        card = new Minimal.MinimalCard({
            model: model,
            highlight_string: 'title',
        });
        let label = new Gtk.Label();
        card.set_title_label_from_model(label);
        expect(label.label.match(/<span .*bgcolor="#000000.*">title<\/span>/)).not.toBeNull();<commit_msg>Fix tests for testCard interface<commit_after>// Copyright 2015 Endless Mobile, Inc.

const Lang = imports.lang;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Mainloop = imports.mainloop;

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

const ArticleObjectModel = imports.search.articleObjectModel;
const CssClassMatcher = imports.tests.CssClassMatcher;
const Minimal = imports.tests.minimal;
const StyleClasses = imports.app.styleClasses;

Gtk.init(null);

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

    beforeEach(function () {
        jasmine.addMatchers(CssClassMatcher.customMatchers);

        model = new ArticleObjectModel.ArticleObjectModel({
            title: 'record title &',
            thumbnail_uri: 'about:blank',
            authors: ['record author &'],
            article_number: 0,
            tags: ['foo', 'bar'],
        });
        card = new Minimal.MinimalCard({
            model: model,
        });
    });

    // FIXME: the following two tests relied to much on exact timings and were
    // fragile on machines under high load or with slower processors. We should
    // rewrite in a way that does not rely on callback timings.
    xit('adds the "invisible" and "fade-in" style classes while fading', function (done) {
        card.FADE_IN_TIME_MS = 20;
        Mainloop.timeout_add(10, () => {
            expect(card).toHaveCssClass(StyleClasses.INVISIBLE);
            expect(card).toHaveCssClass(StyleClasses.FADE_IN);
            return GLib.SOURCE_REMOVE;
        });
        Mainloop.timeout_add(25, () => {
            expect(card).not.toHaveCssClass(StyleClasses.INVISIBLE);
            expect(card).not.toHaveCssClass(StyleClasses.FADE_IN);
            done();
            return GLib.SOURCE_REMOVE;
        });
        card.fade_in();
        Utils.update_gui();
    });

    xit('is insensitive while fading', function (done) {
        card.FADE_IN_TIME_MS = 20;
        Mainloop.timeout_add(10, () => {
            expect(card.sensitive).toBeFalsy();
            return GLib.SOURCE_REMOVE;
        });
        Mainloop.timeout_add(25, () => {
            expect(card.sensitive).toBeTruthy();
            done();
            return GLib.SOURCE_REMOVE;
        });
        card.fade_in();
        Utils.update_gui();
    });

    it('sets a title label visible if model has a title', function () {
        let label = new Gtk.Label();
        card.set_title_label_from_model(label);
        expect(label.visible).toBeTruthy();
    });

    it('sets a context label visible if model has tags', function () {
        let label = new Gtk.Label();
        card.set_context_label_from_model(label);
        expect(label.visible).toBeTruthy();
        expect(label.label).toBe('FOO | BAR');
    });

    it('markup-escapes the title', function () {
        let label = new Gtk.Label();
        card.set_title_label_from_model(label);
        expect(label.label).toContain('&amp;');
    });

    it('sets a author label visible if model has authors', function () {
        let label = new Gtk.Label();
        card.set_author_label_from_model(label);
        expect(label.visible).toBeTruthy();
    });

    it('markup-escapes the authors', function () {
        let label = new Gtk.Label();
        card.set_author_label_from_model(label);
        expect(label.label).toContain('&amp;');
    });

    it('highlights substring in title', function () {
        let css = '.highlighted{background-color:#ff0000;}';
        card = new Minimal.MinimalCard({
            model: model,
            highlight_string: 'title',
        });
        let label = new Gtk.Label();
        label.get_style_context().add_class('highlighted');
        let provider = new Gtk.CssProvider();
        provider.load_from_data(css);
        label.get_style_context().add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
        card.set_title_label_from_model(label);
        expect(label.label.match(/<span .*bgcolor="#ff0000.*">title<\/span>/)).not.toBeNull();
{'fraction_non_alphanumeric': 0.12785504657394411, 'fraction_numerical': 0.00612479265024882, 'mean_word_length': 2.5546485260770977, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '5546263', 'n_tokens_mistral': 2397, 'n_tokens_neox': 2286, 'n_words': 490}