Skip to content

Commit

Permalink
Continue work on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mixu committed Jun 28, 2012
1 parent aea4249 commit db35454
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 20 deletions.
15 changes: 10 additions & 5 deletions lib2/monitor.js
@@ -1,9 +1,14 @@
function Monitor() {
this.width =
this.height =
this.x =
this.y =
var Workspace = require('./workspace.js');

function Monitor(opts) {
if(typeof opts == 'undefined') {
opts = {};
}
this.width = opts.width || 0;
this.height = opts.height || 0 ;
this.x = opts.x || 0;
this.y = opts.y || 0;
this.defaultWorkspace = new Workspace();
}

module.exports = Monitor;
34 changes: 25 additions & 9 deletions lib2/test/monitor.test.js
@@ -1,48 +1,64 @@
var assert = require('assert'),

Monitor = require('../monitor.js');
Monitor = require('../monitor.js'),
Workspace = require('../workspace.js');

exports['given a monitor'] = {

before: function(done) {
beforeEach: function(done) {
this.m = new Monitor();
done();
},

'can get and set x y width height': function(done) {
var m = this.m;
m.x = 100;
assert.equal(m.x, 100);
m.y = 200;
assert.equal(m.y, 200);
m.width = 300;
assert.equal(m.width, 300);
m.height = 400;
assert.equal(m.height, 400);
done();
},

'has a default workspace': function(done) {
assert.ok(this.m.defaultWorkspace instanceof Workspace);
done();
},

'can receive keyboard events': function(done) {
done();
'can receive events': function(done) {
var m = this.m;
m.once('intent:a', function(key) {
assert.equal(key, a);
done();
});
m.emit('intent:a', 'a');
},

'on keyboard event, can go to a new workspace by index': function(done) {
'on intent event, can go to a new workspace by index': function(done) {
done();
},

'on keyboard event, can cycle the layout in the current workspace': function(done) {
'on intent event, can cycle the layout in the current workspace': function(done) {
done();
},

'can add a new window to the current workspace': function(done) {
done();
},

'on keyboard event, move the current window to a different workspace': function(done) {
'on intent event, move the current window to a different workspace': function(done) {
done();
},

'when a window requests fullscreen, activates the built-in monocle mode temporarily': function(done) {

done();
},

'when the window that requested fullscreen is removed or requests normal size, returns to the previous layout': function(done) {

done();
}

};
Expand Down
16 changes: 12 additions & 4 deletions lib2/test/window.test.js
Expand Up @@ -10,20 +10,28 @@ exports['given a window'] = {
},

'can get and set width height x y': function(done){
var w = this.w;
w.x = 100;
assert.equal(w.x, 100);
w.y = 200;
assert.equal(w.y, 200);
w.width = 300;
assert.equal(w.width, 300);
w.height = 400;
assert.equal(w.height, 400);
done();
},

'can get and set title instance klass': function(done) {
done();
},


'can get and set visible': function(done) {

done();
},

'can apply pending changes': function(done) {

'pending changes are only applied on sync() call': function(done) {
done();
}

};
Expand Down
42 changes: 40 additions & 2 deletions lib2/window.js
@@ -1,5 +1,43 @@
function Window() {

function Window(opts) {
if(typeof opts == 'undefined') {
opts = {};
}
this._width = opts.width || 0;
this._height = opts.height || 0 ;
this._x = opts.x || 0;
this._y = opts.y || 0;
this.pending = { };
}

var propertyNames = ['width', 'height', 'x', 'y'];

// define ES5 getters and setters
propertyNames.forEach(function(prop) {
var name = '_'+prop;
Object.defineProperty(Window.prototype, prop, {
get: function(){
return (typeof this.pending[name] != 'undefined'
? this.pending[name] : this[name]);
},
set: function(v){
this.pending[name] = v;
},
enumerable: true
});
});

// applies pending changes as operations
Window.prototype.sync = function() {
var self = this,
changedProperties = propertyNames.filter(function(prop) {
return (this.pending['_'+prop] && this.pending['_'+prop] != this['_'+prop]);
});
// persist dimension change
if(changedProperties.indexOf('width') + changedProperties.indexOf('height') > -1) {
wm.
}
if(changedProperties.indexOf('x') + changedProperties.indexOf('y') > -1) {
}
};

module.exports = Window;

0 comments on commit db35454

Please sign in to comment.