Просмотр исходного кода

Maintenance: Port old preferences permission check tests to capybara.

Bola Ahmed Buari 3 лет назад
Родитель
Сommit
289187238f

+ 0 - 6
script/build/test_slice_tests.sh

@@ -64,7 +64,6 @@ if [ "$LEVEL" == '1' ]; then
   rm test/browser/integration_sipgate_test.rb
   rm test/browser/integration_cti_test.rb
   rm test/browser/preferences_language_test.rb
-  rm test/browser/preferences_permission_check_test.rb
   rm test/browser/preferences_token_access_test.rb
   # test/browser/swich_to_user_test.rb
   # test/browser/taskbar_session_test.rb
@@ -132,7 +131,6 @@ elif [ "$LEVEL" == '2' ]; then
   rm test/browser/integration_sipgate_test.rb
   rm test/browser/integration_cti_test.rb
   rm test/browser/preferences_language_test.rb
-  rm test/browser/preferences_permission_check_test.rb
   rm test/browser/preferences_token_access_test.rb
   rm test/browser/switch_to_user_test.rb
   rm test/browser/taskbar_session_test.rb
@@ -200,7 +198,6 @@ elif [ "$LEVEL" == '3' ]; then
   rm test/browser/integration_sipgate_test.rb
   rm test/browser/integration_cti_test.rb
   rm test/browser/preferences_language_test.rb
-  rm test/browser/preferences_permission_check_test.rb
   rm test/browser/preferences_token_access_test.rb
   rm test/browser/switch_to_user_test.rb
   rm test/browser/taskbar_session_test.rb
@@ -268,7 +265,6 @@ elif [ "$LEVEL" == '4' ]; then
   rm test/browser/integration_sipgate_test.rb
   rm test/browser/integration_cti_test.rb
   rm test/browser/preferences_language_test.rb
-  rm test/browser/preferences_permission_check_test.rb
   rm test/browser/preferences_token_access_test.rb
   rm test/browser/switch_to_user_test.rb
   rm test/browser/taskbar_session_test.rb
@@ -335,7 +331,6 @@ elif [ "$LEVEL" == '5' ]; then
   rm test/browser/integration_sipgate_test.rb
   rm test/browser/integration_cti_test.rb
   rm test/browser/preferences_language_test.rb
-  rm test/browser/preferences_permission_check_test.rb
   rm test/browser/preferences_token_access_test.rb
   rm test/browser/switch_to_user_test.rb
   rm test/browser/taskbar_session_test.rb
@@ -405,7 +400,6 @@ elif [ "$LEVEL" == '6' ]; then
   # rm test/browser/integration_sipgate_test.rb
   # rm test/browser/integration_cti_test.rb
   # test/browser/preferences_language_test.rb
-  # test/browser/preferences_permission_check_test.rb
   # test/browser/preferences_token_access_test.rb
   rm test/browser/switch_to_user_test.rb
   rm test/browser/taskbar_session_test.rb

+ 83 - 0
spec/system/profile/preferences_permission_check_spec.rb

@@ -0,0 +1,83 @@
+# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
+
+require 'rails_helper'
+
+RSpec.describe 'Profile > PreferencesPermissionCheck', type: :system do
+  let(:admin) { create(:admin) }
+  let(:agent) { create(:agent) }
+  let(:customer) { create(:customer) }
+
+  before { visit 'profile' }
+
+  shared_examples 'having profile page link to' do |link_name|
+    it "shows the #{link_name} link" do
+      within '.content .NavBarProfile' do
+        expect(page).to have_link(link_name)
+      end
+    end
+  end
+
+  shared_examples 'not having profile page link to' do |link_name|
+    it "does not show the #{link_name} link" do
+      within '.content .NavBarProfile' do
+        expect(page).to have_no_link(link_name)
+      end
+    end
+  end
+
+  context 'when logged in as admin', authenticated_as: :admin do
+    it_behaves_like 'having profile page link to', 'Password'
+
+    it_behaves_like 'having profile page link to', 'Language'
+
+    it_behaves_like 'having profile page link to', 'Linked Accounts'
+
+    it_behaves_like 'having profile page link to', 'Avatar'
+
+    it_behaves_like 'having profile page link to', 'Notifications'
+
+    it_behaves_like 'having profile page link to', 'Out of Office'
+
+    it_behaves_like 'having profile page link to', 'Calendar'
+
+    it_behaves_like 'having profile page link to', 'Devices'
+
+    it_behaves_like 'having profile page link to', 'Token Access'
+  end
+
+  context 'when logged in as agent', authenticated_as: :agent do
+    it_behaves_like 'having profile page link to', 'Password'
+
+    it_behaves_like 'having profile page link to', 'Language'
+
+    it_behaves_like 'having profile page link to', 'Linked Accounts'
+
+    it_behaves_like 'having profile page link to', 'Avatar'
+
+    it_behaves_like 'having profile page link to', 'Notifications'
+
+    it_behaves_like 'having profile page link to', 'Out of Office'
+
+    it_behaves_like 'having profile page link to', 'Calendar'
+
+    it_behaves_like 'having profile page link to', 'Devices'
+
+    it_behaves_like 'having profile page link to', 'Token Access'
+  end
+
+  context 'when logged in as customer', authenticated_as: :customer do
+    it_behaves_like 'having profile page link to', 'Password'
+
+    it_behaves_like 'having profile page link to', 'Language'
+
+    it_behaves_like 'having profile page link to', 'Linked Accounts'
+
+    it_behaves_like 'having profile page link to', 'Avatar'
+
+    it_behaves_like 'not having profile page link to', 'Notifications'
+
+    it_behaves_like 'not having profile page link to', 'Calendar'
+
+    it_behaves_like 'not having profile page link to', 'Token Access'
+  end
+end

+ 0 - 69
test/browser/preferences_permission_check_test.rb

@@ -1,69 +0,0 @@
-# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
-
-require 'browser_test_helper'
-
-class PreferencesPermissionCheckTest < TestCase
-
-  def test_permission_agent
-    @browser = browser_instance
-    login(
-      username: 'admin@example.com',
-      password: 'test',
-      url:      browser_url,
-    )
-    click(css: 'a[href="#current_user"]')
-    click(css: 'a[href="#profile"]')
-    match(
-      css:   '.content .NavBarProfile',
-      value: 'Password',
-    )
-    match(
-      css:   '.content .NavBarProfile',
-      value: 'Language',
-    )
-    match(
-      css:   '.content .NavBarProfile',
-      value: 'Notifications',
-    )
-    match(
-      css:   '.content .NavBarProfile',
-      value: 'Calendar',
-    )
-    match(
-      css:   '.content .NavBarProfile',
-      value: 'Token Access',
-    )
-  end
-
-  def test_permission_customer
-    @browser = browser_instance
-    login(
-      username: 'nicole.braun@zammad.org',
-      password: 'test',
-      url:      browser_url,
-    )
-    click(css: 'a[href="#current_user"]')
-    click(css: 'a[href="#profile"]')
-    match(
-      css:   '.content .NavBarProfile',
-      value: 'Password',
-    )
-    match(
-      css:   '.content .NavBarProfile',
-      value: 'Language',
-    )
-    match_not(
-      css:   '.content .NavBarProfile',
-      value: 'Notifications',
-    )
-    match_not(
-      css:   '.content .NavBarProfile',
-      value: 'Calendar',
-    )
-    match_not(
-      css:   '.content .NavBarProfile',
-      value: 'Token Access',
-    )
-  end
-
-end