generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for sorting users with capybara
- Loading branch information
1 parent
be90c6a
commit 67b19b5
Showing
4 changed files
with
41 additions
and
28 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
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 |
---|---|---|
|
@@ -4,10 +4,7 @@ | |
|
||
describe "visit admin page", js: true do | ||
let(:time_login) { Time.new(2020, 0o1, 0o1).utc } | ||
let!(:another_user) do | ||
create(:user, email: "[email protected]", password: "12345878", | ||
last_sign_in_at: time_login) | ||
end | ||
let!(:users) { create_list(:user, 5, last_sign_in_at: time_login) } | ||
|
||
before do | ||
@admin = create(:user, :admin) | ||
|
@@ -16,18 +13,34 @@ | |
|
||
it "visits admin page" do | ||
visit account_users_path | ||
expect(page).to have_content "[email protected]" | ||
expect(page).to have_content users.first.email | ||
expect(page).to have_content time_login | ||
end | ||
|
||
context "with sorting" do | ||
it "by id asc" do | ||
visit account_users_path(sort: "id asc") | ||
|
||
expect(page.find("#users > :first-child > :first-child")).to have_content User.first.email | ||
expect(page.find("#users > :last-child > :first-child")).to have_content User.last.email | ||
end | ||
|
||
it "by id desc" do | ||
visit account_users_path(sort: "id desc") | ||
|
||
expect(page.find("#users > :first-child > :first-child")).to have_content User.last.email | ||
expect(page.find("#users > :last-child > :first-child")).to have_content User.first.email | ||
end | ||
end | ||
|
||
context "when user clicks show icon" do | ||
it "redirects to user info page" do | ||
visit account_users_path | ||
within(:css, "#user-info-#{another_user.id}") do | ||
within(:css, "#user-info-#{users.first.id}") do | ||
find(".fa-eye", visible: :all).click | ||
sleep 3 | ||
end | ||
expect(page).to have_current_path(account_user_path(id: another_user.id)) | ||
expect(page).to have_current_path(account_user_path(id: users.first.id)) | ||
expect(page).to have_content "Email" | ||
expect(page).to have_content "First name" | ||
expect(page).to have_content "Last name" | ||
|
@@ -41,11 +54,11 @@ | |
context "when user clicks edit icon" do | ||
it "redirects to user edit info page" do | ||
visit account_users_path | ||
within(:css, "#user-info-#{another_user.id}") do | ||
click_link(href: edit_account_user_path(id: another_user.id)) | ||
within(:css, "#user-info-#{users.first.id}") do | ||
click_link(href: edit_account_user_path(id: users.first.id)) | ||
sleep 3 | ||
end | ||
expect(page).to have_current_path(edit_account_user_path(id: another_user.id)) | ||
expect(page).to have_current_path(edit_account_user_path(id: users.first.id)) | ||
expect(page).to have_content "First name" | ||
expect(page).to have_content "Last name" | ||
expect(page).to have_content "Country" | ||
|
@@ -56,14 +69,14 @@ | |
|
||
context "when edit user`s info correctly" do | ||
it "redirects to user info page" do | ||
visit edit_account_user_path(id: another_user.id) | ||
visit edit_account_user_path(id: users.first.id) | ||
find("#user_first_name").set("John") | ||
find("#user_last_name").set("Doe") | ||
select "Albania", from: "user_country" | ||
find("#user_password").set("111111111") | ||
find("#user_password_confirmation").set("111111111") | ||
find_button("commit").click | ||
expect(page).to have_current_path(account_user_path(id: another_user.id)) | ||
expect(page).to have_current_path(account_user_path(id: users.first.id)) | ||
expect(page).to have_content "John" | ||
expect(page).to have_content "Doe" | ||
expect(page).to have_content "AL" | ||
|
@@ -72,7 +85,7 @@ | |
|
||
context "when edit user`s info wrongly" do | ||
it "show error messages" do | ||
visit edit_account_user_path(id: another_user.id) | ||
visit edit_account_user_path(id: users.first.id) | ||
find("#user_first_name").set("J") | ||
find("#user_last_name").set("D") | ||
select "Albania", from: "user_country" | ||
|
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
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