diff options
author | Semyon Pupkov <mail@semyonpupkov.com> | 2018-02-13 00:17:19 +0500 |
---|---|---|
committer | Semyon Pupkov <mail@semyonpupkov.com> | 2018-02-15 12:06:45 +0500 |
commit | b7f5205ab136f4835006533282002a075bf9053a (patch) | |
tree | 0d6852fe8dd24254ae7f9bc362a94fa50d346e19 | |
parent | 522a79adca2aaff44d513eeb362b9baf5a9390a7 (diff) | |
download | gitlab-ce-b7f5205ab136f4835006533282002a075bf9053a.tar.gz |
Move spinach profile tests to RSpec
https://gitlab.com/gitlab-org/gitlab-ce/issues/23036
-rw-r--r-- | features/profile/profile.feature | 85 | ||||
-rw-r--r-- | features/steps/profile/profile.rb | 226 | ||||
-rw-r--r-- | spec/features/profiles/password_spec.rb | 76 | ||||
-rw-r--r-- | spec/features/profiles/user_edit_profile_spec.rb | 58 | ||||
-rw-r--r-- | spec/features/profiles/user_manages_applications_spec.rb | 39 | ||||
-rw-r--r-- | spec/features/profiles/user_visits_profile_authentication_log_spec.rb | 25 | ||||
-rw-r--r-- | spec/features/profiles/user_visits_profile_spec.rb | 52 |
7 files changed, 231 insertions, 330 deletions
diff --git a/features/profile/profile.feature b/features/profile/profile.feature deleted file mode 100644 index 3263d3e212b..00000000000 --- a/features/profile/profile.feature +++ /dev/null @@ -1,85 +0,0 @@ -@profile -Feature: Profile - Background: - Given I sign in as a user - - Scenario: I look at my profile - Given I visit profile page - Then I should see my profile info - - @javascript - Scenario: I can see groups I belong to - Given I have group with projects - When I visit profile page - And I click on my profile picture - Then I should see my user page - And I should see groups I belong to - - Scenario: I edit profile - Given I visit profile page - Then I change my profile info - And I should see new profile info - - Scenario: I change my password without old one - Given I visit profile password page - When I try change my password w/o old one - Then I should see a missing password error message - And I should be redirected to password page - - Scenario: I change my password - Given I visit profile password page - Then I change my password - And I should be redirected to sign in page - - Scenario: I edit my avatar - Given I visit profile page - Then I change my avatar - And I should see new avatar - And I should see the "Remove avatar" button - And I should see the gravatar host link - - Scenario: I remove my avatar - Given I visit profile page - And I have an avatar - When I remove my avatar - Then I should see my gravatar - And I should not see the "Remove avatar" button - And I should see the gravatar host link - - Scenario: My password is expired - Given my password is expired - And I am not an ldap user - Given I visit profile password page - Then I redirected to expired password page - And I submit new password - And I redirected to sign in page - - Scenario: I unsuccessfully change my password - Given I visit profile password page - When I unsuccessfully change my password - Then I should see a password error message - - Scenario: I visit history tab - Given I logout - And I sign in via the UI - And I have activity - When I visit Authentication log page - Then I should see my activity - - Scenario: I visit my user page - When I visit profile page - And I click on my profile picture - Then I should see my user page - - Scenario: I can manage application - Given I visit profile applications page - Then I should see application form - Then I fill application form out and submit - And I see application - Then I click edit - And I see edit application form - Then I change name of application and submit - And I see that application was changed - Then I visit profile applications page - And I click to remove application - Then I see that application is removed diff --git a/features/steps/profile/profile.rb b/features/steps/profile/profile.rb deleted file mode 100644 index d3b88ae8d2a..00000000000 --- a/features/steps/profile/profile.rb +++ /dev/null @@ -1,226 +0,0 @@ -class Spinach::Features::Profile < Spinach::FeatureSteps - include SharedAuthentication - include SharedPaths - - step 'I should see my profile info' do - expect(page).to have_content "This information will appear on your profile" - end - - step 'I change my profile info' do - fill_in 'user_skype', with: 'testskype' - fill_in 'user_linkedin', with: 'testlinkedin' - fill_in 'user_twitter', with: 'testtwitter' - fill_in 'user_website_url', with: 'testurl' - fill_in 'user_location', with: 'Ukraine' - fill_in 'user_bio', with: 'I <3 GitLab' - fill_in 'user_organization', with: 'GitLab' - click_button 'Update profile settings' - @user.reload - end - - step 'I should see new profile info' do - expect(@user.skype).to eq 'testskype' - expect(@user.linkedin).to eq 'testlinkedin' - expect(@user.twitter).to eq 'testtwitter' - expect(@user.website_url).to eq 'testurl' - expect(@user.bio).to eq 'I <3 GitLab' - expect(@user.organization).to eq 'GitLab' - expect(find('#user_location').value).to eq 'Ukraine' - end - - step 'I change my avatar' do - attach_file(:user_avatar, File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif')) - click_button "Update profile settings" - @user.reload - end - - step 'I should see new avatar' do - expect(@user.avatar).to be_instance_of AvatarUploader - expect(@user.avatar.url).to eq "/uploads/-/system/user/avatar/#{@user.id}/banana_sample.gif" - end - - step 'I should see the "Remove avatar" button' do - expect(page).to have_link("Remove avatar") - end - - step 'I have an avatar' do - attach_file(:user_avatar, File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif')) - click_button "Update profile settings" - @user.reload - end - - step 'I remove my avatar' do - click_link "Remove avatar" - @user.reload - end - - step 'I should see my gravatar' do - expect(@user.avatar?).to eq false - end - - step 'I should not see the "Remove avatar" button' do - expect(page).not_to have_link("Remove avatar") - end - - step 'I should see the gravatar host link' do - expect(page).to have_link("gravatar.com") - end - - step 'I try change my password w/o old one' do - page.within '.update-password' do - fill_in "user_password", with: "22233344" - fill_in "user_password_confirmation", with: "22233344" - click_button "Save password" - end - end - - step 'I change my password' do - page.within '.update-password' do - fill_in "user_current_password", with: "12345678" - fill_in "user_password", with: "22233344" - fill_in "user_password_confirmation", with: "22233344" - click_button "Save password" - end - end - - step 'I unsuccessfully change my password' do - page.within '.update-password' do - fill_in "user_current_password", with: "12345678" - fill_in "user_password", with: "password" - fill_in "user_password_confirmation", with: "confirmation" - click_button "Save password" - end - end - - step "I should see a missing password error message" do - page.within ".flash-container" do - expect(page).to have_content "You must provide a valid current password" - end - end - - step "I should see a password error message" do - page.within '.alert-danger' do - expect(page).to have_content "Password confirmation doesn't match" - end - end - - step 'I have activity' do - create(:closed_issue_event, author: current_user) - end - - step 'I should see my activity' do - expect(page).to have_content "Signed in with standard authentication" - end - - step 'my password is expired' do - current_user.update_attributes(password_expires_at: Time.now - 1.hour) - end - - step "I am not an ldap user" do - current_user.identities.delete - expect(current_user.ldap_user?).to eq false - end - - step 'I redirected to expired password page' do - expect(current_path).to eq new_profile_password_path - end - - step 'I submit new password' do - fill_in :user_current_password, with: '12345678' - fill_in :user_password, with: '12345678' - fill_in :user_password_confirmation, with: '12345678' - click_button "Set new password" - end - - step 'I redirected to sign in page' do - expect(current_path).to eq new_user_session_path - end - - step 'I should be redirected to password page' do - expect(current_path).to eq edit_profile_password_path - end - - step 'I should be redirected to account page' do - expect(current_path).to eq profile_account_path - end - - step 'I click on my profile picture' do - find(:css, '.header-user-dropdown-toggle').click - - page.within ".header-user" do - click_link "Profile" - end - end - - step 'I should see my user page' do - page.within ".cover-block" do - expect(page).to have_content current_user.name - expect(page).to have_content current_user.username - end - end - - step 'I have group with projects' do - @group = create(:group) - @group.add_owner(current_user) - @project = create(:project, :repository, namespace: @group) - @event = create(:closed_issue_event, project: @project) - - @project.add_master(current_user) - end - - step 'I should see groups I belong to' do - page.within ".content" do - click_link "Groups" - end - - page.within "#groups" do - expect(page).to have_content @group.name - end - end - - step 'I should see application form' do - expect(page).to have_content "Add new application" - end - - step 'I fill application form out and submit' do - fill_in :doorkeeper_application_name, with: 'test' - fill_in :doorkeeper_application_redirect_uri, with: 'https://test.com' - click_on "Save application" - end - - step 'I see application' do - expect(page).to have_content "Application: test" - expect(page).to have_content "Application Id" - expect(page).to have_content "Secret" - end - - step 'I click edit' do - click_on "Edit" - end - - step 'I see edit application form' do - expect(page).to have_content "Edit application" - end - - step 'I change name of application and submit' do - expect(page).to have_content "Edit application" - fill_in :doorkeeper_application_name, with: 'test_changed' - click_on "Save application" - end - - step 'I see that application was changed' do - expect(page).to have_content "test_changed" - expect(page).to have_content "Application Id" - expect(page).to have_content "Secret" - end - - step 'I click to remove application' do - page.within '.oauth-applications' do - click_on "Destroy" - end - end - - step "I see that application is removed" do - expect(page.find(".oauth-applications")).not_to have_content "test_changed" - end -end diff --git a/spec/features/profiles/password_spec.rb b/spec/features/profiles/password_spec.rb index 4665626f114..1d7700b6767 100644 --- a/spec/features/profiles/password_spec.rb +++ b/spec/features/profiles/password_spec.rb @@ -1,6 +1,15 @@ require 'spec_helper' describe 'Profile > Password' do + let(:user) { create(:user) } + + def fill_passwords(password, confirmation) + fill_in 'New password', with: password + fill_in 'Password confirmation', with: confirmation + + click_button 'Save password' + end + context 'Password authentication enabled' do let(:user) { create(:user, password_automatically_set: true) } @@ -9,13 +18,6 @@ describe 'Profile > Password' do visit edit_profile_password_path end - def fill_passwords(password, confirmation) - fill_in 'New password', with: password - fill_in 'Password confirmation', with: confirmation - - click_button 'Save password' - end - context 'User with password automatically set' do describe 'User puts different passwords in the field and in the confirmation' do it 'shows an error message' do @@ -73,4 +75,64 @@ describe 'Profile > Password' do end end end + + context 'Change passowrd' do + before do + sign_in(user) + visit(edit_profile_password_path) + end + + it 'does not change user passowrd without old one' do + page.within '.update-password' do + fill_passwords('22233344', '22233344') + end + + page.within '.flash-container' do + expect(page).to have_content 'You must provide a valid current password' + end + end + + it 'does not change password with invalid old password' do + page.within '.update-password' do + fill_in 'user_current_password', with: 'invalid' + fill_passwords('password', 'confirmation') + end + + page.within '.flash-container' do + expect(page).to have_content 'You must provide a valid current password' + end + end + + it 'changes user password' do + page.within '.update-password' do + fill_in "user_current_password", with: user.password + fill_passwords('22233344', '22233344') + end + + expect(current_path).to eq new_user_session_path + end + end + + context 'when password is expired' do + before do + sign_in(user) + + user.update_attributes(password_expires_at: 1.hour.ago) + user.identities.delete + expect(user.ldap_user?).to eq false + end + + it 'needs change user password' do + visit edit_profile_password_path + + expect(current_path).to eq new_profile_password_path + + fill_in :user_current_password, with: user.password + fill_in :user_password, with: '12345678' + fill_in :user_password_confirmation, with: '12345678' + click_button 'Set new password' + + expect(current_path).to eq new_user_session_path + end + end end diff --git a/spec/features/profiles/user_edit_profile_spec.rb b/spec/features/profiles/user_edit_profile_spec.rb new file mode 100644 index 00000000000..0b5eacbe916 --- /dev/null +++ b/spec/features/profiles/user_edit_profile_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe 'User edit profile' do + let(:user) { create(:user) } + + before do + sign_in(user) + visit(profile_path) + end + + it 'changes user profile' do + fill_in 'user_skype', with: 'testskype' + fill_in 'user_linkedin', with: 'testlinkedin' + fill_in 'user_twitter', with: 'testtwitter' + fill_in 'user_website_url', with: 'testurl' + fill_in 'user_location', with: 'Ukraine' + fill_in 'user_bio', with: 'I <3 GitLab' + fill_in 'user_organization', with: 'GitLab' + click_button 'Update profile settings' + + expect(user.reload).to have_attributes( + skype: 'testskype', + linkedin: 'testlinkedin', + twitter: 'testtwitter', + website_url: 'testurl', + bio: 'I <3 GitLab', + organization: 'GitLab' + ) + + expect(find('#user_location').value).to eq 'Ukraine' + expect(page).to have_content('Profile was successfully updated') + end + + context 'user avatar' do + before do + attach_file(:user_avatar, Rails.root.join('spec', 'fixtures', 'banana_sample.gif')) + click_button 'Update profile settings' + end + + it 'changes user avatar' do + expect(page).to have_link('Remove avatar') + + user.reload + expect(user.avatar).to be_instance_of AvatarUploader + expect(user.avatar.url).to eq "/uploads/-/system/user/avatar/#{user.id}/banana_sample.gif" + end + + it 'removes user avatar' do + click_link 'Remove avatar' + + user.reload + + expect(user.avatar?).to eq false + expect(page).not_to have_link('Remove avatar') + expect(page).to have_link('gravatar.com') + end + end +end diff --git a/spec/features/profiles/user_manages_applications_spec.rb b/spec/features/profiles/user_manages_applications_spec.rb new file mode 100644 index 00000000000..387584fef62 --- /dev/null +++ b/spec/features/profiles/user_manages_applications_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe 'User manages applications' do + let(:user) { create(:user) } + + before do + sign_in(user) + visit applications_profile_path + end + + it 'manages applications' do + expect(page).to have_content 'Add new application' + + fill_in :doorkeeper_application_name, with: 'test' + fill_in :doorkeeper_application_redirect_uri, with: 'https://test.com' + click_on 'Save application' + + expect(page).to have_content 'Application: test' + expect(page).to have_content 'Application Id' + expect(page).to have_content 'Secret' + + click_on 'Edit' + + expect(page).to have_content 'Edit application' + fill_in :doorkeeper_application_name, with: 'test_changed' + click_on 'Save application' + + expect(page).to have_content 'test_changed' + expect(page).to have_content 'Application Id' + expect(page).to have_content 'Secret' + + visit applications_profile_path + + page.within '.oauth-applications' do + click_on 'Destroy' + end + expect(page.find('.oauth-applications')).not_to have_content 'test_changed' + end +end diff --git a/spec/features/profiles/user_visits_profile_authentication_log_spec.rb b/spec/features/profiles/user_visits_profile_authentication_log_spec.rb index a50ebb29e01..0f419c3c2c0 100644 --- a/spec/features/profiles/user_visits_profile_authentication_log_spec.rb +++ b/spec/features/profiles/user_visits_profile_authentication_log_spec.rb @@ -3,13 +3,28 @@ require 'spec_helper' describe 'User visits the authentication log' do let(:user) { create(:user) } - before do - sign_in(user) + context 'when user signed in' do + before do + sign_in(user) + end - visit(audit_log_profile_path) + it 'shows correct menu item' do + visit(audit_log_profile_path) + + expect(page).to have_active_navigation('Authentication log') + end end - it 'shows correct menu item' do - expect(page).to have_active_navigation('Authentication log') + context 'when user has activity' do + before do + create(:closed_issue_event, author: user) + gitlab_sign_in(user) + end + + it 'shows user activity' do + visit(audit_log_profile_path) + + expect(page).to have_content 'Signed in with standard authentication' + end end end diff --git a/spec/features/profiles/user_visits_profile_spec.rb b/spec/features/profiles/user_visits_profile_spec.rb index a5d80439143..713112477c8 100644 --- a/spec/features/profiles/user_visits_profile_spec.rb +++ b/spec/features/profiles/user_visits_profile_spec.rb @@ -5,20 +5,58 @@ describe 'User visits their profile' do before do sign_in(user) - - visit(profile_path) end it 'shows correct menu item' do + visit(profile_path) + expect(page).to have_active_navigation('Profile') end - describe 'profile settings', :js do - it 'saves updates' do - fill_in 'user_bio', with: 'bio' - click_button 'Update profile settings' + it 'shows profile info' do + visit(profile_path) + + expect(page).to have_content "This information will appear on your profile" + end + + context 'when user has groups' do + let(:group) do + create :group do |group| + group.add_owner(user) + end + end + + let!(:project) do + create(:project, :repository, namespace: group) do |project| + create(:closed_issue_event, project: project) + project.add_master(user) + end + end + + def click_on_profile_picture + find(:css, '.header-user-dropdown-toggle').click + + page.within ".header-user" do + click_link "Profile" + end + end + + it 'shows user groups', :js do + visit(profile_path) + click_on_profile_picture + + page.within ".cover-block" do + expect(page).to have_content user.name + expect(page).to have_content user.username + end + + page.within ".content" do + click_link "Groups" + end - expect(page).to have_content('Profile was successfully updated') + page.within "#groups" do + expect(page).to have_content group.name + end end end end |