Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Files that were hidden by gitignore

Mike McGann9cf98a6482f1
diff --git a/test/lib/TestSuite.js b/test/lib/TestSuite.js
new file mode 100644
index 000000000..6862994d3
--- /dev/null
+++ b/test/lib/TestSuite.js
@@ -0,0 +1,31 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+/**
+ * Namespace: TestSuite
+ * Harness and testing utilities.
+ */
+var TestSuite = {};
+
+/*
+ * Inform JsMockito that JsTestDriver is being used so it will know when
+ * to clean up.
+ */
+JsHamcrest.Integration.JsTestDriver();
+JsMockito.Integration.JsTestDriver();
+
+/**
+ * Required elements that must appear in the document
+ */
+$(function() {
+ $(document.body).append("<div id='map'></div>");
+});
+
diff --git a/test/lib/TestSuite/Patcher.js b/test/lib/TestSuite/Patcher.js
new file mode 100644
index 000000000..bc424a3da
--- /dev/null
+++ b/test/lib/TestSuite/Patcher.js
@@ -0,0 +1,101 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+/**
+ * Class: TestSuite.Patcher
+ * Patches a series of mock objects which can be undone later. Create a
+ * patcher object, call <apply> in setUp to patch the code with each mock
+ * object, and then call <undo> in the tearDown to remove all patches.
+ *
+ * Example:
+ * This test checks to make sure console.error is invoked when an error
+ * is handled.
+ *
+ * (begin code)
+ * var patcher: null,
+ *
+ * setUp: function() {
+ * patcher = TestSuite.Patcher();
+ * patcher.apply("console.error", mockFunction());
+ * },
+ *
+ * tearDown: function() {
+ * patcher.undo();
+ * },
+ *
+ * testLog: function() {
+ * Worldview.error("This is an error");
+ * verify(console.error)("This is an error");
+ * },
+ * (end code)
+ *
+ * Constructor: Patcher
+ * Creates a new instance.
+ */
+TestSuite.Patcher = function() {
+
+ var self = {};
+
+ // Stack of patches that have been applied.
+ var patches = [];
+
+ /**
+ * Method: apply
+ * Patches an object with a mock.
+ *
+ * Parameters:
+ * - path: String name of the object to patch (e.g., "Worldview.log")
+ * - mock: The object to substitute.
+ *
+ * Throws:
+ * An exception if the object to patch has already been patched.
+ */
+ self.apply = function(path, mock) {
+
+ var parent = null;
+ var node = window;
+ var names = path.split(".");
+
+ for ( var i = 0; i < names.length; i++ ) {
+ var name = names[i];
+ parent = node;
+ if ( parent[name] === undefined ) {
+ throw "In " + path + ", " + name + " is undefined";
+ }
+ node = parent[name];
+ }
+
+ if ( mock !== undefined ) {
+ mock.___PATCH = true;
+ }
+
+ var real = parent[name];
+ parent[name] = mock;
+ patches.push({
+ parent: parent,
+ name: name,
+ real: real
+ });
+ }
+
+ /**
+ * Method: undo
+ * Removes all patches.
+ */
+ self.undo = function() {
+ while ( patches.length > 0 ) {
+ var patch = patches.pop();
+ patch.parent[patch.name] = patch.real;
+ }
+ }
+
+ return self;
+}
diff --git a/test/lib/TestSuite/Tests.js b/test/lib/TestSuite/Tests.js
new file mode 100644
index 000000000..85eb4a62c
--- /dev/null
+++ b/test/lib/TestSuite/Tests.js
@@ -0,0 +1,76 @@
+/*
+ * NASA Worldview
+ *
+ * This code was originally developed at NASA/Goddard Space Flight Center for
+ * the Earth Science Data and Information System (ESDIS) project.
+ *
+ * Copyright (C) 2013 United States Government as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All Rights Reserved.
+ */
+
+/**
+ * Class: TestSuite.Tests
+ * Wrapper for defining test cases.
+ *
+ * Normally, the tearDown method is not called when there is an error running
+ * a test case. Use this instead to ensure that tearDown is always called if
+ * defined.
+ *
+ * Example:
+ * (begin code)
+ * TestCase("Foo", TestSuite.Tests({
+ *
+ * done: null,
+ *
+ * setUp: function() {
+ * done = false;
+ * },
+ *
+ * tearDown: function() {
+ * done = true;
+ * },
+ *
+ * testItem: function() {
+ * // Done should always be false at the start of a test
+ * assertFalse(done);
+ * },
+ * }));
+ * (end code)
+ *
+ * Constructor: Tests
+ * Creates a new instance
+ *
+ * Parameters:
+ * testCases - Object containing the test case functions to execute.
+ */
+TestSuite.Tests = function(testCases) {
+
+ var self = {};
+
+ // Wrap the actual function call for the test case and call tearDown
+ // if an exception is thrown
+ var wrapper = function(target) {
+ return function() {
+ try {
+ target();
+ } catch ( message ) {
+ if ( self.tearDown ) {
+ self.tearDown();
+ }
+ throw message;
+ }
+ }
+ };
+
+ for ( property in testCases ) {
+ if ( property === "setUp" || property === "tearDown" ) {
+ // Simply pass these through
+ self[property] = testCases[property];
+ } else if ( typeof testCases[property] === "function" ) {
+ self[property] = wrapper(testCases[property]);
+ }
+ }
+
+ return self;
+}