generated from mailsg/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
411 additions
and
416 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,71 @@ | ||
require 'rails_helper' | ||
|
||
|
||
RSpec.describe 'categories page', type: :system do | ||
include Devise::Test::IntegrationHelpers | ||
|
||
let!(:user1) do | ||
User.create!( | ||
name: 'Sandeep Ghosh', | ||
email: '[email protected] ', | ||
password: 'pass1234', | ||
password_confirmation: 'pass1234', | ||
confirmed_at: Time.now | ||
include Devise::Test::IntegrationHelpers | ||
|
||
let!(:user1) do | ||
User.create!( | ||
name: 'Sandeep Ghosh', | ||
email: '[email protected] ', | ||
password: 'pass1234', | ||
password_confirmation: 'pass1234', | ||
confirmed_at: Time.now | ||
) | ||
end | ||
|
||
let!(:categories) do | ||
[ | ||
Category.create!( | ||
user: user1, | ||
name: 'Rent', | ||
icon: 'https://images.unsplash.com/photo-1560518883-ce09059eeffa?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8cmVudGFsJTIwcHJvcGVydHl8ZW58MHx8MHx8fDA%3D&w=1000&q=80' | ||
), | ||
Category.create!( | ||
user: user1, | ||
name: 'OTT Subscriptions', | ||
icon: 'https://www.flickonclick.com/wp-content/uploads/2022/07/10-best-OTT-Subscription-plans-in-India-that-are-worth-buying-in-2022.jpg' | ||
) | ||
] | ||
end | ||
|
||
describe 'show correct categories for user' do | ||
before(:example) do | ||
sign_in user1 | ||
visit categories_path | ||
end | ||
|
||
let!(:categories) do | ||
[ | ||
Category.create!( | ||
user: user1, | ||
name: 'Rent', | ||
icon: 'https://images.unsplash.com/photo-1560518883-ce09059eeffa?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8cmVudGFsJTIwcHJvcGVydHl8ZW58MHx8MHx8fDA%3D&w=1000&q=80' | ||
), | ||
Category.create!( | ||
user: user1, | ||
name: 'OTT Subscriptions', | ||
icon: 'https://www.flickonclick.com/wp-content/uploads/2022/07/10-best-OTT-Subscription-plans-in-India-that-are-worth-buying-in-2022.jpg' | ||
) | ||
] | ||
|
||
it 'should have new category link' do | ||
expect(page).to have_link('New category', href: new_category_path, class: 'link_to newcat') | ||
end | ||
|
||
describe 'show correct categories for user' do | ||
before(:example) do | ||
sign_in user1 | ||
visit categories_path | ||
end | ||
|
||
it 'should have new category link' do | ||
expect(page).to have_link('New category', href: new_category_path, class: 'link_to newcat') | ||
end | ||
|
||
it 'should have category details' do | ||
# expect(page).to have_content(category.name) | ||
categories.each do |category| | ||
# Verify icon and name | ||
expect(page).to have_css("img.icon[src='#{category.icon}']") | ||
expect(page).to have_css('span.cname', text: category.name) | ||
|
||
# Verify created_at date | ||
expect(page).to have_css('p', text: category.created_at.to_date.to_s) | ||
|
||
# Verify total_amount | ||
expect(page).to have_css('p.tamount', text: "$#{category.total_amount}") | ||
end | ||
|
||
it 'should have category details' do | ||
# expect(page).to have_content(category.name) | ||
categories.each do |category| | ||
# Verify icon and name | ||
expect(page).to have_css("img.icon[src='#{category.icon}']") | ||
expect(page).to have_css('span.cname', text: category.name) | ||
|
||
# Verify created_at date | ||
expect(page).to have_css('p', text: category.created_at.to_date.to_s) | ||
|
||
# Verify total_amount | ||
expect(page).to have_css('p.tamount', text: "$#{category.total_amount}") | ||
end | ||
end | ||
|
||
describe 'category link' do | ||
before(:example) do | ||
sign_in user1 | ||
visit categories_path | ||
end | ||
|
||
it 'redirects to the category show page when clicking on the link' do | ||
@category = categories.first | ||
|
||
find("a[href=\"#{category_path(@category)}\"]").click | ||
|
||
expect(page).to have_current_path(category_path(@category)) | ||
end | ||
end | ||
|
||
describe 'category link' do | ||
before(:example) do | ||
sign_in user1 | ||
visit categories_path | ||
end | ||
|
||
it 'redirects to the category show page when clicking on the link' do | ||
@category = categories.first | ||
|
||
find("a[href=\"#{category_path(@category)}\"]").click | ||
|
||
expect(page).to have_current_path(category_path(@category)) | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'categories page', type: :system do | ||
include Devise::Test::IntegrationHelpers | ||
|
||
let!(:user1) do | ||
User.create!( | ||
name: 'Sandeep Ghosh', | ||
email: '[email protected]', | ||
password: 'pass1234', | ||
password_confirmation: 'pass1234', | ||
confirmed_at: Time.now | ||
) | ||
include Devise::Test::IntegrationHelpers | ||
|
||
let!(:user1) do | ||
User.create!( | ||
name: 'Sandeep Ghosh', | ||
email: '[email protected]', | ||
password: 'pass1234', | ||
password_confirmation: 'pass1234', | ||
confirmed_at: Time.now | ||
) | ||
end | ||
|
||
let!(:category) do | ||
Category.create!( | ||
user: user1, | ||
name: 'Rent', | ||
icon: 'https://images.unsplash.com/photo-1560518883-ce09059eeffa?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8cmVudGFsJTIwcHJvcGVydHl8ZW58MHx8MHx8fDA%3D&w=1000&q=80' | ||
) | ||
end | ||
|
||
let!(:expenses) do | ||
category.expense.create!([ | ||
{ name: 'home', amount: 12, user: user1 }, | ||
{ name: 'car', amount: 5, user: user1 } | ||
]) | ||
end | ||
|
||
describe 'show correct expenses for a category' do | ||
before(:example) do | ||
sign_in user1 | ||
visit category_path(category) | ||
end | ||
|
||
let!(:category) do | ||
Category.create!( | ||
user: user1, | ||
name: 'Rent', | ||
icon: 'https://images.unsplash.com/photo-1560518883-ce09059eeffa?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8cmVudGFsJTIwcHJvcGVydHl8ZW58MHx8MHx8fDA%3D&w=1000&q=80' | ||
) | ||
it 'has total amount' do | ||
expect(page).to have_content('Total Amount:') | ||
end | ||
|
||
let!(:expenses) do | ||
category.expense.create!([ | ||
{ name: 'home', amount: 12, user: user1 }, | ||
{ name: 'car', amount: 5, user: user1 } | ||
]) | ||
it 'has back link' do | ||
expect(page).to have_link('Back to categories', href: categories_path) | ||
end | ||
|
||
describe 'show correct expenses for a category' do | ||
before(:example) do | ||
sign_in user1 | ||
visit category_path(category) | ||
end | ||
it 'has total amount' do | ||
expect(page).to have_content('Total Amount:') | ||
end | ||
it 'has back link' do | ||
expect(page).to have_link('Back to categories', href: categories_path) | ||
end | ||
|
||
it 'has new expense create link' do | ||
expect(page).to have_link('New expense', href: new_category_expense_path(category)) | ||
end | ||
|
||
it 'has new destroy category link' do | ||
expect(page).to have_button('Delete this category', class: 'link_to delete') | ||
end | ||
it 'has expenses details' do | ||
expenses.each do |expense| | ||
expect(page).to have_content(expense.name) | ||
expect(page).to have_content(expense.amount) | ||
end | ||
|
||
it 'has new expense create link' do | ||
expect(page).to have_link('New expense', href: new_category_expense_path(category)) | ||
end | ||
|
||
it 'has new destroy category link' do | ||
expect(page).to have_button('Delete this category', class: 'link_to delete') | ||
end | ||
it 'has expenses details' do | ||
expenses.each do |expense| | ||
expect(page).to have_content(expense.name) | ||
expect(page).to have_content(expense.amount) | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,65 @@ | ||
require 'rails_helper' | ||
|
||
|
||
RSpec.describe 'categories page', type: :system do | ||
include Devise::Test::IntegrationHelpers | ||
|
||
let!(:user1) do | ||
User.create!( | ||
name: 'Sandeep Ghosh', | ||
email: '[email protected]', | ||
password: 'pass1234', | ||
password_confirmation: 'pass1234', | ||
confirmed_at: Time.now | ||
) | ||
include Devise::Test::IntegrationHelpers | ||
|
||
let!(:user1) do | ||
User.create!( | ||
name: 'Sandeep Ghosh', | ||
email: '[email protected]', | ||
password: 'pass1234', | ||
password_confirmation: 'pass1234', | ||
confirmed_at: Time.now | ||
) | ||
end | ||
|
||
describe 'create new categories for user' do | ||
before(:example) do | ||
sign_in user1 | ||
visit new_category_path | ||
end | ||
|
||
describe 'create new categories for user' do | ||
before(:example) do | ||
sign_in user1 | ||
visit new_category_path | ||
end | ||
|
||
it 'has back link' do | ||
expect(page).to have_link('< Back', href: categories_path, class: 'link_to back') | ||
end | ||
|
||
it 'has form elements' do | ||
within('section.new_cat') do | ||
expect(page).to have_selector('form') | ||
expect(page).to have_field('category[name]') | ||
expect(page).to have_field('category[icon]') | ||
expect(page).to have_button('save') | ||
end | ||
|
||
it 'has back link' do | ||
expect(page).to have_link('< Back', href: categories_path, class: 'link_to back') | ||
end | ||
|
||
it 'has form elements' do | ||
within('section.new_cat') do | ||
expect(page).to have_selector('form') | ||
expect(page).to have_field('category[name]') | ||
expect(page).to have_field('category[icon]') | ||
expect(page).to have_button('save') | ||
end | ||
|
||
it 'should save and go to category page' do | ||
# Create a category with errors | ||
category = Category.new(user: user1, name: 'Rent', icon: 'https://images.unsplash.com/photo-1560518883-ce09059eeffa?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8cmVudGFsJTIwcHJvcGVydHl8ZW58MHx8MHx8fDA%3D&w=1000&q=80') | ||
|
||
within('section.new_cat') do | ||
# Submit the form with invalid data | ||
fill_in 'category[name]', with: category.name | ||
fill_in 'category[icon]', with: category.icon | ||
click_button 'save' | ||
end | ||
|
||
expect(page).to have_current_path(categories_path) | ||
end | ||
|
||
it 'should save and go to category page' do | ||
# Create a category with errors | ||
category = Category.new(user: user1, name: 'Rent', icon: 'https://images.unsplash.com/photo-1560518883-ce09059eeffa?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8cmVudGFsJTIwcHJvcGVydHl8ZW58MHx8MHx8fDA%3D&w=1000&q=80') | ||
|
||
within('section.new_cat') do | ||
# Submit the form with invalid data | ||
fill_in 'category[name]', with: category.name | ||
fill_in 'category[icon]', with: category.icon | ||
click_button 'save' | ||
end | ||
it 'displays error messages when form submission fails' do | ||
# Create a category with errors | ||
category = Category.new(user: user1, name: nil, icon: nil) | ||
|
||
visit new_category_path | ||
|
||
within('section.new_cat') do | ||
# Submit the form with invalid data | ||
fill_in 'category[name]', with: category.name | ||
fill_in 'category[icon]', with: category.icon | ||
click_button 'save' | ||
end | ||
|
||
expect(page).to have_css('div', text: /did not allow this to be saved:/) | ||
|
||
expect(page).to have_current_path(categories_path) | ||
end | ||
|
||
it 'displays error messages when form submission fails' do | ||
# Create a category with errors | ||
category = Category.new(user: user1, name: nil, icon: nil) | ||
|
||
visit new_category_path | ||
|
||
within('section.new_cat') do | ||
# Submit the form with invalid data | ||
fill_in 'category[name]', with: category.name | ||
fill_in 'category[icon]', with: category.icon | ||
click_button 'save' | ||
end | ||
|
||
expect(page).to have_css('div', text: /did not allow this to be saved:/) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.