<commit_before>/* jshint globalstrict: true */
/* global require */

"use strict";

var testing = require('grunt-dom-test');

testing.a("modal")
    .withFile("src/picoModal.js")
    .withUtility("node_modules/chai/chai.js")

    .setup(function ($) {
        $.assert = $.window.chai.assert;
        $.picoModal = $.window.picoModal;
    })

    .should("Be created when 'show' is called").in(function (done, $) {
        $.picoModal(
            "<div>Curse your sudden but inevitable betrayal!</div>"
        ).show();
        $.assert.equal(
            $.query(".pico-content div").one().text(),
            "Curse your sudden but inevitable betrayal!");
        done();
    })

    .should("Be creatable with existing DOM content").using(
        "<div id='myContent'>Curse your sudden but inevitable betrayal!</div>"
    ).in(function (done, $) {

        $.picoModal( $.query("#myContent").one().elem ).show();

        $.assert.equal(
            $.query(".pico-content #myContent").one().text(),
            "Curse your sudden but inevitable betrayal!" );

        $.query("#myContent").one();

        done();
    })

    .should("Be re-usable via .show and .close").in(function (done, $) {
        var modal = $.picoModal("Curse your sudden but inevitable betrayal!");
        $.assert.isFalse( modal.isVisible() );

        modal.show();
        $.assert.isTrue( modal.isVisible() );

        modal.close();
        $.assert.isFalse( modal.isVisible() );

        modal.show();
        $.assert.isTrue( modal.isVisible() );

        done();
    })

    .should("Allow functions as options").in(function (done, $) {
        var modal = $.picoModal({
            content: "Curse your sudden but inevitable betrayal!",
            width: function (def) {
                $.assert.equal(def, 'auto');
                return 200;
            }
        }).show();

        $.assert.equal('200px', modal.modalElem().style.width);

        done();
    })

    .should("Be destroyable").in(function (done, $) {
        var modal = $.picoModal("Curse your sudden but inevitable betrayal!");
        $.assert.equal($.query(".pico-content").count, 0);

        modal.show();
        $.assert.equal($.query(".pico-content").count, 1);

        modal.close();
        $.assert.equal($.query(".pico-content").count, 1);

        modal.destroy();
        $.assert.equal($.query(".pico-content").count, 0);

        done();
    })

    .should("Allow its DOM to be prebuilt").in(function (done, $) {
        var modal = $.picoModal("Curse your sudden but inevitable betrayal!");
        $.assert.isFalse( modal.isVisible() );
        $.assert.equal($.query(".pico-content").count, 0);

        modal.buildDom();
        $.assert.isFalse( modal.isVisible() );
        $.assert.equal($.query(".pico-content").count, 1);

        done();
    })

    .should("Stay on screen when really tall").in(function (done, $) {
        var modal = $.picoModal(
            "<div style='height: 20000px;'>" +
                "Curse your sudden but inevitable betrayal!" +
            "</div>"
        ).show();

        var rect = modal.modalElem().getBoundingClientRect();
        $.assert.isAbove(rect.top, -1);
        $.assert.isBelow(rect.bottom, $.window.innerHeight + 1);

        done();
    })


    .and("Modal styling")

    .should("Allow a specific width to be set").in(function (done, $) {
        $.picoModal({
            content: "Curse your sudden but inevitable betrayal!",
            width: 50
        }).show();

        $.assert.equal( '50px', $.query(".pico-content").one().styles().width );

        done();
    })

    .should("Allow custom classes to be added").in(function (done, $) {
        var modal = $.picoModal({
            content: "Curse your sudden but inevitable betrayal!",
            modalClass: "my-modal",
            overlayClass: "my-overlay",<commit_msg>Fix width definining test in IE<commit_after>/* jshint globalstrict: true */
/* global require */

"use strict";

var testing = require('grunt-dom-test');

testing.a("modal")
    .withFile("src/picoModal.js")
    .withUtility("node_modules/chai/chai.js")

    .setup(function ($) {
        $.assert = $.window.chai.assert;
        $.picoModal = $.window.picoModal;
    })

    .should("Be created when 'show' is called").in(function (done, $) {
        $.picoModal(
            "<div>Curse your sudden but inevitable betrayal!</div>"
        ).show();
        $.assert.equal(
            $.query(".pico-content div").one().text(),
            "Curse your sudden but inevitable betrayal!");
        done();
    })

    .should("Be creatable with existing DOM content").using(
        "<div id='myContent'>Curse your sudden but inevitable betrayal!</div>"
    ).in(function (done, $) {

        $.picoModal( $.query("#myContent").one().elem ).show();

        $.assert.equal(
            $.query(".pico-content #myContent").one().text(),
            "Curse your sudden but inevitable betrayal!" );

        $.query("#myContent").one();

        done();
    })

    .should("Be re-usable via .show and .close").in(function (done, $) {
        var modal = $.picoModal("Curse your sudden but inevitable betrayal!");
        $.assert.isFalse( modal.isVisible() );

        modal.show();
        $.assert.isTrue( modal.isVisible() );

        modal.close();
        $.assert.isFalse( modal.isVisible() );

        modal.show();
        $.assert.isTrue( modal.isVisible() );

        done();
    })

    .should("Allow functions as options").in(function (done, $) {
        var modal = $.picoModal({
            content: "Curse your sudden but inevitable betrayal!",
            width: function (def) {
                $.assert.equal(def, 'auto');
                return 200;
            }
        }).show();

        $.assert.equal('200px', modal.modalElem().style.width);

        done();
    })

    .should("Be destroyable").in(function (done, $) {
        var modal = $.picoModal("Curse your sudden but inevitable betrayal!");
        $.assert.equal($.query(".pico-content").count, 0);

        modal.show();
        $.assert.equal($.query(".pico-content").count, 1);

        modal.close();
        $.assert.equal($.query(".pico-content").count, 1);

        modal.destroy();
        $.assert.equal($.query(".pico-content").count, 0);

        done();
    })

    .should("Allow its DOM to be prebuilt").in(function (done, $) {
        var modal = $.picoModal("Curse your sudden but inevitable betrayal!");
        $.assert.isFalse( modal.isVisible() );
        $.assert.equal($.query(".pico-content").count, 0);

        modal.buildDom();
        $.assert.isFalse( modal.isVisible() );
        $.assert.equal($.query(".pico-content").count, 1);

        done();
    })

    .should("Stay on screen when really tall").in(function (done, $) {
        var modal = $.picoModal(
            "<div style='height: 20000px;'>" +
                "Curse your sudden but inevitable betrayal!" +
            "</div>"
        ).show();

        var rect = modal.modalElem().getBoundingClientRect();
        $.assert.isAbove(rect.top, -1);
        $.assert.isBelow(rect.bottom, $.window.innerHeight + 1);

        done();
    })


    .and("Modal styling")

    .should("Allow a specific width to be set").in(function (done, $) {
        var modal = $.picoModal({
            content: "Curse your sudden but inevitable betrayal!",
            width: 150
        }).show();

        var width =
            modal.modalElem().getBoundingClientRect().width ||
            modal.modalElem().style.width.replace(/[^0-9]/g, "");

        $.assert.equal( width, 150 );

        done();
    })

    .should("Allow custom classes to be added").in(function (done, $) {
        var modal = $.picoModal({
            content: "Curse your sudden but inevitable betrayal!",
            modalClass: "my-modal",
            overlayClass: "my-overlay",
{'fraction_non_alphanumeric': 0.17868893950898507, 'fraction_numerical': 0.006327512022272842, 'mean_word_length': 2.1274238227146816, 'pattern_counts': {'":': 0, '<': 15, '<?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': '2924725', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2243, 'n_words': 510}