Skip to content

Commit

Permalink
Merge pull request LinkedInAttic#353 from jasonbelmonti/2.x
Browse files Browse the repository at this point in the history
Added unit tests for VenusTestList.js
  • Loading branch information
rbakr committed Mar 16, 2015
2 parents 8185a52 + 048d808 commit 1fe3abf
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 46 deletions.
22 changes: 11 additions & 11 deletions .venus/templates/default.tl
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@
<h1><%= test.name %></h1>
<ul class="test-list">
<% if (test.status === 'PASSED') { %>
<li class="pass">
<ul>
<li class="summary">✓ <%= test.message %></li>
</ul>
</li>
<li class="pass">
<ul>
<li class="summary">✓ <%= test.message %></li>
</ul>
</li>
<% } else { %>
<li class="fail">
<ul>
<li class="summary">X <%= test.message %></li>
<li class="details"><pre><%= test.stackTrace %></pre></li>
</ul>
</li>
<li class="fail">
<ul>
<li class="summary">X <%= test.message %></li>
<li class="details"><pre><%= test.stackTrace %></pre></li>
</ul>
</li>
<% } %>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion js/runner_client/VenusClientLibrary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Venus
* Copyright 2013 LinkedIn
* Copyright 2015 LinkedIn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
31 changes: 21 additions & 10 deletions js/runner_client/VenusTestList.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,38 @@
**/

var VenusTestList = {

constants: {
PASSED : 'passed',
FAILED : 'failed',
PENDING : 'pending',
},

selectors: {
TEST_CLASS: '.test',
TEST_ID: '#test-',
LOADER: '#loading'
},
/**
* Shows the test result status ('failed', 'pending', 'passed')
*
* @param {Object} result
*/
postTestResults: function(result) {
var PASSED = 'passed',
FAILED = 'failed',
PENDING = 'pending',

testId = result.testId,
$el = $('#test-' + testId),
resultClass = (!result.done.failed) ? PASSED : FAILED;
var testId = result.testId,
$el = $(this.selectors["TEST_ID"] + testId),
resultClass = (!result.done.failed) ? this.constants["PASSED"] : this.constants["FAILED"];

// reset the status of the result
$el.removeClass([this.constants["PASSED"], this.constants["FAILED"], this.constants["PENDING"]].join(' '));

// reset the status of the results
$el.removeClass([PASSED, FAILED, PENDING].join(' '));
// update the status of the result
$el.addClass(resultClass);

// hide the loading indicator if there are no pending tests
if (!$('.test.' + PENDING).length) {
$('#loading').hide();
if (!$(this.selectors["TEST"] + '.' + this.constants.PENDING).length) {
$(this.selectors["LOADER"]).hide();
}
}
};
54 changes: 34 additions & 20 deletions js/runner_client/VenusUi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Venus
* Copyright 2013 LinkedIn
* Copyright 2015 LinkedIn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,14 +24,28 @@
function VenusUi(config) {
var self = this;

this.config = config;
this.$resultsView = $('#results-view');
this.$resultsButton = $('#results-button');
this.$sandboxView = $('#sandbox-view');
this.$sandboxButton = $('#sandbox-button');
this.$resultsTemplate = $('#results-template');
this.ACTIVE_CLASS = 'active';
this.SELECTED_CLASS = 'selected';
this._selectors = {
RESULTS_VIEW: '#results-view',
RESULTS_BUTTON: '#results-button',
RESULTS_TEMPLATE: '#results-template',
SANDBOX_VIEW: '#sandbox-view',
SANDBOX_BUTTON: '#sandbox-button',
SUCCESS: 'success',
FAILURE: 'error',
ACTIVE: 'active',
SELECTED: 'selected'
};

this._events = {
RESULTS: 'results'
}

this.config = config;
this.$resultsView = $(this._selectors.RESULTS_VIEW);
this.$resultsButton = $(this._selectors.RESULTS_BUTTON);
this.$resultsTemplate = $(this._selectors.RESULTS_TEMPLATE);
this.$sandboxView = $(this._selectors.SANDBOX_VIEW);
this.$sandboxButton = $(this._selectors.SANDBOX_BUTTON);

// show the test results if any and attach the event handlers
this.showResults();
Expand All @@ -44,27 +58,27 @@ function VenusUi(config) {
self.showSandbox();
});

$(document).on('results', self.onResults.bind(this));
$(document).on(self._events.RESULTS, self.onResults.bind(this));
}

/**
* Shows the test results
*/
VenusUi.prototype.showResults = function() {
this.$resultsView.addClass(this.ACTIVE_CLASS);
this.$sandboxView.removeClass(this.ACTIVE_CLASS);
this.$resultsButton.parent().addClass(this.SELECTED_CLASS);
this.$sandboxButton.parent().removeClass(this.SELECTED_CLASS);
this.$resultsView.addClass(this._selectors.ACTIVE);
this.$sandboxView.removeClass(this._selectors.ACTIVE);
this.$resultsButton.parent().addClass(this._selectors.SELECTED);
this.$sandboxButton.parent().removeClass(this._selectors.SELECTED);
};

