Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Commit

Permalink
Prepare for an (aspirational) JavaScript testing environment.
Browse files Browse the repository at this point in the history
This commit includes BackboneJS as part of our `package.json`'s
`devDependencies` and configures Karma to load it as necessary. This
means we are mostly ready for testing Backbone components when and if we
figure out what, exactly, we'd like to test.

Previous to this commit, there was a rather contrived test for a single
method. However, that was only ever being used in one place, so I've
refactored it and removed it from the test suite as it's a single jQuery
call, anyway.
  • Loading branch information
fabacab committed Dec 12, 2016
1 parent 1292daa commit 7fabde0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 23 deletions.
10 changes: 0 additions & 10 deletions buoy.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,9 @@ var BUOY = (function () {
});
};

/**
* Helper to get the number of Buoy Alerts shown in the admin bar.
*
* @return {number}
*/
var countIncidentMenuItems = function () {
return jQuery('#wp-admin-bar-buoy-alerts-menu').length;
};

return {
'init': init,
'installWebApp': installWebApp,
'countIncidentMenuItems': countIncidentMenuItems,
'Models': Models,
'Views': Views,
'Collections': Collections
Expand Down
9 changes: 1 addition & 8 deletions includes/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,6 @@
this.$el.removeClass('hidden');
};

/**
* Hide the Choose Teams Panel.
*/
BUOY.Views.ChooseTeamsPanel.prototype.hide = function () {
this.$el.addClass('hidden');
};

/**
* Handles the alert submission form (a new alert).
*
Expand Down Expand Up @@ -363,7 +356,7 @@
jQuery.post(this.$el.attr('href'), data, function (response) {
if (response.success) {
item.$el.remove();
if (0 === BUOY.countIncidentMenuItems()) {
if (0 === jQuery('#wp-admin-bar-buoy-alerts-menu a').length) {
jQuery('#wp-admin-bar-buoy-alerts-menu').remove();
}
}
Expand Down
3 changes: 3 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module.exports = function(config) {
// list of files / patterns to load in the browser
files: [
'bower_components/*/dist/**/*.js',
'node_modules/underscore/underscore.js',
'node_modules/backbone/backbone.js',
'buoy.js',
'includes/alert.js',
'tests/**/*.js'
],

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"homepage": "https://meitar.github.io/better-angels/",
"devDependencies": {
"backbone": "^1.3.3",
"jasmine-core": "^2.4.1",
"karma": "^0.13.19",
"karma-firefox-launcher": "^0.1.7",
Expand Down
35 changes: 30 additions & 5 deletions tests/my_first_test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
/**
* Aspirational JavaScript testing file for Buoy client-side.
*
* @file Client-side Buoy tests.
*
* @see {@link https://github.com/betterangels/buoy/wiki/Setting-up-a-development-environment#running-tests}
*
* @todo Look into SinonJS for mocking Ajax calls and other difficult
* testing stuff.
*/

'use strict';

describe("BUOY main class", function() {
it("counts number of menu items", function() {
$(document.body).append('<div id="wp-admin-bar-buoy-alerts-menu"> <a> test </a> <a> test2 </a> </div>')
expect(BUOY.countIncidentMenuItems()).toBe(2)
});
/**
* Main Buoy module tests.
*/
describe("Buoy main class", function() {
// TODO
});

/**
* Buoy Alert module tests.
*/
describe('Buoy Alert module', function () {
// TODO
});

/**
* Buoy Map module tests.
*/
describe('Buoy Map module', function () {
// TODO
});

0 comments on commit 7fabde0

Please sign in to comment.