Skip to content

Commit

Permalink
Merge pull request #2373 from internetee/test-for-auction-admin-view
Browse files Browse the repository at this point in the history
test for the auction view
  • Loading branch information
vohmar authored May 9, 2022
2 parents 10b647c + 9d33421 commit 52863aa
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/views/admin/auctions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
class: 'btn btn-primary' %>
</div>
<div >
<%= link_to "#", class: "btn btn-warning edit",
<%= link_to "#", class: "btn btn-warning edit", id: 'reserved-modal',
data: {
toggle: "modal",
url: admin_reserved_domains_path,
Expand All @@ -74,7 +74,7 @@

<div style="display: flex; flex-direction: row; align-items: center;">
<%= text_field_tag :domain, params[:domain], class: 'form-control', placeholder: 'domain name' %>
<%= f.submit 'Create', class: 'btn btn-primary', style: 'margin-left: .4rem;' %>
<%= f.submit 'Create', class: 'btn btn-primary', style: 'margin-left: .4rem;', id: 'new-auction-btn' %>
</div>
<% end %>

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/files/auction_domains_list.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name
tere.test
chao.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name
tere.test
chao.test
cha.chacha
4 changes: 2 additions & 2 deletions test/integration/admin_area/account_activities_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AdminAreaAccountActivitiesIntegrationTest < ApplicationSystemTestCase
sign_in users(:admin)
@original_default_language = Setting.default_language
end

def test_show_account_activities_page
account_activities(:one).update(sum: "123.00")
visit admin_account_activities_path
Expand All @@ -19,7 +19,7 @@ def test_default_url_params
visit admin_root_path
click_link_or_button 'Settings', match: :first
find(:xpath, "//ul/li/a[text()='Account activities']").click

assert has_current_path?(admin_account_activities_path(created_after: 'today'))
end

Expand Down
173 changes: 173 additions & 0 deletions test/integration/admin_area/auction_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
require 'test_helper'
require 'application_system_test_case'

class AdminAreaAuctionIntegrationTest < ApplicationSystemTestCase
setup do
sign_in users(:admin)
@original_default_language = Setting.default_language
end

def test_should_open_index_page
visit admin_root_path
click_link_or_button 'Settings', match: :first
find(:xpath, "//ul/li/a[text()='Auctions']").click

assert_text 'Auctions'
end

def test_search_domains
visit admin_auctions_path

auction = auctions(:one)
fill_in 'domain_matches', :with => auction.domain
find(:xpath, ".//button[./span[contains(@class, 'glyphicon-search')]]", match: :first).click

assert_text auction.domain
assert_text 'auto'
assert_text 'no_bids'
end

def test_filter_no_bids_auction
auction_one = auctions(:one)
auction_two = auctions(:idn)

visit admin_auctions_path
select "no_bids", :from => "statuses_contains"
find(:xpath, ".//button[./span[contains(@class, 'glyphicon-search')]]", match: :first).click

assert_text auction_one.domain
assert_text auction_two.domain
end

def test_manually_create_auction
visit admin_auctions_path

fill_in 'domain', :with => 'new-awesome-auction.test'
find(:id, "new-auction-btn", match: :first).click

assert_text 'new-awesome-auction.test'
assert_text 'manual'
assert_text 'started'
end

def test_manually_create_auction_with_punycode
visit admin_auctions_path

fill_in 'domain', :with => 'xn--phimtte-10ad.test'
find(:id, "new-auction-btn", match: :first).click

assert_text 'xn--phimtte-10ad.test'
assert_text 'manual'
assert_text 'started'
end

def test_raise_error_if_try_to_add_auction_with_invalid_zone
visit admin_auctions_path

fill_in 'domain', :with => 'new-awesome-auction.chuchacha'
find(:id, "new-auction-btn", match: :first).click

assert_no_text 'new-awesome-auction.chuchacha'
assert_text 'Cannot generate domain. Reason: invalid format'
end

def test_raise_error_if_try_to_add_auction_with_invalid_format
visit admin_auctions_path

fill_in 'domain', :with => '#de$er.test'
find(:id, "new-auction-btn", match: :first).click

assert_no_text '#de$er.test'
assert_text 'Cannot generate domain. Reason: invalid format'
end

def test_raise_error_if_try_to_add_same_domain
visit admin_auctions_path

fill_in 'domain', :with => 'new-awesome-auction.test'
find(:id, "new-auction-btn", match: :first).click
fill_in 'domain', :with => 'new-awesome-auction.test'
find(:id, "new-auction-btn", match: :first).click

assert_text 'Adding new-awesome-auction.test failed - domain registered or regsitration is blocked'
end

def test_raise_error_if_try_to_add_registred_domain
visit admin_auctions_path
domain = domains(:shop)

fill_in 'domain', :with => domain.name
find(:id, "new-auction-btn", match: :first).click

assert_text "Adding #{domain.name} failed - domain registered or regsitration is blocked"
end

def test_raise_error_if_try_to_add_blocked_domain
visit admin_auctions_path
domain = blocked_domains(:one)

fill_in 'domain', :with => domain.name
find(:id, "new-auction-btn", match: :first).click

assert_text "Adding #{domain.name} failed - domain registered or regsitration is blocked"
end

def test_raise_error_if_try_to_add_disputed_domain
visit admin_auctions_path
domain = disputes(:active)

fill_in 'domain', :with => domain.domain_name
find(:id, "new-auction-btn", match: :first).click

assert_text "Adding #{domain.domain_name} failed - domain registered or regsitration is blocked"
end

def test_upload_invalid_csv_file
visit admin_auctions_path

attach_file(:q_file, Rails.root.join('test', 'fixtures', 'files', 'mass_actions', 'invalid_mass_force_delete_list.csv').to_s)
click_link_or_button 'Upload csv'
assert_text "Invalid CSV format. Should be column with 'name' where is the list of name of domains!"
end

def test_upload_valid_csv_file
visit admin_auctions_path

attach_file(:q_file, Rails.root.join('test', 'fixtures', 'files', 'auction_domains_list.csv').to_s)
click_link_or_button 'Upload csv'
assert_text "tere.test"
assert_text "chao.test"
end

def test_upload_valid_csv_file_with_invalid_item
visit admin_auctions_path

attach_file(:q_file, Rails.root.join('test', 'fixtures', 'files', 'auction_domains_list_with_invalid_item.csv').to_s)
click_link_or_button 'Upload csv'
assert_text "tere.test"
assert_text "chao.test"
assert_text "These domains were ignored: cha.chacha"
end

def test_should_remove_domain_from_reserved_if_it_added_to_auction
visit admin_auctions_path
domain = reserved_domains(:one)

fill_in 'domain', :with => domain.name
find(:id, "new-auction-btn", match: :first).click

assert_text domain.name
assert_text 'manual'
assert_text 'started'

visit admin_reserved_domains_path
assert_no_text domain.name
end

def test_should_open_reserved_page_in_modal_window
visit admin_auctions_path

find(:id, "reserved-modal", match: :first).click
assert_text 'Reserved domains'
end
end

0 comments on commit 52863aa

Please sign in to comment.