Nickolay - Test.Run-0.06

Documentation | Source
Class('Test.Run.Harness.Browser.UI.Viewport', {
    
    isa : Ext.Viewport,
    
    have : {
        title           : null,
        
        harness         : null,
        
        urls            : null
    },
    
    before : {
        
        initComponent : function () {
            this.urls = {}
            
            Ext.apply(this, {
                
                slots : true,
                
                id : 'outer',
                
                layout : 'border',
                items : [
                    {
                        region : 'north',
                        slot : 'title',
                        
                        cls : 'x-test-title',
                        
                        html : '<a href="http://code.google.com/p/joose-js/"><div class="joose-logo"></div></a><h1>' + this.title + '</h1> ',
                        
                        height : 75
                    },
                    {
                        region : 'center',
                        
                        id : 'inner',
                        
                        layout : 'border',
                        
                        items : [
                            {
                                region : 'west',
                                xtype : 'testgrid',
                                slot : 'tests',
                                
                                split : true,
                                
                                harness : this.harness
                            },
                            {
                                region : 'center',
                                xtype : 'tabpanel',
                                slot : 'tabs',
                                
                                enableTabScroll : true
                            }
                        ]
                    }
                ]
            })
        }
        //eof initComponent
    },
    
    
    after : {
        initComponent : function () {
            var slots = this.slots
            
            var paused = false
            
            slots.tests.on('rowselect', function (grid, record) {
                if (!paused) {
                    paused = true
                    slots.tabs.activate(this.urls[record.get('name')].assertionGrid)
                    paused = false
                }
            }, this)
            
            slots.tabs.on('tabchange', function (tabs, panel) {
                if (!paused) {
                    paused = true
                    
                    var url = panel.url
                    
                    slots.tests.getSelectionModel().selectRecords([ this.getTestRecordByURL(url) ])
                    
                    paused = false
                }
            }, this)
        }
    },
    
    
    methods : {
        
        getTestRecordByURL : function (url) {
            var testStore   = this.slots.tests.store
            
            return testStore.getAt(testStore.find('name', url))
        },
        
        
        addUrlRecord : function (url) {
            var slots       = this.slots
            var testStore   = slots.tests.store
            var recType     = testStore.recordType
            
            var record = this.getTestRecordByURL(url)
            
            if (!record) { 
                record = new recType({ name : url })
                
                testStore.add([ record ])
            }
            
            var urlData     = this.urls[url]
            if (!urlData) urlData = this.urls[url] = {}
            
            var assertionGrid = urlData.assertionGrid
            
            if (!assertionGrid) {
                urlData.assertionGrid = assertionGrid = new Test.Run.Harness.Browser.UI.AssertionGrid({
                    title   : record.get('name'),
                    url     : url
                })
            
                slots.tabs.add(assertionGrid)
                
                if (slots.tabs.items.getCount() == 1) slots.tabs.activate(0)
            }
        },
        
        
        testStart : function (test) {
            var slots = this.slots
            var testStore = slots.tests.store
            
            this.urls[test.url].testRecord = testStore.getAt(testStore.find('name', test.url))
        },
        
        
        testUpdate : function (test, result) {
            var urlData     = this.urls[test.url]
            var testRecord  = urlData.testRecord
            
            testRecord.set('passCount', test.passCount)
            testRecord.set('failCount', test.failCount)
            testRecord.commit()
            
            var assertStore = urlData.assertionGrid.store
            var assertRecType = assertStore.recordType
            
            assertStore.add([
                new assertRecType({
                    indx        : test.assertCount,
                    ok          : result.pass ? 'ok' : 'not ok',
                    description : result.description,
                    type        : result.meta.name
                })
            ])
        },
        
        
        testEnd : function (test) {
            var urlData     = this.urls[test.url]
            var testRecord  = urlData.testRecord
            
            testRecord.set('time', (test.execEnd - test.startDate) + 'ms')
            testRecord.commit()
        },
        
        
        removeTest : function (test) {
            var urlData     = this.urls[test.url]
            var testRecord  = urlData.testRecord
            
            testRecord.set('passCount', 0)
            testRecord.set('failCount', 0)
            testRecord.set('time', '')
            testRecord.commit()
            
            var assertionGrid = urlData.assertionGrid
            assertionGrid.store.removeAll()
        }        
        
        
    }
    
})
//eof Test.Run.Harness.Browser.UI.Viewport