Skip to content

Commit

Permalink
[#2458] Add unit tests for the stats-nav module
Browse files Browse the repository at this point in the history
  • Loading branch information
aron committed Aug 6, 2012
1 parent 54f9dfa commit 9729f1c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ckanext/stats/public/ckanext/stats/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
<script src="../../../base/javascript/i18n.js"></script>
<script src="../../../base/javascript/main.js"></script>
<script src="../javascript/modules/plot.js"></script>
<script src="../javascript/modules/stats-nav.js"></script>

<!-- Suite -->
<script src="./spec/modules/plot.spec.js"></script>
<script src="./spec/modules/stats-nav.spec.js"></script>

<script>
beforeEach(function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*globals describe before beforeEach afterEach it assert sinon ckan jQuery */
describe('ckan.module.StatsNavModule()', function () {
var StatsNavModule = ckan.module.registry['stats-nav'];

beforeEach(function () {
this.el = document.createElement('div');
this.sandbox = ckan.sandbox();
this.sandbox.body = this.fixture;
this.sandbox.location = {
href: '',
hash: ''
};
this.module = new StatsNavModule(this.el, {}, this.sandbox);

jQuery.fn.tab = sinon.stub();
});

afterEach(function () {
this.module.teardown();

delete jQuery.fn.tab;
});

describe('.initialize()', function () {
it('should listen for shown events and update the location.hash', function () {
var anchor = jQuery('<a />').attr('href', '#stats-test')[0];

this.module.initialize();
this.module.el.trigger({type: 'shown', target: anchor});

assert.equal(this.sandbox.location.hash, 'test');
});

it('should select the tab from the location hash on init', function () {
var anchor = jQuery('<a />').attr('href', '#stats-test').appendTo(this.el);

this.sandbox.location.hash = '#test';
this.module.initialize();

assert.called(jQuery.fn.tab);
assert.calledWith(jQuery.fn.tab, 'show');
});
});
});

0 comments on commit 9729f1c

Please sign in to comment.