Skip to content

Commit

Permalink
created test for adding products to cart
Browse files Browse the repository at this point in the history
  • Loading branch information
julienguyenn committed Feb 11, 2020
1 parent 7a4c678 commit e53702a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
38 changes: 38 additions & 0 deletions spec/features/add_to_cart_spec.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions spec/features/home_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions spec/features/product_details_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e53702a

Please sign in to comment.