From e53702a79f9a8b9bf25220e22b682786b211786a Mon Sep 17 00:00:00 2001 From: Julie Nguyen Date: Tue, 11 Feb 2020 17:15:45 +0000 Subject: [PATCH] created test for adding products to cart --- spec/features/add_to_cart_spec.rb | 38 +++++++++++++++++++++++++++ spec/features/home_page_spec.rb | 4 +-- spec/features/product_details_spec.rb | 35 ++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 spec/features/add_to_cart_spec.rb create mode 100644 spec/features/product_details_spec.rb diff --git a/spec/features/add_to_cart_spec.rb b/spec/features/add_to_cart_spec.rb new file mode 100644 index 0000000..9bb2ffe --- /dev/null +++ b/spec/features/add_to_cart_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +RSpec.feature "Item is added to cart", type: :feature, js: true do + + # SETUP + before :each do + # create the category in our database + @category = Category.create! name: 'Apparel' + + # creates the product in our database + @category.products.create!( + name: "Men's T-Shirt", + description: "This is a men's t-shirt, for everyone", + image: open_asset('apparel1.jpg'), + quantity: 10, + price: 64.99 + ) + end + + scenario "They see all products on the homepage" do + # This is the homepage + visit root_path + + # The cart should start as empty + expect(page).to have_content "My Cart (0)", count: 1 + # save_and_open_screenshot + + + # clicks 'add' to add the product to the cart + click_button 'Add' + + # expects product page to display when clicked + expect(page).to have_content "My Cart (1)", count: 1 + # save_and_open_screenshot + end + + +end diff --git a/spec/features/home_page_spec.rb b/spec/features/home_page_spec.rb index 4c35510..9da86c0 100644 --- a/spec/features/home_page_spec.rb +++ b/spec/features/home_page_spec.rb @@ -21,9 +21,9 @@ # This is the act visit root_path - # Takes a screenshot - save_and_open_screenshot + # Takes a screenshot + # save_and_open_screenshot # This is to verify expect(page).to have_css 'article.product', count: 10 end diff --git a/spec/features/product_details_spec.rb b/spec/features/product_details_spec.rb new file mode 100644 index 0000000..abab7b6 --- /dev/null +++ b/spec/features/product_details_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +RSpec.feature "Visitor navigates to the product page", type: :feature, js: true do + + # SETUP + before :each do + # create the category in our database + @category = Category.create! name: 'Apparel' + + # creates the product in our database + @category.products.create!( + name: "Men's T-Shirt", + description: "This is a men's t-shirt, for everyone", + image: open_asset('apparel1.jpg'), + quantity: 10, + price: 64.99 + ) + end + + scenario "They see all products on the homepage" do + # This is the act + visit root_path + + click_link 'Details' + + # expects product page to display when clicked + expect(page).to have_content "Apparel ยป Men's T-Shirt", count: 1 + + + # Takes a screenshot + # save_and_open_screenshot + end + + +end