This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from jasonLaster/radio
Add radio to wreqr
- Loading branch information
Showing
15 changed files
with
1,023 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
describe('Executing `connectCommands` with a hash as the first argument', function() { | ||
|
||
var | ||
ch, | ||
label1 = 'one', | ||
label2 = 'two', | ||
cbOne, | ||
cbTwo, | ||
p, | ||
ret, | ||
commandsHash; | ||
|
||
beforeEach(function() { | ||
|
||
cbOne = function() {}; | ||
cbTwo = function() {}; | ||
ch = Wreqr.radio.channel('foo'); | ||
|
||
commandsHash = {}; | ||
commandsHash[label2] = cbOne; | ||
commandsHash[label1] = cbTwo; | ||
|
||
ret = ch.connectCommands( commandsHash ); | ||
|
||
p = ch.commands._wreqrHandlers || {}; | ||
|
||
}); | ||
|
||
afterEach(function() { | ||
ch.reset(); | ||
}); | ||
|
||
it( 'should attach the listeners to the Channel', function() { | ||
expect(_.keys(p)).toEqual( [label2, label1] ); | ||
}); | ||
|
||
it( 'should return the Channel', function() { | ||
expect( ret ).toBe( ch ); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
describe('Executing `connectEvents` with a hash as the first argument', function() { | ||
|
||
var | ||
ch, | ||
label1 = 'one', | ||
label2 = 'two', | ||
cbOne, | ||
cbTwo, | ||
p, | ||
ret, | ||
eventsHash; | ||
|
||
beforeEach(function() { | ||
|
||
cbOne = function() {}; | ||
cbTwo = function() {}; | ||
ch = Wreqr.radio.channel('test'); | ||
|
||
eventsHash = {}; | ||
eventsHash[label2] = cbOne; | ||
eventsHash[label1] = cbTwo; | ||
|
||
ret = ch.connectEvents( eventsHash ); | ||
|
||
p = ch.vent._events || {}; | ||
|
||
}); | ||
|
||
afterEach(function() { | ||
ch.reset(); | ||
}); | ||
|
||
it( 'should attach the listeners to the Channel', function() { | ||
expect(_.keys(p)).toEqual( [label2, label1] ); | ||
}); | ||
|
||
it( 'should return the Channel', function() { | ||
expect( ret ).toBe( ch ); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
describe('Executing `connectRequests` with a hash as the first argument', function() { | ||
|
||
var | ||
ch, | ||
label1 = 'one', | ||
label2 = 'two', | ||
cbOne, | ||
cbTwo, | ||
p, | ||
ret, | ||
requestsHash; | ||
|
||
beforeEach(function() { | ||
|
||
cbOne = function() {}; | ||
cbTwo = function() {}; | ||
ch = Wreqr.radio.channel('test'); | ||
|
||
requestsHash = {}; | ||
requestsHash[label2] = cbOne; | ||
requestsHash[label1] = cbTwo; | ||
|
||
ret = ch.connectRequests( requestsHash ); | ||
|
||
p = ch.reqres._wreqrHandlers || {}; | ||
|
||
}); | ||
|
||
afterEach(function() { | ||
ch.reset(); | ||
}); | ||
|
||
it( 'should attach the listeners to the Channel', function() { | ||
expect(_.keys(p)).toEqual( [label2, label1] ); | ||
}); | ||
|
||
it( 'should return the Channel', function() { | ||
expect( ret ).toBe( ch ); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
describe('Creating a Channel', function() { | ||
|
||
var | ||
ch, | ||
chName, | ||
name = 'test', | ||
v, c, r; | ||
|
||
beforeEach(function() { | ||
ch = new Wreqr.Channel( name ); | ||
}); | ||
|
||
it( 'should set the name', function() { | ||
expect( ch.channelName ).toEqual( name ); | ||
}); | ||
|
||
it( 'should instantiate a new instance of each messaging system', function() { | ||
expect( ch.vent instanceof Backbone.Wreqr.EventAggregator ).toBeTruthy(); | ||
expect( ch.commands instanceof Backbone.Wreqr.Commands ).toBeTruthy(); | ||
expect( ch.reqres instanceof Backbone.Wreqr.RequestResponse ).toBeTruthy(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
describe('Running `resetChannel`', function() { | ||
|
||
var | ||
ch, | ||
v1Stub, v2Stub, cStub, rStub, | ||
v, c, r, | ||
ret; | ||
|
||
beforeEach(function() { | ||
|
||
ch = new Wreqr.Channel( 'test' ); | ||
v = ch.vent; | ||
c = ch.commands; | ||
r = ch.reqres; | ||
v1Stub = sinon.spy( v, "off"); | ||
v2Stub = sinon.spy( v, "stopListening"); | ||
cStub = sinon.spy( c, "removeAllHandlers"); | ||
rStub = sinon.spy( r, "removeAllHandlers"); | ||
|
||
ret = ch.reset(); | ||
|
||
}); | ||
|
||
afterEach(function() { | ||
|
||
v1Stub.restore(); | ||
v2Stub.restore(); | ||
cStub.restore(); | ||
rStub.restore(); | ||
|
||
}); | ||
|
||
it( 'should call the reset functions for each messaging system', function() { | ||
expect( v1Stub ).toHaveBeenCalledOnce(); | ||
expect( v2Stub ).toHaveBeenCalledOnce(); | ||
expect( cStub ).toHaveBeenCalledOnce(); | ||
expect( rStub ).toHaveBeenCalledOnce(); | ||
}); | ||
|
||
it( 'should return the Channel', function() { | ||
expect( ret ).toBe( ch ); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
describe('radio.channel', function () { | ||
|
||
var channel, channelName; | ||
|
||
describe('with no arguments', function() { | ||
|
||
it( 'should throw an exception', function() { | ||
expect( function() { Wreqr.radio.channel()} ).toThrow(); | ||
}); | ||
|
||
}); | ||
|
||
describe('for a nonexistent channel', function() { | ||
|
||
beforeEach(function() { | ||
channel = Wreqr.radio.channel('lala'); | ||
}); | ||
|
||
it( 'should return an instance of the default channel', function() { | ||
expect( channel.channelName ).toEqual( 'lala' ); | ||
}); | ||
|
||
}); | ||
|
||
describe('twice with the same name', function() { | ||
|
||
var chOne, chTwo; | ||
|
||
beforeEach(function() { | ||
|
||
chOne = Wreqr.radio.channel( 'lala' ); | ||
chTwo = Wreqr.radio.channel( 'lala' ); | ||
|
||
}); | ||
|
||
it( 'should return the same channel', function() { | ||
expect( chOne ).toBe( chTwo ); | ||
}); | ||
|
||
}); | ||
|
||
}); |
Oops, something went wrong.