jsinput_spec.js 1.8 KB
Newer Older
1
xdescribe("A jsinput has:", function () {
2 3 4 5 6 7 8 9 10 11 12 13 14 15

    beforeEach(function () {
        $('#fixture').remove();
        $.ajax({
            async: false,
            url: 'mainfixture.html',
            success: function(data) {
                $('body').append($(data));
            }
        });
    });



16
    describe("The jsinput constructor", function(){
17

18
        var iframe1 = $(document).find('iframe')[0];
19 20

        var testJsElem = jsinputConstructor({
21 22
            id: 1,
            elem: iframe1,
23 24 25 26 27 28 29 30
            passive: false
        });

        it("Returns an object", function(){
            expect(typeof(testJsElem)).toEqual('object');
        });

        it("Adds the object to the jsinput array", function() {
31
            expect(jsinput.exists(1)).toBe(true);
32 33 34 35 36 37 38 39
        });

        describe("The returned object", function() {

            it("Has a public 'update' method", function(){
                expect(testJsElem.update).toBeDefined();  
            });

40 41 42 43 44 45 46
            it("Returns an 'update' that is idempotent", function(){
                var orig = testJsElem.update();
                for (var i = 0; i++; i < 5) {
                    expect(testJsElem.update()).toEqual(orig);
                }
            });

47
            it("Changes the parent's inputfield", function() {
48
                testJsElem.update();
49
              
50 51 52 53
            });
        });
    });

54

55 56 57 58 59 60
    describe("The walkDOM functions", function() {

        walkDOM();

        it("Creates (at least) one object per iframe", function() {
            jsinput.arr.length >= 2; 
61 62
        });

63 64 65 66 67 68
        it("Does not create multiple objects with the same id", function() {
            while (jsinput.arr.length > 0) {
                var elem = jsinput.arr.pop();
                expect(jsinput.exists(elem.id)).toBe(false);
            }
        });
69
    });
70
})