<commit_before>YUI.add('dialog-base-test', function (Y) {

var Assert = Y.Assert,
    suite;

suite = new Y.Test.Suite('dialog');

suite.add(new Y.Test.Case({
    name: 'Lifecycle',

    '`destroy()` should destroy the view': function () {
        var dialog = new Y.Libbit.Dialog();

        dialog.error('Test title', 'Test message body.', true);

        Assert.isFalse(dialog.get('destroyed'));
        Assert.isObject(Y.one('.libbit-dialog'));

        dialog.destroy();

        Assert.isTrue(dialog.get('destroyed'));
        Assert.isNull(Y.one('.libbit-dialog'));
    },

    '`destroy()` shouldn\'t throw an error when called before the dialog is shown': function () {
        var dialog = new Y.Libbit.Dialog();

        Assert.isFalse(dialog.get('destroyed'));

        dialog.destroy();

        Assert.isTrue(dialog.get('destroyed'));
    }
}));

suite.add(new Y.Test.Case({
    name: 'Basic',

    '`confirm()` should render the confirmation dialog correctly': function () {
        var dialog = new Y.Libbit.Dialog();

        var title      = 'Test Title';
        var message    = 'Test message body.';
        var confirmVal = 'Confirm!';

        dialog.confirm(title, message, undefined, false, confirmVal);

        var titleNode   = Y.one('.libbit-dialog').one('.yui3-widget-hd');
        var messageNode = Y.one('.libbit-dialog').one('.yui3-widget-bd').one('p');
        var primaryNode = Y.one('.libbit-dialog').one('.yui3-widget-ft').one('.btn-primary');

        Assert.areEqual(titleNode.get('text'), title);
        Assert.areEqual(messageNode.get('text'), message);
        Assert.areEqual(primaryNode.get('text'), confirmVal);

        dialog.destroy();
    },

    '`error()` should render the error dialog correctly': function () {
        var dialog = new Y.Libbit.Dialog();

        var title      = 'Test Title';
        var message    = 'Test message body.';

        dialog.error(title, message, false);

        var titleNode   = Y.one('.libbit-dialog').one('.yui3-widget-hd');
        var messageNode = Y.one('.libbit-dialog').one('.yui3-widget-bd').one('p');

        Assert.areEqual(titleNode.get('text'), title);
        Assert.areEqual(messageNode.get('text'), message);

        dialog.destroy();
    }
}));

suite.add(new Y.Test.Case({
    name: 'Callbacks',

    '`confirm()` should close on cancel': function () {
        var dialog = new Y.Libbit.Dialog();

        var title   = 'Test Title';
        var message = 'Test message body.';

        dialog.confirm(title, message);

        Y.one('.yui3-widget-buttons').one('.btn').simulate('click');

        Assert.isNull(Y.one('.libbit-dialog'));
    },

    '`confirm()` should execute confirm callback method': function () {
        var dialog = new Y.Libbit.Dialog(),
            mock   = Y.Mock;

        var title   = 'Test Title';
        var message = 'Test message body.';

        Y.Mock.expect(mock, { method: "callback", args: [] });

        dialog.confirm(title, message, mock.callback);

        Y.one('.yui3-widget-buttons').one('.btn-primary').simulate('click');

        Y.Mock.verify(mock);
        Assert.isNull(Y.one('.libbit-dialog'));
    }
}));

suite.add(new Y.Test.Case({
    name: 'Element focus',

    'Default button should be focussed': function () {
        var dialog;

        dialog = Y.Libbit.Dialog.error('Test Title', 'Test message body.');
        Y.Assert.areSame(Y.one('.yui3-widget-buttons').one('.btn').getDOMNode(), document.activeElement);
        dialog.destroy();

        dialog = Y.Libbit.Dialog.confirm('Test Title', 'Test message body.');
        Y.Assert.areSame(Y.one('.yui3-widget-buttons').one('.btn-primary').getDOMNode(), document.activeElement);
        dialog.destroy();
    }
}));

suite.add(new Y.Test.Case({
    name: 'Keyboard events',

    '`escape` key should close the dialog': function () {
        var dialog;

        dialog = Y.Libbit.Dialog.error('Test Title', 'Test message body.');

        // Y.one('.yui3-panel-content').simulate('keydown', {keyCode: 27});
        // Assert.isNull(Y.one('.libbit-dialog'));
    }
}));

Y.Test.Runner.add(suite);

}, '@VERSION@', {
    requires: ['libbit-dialog', 'test']
});<commit_msg>Test fix<commit_after>YUI.add('dialog-base-test', function (Y) {

var Assert = Y.Assert,
    suite;

suite = new Y.Test.Suite('Dialog');

suite.add(new Y.Test.Case({
    name: 'Lifecycle',

    '`destroy()` should destroy the view': function () {
        var dialog = new Y.Libbit.Dialog();

        dialog.error('Test title', 'Test message body.', true);

        Assert.isFalse(dialog.get('destroyed'));
        Assert.isObject(Y.one('.libbit-dialog'));

        dialog.destroy();

        Assert.isTrue(dialog.get('destroyed'));
        Assert.isNull(Y.one('.libbit-dialog'));
    },

    '`destroy()` shouldn\'t throw an error when called before the dialog is shown': function () {
        var dialog = new Y.Libbit.Dialog();

        Assert.isFalse(dialog.get('destroyed'));

        dialog.destroy();

        Assert.isTrue(dialog.get('destroyed'));
    }
}));

suite.add(new Y.Test.Case({
    name: 'Basic',

    '`confirm()` should render the confirmation dialog correctly': function () {
        var dialog = new Y.Libbit.Dialog();

        var title      = 'Test Title';
        var message    = 'Test message body.';
        var confirmVal = 'Confirm!';

        dialog.confirm(title, message, undefined, false, confirmVal);

        var titleNode   = Y.one('.libbit-dialog').one('.yui3-widget-hd');
        var messageNode = Y.one('.libbit-dialog').one('.yui3-widget-bd').one('p');
        var primaryNode = Y.one('.libbit-dialog').one('.yui3-widget-ft').one('.btn-primary');

        Assert.areEqual(titleNode.get('text'), title);
        Assert.areEqual(messageNode.get('text'), message);
        Assert.areEqual(primaryNode.get('text'), confirmVal);

        dialog.destroy();
    },

    '`error()` should render the error dialog correctly': function () {
        var dialog = new Y.Libbit.Dialog();

        var title      = 'Test Title';
        var message    = 'Test message body.';

        dialog.error(title, message, false);

        var titleNode   = Y.one('.libbit-dialog').one('.yui3-widget-hd');
        var messageNode = Y.one('.libbit-dialog').one('.yui3-widget-bd').one('p');

        Assert.areEqual(titleNode.get('text'), title);
        Assert.areEqual(messageNode.get('text'), message);

        dialog.destroy();
    }
}));

suite.add(new Y.Test.Case({
    name: 'Callbacks',

    '`confirm()` should close on cancel': function () {
        var dialog = new Y.Libbit.Dialog();

        var title   = 'Test Title';
        var message = 'Test message body.';

        dialog.confirm(title, message);

        Y.one('.yui3-widget-buttons').one('.btn').simulate('click');

        Assert.isNull(Y.one('.libbit-dialog'));
    },

    '`confirm()` should execute confirm callback method': function () {
        var dialog = new Y.Libbit.Dialog(),
            mock   = Y.Mock;

        var title   = 'Test Title';
        var message = 'Test message body.';

        Y.Mock.expect(mock, { method: "callback", args: [] });

        dialog.confirm(title, message, mock.callback);

        Y.one('.yui3-widget-buttons').one('.btn-primary').simulate('click');

        Y.Mock.verify(mock);
        Assert.isNull(Y.one('.libbit-dialog'));
    }
}));

suite.add(new Y.Test.Case({
    name: 'Element focus',

    'Default button should be focussed': function () {
        var dialog;

        dialog = Y.Libbit.Dialog.error('Test Title', 'Test message body.');
        Y.Assert.areSame(Y.one('.yui3-widget-buttons').one('.btn').getDOMNode(), document.activeElement);
        dialog.destroy();

        dialog = Y.Libbit.Dialog.confirm('Test Title', 'Test message body.');
        Y.Assert.areSame(Y.one('.yui3-widget-buttons').one('.btn-primary').getDOMNode(), document.activeElement);
        dialog.destroy();
    }
}));

suite.add(new Y.Test.Case({
    name: 'Keyboard events',

    '`escape` key should close the dialog': function () {
        var dialog;

        dialog = Y.Libbit.Dialog.error('Test Title', 'Test message body.');

        Y.one('.yui3-panel-content').simulate('keydown', {keyCode: 27});
        Assert.isNull(Y.one('.libbit-dialog'));
    }
}));

Y.Test.Runner.add(suite);

}, '@VERSION@', {
    requires: ['libbit-dialog', 'test']
});
{'fraction_non_alphanumeric': 0.1822089552238806, 'fraction_numerical': 0.002865671641791045, 'mean_word_length': 2.6512641673931996, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3746316', 'n_tokens_mistral': 2594, 'n_tokens_neox': 2505, 'n_words': 517}