Permalink
Browse files

Start specing the interactions.

  • Loading branch information...
1 parent 3e0a2c2 commit ac9a8e6392cb7ebcfd0ad7da71092b0fd5bdd9fd @cesutherland cesutherland committed Mar 27, 2012
Showing with 63 additions and 2 deletions.
  1. +1 −0 spec/SpecRunner.html
  2. +9 −0 spec/helpers/MockAction.js
  3. +6 −2 spec/helpers/MockAdapter.js
  4. +1 −0 spec/jasmine.yml
  5. +46 −0 spec/js/Interaction.js
View
@@ -24,6 +24,7 @@
<script type="text/javascript" src="../js/Interaction.js"></script>
<!-- Helpers: -->
+ <script type="text/javascript" src="helpers/MockAction.js"></script>
<script type="text/javascript" src="helpers/MockAdapter.js"></script>
<script type="text/javascript" src="helpers/MockComponent.js"></script>
@@ -0,0 +1,9 @@
+function MockAction () {
+ this.events = [
+ {
+ handler : 'handle',
+ consumer : 'consume'
+ },
+ 'handleConsume'
+ ];
+}
@@ -1,7 +1,11 @@
function MockAdapter () {}
MockAdapter.prototype = {
- attach : function () {},
+ attach : function (component, name, callback) {
+ bean.add.apply(bean, arguments);
+ },
detach : function () {},
- trigger : function () {},
+ trigger : function () {
+ bean.fire.apply(bean, arguments);
+ },
destroy : function () {}
};
View
@@ -11,6 +11,7 @@ src_files:
- "js/Preprocessor.js"
- "js/Interaction.js"
helper_files:
+ - "MockAction.js"
- "MockAdapter.js"
- "MockComponent.js"
spec_files:
View
@@ -49,6 +49,52 @@ describe('Interaction', function () {
expect(interaction.followers).toContain(b);
});
+ describe('Actions', function () {
+ var
+ interaction, action, a, b;
+
+ beforeEach(function () {
+ interaction = new H.Interaction();
+ action = new MockAction();
+ a = new H.Component({adapter : new MockAdapter()});
+ b = new H.Component({adapter : new MockAdapter()});
+ });
+
+ it('adds an action', function () {
+ interaction.add(action);
+ expect(interaction.actions).toContain(action);
+ });
+
+ it('triggers an action on followers', function () {
+
+ interaction.leader(a);
+ interaction.follower(b);
+ interaction.add(action);
+
+ spyOn(b, 'trigger').andCallThrough();
+ a.trigger('handle');
+
+ expect(b.trigger).toHaveBeenCalled();
+ });
+
+ it('triggers an action on followers', function () {
+
+ interaction.leader(a);
+ interaction.follower(b);
+ interaction.add(action);
+
+ spyOn(a, 'trigger').andCallThrough();
+ spyOn(b, 'trigger').andCallThrough();
+
+ a.trigger('handleConsume');
+
+ expect(b.trigger).toHaveBeenCalled();
+ expect(a.trigger.callCount).toBe(1);
+ expect(b.trigger.callCount).toBe(1);
+ });
+
+ });
+
describe('Chaining', function () {
var
interaction, component;

0 comments on commit ac9a8e6

Please sign in to comment.