import expect from 'expect';
import createSwitchAction from '../src';

describe('createSwitchAction', () => {
  it('should exist', () => {
    expect(typeof createSwitchAction !== 'undefined').toBe(true);
  });

  const ADD = 'ADD';
  const SUB = 'SUB';
  const OTHER = 'OTHER';
  const INC = 'INC';

  function addReducer(state, {amount}) {
    return state + amount;
  }

  function subReducer(state, {amount}) {
    return state - amount;
  }

  function incReducer(state) {
    return state + 1;
  }

  const switchAction = createSwitchAction({
    [ADD]: addReducer,
    [SUB]: subReducer,
    [INC]: incReducer,
  });

  it('should call a reducer according to an action type', () => {
    const addAction = {
      type: ADD,
      payload: {
        amount: 2,
      },
    };

    const subAction = {
      type: SUB,
      payload: {
        amount: 2,
      },
    };

    expect(switchAction(5, addAction)).toBe(7);
    expect(switchAction(5, subAction)).toBe(3);
  });

  it('should return the state for an unknown action', () => {
    const otherAction = {
      type: OTHER,
      payload: {
        other: 'data',
      },
    };

    expect(switchAction(5, otherAction)).toBe(5);
  });

  it('should accept actions without payload', () => {
    const incAction = {
      type: INC,
    };

    expect(switchAction(5, incAction)).toBe(6);
  });
});

@@ -292,16 +292,53 @@
 = 'INC';
+%0A  const RETURN_THIS = 'RETURN_THIS';
 %0A%0A  func
@@ -535,16 +535,71 @@
 1;%0A  %7D%0A%0A
+  function returnThisReducer() %7B%0A    return this;%0A  %7D%0A%0A
   const 
@@ -676,24 +676,24 @@
 subReducer,%0A
-
     %5BINC%5D: i
@@ -703,16 +703,54 @@
 educer,%0A
+    %5BRETURN_THIS%5D: returnThisReducer,%0A
   %7D);%0A%0A 
@@ -1482,13 +1482,220 @@
 );%0A  %7D);
+%0A%0A  it('should retain the %60this%60 context', () =%3E %7B%0A    const returnThisAction = %7B%0A      type: RETURN_THIS,%0A    %7D;%0A%0A    expect(switchAction.call('thisContext', 5, returnThisAction)).toBe('thisContext');%0A  %7D);
 %0A%7D);%0A

add test case