Permalink
Browse files

added more tests; added error handling

  • Loading branch information...
1 parent 5a715b6 commit ad1f5c22c303172035aa9afbd37579d69e812629 @Joe8Bit committed Aug 4, 2012
Oops, something went wrong.
View
@@ -24,7 +24,7 @@
<!-- More ideas for your <head> here: h5bp.com/d/head-Tips -->
<script src="../lib/jquery.min.js"></script>
- <script src="../dist/jquery.github.min.js"></script>
+ <script src="../src/jquery.github.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#insert-here").github();
View
@@ -24,7 +24,7 @@ module.exports = function(grunt) {
},
jasmine: {
all: {
- src:['specs/SpecRunner.html'],
+ src:['specs/*.html'],
errorReporting: true,
timeout: 20000
}
@@ -53,6 +53,6 @@
</head>
<body>
- <div id="insert-here" style="display: none"></div>
+ <div id="insert-here"></div>
</body>
</html>
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+ <title>Jasmine Spec Runner</title>
+
+ <link rel="shortcut icon" type="image/png" href="lib/jasmine-1.2.0/jasmine_favicon.png">
+ <link rel="stylesheet" type="text/css" href="lib/jasmine-1.2.0/jasmine.css">
+
+ <script type="text/javascript" src="../lib/jquery.min.js"></script>
+
+ <script type="text/javascript" src="lib/jasmine-1.2.0/jasmine.js"></script>
+ <script type="text/javascript" src="lib/jasmine-1.2.0/jasmine-html.js"></script>
+ <script type="text/javascript" src="helpers/jasmine-helper.js"></script>
+ <script type="text/javascript" src="helpers/jasmine-jquery-1.3.1.js"></script>
+
+ <!-- include source files here... -->
+ <script type="text/javascript" src="spec/github_error.js"></script>
+
+ <!-- include spec files here... -->
+ <script type="text/javascript" src="../src/jquery.github.js"></script>
+ <link rel="stylesheet" type="text/css" href="../src/github.css">
+
+ <script type="text/javascript">
+ (function() {
+ var jasmineEnv = jasmine.getEnv();
+ jasmineEnv.updateInterval = 1000;
+
+ var htmlReporter = new jasmine.HtmlReporter();
+
+ jasmineEnv.addReporter(htmlReporter);
+
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+
+ var currentWindowOnload = window.onload;
+
+ window.onload = function() {
+ if (currentWindowOnload) {
+ currentWindowOnload();
+ }
+ execJasmine();
+ };
+
+ function execJasmine() {
+ jasmineEnv.execute();
+ }
+
+ })();
+ </script>
+
+</head>
+
+<body>
+ <div id="insert-here"></div>
+</body>
+</html>
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+ <title>Jasmine Spec Runner</title>
+
+ <link rel="shortcut icon" type="image/png" href="lib/jasmine-1.2.0/jasmine_favicon.png">
+ <link rel="stylesheet" type="text/css" href="lib/jasmine-1.2.0/jasmine.css">
+
+ <script type="text/javascript" src="../lib/jquery.min.js"></script>
+
+ <script type="text/javascript" src="lib/jasmine-1.2.0/jasmine.js"></script>
+ <script type="text/javascript" src="lib/jasmine-1.2.0/jasmine-html.js"></script>
+ <script type="text/javascript" src="helpers/jasmine-helper.js"></script>
+ <script type="text/javascript" src="helpers/jasmine-jquery-1.3.1.js"></script>
+
+ <!-- include source files here... -->
+ <script type="text/javascript" src="spec/github_extended-info.js"></script>
+
+ <!-- include spec files here... -->
+ <script type="text/javascript" src="../src/jquery.github.js"></script>
+ <link rel="stylesheet" type="text/css" href="../src/github.css">
+
+ <script type="text/javascript">
+ (function() {
+ var jasmineEnv = jasmine.getEnv();
+ jasmineEnv.updateInterval = 1000;
+
+ var htmlReporter = new jasmine.HtmlReporter();
+
+ jasmineEnv.addReporter(htmlReporter);
+
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+
+ var currentWindowOnload = window.onload;
+
+ window.onload = function() {
+ if (currentWindowOnload) {
+ currentWindowOnload();
+ }
+ execJasmine();
+ };
+
+ function execJasmine() {
+ jasmineEnv.execute();
+ }
+
+ })();
+ </script>
+
+</head>
+
+<body>
+ <div id="insert-here"></div>
+</body>
+</html>
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+ <title>Jasmine Spec Runner</title>
+
+ <link rel="shortcut icon" type="image/png" href="lib/jasmine-1.2.0/jasmine_favicon.png">
+ <link rel="stylesheet" type="text/css" href="lib/jasmine-1.2.0/jasmine.css">
+
+ <script type="text/javascript" src="../lib/jquery.min.js"></script>
+
+ <script type="text/javascript" src="lib/jasmine-1.2.0/jasmine.js"></script>
+ <script type="text/javascript" src="lib/jasmine-1.2.0/jasmine-html.js"></script>
+ <script type="text/javascript" src="helpers/jasmine-helper.js"></script>
+ <script type="text/javascript" src="helpers/jasmine-jquery-1.3.1.js"></script>
+
+ <!-- include source files here... -->
+ <script type="text/javascript" src="spec/github_show-followers.js"></script>
+
+ <!-- include spec files here... -->
+ <script type="text/javascript" src="../src/jquery.github.js"></script>
+ <link rel="stylesheet" type="text/css" href="../src/github.css">
+
+ <script type="text/javascript">
+ (function() {
+ var jasmineEnv = jasmine.getEnv();
+ jasmineEnv.updateInterval = 1000;
+
+ var htmlReporter = new jasmine.HtmlReporter();
+
+ jasmineEnv.addReporter(htmlReporter);
+
+ jasmineEnv.specFilter = function(spec) {
+ return htmlReporter.specFilter(spec);
+ };
+
+ var currentWindowOnload = window.onload;
+
+ window.onload = function() {
+ if (currentWindowOnload) {
+ currentWindowOnload();
+ }
+ execJasmine();
+ };
+
+ function execJasmine() {
+ jasmineEnv.execute();
+ }
+
+ })();
+ </script>
+
+</head>
+
+<body>
+ <div id="insert-here"></div>
+</body>
+</html>
View
@@ -66,8 +66,37 @@ describe("Github Widget", function() {
it("by displaying extended user information when hovering on their avatar", function() {
$('#ghw-user a').trigger('mouseover');
expect($("#ghw-extended-user-info")).toBeVisible();
- $('#ghw-user a').trigger('mouseout');
- expect($("#ghw-extended-user-info")).not.toBeVisible();
+ });
+
+ it("by displaying a repo description when hovering on the repo title", function() {
+ $('.ghw-title a').trigger('mouseover');
+ expect($(".ghw-github-tooltip-content")).toBeVisible();
+ });
+
+ it("by displaying extened info about a repos forks when hovering", function() {
+ $('.ghw-forks:first-child').trigger('mouseover');
+ expect($(".ghw-forks:first-child .ghw-github-tooltip-content")).toBeVisible();
+ expect($(".ghw-forks:first-child .ghw-github-tooltip-content")).not.toBeEmpty();
+ });
+
+ });
+
+ describe("should load the correct information from Github for the default user", function() {
+
+ it("by displaying the correct user name", function() {
+ expect($("#ghw-github-user-data h2 a").text()).toEqual("JoePettersson");
+ });
+
+ it("by displaying the correct number of followers", function() {
+ expect(parseFloat($("#ghw-current-followers").text())).toBeGreaterThan(1);
+ });
+
+ it("by displaying one of the correct repos", function() {
+ expect($(".ghw-title:first-child a").text()).toContain("A-simple-jQuery-powered-image-slider");
+ });
+
+ it("by containging the correct descrption for one of the repos", function() {
+ expect($(".ghw-title:first-child a").attr("data-description")).toContain("<p>A-simple-jQuery-powered-image-slider</p>A simple but elegant image slider based on a design by Orman Clark");
});
});
@@ -0,0 +1,18 @@
+describe("Github Widget", function() {
+
+ // Instantiate our default widget
+ $(document).ready(function(){
+ $("#insert-here").github({
+ user: "alsjq9eq"
+ });
+ });
+
+ describe("should behave in a predictable way when errors happen", function() {
+
+ it("by displaying a message to the user when a bad user is requested", function() {
+ expect($("#ghw-github-user-data h2 a").text()).toContain("User not found");
+ });
+
+ });
+
+});
@@ -0,0 +1,18 @@
+describe("Github Widget", function() {
+
+ // Instantiate our default widget
+ $(document).ready(function(){
+ $("#insert-here").github({
+ show_extended_info: false
+ });
+ });
+
+ describe("should not display", function() {
+
+ it("extended user info when the option is set to false", function() {
+ expect($("#ghw-extended-user-info")).not.toExist();
+ });
+
+ });
+
+});
@@ -0,0 +1,18 @@
+describe("Github Widget", function() {
+
+ // Instantiate our default widget
+ $(document).ready(function(){
+ $("#insert-here").github({
+ show_follows: false
+ });
+ });
+
+ describe("should not display", function() {
+
+ it("a users followers when the option is set to false", function() {
+ expect($("#ghw-current-followers")).not.toExist();
+ });
+
+ });
+
+});
View
@@ -19,6 +19,8 @@
this.options = $.extend({}, defaults, options);
// Instantiate our init function, it inherits the options object, so we don't need to explicitly pass it
this.init();
+
+ this.errorType = '';
}
// Our Prototype!
@@ -99,10 +101,16 @@
markup += '</div>';
}
markup += '<div id="ghw-github-user-data">';
- markup += '<h2><a href="' + user.html_url + '">' + user.login + '</a></h2>';
+ markup += '<h2><a href="' + user.html_url + '">';
+ if (typeof user.login !== "undefined") {
+ markup += user.login;
+ } else {
+ markup += 'User not found';
+ }
+ markup += '</a></h2>';
markup += '<a href="' + user.html_url + '" id="ghw-header-total-repos">' + user.public_repos + ' repos</a>';
// Check if the option to show followers is set to true, if not, don't show it
- if (options.show_follows === true) {
+ if (options.show_follows === true && typeof user.login !== "undefined") {
markup += ' | <a href="https://github.com/' + user.login.toLowerCase() + '/followers" id="ghw-current-followers">' + user.followers + ' followers</a>';
}
markup += '</div>';

0 comments on commit ad1f5c2

Please sign in to comment.