Skip to content

Commit

Permalink
Issue privly#191: Unit tests for SplitImage.
Browse files Browse the repository at this point in the history
  • Loading branch information
vatsalj committed Mar 12, 2015
1 parent 8a59dea commit 6aeda38
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 28 deletions.
16 changes: 13 additions & 3 deletions SplitImage/js/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ function save(imageURL) {
*/
function initializeApplication() {

//
// Add event listerner on hidden input field
document.getElementById('files').addEventListener('change',
handleFileSelect, false);

// Handle drag and drop
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
Expand All @@ -78,4 +78,14 @@ function initializeApplication() {
callbacks.pendingLogin();
}

document.addEventListener('DOMContentLoaded', initializeApplication);
// Initialize the application
document.addEventListener('DOMContentLoaded',
function() {

// Don't start the script if it is running in a Headless
// browser
if( document.getElementById("logout_link") ) {
initializeApplication();
}
}
);
38 changes: 23 additions & 15 deletions SplitImage/js/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,30 @@ function encryptBeforeUpdate(evt, callback) {
state.isInlineEdit = false;
}

// Make the Tooltip display this App's name.
privlyTooltip.appName = "SplitImage";
function initializeApplication() {

// Make the Tooltip display this App's name.
privlyTooltip.appName = "SplitImage";

var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);

// Start the app
callbacks.pendingContent(processResponseContent);

// Replace the update function so we never send the cleartext server side.
callbacks.update = encryptBeforeUpdate;
}

// Initialize the application
document.addEventListener('DOMContentLoaded',
function(){

// Handle drag and drop on update
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);

// Start the app
callbacks.pendingContent(processResponseContent);
document.addEventListener('DOMContentLoaded',
function() {

// Don't start the script if it is running in a Headless
// browser
if( document.getElementById("logout_link") ) {
initializeApplication();
}
}
);

// Replace the update function so we never send the cleartext server side.
callbacks.update = encryptBeforeUpdate;
42 changes: 39 additions & 3 deletions SplitImage/test/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,47 @@
* This spec is managed by the Jasmine testing library.
**/


describe ("SplitImage New Suite", function() {

var new_fixtures = [
'<a class="home_domain">Privly</a>',
'<a class="legal_nav">Legal</a>',
'<a class="account_url">Account<a/>',
'<a id="logout_link">Logout</a>',
'<ul><li class="mobile_hide"></li></ul>',
'<div id="drop_zone"></div>',
'<input type="file" id="files" multiple />',
'<button id="save"></button>'
]

beforeEach(function() {
for (var i=0; i<new_fixtures.length; i++) {
document.body.innerHTML += new_fixtures[i];
}
});

afterEach(function() {
document.body.innerHTML = '';
});

it("initializes properly", function() {
// pass
// todo, this should be called automatically but I don't believe
// the DOMContentLoaded event is being fired in this testing environment
initializeApplication();

var domain = privlyNetworkService.contentServerDomain();

if( privlyNetworkService.platformName() !== "HOSTED" ) {

// if the app is not hosted, the user should first be directed to the
// content_server page of the app bundle.
expect($(".home_domain").attr("href")).toBe('../Help/content_server.html');
} else {

// if the application is hosted, the URL should connect to the domain's root
expect($(".home_domain").attr("href")).toBe("http://" + window.location.href.split("/")[2]);
}
expect(domain.split("/")[2]).toBe($(".home_domain").text());
});

});

43 changes: 38 additions & 5 deletions SplitImage/test/show.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
/**
* @fileOverview tests.js Gives testing code for the show page.
* @fileOverview show.js Gives testing code for the show page.
* This spec is managed by the Jasmine testing library.
**/

describe ("SplitImaage Show Suite", function() {

describe ("SplitImage Show Suite", function() {

var show_fixtures = [
'<a class="home_domain">Privly</a>',
'<a id="logout_link">Logout</a>',
'<div id="drop_zone"></div>',
'<input type="file" id="files" multiple />',
'<button id="update"></button>',
]

beforeEach(function() {
for (var i=0; i<show_fixtures.length; i++) {
document.body.innerHTML += show_fixtures[i];
}
});

afterEach(function() {
document.body.innerHTML = '';
});

it("initializes properly", function() {
// pass

initializeApplication();

var domain = privlyNetworkService.contentServerDomain();

if( privlyNetworkService.platformName() !== "HOSTED" ) {

// if the app is not hosted, the user should first be directed to the
// content_server page of the app bundle.
expect($(".home_domain").attr("href")).toBe('../Help/content_server.html');
} else {

// if the application is hosted, the URL should connect to the domain's root
expect($(".home_domain").attr("href")).toBe("http://" + window.location.href.split("/")[2]);
}
expect(domain.split("/")[2]).toBe($(".home_domain").text());
});

});

4 changes: 2 additions & 2 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"devDependencies": {
"karma": "^0.12.31",
"karma-chrome-launcher": "^0.1.7",
"karma-coverage": "~0.2",
"karma-firefox-launcher": "^0.1.4",
"karma-html2js-preprocessor": "^0.1.0",
"karma-jasmine": "^0.3.5",
"karma-safari-launcher": "^0.1.1",
"karma-sauce-launcher": "^0.2.10",
"karma-coverage": "~0.2"
"karma-sauce-launcher": "^0.2.10"
}
}
2 changes: 2 additions & 0 deletions test/run_each.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ runTest 'shared/javascripts/privly-web/new.js,PlainPost/js/new.js,PlainPost/test
runTest 'shared/javascripts/privly-web/show.js,PlainPost/js/show.js,PlainPost/test/show.js'
runTest 'shared/javascripts/privly-web/new.js,Message/js/base64.js,Message/js/rawdeflate.js,Message/js/rawinflate.js,Message/js/zerobin.js,Message/js/new.js,Message/test/new.js,Message/test/zerobin.js'
runTest 'shared/javascripts/privly-web/show.js,Message/js/base64.js,Message/js/rawdeflate.js,Message/js/rawinflate.js,Message/js/zerobin.js,Message/js/show.js,Message/test/show.js,Message/test/zerobin.js'
runTest 'shared/javascripts/privly-web/new.js,SplitImage/js/file_processing.js,SplitImage/js/new.js,SplitImage/test/new.js'
runTest 'shared/javascripts/privly-web/show.js,Message/js/base64.js,Message/js/rawdeflate.js,Message/js/rawinflate.js,Message/js/zerobin.js,SplitImage/js/file_processing.js,SplitImage/js/show.js,SplitImage/test/show.js'

if [ ! $ISFAIL -eq 0 ]
then
Expand Down

0 comments on commit 6aeda38

Please sign in to comment.