Class('Test.Run.Harness.Browser.UI.Viewport', {
isa : Ext.Viewport,
have : {
title : null,
harness : null,
dataForURL : null
},
before : {
initComponent : function () {
this.dataForURL = {}
Ext.apply(this, {
slots : true,
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',
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 me = this
var slots = this.slots
var paused = false
slots.tests.on('rowselect', function (grid, record) {
if (!paused) {
paused = true
slots.tabs.activate(me.dataForURL[ record.get('url') ].assertionGrid)
paused = false
}
})
slots.tabs.on('tabchange', function (tabs, panel) {
if (!paused && panel) {
paused = true
var url = panel.url
slots.tests.getSelectionModel().selectRecords([ me.getTestRecordByURL(url) ])
paused = false
}
})
}
},
methods : {
declareTests : function (descriptors) {
var slots = this.slots
var testStore = slots.tests.store
var recType = testStore.recordType
testStore.removeAll()
slots.tabs.removeAll()
Joose.A.each(descriptors, function (desc, index) {
var url = desc.url
var record = new recType({
url : url,
index : index,
isStarting : true
})
testStore.add([ record ])
var urlData = this.dataForURL[ url ] = {}
urlData.testRecord = record
var assertionGrid = urlData.assertionGrid = new Test.Run.Harness.Browser.UI.AssertionGrid({
title : url,
url : url
})
slots.tabs.add(assertionGrid)
if (index == 0) slots.tabs.activate(0)
}, this)
},
getTestRecordByURL : function (url) {
var testStore = this.slots.tests.store
return testStore.getAt(testStore.find('url', url))
},
onTestStart : function (test) {
var urlData = this.dataForURL[ test.url ]
var testRecord = urlData.testRecord
testRecord.set('passCount', 0)
testRecord.set('failCount', 0)
testRecord.set('time', '')
testRecord.set('isStarting', false)
testRecord.commit()
var assertionGrid = urlData.assertionGrid
assertionGrid.store.removeAll()
},
onTestUpdate : function (test, result) {
var urlData = this.dataForURL[ test.url ]
var testRecord = urlData.testRecord
testRecord.set('passCount', test.getPassCount())
testRecord.set('failCount', test.getFailCount())
testRecord.commit()
var assertStore = urlData.assertionGrid.store
var assertRecType = assertStore.recordType
assertStore.add([
new assertRecType({
index : result.index,
ok : result.passed ? 'ok' : 'not ok',
isTodo : result.isTodo,
description : result.description,
type : result.meta.name
})
])
},
onTestEnd : function (test) {
var urlData = this.dataForURL[ test.url ]
var testRecord = urlData.testRecord
testRecord.set('time', test.getTimeLength() + 'ms')
testRecord.commit()
var assertStore = urlData.assertionGrid.store
var assertRecType = assertStore.recordType
assertStore.add([
new assertRecType({
index : -1,
ok : 'ok',
description : test.getSummaryMessage('<br>'),
type : 'Test.Run.Result.Diagnostic'
})
])
}
}
})
//eof Test.Run.Harness.Browser.UI.Viewport