Permalink
Browse files

added jasmine but I'm getting a strange error

  • Loading branch information...
1 parent bf28105 commit 6c66dd3708e0ed6ce921ce8a46ef7831323e5d28 @cheezy committed May 1, 2011
View
@@ -11,7 +11,6 @@ gem 'jquery-rails'
group :test do
gem 'rspec'
- gem 'jasmine'
gem 'factory_girl_rails'
group :cucumber do
@@ -24,4 +23,5 @@ end
group :development, :test do
gem 'rspec-rails'
+ gem 'jasmine'
end
View
@@ -130,8 +130,6 @@ GEM
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.27)
- watir-webdriver (0.2.3)
- selenium-webdriver (>= 0.2.0)
will_paginate (3.0.pre2)
xpath (0.1.4)
nokogiri (~> 1.3)
@@ -151,5 +149,4 @@ DEPENDENCIES
rspec
rspec-rails
sqlite3-ruby
- watir-webdriver
will_paginate (>= 3.0pre2)
@@ -17,13 +17,11 @@
<td colspan="2"></td>
<td><%= check_box_tag 'toy'%> Chew Toy ($8.99)</td>
<td><div class="toy-amount"></div></td>
- <td></td>
</tr>
<tr>
<td colspan="2"></td>
<td><%= check_box_tag 'carrier'%> Travel Carrier ($39.99)</td>
<td><div class="carrier-amount"></div></td>
- <td></td>
</tr>
<tr>
<td colspan="2"></td>
@@ -1,50 +1,63 @@
-$(function() {
+var Adoption = function() {
+ jQuery.extend(this);
$('#collar').live('click', function(event) {
- handleClickEvent(event, '.collar-amount', 19.99);
+ Adoption.prototype.handleClickEvent(event, '.collar-amount', 19.99);
});
$('#toy').live('click', function(event) {
- handleClickEvent(event, '.toy-amount', 8.99);
+ Adoption.prototype.handleClickEvent(event, '.toy-amount', 8.99);
});
$('#carrier').live('click', function(event) {
- handleClickEvent(event, '.carrier-amount', 39.99);
+ Adoption.prototype.handleClickEvent(event, '.carrier-amount', 39.99);
});
$('#vet').live('click', function(event) {
- handleClickEvent(event, '.vet-amount', 69.99);
+ Adoption.prototype.handleClickEvent(event, '.vet-amount', 69.99);
});
+}
+
+Adoption.prototype = {
+ handleClickEvent: function(event, cls, price) {
+ if (event.target.checked) {
+ $(event.target).parent().parent().find(cls).first().html('$'+price);
+ Adoption.prototype.increaseCartTotal(price);
+ } else {
+ $(event.target).parent().parent().find(cls).first().empty();
+ Adoption.prototype.decreaseCartTotal(price);
+ }
+ },
+
+ increaseCartTotal: function(amount) {
+ var priceCell = $('.total_cell').children().first();
+ var total = Adoption.prototype.cartTotal(priceCell);
+ total = total + amount;
+ priceCell.html("$" + Adoption.prototype.roundNumber(total, 2));
+ },
+
+ decreaseCartTotal: function(amount) {
+ Adoption.prototype.increaseCartTotal(-1*amount);
+ },
+
+
+ cartTotal: function(priceCell) {
+ var priceCell = $('.total_cell').children().first();
+ var cartTotal = priceCell.html();
+ var len = cartTotal.length;
+ return parseFloat(cartTotal.substr(1, len));
+ },
+
+ roundNumber: function(number, decimalPlaces) {
+ return Math.round(number * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces);
+ }
+};
-});
+var adoption;
-var handleClickEvent = function(event, cls, price) {
- if (event.target.checked) {
- $(event.target).parent().parent().find(cls).first().html('$'+price);
- increaseCartTotal(price);
- } else {
- $(event.target).parent().parent().find(cls).first().empty();
- decreaseCartTotal(price);
- };
-};
+$(function() {
+ adoption = new Adoption();
+});
-var increaseCartTotal = function(amount) {
- var priceCell = $('.total_cell').children().first();
- var total = cartTotal(priceCell);
- total = total + amount;
- priceCell.html("$" + roundNumber(total, 2));
-};
-var decreaseCartTotal = function(amount) {
- increaseCartTotal(-1*amount);
-};
-var cartTotal = function(priceCell) {
- var priceCell = $('.total_cell').children().first();
- var cartTotal = priceCell.html();
- var len = cartTotal.length;
- return parseFloat(cartTotal.substr(1, len));
-};
-var roundNumber = function(number, decimalPlaces) {
- return Math.round(number * Math.pow(10, decimalPlaces)) / Math.pow(10, decimalPlaces);
-};
@@ -0,0 +1,24 @@
+describe("Adoption", function() {
+ var adoption;
+
+ beforeEach(function() {
+ loadFixtures("adoption.html");
+ adoption = new Adoption();
+ });
+
+ it("should add the Collar & Leash to the total when it is selected", function() {
+ var cartTotal = $('.total_cell').children().first().html();
+ expect(cartTotal).toEqual("$34.95");
+ expect($('#collar')).not.toBeChecked();
+ $('#collar').click();
+ expect($('#collar')).toBeChecked();
+
+// I'm getting two click events each with the target unchecked
+
+// expect($('.total_cell').children().first()).toHaveHtml("$34.95");
+// expect($('.collar-amount')).toHaveHtml("19.99");
+// cartTotal = $('.total_cell').children().first().html();
+// expect(cartTotal).toEqual("$54.94");
+ });
+
+});
@@ -0,0 +1,37 @@
+<table>
+ <tr>
+ <td><img alt="Brook" src="/images/Brook.jpg?1287323739" width="30" /></td>
+ <td><h2>Brook:</h2></td>
+ <td><h2>Female - Golden Retriever</h2></td>
+ <td class="item_price"><h2>$34.95</h2></td>
+ </tr>
+ <tr>
+ <td colspan="2"></td>
+ <td><h3>Additional Products/Services</h3></td>
+ </tr>
+ <tr>
+ <td colspan="2"></td>
+ <td><input id="collar" name="collar" type="checkbox" value="1" /> Colllar & Leash ($19.99)</td>
+ <td><div class="collar-amount"></div></td>
+ </tr>
+ <tr>
+ <td colspan="2"></td>
+ <td><input id="toy" name="toy" type="checkbox" value="1" /> Chew Toy ($8.99)</td>
+ <td><div class="toy-amount"></div></td>
+ </tr>
+ <tr>
+ <td colspan="2"></td>
+ <td><input id="carrier" name="carrier" type="checkbox" value="1" /> Travel Carrier ($39.99)</td>
+ <td><div class="carrier-amount"></div></td>
+ </tr>
+ <tr>
+ <td colspan="2"></td>
+ <td><input id="vet" name="vet" type="checkbox" value="1" /> First Vet Visit ($69.99)</td>
+ <td><div class="vet-amount"></div></td>
+ </tr>
+ <tr class="total_line">
+ <td></td>
+ <td colspan="2"><h2>Total</h2></td>
+ <td class="total_cell"><h2>$34.95</h2></td>
+ </tr>
+</table>
No changes.
@@ -0,0 +1,9 @@
+beforeEach(function() {
+ this.addMatchers({
+ toBePlaying: function(expectedSong) {
+ var player = this.actual;
+ return player.currentlyPlayingSong === expectedSong
+ && player.isPlaying;
+ }
+ })
+});
Oops, something went wrong.

0 comments on commit 6c66dd3

Please sign in to comment.