Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: ivarni/pictureshare
base: d07f6d2881
...
head fork: ivarni/pictureshare
compare: 8526577ab9
  • 4 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
8 lib/client/app.js
@@ -1,8 +0,0 @@
-var PictureShareApp = function() {
-
- this.init = function() {
- var app = new views.AppView();
-
- }
-
-}
View
35 lib/client/pictureshare.js
@@ -1,16 +1,27 @@
-function msgReceived(msg) {
- $echoField.html(msg.data);
+var PictureShareApp = function() {
+
+ this.newFile = function(data) {
+ console.log('huzza!');
+ this.socket.json.send({ file: data });
+ }
+
+ this.init = function() {
+ this.socket = io.connect();
+
+ this.socket.on('message', function(msg) {
+ console.log(msg);
+ });
+
+
+ var app = new views.FormView({
+ model: new models.FormModel()
+ });
+ app.render();
+ $('div#content').html(app.el);
+ }
}
$(document).ready(function() {
- $echoField = $('#echoField');
- $inputField = $('#inputField');
- $inputField.keyup(function() {
- socket.send($(this).val());
- });
-
- var socket = io.connect();
- socket.on('message', function(msg) {
- msgReceived(msg);
- });
+ window.app = new PictureShareApp();
+ window.app.init();
});
View
23 lib/client/views.js
@@ -1,4 +1,25 @@
var views = this.views || {};
-views.AppView = Backbone.View.extend();
+views.FormView = Backbone.View.extend({
+ tagName: 'div',
+
+ newFile: function() {
+ window.app.newFile(this.model.get('value'));
+ },
+
+ updateModel: function(event) {
+ this.model.set('value', event.target.value);
+ },
+
+ render: function() {
+ $(this.el).html(_.template(this.template, {}));
+ },
+
+ events: {
+ 'click .save' : 'newFile',
+ 'change' : 'updateModel'
+ },
+
+ template: '<input /><button class="save"/>'
+});
View
3  lib/shared/models.js
@@ -0,0 +1,3 @@
+var models = this.models || {};
+
+models.FormModel = Backbone.Model.extend();
View
3  test/buster.js
@@ -4,9 +4,10 @@ config['Pictureshare'] = {
rootPath : '../',
environment : 'browser',
sources : [
+ 'public/js/vendor/jquery-1.7.2.js',
'public/js/vendor/underscore.js',
+ 'public/js/vendor/backbone.js',
'node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js',
- 'public/js/**/*.js',
'lib/**/*.js'
],
tests: [
View
49 test/formview_test.js
@@ -0,0 +1,49 @@
+buster.testCase('FormView', {
+ setUp: function() {
+ this.view = new views.FormView({
+ model : new models.FormModel()
+ });
+ this.view.render();
+ },
+
+ 'when the view renders': {
+
+ 'its main element is a div': function() {
+ assert.tagName(this.view.el, "div");
+ },
+
+ 'it renders an input box': function() {
+ expect($(this.view.el).find('input').length).toEqual(1);
+ },
+
+ 'it renders a submit button': function() {
+ var els = $(this.view.el).find('button');
+ expect(els.length).toEqual(1);
+ assert.className(els[0], "save");
+ }
+ },
+
+ 'when the save button is clicked': {
+ setUp: function() {
+ window.app = { newFile: function(){} };
+ this.viewStub = sinon.stub(window.app, 'newFile');
+ },
+
+ 'it calls the save method on the controller': function() {
+ this.view.model.set('value', 'foo');
+ $(this.view.el).find('button.save').trigger('click');
+ expect(this.viewStub).toHaveBeenCalledWith('foo');
+ }
+
+ },
+
+ 'when the value of the input box changes': {
+ 'it updates the model': function() {
+ buster.log($(this.view.el).find('input').val('text'));
+ buster.log($(this.view.el).find('input').trigger('change'));
+
+ assert.match(this.view.model.get('value'), 'text');
+ }
+ }
+
+});
View
52 test/pictureshare_test.js
@@ -1,8 +1,46 @@
-buster.testCase('When the app is created', {
- 'it renders the main view': function() {
- this.stub = sinon.stub(window.views, 'AppView');
- var app = new PictureShareApp();
- app.init();
- assert(this.stub.called);
+buster.testCase('Pictureshare Controller', {
+
+ setUp: function() {
+ var renderStub = { render: function(){} };
+ this.renderStub = sinon.stub(renderStub, 'render');
+ this.viewStub = sinon.stub(window.views, 'FormView');
+ this.viewStub.returns(renderStub);
+
+ this.jsonStub = { send: function(){} };
+ var onSendStub = { on: function(){}, json: this.jsonStub }
+ this.sendStub = sinon.stub(this.jsonStub, 'send');
+ this.socketStub = sinon.stub(io, 'connect');
+ this.socketStub.returns(onSendStub);
+
+ this.app = new PictureShareApp();
+ this.app.init();
+ },
+
+ tearDown: function() {
+ this.viewStub.restore();
+ this.socketStub.restore();
+ },
+
+ 'When the app is created' : {
+
+ 'it renders the form view': function() {
+ expect(this.viewStub).toHaveBeenCalled();
+ expect(this.renderStub).toHaveBeenCalled();
+ },
+
+ 'it connects to its socket': function() {
+ expect(this.socketStub).toHaveBeenCalled();
+ }
+ },
+
+ 'when a new file gets created': {
+
+ 'the data is sent to the server' : function() {
+ this.app.newFile('data');
+ expect(this.sendStub).toHaveBeenCalledWith({ file: 'data' });
+ }
+
}
-});
+
+
+});
View
8 views/index.jade
@@ -7,17 +7,13 @@ html(lang='en')
script(src='/js/vendor/underscore.js')
script(src='/js/vendor/backbone.js')
script(src='/socket.io/socket.io.js')
- script(src='/js/client/app.js')
+ script(src='/js/shared/models.js')
+ script(src='/js/client/views.js')
script(src='/js/client/pictureshare.js')
body
#heading
h1 Pictureshare
#content
- input#inputField
- #pictures
- ul#picture_list
- #movies
- ul#movie_list
#footer
p
span#echoField
View
9 web.js
@@ -12,7 +12,11 @@ app.set('view options', { layout: false });
io.sockets.on('connection', function(socket) {
socket.on('message', function(data) {
- io.sockets.json.send({ data: data });
+ for (k in data) {
+ console.log(k);
+ }
+ console.log('data: ' + data.file);
+ io.sockets.json.send(data);
});
});
@@ -29,7 +33,8 @@ app.get('/js/client/:path', function(req, res) {
});
app.get('/js/shared/:path', function(req, res) {
- res.sendfile('./lib/shared' + req.params.path);
+ console.log(req.params.path);
+ res.sendfile('./lib/shared/' + req.params.path);
});
app.get('/', function(req, res) {

No commit comments for this range

Something went wrong with that request. Please try again.