/**
* Shows the sandbox fixture
*/
VenusUi.prototype.showSandbox = function() {
this.$resultsView.removeClass(this.ACTIVE_CLASS);
this.$sandboxView.addClass(this.ACTIVE_CLASS);
this.$resultsButton.parent().removeClass(this.SELECTED_CLASS);
this.$sandboxButton.parent().addClass(this.SELECTED_CLASS);
this.$resultsView.removeClass(this._selectors.ACTIVE);
this.$sandboxView.addClass(this._selectors.ACTIVE);
this.$resultsButton.parent().removeClass(this._selectors.SELECTED);
this.$sandboxButton.parent().addClass(this._selectors.SELECTED);
};

/**
Expand All @@ -87,14 +101,14 @@ VenusUi.prototype.onResults = function(e, results) {
* Shows that at least one test failed
*/
VenusUi.prototype.failNav = function() {
this.config.nav.addClass('error');
this.config.nav.addClass(this._selectors.FAILURE);
};

/**
* Shows that no error was encountered
*/
VenusUi.prototype.successNav = function() {
this.config.nav.addClass('success');
this.config.nav.addClass(this._selectors.SUCCESS);
};

/**
Expand Down
5 changes: 4 additions & 1 deletion locales/pirate.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,8 @@
"Ensures all other Venus processes are killed before starting": "Ensures all other Venus processes are killed before starting",
"Using environment ie8": "Using environment ie8",
"Using environment ie7": "Using environment ie7",
"Use https": "Use https"
"Use https": "Use https",
"The test file \"/Users/jasonbelmonti/Documents/Workspace/Development/Open_Source/venus.js/runner_client/\" could not be found": "The test file \"/Users/jasonbelmonti/Documents/Workspace/Development/Open_Source/venus.js/runner_client/\" could not be found",
"The test file \"/Users/jasonbelmonti/Documents/Workspace/Development/Open_Source/venus.js/runner_client\" could not be found": "The test file \"/Users/jasonbelmonti/Documents/Workspace/Development/Open_Source/venus.js/runner_client\" could not be found",
"VenusUi.spec.js: Includes specified in your annotations could not be found\n - ../polyfill/bind-polyfill.js\n": "VenusUi.spec.js: Includes specified in your annotations could not be found\n - ../polyfill/bind-polyfill.js\n"
}
8 changes: 5 additions & 3 deletions test/unit/client/.venus/config
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
basePaths: {
'runnerClient': '../../../../js/runner_client'
'runnerClient': '../../../../js/runner_client',
},

includes: {
dom: [
'../../../../js/underscore/underscore-min.js'
],
default: [
'../../../../js/jquery/jquery-1.10.0.min.js',
'mocks/venusTestList.js',
'mocks/venus.js'
]
}
}
}
53 changes: 53 additions & 0 deletions test/unit/client/runner_client/VenusTestList.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
/**
* @venus-include-group dom
* @venus-fixture fixtures/VenusTestList.fixture.html
* @venus-code runnerClient/VenusTestList.js
*/



describe('VenusTestList', function() {
var constants = {
testId: '01',
testPrefix: '#test-'
}
it('should expect on the window as VenusTestList', function() {
expect(window.VenusTestList).to.be.ok();
});

it('should remove \'pending\' class and add \'passed\' class to passed tests', function() {
var vtl = window.VenusTestList,
resultFixture = $(constants.testPrefix + constants.testId);
result = {
testId: constants.testId,
done: {
failed: false
}
};

vtl.postTestResults(result);
expect(resultFixture.hasClass(vtl.constants["PASSED"])).to.be(true);
expect(resultFixture.hasClass(vtl.constants["PENDING"])).to.be(false);
});

it('should remove \'pending\' class and add \'failed\' class to passed tests', function() {
var vtl = window.VenusTestList,
resultFixture = $(constants.testPrefix + constants.testId);
result = {
testId: constants.testId,
done: {
failed: true
}
};

vtl.postTestResults(result);
expect(resultFixture.hasClass(vtl.constants["FAILED"])).to.be(true);
expect(resultFixture.hasClass(vtl.constants["PENDING"])).to.be(false);
});

it('should hide the loading indicator if there are no pending tests', function() {
var vtl = window.VenusTestList,
loader = $(vtl.selectors["LOADER"]);
result = {
testId: constants.testId,
done: {
failed: true
}
};

vtl.postTestResults(result);
expect(loader.css('display')).to.be('none');
});
});
Loading

0 comments on commit 1fe3abf

Please sign in to comment.