Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Merge pull request #18 from kadirahq/tests
Browse files Browse the repository at this point in the history
Add more tests for KnobManager
  • Loading branch information
arunoda authored Sep 9, 2016
2 parents 2725dee + 39afa20 commit 7b7d70c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/tests/KnobManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import sinon from 'sinon';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import KnobManager from '../KnobManager';
const { describe, it, beforeEach } = global;

Expand Down Expand Up @@ -44,5 +46,54 @@ describe('KnobManager', () => {
expect(testManager.knobStore.set.calledWith('foo', newKnob)).to.equal(true);
});
});

describe('when the knob is not present in the knobStore', () => {
const testManager = new KnobManager();

beforeEach(() => {
testManager.knobStore = {
set: sinon.spy(),
get: sinon.stub(),
};

testManager.knobStore.get.onFirstCall().returns(undefined);
testManager.knobStore.get.onSecondCall().returns('normal value');
});

it('should return the new default knob value when default has changed', () => {
const defaultKnob = {
name: 'foo',
value: 'normal value',
};
testManager.knob('foo', defaultKnob);

const newKnob = {
...defaultKnob,
defaultValue: defaultKnob.value,
};

expect(testManager.knobStore.set.calledWith('foo', newKnob)).to.equal(true);
});
});
});

describe('wrapStory()', () => {
it('should contain the story and add correct props', () => {
const testManager = new KnobManager();

const testChannel = {};
const testStory = () => (<div id="test-story">Test Content</div>);
const testContext = {
kind: 'Foo',
story: 'bar baz',
};
const wrappedStory = testManager.wrapStory(testChannel, testStory, testContext);
const wrapper = shallow(wrappedStory);
expect(wrapper.find('#test-story')).to.have.length(1);

const storyWrapperProps = wrappedStory.props;
expect(storyWrapperProps.channel).to.equal(testChannel);
expect(storyWrapperProps.context).to.equal(testContext);
});
});
});

0 comments on commit 7b7d70c

Please sign in to comment.