Created
October 24, 2013 22:59
-
-
Save chyld/7146607 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test('Add Items to Shopping Cart', function(){ | |
expect(1); | |
createTestProduct('iPad Air', 'ipad-air.png', 1, 500, 10); // sale - 450 | |
createTestProduct('iPhone 5s', 'iphone-5s.png', 0.5, 200, 0); // sale - 200 | |
createTestProduct('Apple TV', 'apple-tv.png', 1.5, 100, 5); // sale - 95 | |
createTestCustomer('Bob', 'bob.png', true); | |
createTestCustomer('Sally', 'sally.png', false); | |
$('select#select-customer').val('Sally'); | |
$('select#select-customer').trigger('change'); | |
// 2 iphone 5s | |
$('#products tr:nth-child(3) .product-image img').trigger('click'); | |
$('#products tr:nth-child(3) .product-image img').trigger('click'); | |
// 1 ipad air | |
$('#products tr:nth-child(2) .product-image img').trigger('click'); | |
// 1 apple tv | |
$('#products tr:nth-child(4) .product-image img').trigger('click'); | |
equal(db.cart.customer.name, 'Sally', 'shopping cart should belong to sally'); | |
ok(db.cart.customer instanceof Customer, 'sally should be a Customer'); | |
equal(db.cart.products.length, 4, 'should be 4 items in shopping cart'); | |
ok(db.cart.products[0] instanceof Product, 'item in products should be a Product'); | |
equal(db.cart.totals.count, 4, 'should have choosen 4 items'); | |
equal(db.cart.totals.amount, 945, 'amount total should be 945'); | |
equal(db.cart.totals.weight, 3.5, 'weight total should be 3.5'); | |
// domestic $0.50 lb / international $1.50 lb | |
equal(db.cart.totals.shipping, 5.25, 'shipping total should be 5.25'); | |
equal(db.cart.totals.grand, 950.25, 'amount total should be 945'); | |
equal($('#cart thead tr').length, 1, 'should be a header'); | |
equal($('#cart tfoot tr').length, 1, 'should be a footer'); | |
equal($('#cart tbody tr').length, 3, 'should be 3 items in body'); | |
equal($('#cart tbody tr:nth-child(1) .product-name').text(), 'iPhone 5s', 'name should be iphone 5s'); | |
equal($('#cart tbody tr:nth-child(1) .product-count').text(), '2', 'count should be 2'); | |
equal($('#cart tfoot tr #cart-count').text(), '4', 'should have 4 items in cart'); | |
equal($('#cart tfoot tr #cart-amount').text(), '$945.00', 'should have $945.00 in amount'); | |
equal($('#cart tfoot tr #cart-weight').text(), '3.5 lbs', 'should have 3.5 lbs for weight'); | |
equal($('#cart tfoot tr #cart-shipping').text(), '$5.25', 'should have $5.25 for shipping'); | |
equal($('#cart tfoot tr #cart-grand').text(), '$950.25', 'should have $950.25 for grand'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment