sightglass-overlay.spec.js 2.98 KB
define(function(require) {
    'use strict';

    var $ = require('jquery');
    window.jQuery = $;
    var SightglassOverlay = require('sightglass-overlay');
    require('rivets-backbone-adapter-brainfood');
    var _ = require('underscore');
    var Backbone = require('backbone');
    var rivets = require('rivets');

    //rivets.config.rootInterface = ':';
    /* global console:false */

    describe('SightglassOverlay', function() {
        var rootScope, rootNode;
        beforeEach(function() {
            rootScope = new Backbone.Model({
                sub: new Backbone.Model({
                    subKey: 'sub-key',
                    list: new Backbone.Collection([
                        {key: 'A'},
                        {key: 'B'},
                        {key: 'C'},
                    ], {parse: true}),
                }),
                list: new Backbone.Collection([
                    {key: 'A'},
                    {key: 'B'},
                    {key: 'C'},
                ], {parse: true}),
                constant: 'this-is-a-constant',
            });
            rootNode = $($.parseHTML('<div>{:constant}<div rv-bfeach-item=":list">key:{:item:key} constant:{:constant}<ul><li rv-bfeach-subitem=":sub:list">sub-key:{:subitem:key} constant:{:constant}<input rv-value=":inputValue" /></li></ul></div></div>'));
        });
        it('returns defined', function() {
            expect(SightglassOverlay).toBeDefined();
        });
        describe('makeOverrideAdapters', function() {
            var newAdapters, roData, rivetsView;
            beforeEach(function() {
                roData = {};
                roData[':sub:list'] = new Backbone.Collection([
                    {key: 'sub1'},
                    {key: 'sub2'},
                    {key: 'sub3'},
                ], {parse: true});
                roData[':list'] = new Backbone.Collection([
                    {key: '1'},
                    {key: '2'},
                    {key: '3'},
                ], {parse: true});
                newAdapters = SightglassOverlay.makeOverrideAdapters(rivets.adapters, roData);
                rivetsView = rivets.bind(rootNode, rootScope, {adapters: newAdapters});
            });
            xit('test', function() {
                var subListHtml = '<ul><!-- rivets: bfeach-subitem --><li>sub-key:sub1 constant:this-is-a-constant<input rv-value=":inputValue"></li><li>sub-key:sub2 constant:this-is-a-constant<input rv-value=":inputValue"></li><li>sub-key:sub3 constant:this-is-a-constant<input rv-value=":inputValue"></li></ul>';
                expect(rootNode.html()).toEqual(
                    'this-is-a-constant' +
                    '<!-- rivets: bfeach-item -->' +
                    '<div>key:1 constant:this-is-a-constant' + subListHtml + '</div>' +
                    '<div>key:2 constant:this-is-a-constant' + subListHtml + '</div>' +
                    '<div>key:3 constant:this-is-a-constant' + subListHtml + '</div>'
                );
            });
        });
    });
});