Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactored ui classes and their tests so that now they can be tested …

…wo the use of sandboxed-module.
  • Loading branch information...
commit fa112b96abd3aa78ab383d15f02cf659469ebeb8 1 parent bb968d3
@airportyh authored
View
6 lib/dev_mode_app.js
@@ -156,10 +156,12 @@ App.prototype = {
this.emit('exit')
this.cleanUpLaunchers(function(){
self.runExitHook(function(){
- self.view.cleanup(function(){
+ if (self.view) self.view.cleanup(die)
+ else die()
+ function die(){
if (err) console.error(err.stack)
process.exit(code)
- })
+ }
})
})
}
View
23 lib/ui/appview.js
@@ -13,7 +13,7 @@ var constants = require('./constants')
var RunnerTab = tabs.RunnerTab
var RunnerTabs = tabs.RunnerTabs
var getTermSize = require('../gettermsize')
-var screen = require('./screen')
+var Screen = require('./screen')
var pad = require('../strutils').pad
var log = require('winston')
var ErrorMessagesPanel = require('./error_messages_panel')
@@ -31,9 +31,18 @@ var AppView = module.exports = View.extend({
var app = attrs.app
this.name = 'Testem'
this.app = app
+ if (!this.get('screen')){
+ this.set('screen', Screen())
+ }
+
this.initCharm()
+
+ var screen = this.get('screen')
- var runnerTabs = this.runnerTabs = new RunnerTabs([], {appview: this})
+ var runnerTabs = this.runnerTabs = new RunnerTabs([], {
+ appview: this
+ , screen: screen
+ })
this.set({
runnerTabs: runnerTabs
})
@@ -45,6 +54,7 @@ var AppView = module.exports = View.extend({
runner: runner
, index: idx
, appview: self
+ , screen: screen
})
runnerTabs.push(tab)
})
@@ -68,6 +78,7 @@ var AppView = module.exports = View.extend({
this.errorMessagesPanel = new ErrorMessagesPanel({
appview: this
, text: ''
+ , screen: screen
})
this.errorMessagesPanel.on('change:text', function(m, text){
self.set('isPopupVisible', !!text)
@@ -75,7 +86,7 @@ var AppView = module.exports = View.extend({
this.startMonitorTermSize()
}
, initCharm: function(){
-
+ var screen = this.get('screen')
screen.reset()
screen.erase('screen')
screen.cursor(false)
@@ -88,9 +99,11 @@ var AppView = module.exports = View.extend({
}
, startMonitorTermSize: function(){
var self = this
+ var screen = self.get('screen')
;(function checkTermSize(){
getTermSize(function(cols, lines){
+
if (cols !== self.get('cols') || lines !== self.get('lines')){
screen.enableScroll(constants.LogPanelUnusedLines, lines - 1)
self.set({
@@ -121,6 +134,7 @@ var AppView = module.exports = View.extend({
, renderTop: function(){
if (this.isPopupVisible()) return
+ var screen = this.get('screen')
var url = 'http://localhost:' + this.app.config.get('port')
var cols = this.get('cols')
screen
@@ -140,6 +154,7 @@ var AppView = module.exports = View.extend({
if (this.isPopupVisible()) return
if (this.runners.length > 0) return
+ var screen = this.get('screen')
var lines = this.get('lines')
var cols = this.get('cols')
var textLineIdx = Math.floor(lines / 2 + 2)
@@ -153,6 +168,7 @@ var AppView = module.exports = View.extend({
, renderBottom: function(){
if (this.isPopupVisible()) return
+ var screen = this.get('screen')
var cols = this.get('cols')
var msg = (
!this.get('atLeastOneRunner') ?
@@ -233,6 +249,7 @@ var AppView = module.exports = View.extend({
}
, cleanup: function(cb){
+ var screen = this.get('screen')
screen.display('reset')
screen.erase('screen')
screen.position(0, 0)
View
2  lib/ui/error_messages_panel.js
@@ -1,7 +1,6 @@
var ScrollableTextPanel = require('./scrollable_text_panel')
var log = require('winston')
var Chars = require('../chars')
-var screen = require('./screen')
var ErrorMessagesPanel = module.exports = ScrollableTextPanel.extend({
initialize: function(attrs){
@@ -27,6 +26,7 @@ var ErrorMessagesPanel = module.exports = ScrollableTextPanel.extend({
var width = this.get('width') + 1
var height = this.get('height') + 1
+ var screen = this.get('screen')
screen.foreground('red')
screen.position(col, line)
screen.write(Chars.topLeft + Array(width).join(Chars.horizontal) + Chars.topRight)
View
30 lib/ui/runner_tabs.js
@@ -15,7 +15,7 @@ var pad = require('../strutils').pad
var log = require('winston')
var Chars = require('../chars')
var assert = require('assert')
-var screen = require('./screen')
+var Screen = require('./screen')
var growl = require('growl')
var constants = require('./constants')
var TabWidth = constants.TabWidth
@@ -33,18 +33,22 @@ var RunnerTab = exports.RunnerTab = View.extend({
, width: TabWidth
, initialize: function(){
var runner = this.get('runner')
- , results = runner.get('results')
- , index = this.get('index')
- , appview = this.get('appview')
- , app = appview.app
- , config = app.config
- , self = this
-
+ var results = runner.get('results')
+ var index = this.get('index')
+ var appview = this.get('appview')
+ var app = appview.app
+ var config = app.config
+ var self = this
var visible = appview.get('currentTab') === index
+ if (!this.get('screen')){
+ this.set('screen', Screen())
+ }
+
this.splitPanel = new SplitLogPanel({
runner: runner
, appview: appview
, visible: visible
+ , screen: this.get('screen')
})
this.spinnerIdx = 0
@@ -158,6 +162,7 @@ var RunnerTab = exports.RunnerTab = View.extend({
, renderRunnerName: function(){
if (this.isPopupVisible()) return
+ var screen = this.get('screen')
var index = this.get('index')
var line = this.line
var width = this.width
@@ -180,6 +185,7 @@ var RunnerTab = exports.RunnerTab = View.extend({
, renderResults: function(){
if (this.isPopupVisible()) return
+ var screen = this.get('screen')
var index = this.get('index')
var line = this.line
var width = this.width
@@ -228,6 +234,8 @@ var RunnerTab = exports.RunnerTab = View.extend({
}
, renderUnselected: function(){
if (this.isPopupVisible()) return
+
+ var screen = this.get('screen')
var index = this.get('index')
var width = this.width
var height = this.height
@@ -252,6 +260,7 @@ var RunnerTab = exports.RunnerTab = View.extend({
}
, renderSelected: function(){
if (this.isPopupVisible()) return
+ var screen = this.get('screen')
var index = this.get('index')
var width = this.width
var height = this.height
@@ -291,6 +300,7 @@ var RunnerTabs = exports.RunnerTabs = Backbone.Collection.extend({
, initialize: function(arr, attrs){
this.appview = attrs.appview
var self = this
+ this.screen = attrs.screen || Screen()
this.appview.runners().on('remove', function(removed, runners, options){
var idx = options.index
var tab = self.at(idx)
@@ -323,7 +333,7 @@ var RunnerTabs = exports.RunnerTabs = Backbone.Collection.extend({
}
, blankOutBackground: function(){
if (this.isPopupVisible()) return
-
+ var screen = this.screen
var cols = this.appview.get('cols')
for (var i = 0; i < TabHeight; i++){
screen
@@ -339,6 +349,7 @@ var RunnerTabs = exports.RunnerTabs = Backbone.Collection.extend({
}
, renderLine: function(){
if (this.isPopupVisible()) return
+ var screen = this.screen
var startCol = this.length * TabWidth
var lineLength = this.appview.get('cols') - startCol + 1
if (lineLength > 0){
@@ -349,6 +360,7 @@ var RunnerTabs = exports.RunnerTabs = Backbone.Collection.extend({
}
, eraseLast: function(){
if (this.isPopupVisible()) return
+ var screen = this.screen
var index = this.length
var width = TabWidth
var height = TabHeight
View
8 lib/ui/screen.js
@@ -1,9 +1,13 @@
var getTermSize = require('../gettermsize')
+var charm
+
function initCharm(){
+
+ if (charm) return charm
// A wrapper around charm (gives the same API) that automatically parks the cursor
// to the bottom right corner when not in use
- var charm = function(charm){
+ charm = function(charm){
var timeoutID
function parkCursor(){
getTermSize(function(cols, lines){
@@ -40,4 +44,4 @@ function initCharm(){
}
require('../patchcharm.js')
-module.exports = initCharm()
+module.exports = initCharm
View
8 lib/ui/scrollable_text_panel.js
@@ -1,7 +1,7 @@
var View = require('./view')
var log = require('winston')
var splitLines = require('../strutils').splitLines
-var screen = require('./screen')
+var Screen = require('./screen')
// This is a generic scrollable text viewer widget. Should be refactored
// out to another file or npm module at some point.
@@ -19,6 +19,9 @@ var ScrollableTextPanel = module.exports = View.extend({
// * height and width
, initialize: function(){
var self = this
+ if (!this.get('screen')){
+ this.set('screen', Screen())
+ }
this.updateTextLines()
this.observe(this, 'change:text change:width', function(model, text){
self.updateTextLines()
@@ -99,7 +102,8 @@ var ScrollableTextPanel = module.exports = View.extend({
}
, render: function(firstOrLast){
if (!this.get('visible')) return
-
+
+ var screen = this.get('screen')
var startLine = this.get('line')
var col = this.get('col')
var width = this.get('width')
View
8 lib/ui/split_log_panel.js
@@ -5,7 +5,7 @@ var tabs = require('./constants')
var StyledString = require('styled_string')
var Chars = require('../chars')
var indent = require('../strutils').indent
-
+var Screen = require('./screen')
function failureDisplay(item){
var extra = ''
@@ -51,20 +51,26 @@ var SplitLogPanel = module.exports = View.extend({
, focus: 'top'
}
, initialize: function(attrs){
+ if (!this.get('screen')){
+ this.set('screen', Screen())
+ }
var runner = this.get('runner')
var results = runner.get('results')
var messages = runner.get('messages')
var appview = this.get('appview')
var visible = this.get('visible')
var self = this
+ var screen = this.get('screen')
var topPanel = this.topPanel = new ScrollableTextPanel({
line: tabs.TabStartLine + tabs.TabHeight - 1
, col: 0
, visible: visible
+ , screen: screen
})
var bottomPanel = this.bottomPanel = new ScrollableTextPanel({
col: 0
, visible: visible
+ , screen: screen
})
this.observe(appview, 'change:cols change:lines', function(){
self.syncDimensions()
View
3  package.json
@@ -65,8 +65,7 @@
"sinon-chai": "*",
"bufferstream": "*",
"request": "~2.12.0",
- "jsdom": "~0.5.2",
- "sandboxed-module": "~0.2.0"
+ "jsdom": "~0.5.2"
},
"bin": {
"testem": "./testem.js"
View
3  testem.yml
@@ -12,6 +12,9 @@ launchers:
command: mocha server_tests.js -R tap
protocol: tap
cwd: tests
+ UI:
+ command: mocha tests/ui/error_messages_panel_tests.js -R tap
+ protocol: tap
launch_in_dev:
- All
launch_in_ci:
View
20 tests/ui/appview_tests.js
@@ -0,0 +1,20 @@
+var AppView = require('../../lib/ui/appview')
+var Backbone = require('backbone')
+var screen = require('./fake_screen')
+
+describe('AppView', function(){
+
+ it('initializes', function(){
+ var app = new Backbone.Model
+ app.config = {get: function(){ return 1234 }}
+ app.runners = new Backbone.Collection
+ var appview = new AppView({
+ app: app
+ , screen: screen
+ })
+ appview.renderTop()
+ appview.renderMiddle()
+ appview.renderBottom()
+ })
+
+})
View
15 tests/ui/error_messages_panel_tests.js
@@ -1,18 +1,6 @@
-var libDir = '../../lib/'
-var sandbox = require('sandboxed-module')
var expect = require('chai').expect
var screen = require('./fake_screen')
-var ScrollableTextPanel = sandbox.require(libDir + 'ui/scrollable_text_panel', {
- requires: {
- './screen': screen
- }
-})
-var ErrorMessagesPanel = sandbox.require(libDir + 'ui/error_messages_panel', {
- requires: {
- './screen': screen
- , './scrollable_text_panel': ScrollableTextPanel
- }
-})
+var ErrorMessagesPanel = require('../../lib/ui/error_messages_panel')
describe('ErrorMessagesPanel', function(){
var panel
@@ -24,6 +12,7 @@ describe('ErrorMessagesPanel', function(){
, width: 10
, height: 10
, text: 'blah'
+ , screen: screen
})
})
it('initializes', function(){})
View
19 tests/ui/fake_screen.js
@@ -1,3 +1,5 @@
+var EventEmitter = require('events').EventEmitter
+
var width = 100
var height = 100
var line = 0
@@ -17,7 +19,8 @@ function initialize(){
initialize()
var FakeScreen = {
- $setSize: function(w, h){
+ __proto__: EventEmitter.prototype
+ , $setSize: function(w, h){
width = w
height = h
initialize()
@@ -48,13 +51,14 @@ var FakeScreen = {
var original = buffer[line]
if (!original){
- throw new Error('Attempt to draw out of bounds: ' + str)
+ //throw new Error('Attempt to draw out of bounds: ' + str)
+ original = ''
}
var before = original.substring(0, col)
var after = original.substring(col + str.length)
var result = (before + str + after)
if (result.length > width){
- throw new Error('Attempt to draw out of bounds: ' + result)
+ //throw new Error('Attempt to draw out of bounds: ' + result)
}
buffer[line] = result
col += str.length
@@ -71,6 +75,15 @@ var FakeScreen = {
, display: function(){
return this
}
+ , reset: function(){
+ return this
+ }
+ , cursor: function(){
+ return this
+ }
+ , enableScroll: function(){
+ return this
+ }
}
Object.defineProperty(FakeScreen, 'buffer', {
View
4 tests/ui/fake_screen_tests.js
@@ -47,6 +47,9 @@ describe('FakeScreen', function(){
screen.erase('end')
expect(screen.buffer[0]).to.equal('hello ')
})
+
+ /* I am now thinking that screen should be smart and just
+ trim extra characters, so don't need these
it('throws if drawing out of bounds vertically', function(){
screen.position(11, 0)
expect(function(){ screen.write('hello') }).to.throw(/out of bounds/)
@@ -77,6 +80,7 @@ describe('FakeScreen', function(){
' ',
' ' ])
})
+*/
context('has 3 lines of text', function(){
beforeEach(function(){
View
53 tests/ui/runner_tabs_tests.js
@@ -1,25 +1,7 @@
-var libDir = '../../lib/'
-var sandbox = require('sandboxed-module')
var expect = require('chai').expect
var screen = require('./fake_screen')
var Backbone = require('backbone')
-var ScrollableTextPanel = sandbox.require(libDir + 'ui/scrollable_text_panel', {
- requires: {
- './screen': screen
- }
-})
-var SplitLogPanel = sandbox.require(libDir + 'ui/split_log_panel', {
- requires: {
- './screen': screen
- , './scrollable_text_panel': ScrollableTextPanel
- }
-})
-var runnertabs = sandbox.require(libDir + 'ui/runner_tabs', {
- requires: {
- './screen': screen
- , './split_log_panel': SplitLogPanel
- }
-})
+var runnertabs = require('../../lib/ui/runner_tabs')
var RunnerTab = runnertabs.RunnerTab
var RunnerTabs = runnertabs.RunnerTabs
@@ -42,6 +24,7 @@ describe('RunnerTab', function(){
, appview: appview
, selected: true
, index: 0
+ , screen: screen
})
})
@@ -105,6 +88,7 @@ describe('RunnerTab', function(){
, appview: appview
, selected: true
, index: 0
+ , screen: screen
})
})
it('renders test results', function(done){
@@ -143,4 +127,33 @@ describe('RunnerTab', function(){
})
})
-// TODO test RunnerTabs
+
+describe('RunnerTabs', function(){
+
+ it('initializes', function(){
+ screen.$setSize(20, 8)
+ var runner = new Backbone.Model({
+ name: 'Bob'
+ , messages: new Backbone.Collection
+ })
+ runner.hasMessages = function(){ return false }
+ var appview = new Backbone.Model({currentTab: 0, cols: 20})
+ appview.app = {config: {}}
+ appview.isPopupVisible = function(){ return false }
+ appview.runners = function(){ return new Backbone.Collection }
+ var tab = new RunnerTab({
+ runner: runner
+ , appview: appview
+ , selected: true
+ , index: 0
+ , screen: screen
+ })
+ appview.isPopupVisible = function(){ return false }
+ var tabs = new RunnerTabs([tab], {
+ appview: appview,
+ screen: screen
+ })
+ tabs.reRenderAll()
+ tabs.eraseLast()
+ })
+})
View
11 tests/ui/scrollable_text_panel_tests.js
@@ -1,13 +1,6 @@
var expect = require('chai').expect
-var sandbox = require('sandboxed-module')
-var spy = require('sinon').spy
-var libDir = '../../lib/'
var screen = require('./fake_screen')
-var ScrollableTextPanel = sandbox.require(libDir + 'ui/scrollable_text_panel', {
- requires: {
- './screen': screen
- }
-})
+var ScrollableTextPanel = require('../../lib/ui/scrollable_text_panel')
describe('ScrollableTextPanel', function(){
@@ -23,6 +16,7 @@ describe('ScrollableTextPanel', function(){
, col: 0
, width: 10
, height: 2
+ , screen: screen
})
})
it('renders stuff', function(){
@@ -91,6 +85,7 @@ describe('ScrollableTextPanel', function(){
, width: 6
, height: 6
, text: 'Charm objects pass along the data events from their input stream except for events generated from querying the terminal device.'
+ , screen: screen
})
})
View
15 tests/ui/split_log_panel_tests.js
@@ -1,20 +1,8 @@
var expect = require('chai').expect
-var sandbox = require('sandboxed-module')
var Backbone = require('backbone')
var sinon = require('sinon')
-var libDir = '../../lib/'
var screen = require('./fake_screen')
-var ScrollableTextPanel = sandbox.require(libDir + 'ui/scrollable_text_panel', {
- requires: {
- './screen': screen
- }
-})
-var SplitLogPanel = sandbox.require(libDir + 'ui/split_log_panel', {
- requires: {
- './screen': screen
- , './scrollable_text_panel': ScrollableTextPanel
- }
-})
+var SplitLogPanel = require('../../lib/ui/split_log_panel')
describe('SplitLogPanel', function(){
@@ -38,6 +26,7 @@ describe('SplitLogPanel', function(){
runner: runner
, appview: appview
, visible: true
+ , screen: screen
})
})
View
1  tests/ui/view_tests.js
@@ -1,5 +1,4 @@
var expect = require('chai').expect
-var sandbox = require('sandboxed-module')
var spy = require('sinon').spy
var View = require('../../lib/ui/view')
var Backbone = require('backbone')
Please sign in to comment.
Something went wrong with that request. Please try again.