Skip to content

Commit

Permalink
Google Summer of Code 2016 JavaScript Testing project: Tests for swit…
Browse files Browse the repository at this point in the history
…cher.js library (#11645)

* switcher.js test suite

* Removed a new line

* Restructured code
  • Loading branch information
Ruchiranga authored and wilsonge committed Aug 17, 2016
1 parent b6dfa10 commit 2997de7
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/javascript/switcher/fixtures/fixture.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div id="switcherjs">
<ul id="submenu">
<li>
<a href="#" onclick="return false;" id="toggler-1">Toggler 1</a>
</li>
<li>
<a href="#" onclick="return false;" id="toggler-2">Toggler 2</a>
</li>
<li>
<a href="#" onclick="return false;" id="toggler-3">Toggler 3</a>
</li>
</ul>
<div id="config-document">
<div id="page-toggler-1" class="tab">
<div id="content-toggler-1">
Toggler 1 Content
</div>
</div>
<div id="page-toggler-2" class="tab">
<div id="content-toggler-2">
Toggler 2 Content
</div>
</div>
<div id="page-toggler-3" class="tab">
<div id="content-toggler-3">
Toggler 3 Content
</div>
</div>
</div>
</div>
24 changes: 24 additions & 0 deletions tests/javascript/switcher/spec-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package Joomla
* @subpackage JavaScript Tests
* @since __DEPLOY_VERSION__
* @version 1.0.0
*/

define(['jquery', 'text!testsRoot/switcher/fixtures/fixture.html', 'libs/switcher'], function ($, fixture) {
$('body').append(fixture);

spy_on_show = jasmine.createSpy('on_show');
spy_on_hide = jasmine.createSpy('on_hide');

var toggler = document.getElementById('submenu');
var element = document.getElementById('config-document');
var options = {
onShow : spy_on_show,
onHide : spy_on_hide
};

switcher = new JSwitcher(toggler, element, options);
});
94 changes: 94 additions & 0 deletions tests/javascript/switcher/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @package Joomla
* @subpackage JavaScript Tests
* @since __DEPLOY_VERSION__
* @version 1.0.0
*/

define(['jquery', 'testsRoot/switcher/spec-setup', 'jasmineJquery'], function ($) {

describe('Switcher ', function () {
describe('After running initializer code', function () {
it('Should bind click event to each toggler', function () {
expect($('#toggler-1')).toHandle('click');
expect($('#toggler-2')).toHandle('click');
expect($('#toggler-3')).toHandle('click');
});

it('Should display content of toggler-1', function () {
expect($('#content-toggler-1')).toBeVisible();
});

it('Should add class active to toggler-1', function () {
expect($('#toggler-1')).toHaveClass('active');
});

it('Should not let rest of the togglers to have class active', function () {
expect($('#toggler-2')).not.toHaveClass('active');
expect($('#toggler-3')).not.toHaveClass('active');
});

it('Should set document.location.hash to #toggler-1', function () {
expect(document.location.hash).toEqual('#toggler-1');
});

it('Should call onHide callback function', function () {
expect(spy_on_hide).toHaveBeenCalledWith(jasmine.objectContaining({length: 1}));
});
});

describe('On clicking toggler-2', function () {
beforeAll(function () {
$('#toggler-2').click();
});

it('Should hide content of toggler-1', function () {
expect($('#content-toggler-1')).not.toBeVisible();
});

it('Should call onShow callback function', function () {
expect(spy_on_show).toHaveBeenCalledWith(jasmine.objectContaining({length: 1}));
});

it('Should remove class active from toggler-1', function () {
expect($('#toggler-1')).not.toHaveClass('active');
});

it('Should show content of toggler-2', function () {
expect($('#content-toggler-2')).toBeVisible();
});

it('Should call onHide callback function', function () {
expect(spy_on_hide).toHaveBeenCalledWith(jasmine.objectContaining({length: 1}));
});

it('Should add class active to toggler-2', function () {
expect($('#toggler-2')).toHaveClass('active');
});

it('Should set document.location.hash to #toggler-2', function () {
expect(document.location.hash).toEqual('#toggler-2');
});
});

describe('On function return', function () {
it('Should return display function', function () {
expect(switcher.display).toEqual(jasmine.any(Function));
});

it('Should return hide function', function () {
expect(switcher.hide).toEqual(jasmine.any(Function));
});

it('Should return hideAll function', function () {
expect(switcher.hideAll).toEqual(jasmine.any(Function));
});

it('Should return show function', function () {
expect(switcher.show).toEqual(jasmine.any(Function));
});
});
});
});

0 comments on commit 2997de7

Please sign in to comment.