describe("modal-pattern", function() {
    var pattern;

    requireDependencies(["patterns/modal"], function(cls) {
        pattern = cls;
    });

    // Reset the lab before each test
    beforeEach(function() {
        $("#lab *").remove();
    });

    describe("init", function() {
        it("Modal with single element", function() {
            $("#lab").html([
                '<div class="pat-modal" id="modal">',
                '  <p>Modal content</p>',
                '</div>'
                ].join('\n'));
            var $modal = $("#modal");
            pattern.init($modal);
            expect($modal.find(".header").length).toBeTruthy();
            expect($modal.find(".header").text()).toBe("Close");
            expect($modal.find(".header .close-panel").length).toBeTruthy();
            expect($modal.find(".panel-content").length).toBeTruthy();
            expect($modal.find(".panel-content").text()).toBe("Modal content");
        });

        it("Modal with header ", function() {
            $("#lab").html([
                '<div class="pat-modal" id="modal">',
                '  <h3>Modal header</h3>',
                '  <p>Modal content</p>',
                '</div>'
                ].join('\n'));
            var $modal = $("#modal");
            pattern.init($modal);
            expect($modal.find(".header").text()).toBe("Modal headerClose");
            expect($modal.find(".header .close-panel").length).toBeTruthy();
            expect($modal.find(".panel-content").text()).toBe("Modal content");
        });

        it("Modal with multiple content items ", function() {
            $("#lab").html([
                '<div class="pat-modal" id="modal">',
                '  <h3>Modal header</h3>',
                '  <p>Modal content</p>',
                '  <h4>Subheader</h4>',
                '  <p>More content</p>',
                '</div>'
                ].join('\n'));
            var $modal = $("#modal");
            pattern.init($modal);
            expect($modal.find(".header").text()).toBe("Modal headerClose");
            expect($modal.find(".header .close-panel").length).toBeTruthy();
            expect($modal.find(".panel-content p").length).toBe(2);
            expect($modal.find(".panel-content h4").length).toBe(1);
        });

    });
});

// jshint indent: 4, browser: true, jquery: true, quotmark: double
// vim: sw=4 expandtab

@@ -1,16 +1,84 @@
+/*global $, beforeEach, describe, expect, it, requireDependencies*/%0A
 describe(%22modal-
@@ -91,29 +91,49 @@
 n%22, function
+ 
 () %7B%0A
+    %22use strict%22;%0A%0A
     var patt
@@ -190,16 +190,17 @@
 function
+ 
 (cls) %7B%0A
@@ -284,32 +284,33 @@
 oreEach(function
+ 
 () %7B%0A        $(%22
@@ -358,32 +358,33 @@
 %22init%22, function
+ 
 () %7B%0A        it(
@@ -412,32 +412,33 @@
 ement%22, function
+ 
 () %7B%0A           
@@ -580,36 +580,32 @@
 v%3E'%0A            
-    
 %5D.join('%5Cn'));%0A 
@@ -1078,32 +1078,33 @@
 ader %22, function
+ 
 () %7B%0A           
@@ -1289,36 +1289,32 @@
 v%3E'%0A            
-    
 %5D.join('%5Cn'));%0A 
@@ -1688,16 +1688,17 @@
 function
+ 
 () %7B%0A   
@@ -1972,36 +1972,32 @@
 v%3E'%0A            
-    
 %5D.join('%5Cn'));%0A 
@@ -2367,24 +2367,1466 @@
        %7D);%0A%0A
+        it(%22Modal with a form that has the pat-modal CSS class%22, function () %7B%0A%0A            var $modal,       // main modal container%0A                $modalLink;   // link that triggers the modal%0A%0A            $(%22#lab%22).html(%5B%0A                '%3Ca id=%22modalLink%22 class=%22pat-modal%22',%0A                '   href=%22../demo/bug_modal/modal-sources.html%22%3EOpen a modal',%0A                '   containing a form with pat-modal CSS class.%3C/a%3E'%0A            %5D.join('/n'));%0A%0A            $modalLink = $(%22#modalLink%22);%0A            pattern.init($modalLink);%0A%0A            // najprej #modalLink ne obstaja%0A            $modal = $(%22div#pat-modal%22);%0A            expect($modal.length).toBe(0);%0A%0A            $modalLink.click();    // trigger panel loading%0A%0A            // TODO: we need to insert a delay here so that the asynchronous%0A            // AJAX injection of the potentially problematic HTML finishes ...%0A            // and only AFTER THAT we test that everything is still OK%0A            // (read: that the modal still exists in DOM)%0A            // NOTE: If AJAX request in inject.execute() is performed in a%0A            // synchronous way, a delay is not need and this test detects a%0A            // bug in modal._init_inject1()%0A%0A            // div#pat-modal should still exist even after the click has%0A            // loaded and injected problematic HTML%0A            $modal = $(%22div#pat-modal%22);%0A            expect($modal.length).toBeGreaterThan(0);%0A        %7D);%0A
     %7D);%0A%7D);%0A

Add provisional test for #111 fix